0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2025-01-27 21:39:16 -05:00

fix(console): update user data (#1184)

This commit is contained in:
Xiao Yijun 2022-06-22 11:36:43 +08:00 committed by GitHub
parent ed3c93afdc
commit a3d3a79dd9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 6 deletions

View file

@ -69,7 +69,7 @@ const UserDetails = () => {
const {
field: { onChange, value },
} = useController({ name: 'customData', control, rules: { required: true } });
} = useController({ name: 'customData', control });
const api = useApi();
useEffect(() => {
@ -87,7 +87,9 @@ const UserDetails = () => {
return;
}
const customData = safeParseJson(formData.customData);
const { customData: inputtedCustomData, name, avatar, roleNames } = formData;
const customData = inputtedCustomData ? safeParseJson(inputtedCustomData) : {};
if (!customData) {
toast.error(t('user_details.custom_data_invalid'));
@ -96,9 +98,9 @@ const UserDetails = () => {
}
const payload: Partial<User> = {
name: formData.name,
avatar: formData.avatar,
roleNames: formData.roleNames,
name,
avatar,
roleNames,
customData,
};

View file

@ -162,6 +162,19 @@ describe('adminUserRoutes', () => {
});
});
it('PATCH /users/:userId should allow updated with empty avatar', async () => {
const name = 'Micheal';
const avatar = '';
const response = await userRequest.patch('/users/foo').send({ name, avatar });
expect(response.status).toEqual(200);
expect(response.body).toEqual({
...mockUserResponse,
name,
avatar,
});
});
it('PATCH /users/:userId should updated with one field if the other is undefined', async () => {
const name = 'Micheal';

View file

@ -112,7 +112,7 @@ export default function adminUserRoutes<T extends AuthedRouter>(router: T) {
params: object({ userId: string() }),
body: object({
name: string().nullable().optional(),
avatar: string().url().nullable().optional(),
avatar: string().url().or(literal('')).nullable().optional(),
customData: arbitraryObjectGuard.optional(),
roleNames: string().array().optional(),
}),