fix(ProfileSettings): don't submit password unless changed

This commit is contained in:
Ali BARIN
2023-04-06 13:34:43 +00:00
parent 2840fce856
commit c64ca9d9b7
3 changed files with 25 additions and 8 deletions

View File

@@ -4,9 +4,8 @@ export const UPDATE_USER = gql`
mutation UpdateUser($input: UpdateUserInput) { mutation UpdateUser($input: UpdateUserInput) {
updateUser(input: $input) { updateUser(input: $input) {
id id
email
fullName fullName
updatedAt email
} }
} }
`; `;

View File

@@ -6,8 +6,6 @@ export const GET_CURRENT_USER = gql`
id id
fullName fullName
email email
createdAt
updatedAt
} }
} }
`; `;

View File

@@ -19,6 +19,12 @@ import { UPDATE_USER } from 'graphql/mutations/update-user';
import useFormatMessage from 'hooks/useFormatMessage'; import useFormatMessage from 'hooks/useFormatMessage';
import useCurrentUser from 'hooks/useCurrentUser'; import useCurrentUser from 'hooks/useCurrentUser';
type TMutationInput = {
fullName: string;
email: string;
password?: string;
}
const validationSchema = yup const validationSchema = yup
.object({ .object({
fullName: yup.string().required(), fullName: yup.string().required(),
@@ -44,12 +50,26 @@ function ProfileSettings() {
const [updateUser] = useMutation(UPDATE_USER); const [updateUser] = useMutation(UPDATE_USER);
const handleProfileSettingsUpdate = async (data: any) => { const handleProfileSettingsUpdate = async (data: any) => {
const { fullName , password, email } = data; const { fullName, password, email } = data;
const mutationInput: TMutationInput = {
fullName,
email,
}
if (password) {
mutationInput.password = password;
}
await updateUser({ await updateUser({
variables: { variables: {
input: { input: mutationInput,
},
optimisticResponse: {
updateUser: {
__typename: 'User',
id: currentUser.id,
fullName, fullName,
password,
email, email,
}, },
}, },