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 {
|
const {
|
||||||
field: { onChange, value },
|
field: { onChange, value },
|
||||||
} = useController({ name: 'customData', control, rules: { required: true } });
|
} = useController({ name: 'customData', control });
|
||||||
const api = useApi();
|
const api = useApi();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
@ -87,7 +87,9 @@ const UserDetails = () => {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const customData = safeParseJson(formData.customData);
|
const { customData: inputtedCustomData, name, avatar, roleNames } = formData;
|
||||||
|
|
||||||
|
const customData = inputtedCustomData ? safeParseJson(inputtedCustomData) : {};
|
||||||
|
|
||||||
if (!customData) {
|
if (!customData) {
|
||||||
toast.error(t('user_details.custom_data_invalid'));
|
toast.error(t('user_details.custom_data_invalid'));
|
||||||
|
@ -96,9 +98,9 @@ const UserDetails = () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const payload: Partial<User> = {
|
const payload: Partial<User> = {
|
||||||
name: formData.name,
|
name,
|
||||||
avatar: formData.avatar,
|
avatar,
|
||||||
roleNames: formData.roleNames,
|
roleNames,
|
||||||
customData,
|
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 () => {
|
it('PATCH /users/:userId should updated with one field if the other is undefined', async () => {
|
||||||
const name = 'Micheal';
|
const name = 'Micheal';
|
||||||
|
|
||||||
|
|
|
@ -112,7 +112,7 @@ export default function adminUserRoutes<T extends AuthedRouter>(router: T) {
|
||||||
params: object({ userId: string() }),
|
params: object({ userId: string() }),
|
||||||
body: object({
|
body: object({
|
||||||
name: string().nullable().optional(),
|
name: string().nullable().optional(),
|
||||||
avatar: string().url().nullable().optional(),
|
avatar: string().url().or(literal('')).nullable().optional(),
|
||||||
customData: arbitraryObjectGuard.optional(),
|
customData: arbitraryObjectGuard.optional(),
|
||||||
roleNames: string().array().optional(),
|
roleNames: string().array().optional(),
|
||||||
}),
|
}),
|
||||||
|
|
Loading…
Add table
Reference in a new issue