mirror of
https://github.com/strapi/strapi.git
synced 2025-12-25 06:04:29 +00:00
add types and comment
This commit is contained in:
parent
b6345ffd2d
commit
ae4ceab052
@ -131,10 +131,24 @@ const ProfilePage = () => {
|
||||
UpdateUsersMeBody
|
||||
>(
|
||||
async (body) => {
|
||||
const { confirmPassword: _confirmPassword, currentTheme, ...dataToSend } = body;
|
||||
const { confirmPassword: _confirmPassword, currentTheme, ...bodyRest } = body;
|
||||
let dataToSend = bodyRest;
|
||||
|
||||
if (dataToSend.password === '') {
|
||||
delete dataToSend.password;
|
||||
const isPasswordRequestBody = (
|
||||
data: UpdateMe.Request['body']
|
||||
): data is UpdateMe.PasswordRequestBody => {
|
||||
return 'password' in data;
|
||||
};
|
||||
|
||||
// The password fields are optional. If the user didn't touch them, don't send any password
|
||||
// to the API, because an empty string would throw a validation error
|
||||
if (isPasswordRequestBody(dataToSend) && dataToSend.password === '') {
|
||||
const {
|
||||
password: _password,
|
||||
currentPassword: _currentPassword,
|
||||
...passwordRequestBodyRest
|
||||
} = dataToSend;
|
||||
dataToSend = passwordRequestBodyRest;
|
||||
}
|
||||
|
||||
const { data } = await put<UpdateMe.Response>('/admin/users/me', dataToSend);
|
||||
@ -259,8 +273,7 @@ const ProfilePage = () => {
|
||||
username,
|
||||
preferedLanguage,
|
||||
currentTheme,
|
||||
password,
|
||||
confirmPassword,
|
||||
...passwordValues
|
||||
},
|
||||
handleChange,
|
||||
isSubmitting,
|
||||
@ -298,7 +311,7 @@ const ProfilePage = () => {
|
||||
<PasswordSection
|
||||
errors={errors}
|
||||
onChange={handleChange}
|
||||
values={{ password, confirmPassword }}
|
||||
values={passwordValues}
|
||||
/>
|
||||
)}
|
||||
<PreferencesSection
|
||||
|
||||
@ -20,17 +20,22 @@ export declare namespace GetMe {
|
||||
* PUT /users/me - Update the current admin user
|
||||
*/
|
||||
export declare namespace UpdateMe {
|
||||
export interface BaseRequestBody {
|
||||
email?: string;
|
||||
firstname?: string;
|
||||
lastname?: string;
|
||||
username?: string;
|
||||
preferedLanguage?: string;
|
||||
}
|
||||
|
||||
export interface PasswordRequestBody extends BaseRequestBody {
|
||||
currentPassword: string;
|
||||
password: string;
|
||||
}
|
||||
|
||||
export interface Request {
|
||||
query: {};
|
||||
body: {
|
||||
email?: string;
|
||||
firstname?: string;
|
||||
lastname?: string;
|
||||
username?: string;
|
||||
password?: string;
|
||||
currentPassword?: string;
|
||||
preferedLanguage?: string;
|
||||
};
|
||||
body: BaseRequestBody | PasswordRequestBody;
|
||||
}
|
||||
|
||||
export interface Response {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user