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) {
updateUser(input: $input) {
id
email
fullName
updatedAt
email
}
}
`;

View File

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

View File

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