fix(ProfileSettings): don't submit password unless changed
This commit is contained in:
@@ -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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
@@ -6,8 +6,6 @@ export const GET_CURRENT_USER = gql`
|
|||||||
id
|
id
|
||||||
fullName
|
fullName
|
||||||
email
|
email
|
||||||
createdAt
|
|
||||||
updatedAt
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
@@ -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(),
|
||||||
@@ -45,11 +51,25 @@ function ProfileSettings() {
|
|||||||
|
|
||||||
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,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
Reference in New Issue
Block a user