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:
parent
ed3c93afdc
commit
a3d3a79dd9
3 changed files with 21 additions and 6 deletions
|
@ -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,
|
||||
};
|
||||
|
||||
|
|
|
@ -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';
|
||||
|
||||
|
|
|
@ -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(),
|
||||
}),
|
||||
|
|
Loading…
Add table
Reference in a new issue