feat(profile): add capability to update user's full name
This commit is contained in:
@@ -4,6 +4,7 @@ type Params = {
|
|||||||
input: {
|
input: {
|
||||||
email: string;
|
email: string;
|
||||||
password: string;
|
password: string;
|
||||||
|
fullName: string;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -15,6 +16,7 @@ const updateUser = async (
|
|||||||
const user = await context.currentUser.$query().patchAndFetch({
|
const user = await context.currentUser.$query().patchAndFetch({
|
||||||
email: params.input.email,
|
email: params.input.email,
|
||||||
password: params.input.password,
|
password: params.input.password,
|
||||||
|
fullName: params.input.fullName,
|
||||||
});
|
});
|
||||||
|
|
||||||
return user;
|
return user;
|
||||||
|
@@ -351,6 +351,7 @@ input CreateUserInput {
|
|||||||
input UpdateUserInput {
|
input UpdateUserInput {
|
||||||
email: String
|
email: String
|
||||||
password: String
|
password: String
|
||||||
|
fullName: String
|
||||||
}
|
}
|
||||||
|
|
||||||
input ForgotPasswordInput {
|
input ForgotPasswordInput {
|
||||||
|
@@ -5,6 +5,7 @@ export const UPDATE_USER = gql`
|
|||||||
updateUser(input: $input) {
|
updateUser(input: $input) {
|
||||||
id
|
id
|
||||||
email
|
email
|
||||||
|
fullName
|
||||||
updatedAt
|
updatedAt
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -83,8 +83,11 @@
|
|||||||
"execution.noDataTitle": "No data",
|
"execution.noDataTitle": "No data",
|
||||||
"execution.noDataMessage": "We successfully ran the execution, but there was no new data to process.",
|
"execution.noDataMessage": "We successfully ran the execution, but there was no new data to process.",
|
||||||
"profileSettings.title": "My Profile",
|
"profileSettings.title": "My Profile",
|
||||||
|
"profileSettings.fullName": "Full name",
|
||||||
|
"profileSettings.updateFullName": "Update full name",
|
||||||
"profileSettings.email": "Email",
|
"profileSettings.email": "Email",
|
||||||
"profileSettings.updateEmail": "Update email",
|
"profileSettings.updateEmail": "Update email",
|
||||||
|
"profileSettings.updatedFullName": "Your full name has been updated.",
|
||||||
"profileSettings.newPassword": "New password",
|
"profileSettings.newPassword": "New password",
|
||||||
"profileSettings.confirmNewPassword": "Confirm new password",
|
"profileSettings.confirmNewPassword": "Confirm new password",
|
||||||
"profileSettings.updatedEmail": "Your email has been updated.",
|
"profileSettings.updatedEmail": "Your email has been updated.",
|
||||||
|
@@ -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';
|
||||||
|
|
||||||
|
const fullNameValidationSchema = yup
|
||||||
|
.object({
|
||||||
|
fullName: yup.string().required(),
|
||||||
|
})
|
||||||
|
.required();
|
||||||
|
|
||||||
const emailValidationSchema = yup
|
const emailValidationSchema = yup
|
||||||
.object({
|
.object({
|
||||||
email: yup.string().email().required(),
|
email: yup.string().email().required(),
|
||||||
@@ -49,6 +55,22 @@ function ProfileSettings() {
|
|||||||
const formatMessage = useFormatMessage();
|
const formatMessage = useFormatMessage();
|
||||||
const [updateUser] = useMutation(UPDATE_USER);
|
const [updateUser] = useMutation(UPDATE_USER);
|
||||||
|
|
||||||
|
const handleFullNameUpdate = async (data: any) => {
|
||||||
|
const fullName = data.fullName;
|
||||||
|
|
||||||
|
await updateUser({
|
||||||
|
variables: {
|
||||||
|
input: {
|
||||||
|
fullName,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
enqueueSnackbar(formatMessage('profileSettings.updatedFullName'), {
|
||||||
|
variant: 'success',
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
const handleEmailUpdate = async (data: any) => {
|
const handleEmailUpdate = async (data: any) => {
|
||||||
const email = data.email;
|
const email = data.email;
|
||||||
|
|
||||||
@@ -100,6 +122,42 @@ function ProfileSettings() {
|
|||||||
</Grid>
|
</Grid>
|
||||||
|
|
||||||
<Grid item xs={12} justifyContent="flex-end">
|
<Grid item xs={12} justifyContent="flex-end">
|
||||||
|
<StyledForm
|
||||||
|
defaultValues={{ ...currentUser }}
|
||||||
|
onSubmit={handleFullNameUpdate}
|
||||||
|
resolver={yupResolver(fullNameValidationSchema)}
|
||||||
|
mode="onChange"
|
||||||
|
sx={{ mb: 2 }}
|
||||||
|
render={({
|
||||||
|
formState: {
|
||||||
|
errors,
|
||||||
|
touchedFields,
|
||||||
|
isDirty,
|
||||||
|
isValid,
|
||||||
|
isSubmitting,
|
||||||
|
},
|
||||||
|
}) => (
|
||||||
|
<>
|
||||||
|
<TextField
|
||||||
|
fullWidth
|
||||||
|
name="fullName"
|
||||||
|
label={formatMessage('profileSettings.fullName')}
|
||||||
|
margin="normal"
|
||||||
|
error={touchedFields.fullName && !!errors?.fullName}
|
||||||
|
helperText={errors?.fullName?.message || ' '}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
variant="contained"
|
||||||
|
type="submit"
|
||||||
|
disabled={!isDirty || !isValid || isSubmitting}
|
||||||
|
>
|
||||||
|
{formatMessage('profileSettings.updateFullName')}
|
||||||
|
</Button>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
<StyledForm
|
<StyledForm
|
||||||
defaultValues={{ ...currentUser}}
|
defaultValues={{ ...currentUser}}
|
||||||
onSubmit={handleEmailUpdate}
|
onSubmit={handleEmailUpdate}
|
||||||
|
Reference in New Issue
Block a user