Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions web/sdk/client/views/profile/profile-update-body.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { profileUpdateBody } from './profile-update-body';

describe('profileUpdateBody', () => {
const storedUser = {
id: 'user-1',
name: 'jane_doe',
title: 'Jane Doe',
email: 'jane@raystack.org',
avatar: 'data:image/png;base64,old',
metadata: { onboarded: true, team: 'core' }
};

it('leaves out metadata when only the avatar changes', () => {
const formValues = { ...storedUser, avatar: 'data:image/png;base64,new' };

const body = profileUpdateBody(formValues, storedUser.name);

expect(body).toEqual({
title: 'Jane Doe',
email: 'jane@raystack.org',
avatar: 'data:image/png;base64,new',
name: 'jane_doe'
});
expect(body).not.toHaveProperty('metadata');
});

it('leaves out metadata when the title changes', () => {
const formValues = { ...storedUser, title: 'Jane Smith' };

const body = profileUpdateBody(formValues, storedUser.name);

expect(body.title).toBe('Jane Smith');
expect(body).not.toHaveProperty('metadata');
});
});
17 changes: 17 additions & 0 deletions web/sdk/client/views/profile/profile-update-body.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
export interface ProfileFormValues {
title: string;
email: string;
avatar?: string;
}

export function profileUpdateBody(
values: ProfileFormValues,
currentName: string | undefined
) {
return {
title: values.title,
email: values.email,
avatar: values.avatar,
name: currentName
};
}
3 changes: 2 additions & 1 deletion web/sdk/client/views/profile/profile-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { DeleteUserDialog } from '../../components/delete-user-dialog';
import styles from './profile-view.module.css';

import { handleConnectError } from '~/utils/error';
import { profileUpdateBody } from './profile-update-body';

const profileSchema = yup
.object({
Expand Down Expand Up @@ -101,7 +102,7 @@ export function ProfileView({
async function onSubmit(data: FormData) {
try {
if (!user?.id) return;
await updateCurrentUser({ body: data });
await updateCurrentUser({ body: profileUpdateBody(data, user.name) });
toastManager.add({ title: 'Updated user', type: 'success' });
} catch (err) {
handleConnectError(err, {
Expand Down
Loading