-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from brunomous/feature/user-profile
Implement User Profile workflow
- Loading branch information
Showing
10 changed files
with
18,080 additions
and
19 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
packages/frontend/src/pages/Profile/ChangePasswordForm.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import { FC, useState } from "react"; | ||
import { SchemaForm } from "@concepta/react-material-ui"; | ||
import Box from "@mui/material/Box"; | ||
import Button from "@mui/material/Button"; | ||
import useTheme from "@mui/material/styles/useTheme"; | ||
|
||
import { type PasswordChangeFormData } from "./types"; | ||
import { | ||
passwordChangeFormSchema, | ||
passwordChangeUiSchema, | ||
customValidate, | ||
} from "./constants"; | ||
|
||
interface ChangePasswordFormProps { | ||
closePasswordChangeModal: () => void; | ||
openConfirmationModal: () => void; | ||
} | ||
|
||
const ChangePasswordForm: FC<ChangePasswordFormProps> = ({ | ||
closePasswordChangeModal, | ||
openConfirmationModal, | ||
}) => { | ||
const theme = useTheme(); | ||
|
||
const [formData, setFormData] = useState<PasswordChangeFormData>({ | ||
oldPassword: "", | ||
newPassword: "", | ||
confirmNewPassword: "", | ||
}); | ||
|
||
const handleFormSubmit = async () => { | ||
closePasswordChangeModal(); | ||
openConfirmationModal(); | ||
}; | ||
|
||
return ( | ||
<SchemaForm.Form | ||
schema={passwordChangeFormSchema} | ||
uiSchema={passwordChangeUiSchema} | ||
onSubmit={handleFormSubmit} | ||
noHtml5Validate={true} | ||
showErrorList={false} | ||
customValidate={customValidate} | ||
formData={formData} | ||
onChange={({ formData }) => { | ||
setFormData(formData); | ||
}} | ||
> | ||
<Box | ||
display="flex" | ||
flexDirection="row" | ||
alignItems="center" | ||
justifyContent="flex-end" | ||
mt={4} | ||
gap={2} | ||
> | ||
<Button | ||
variant="outlined" | ||
sx={{ | ||
color: theme.palette.text.primary, | ||
borderColor: theme.palette.text.primary, | ||
textTransform: "capitalize", | ||
}} | ||
onClick={() => closePasswordChangeModal()} | ||
> | ||
Cancel | ||
</Button> | ||
<Button | ||
type="submit" | ||
variant="contained" | ||
sx={{ textTransform: "capitalize" }} | ||
> | ||
Save | ||
</Button> | ||
</Box> | ||
</SchemaForm.Form> | ||
); | ||
}; | ||
|
||
export default ChangePasswordForm; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { FC } from "react"; | ||
import { Text } from "@concepta/react-material-ui"; | ||
import Box from "@mui/material/Box"; | ||
import Button from "@mui/material/Button"; | ||
import CheckIcon from "@mui/icons-material/Check"; | ||
|
||
interface Props { | ||
handleClose: () => void; | ||
} | ||
|
||
const ConfirmationModal: FC<Props> = ({ handleClose }) => { | ||
return ( | ||
<Box display="flex" flexDirection="column" alignItems="center" padding={2}> | ||
<Box | ||
display="flex" | ||
sx={{ | ||
backgroundColor: "#d1fae5", | ||
padding: "12px", | ||
borderRadius: "50%", | ||
mb: 2, | ||
}} | ||
> | ||
<CheckIcon fontSize="small" /> | ||
</Box> | ||
<Text fontSize={18} fontWeight={500} color="text.primary"> | ||
Password Changed | ||
</Text> | ||
<Text | ||
fontSize={14} | ||
fontWeight={400} | ||
color="text.secondary" | ||
sx={{ mb: 3 }} | ||
> | ||
Your Password has been changed successfully | ||
</Text> | ||
<Button variant="contained" onClick={handleClose} fullWidth> | ||
Go back to profile | ||
</Button> | ||
</Box> | ||
); | ||
}; | ||
|
||
export default ConfirmationModal; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { UiSchema, RJSFSchema, CustomValidator } from "@rjsf/utils"; | ||
import { CustomTextFieldWidget } from "@concepta/react-material-ui/dist/styles/CustomWidgets"; | ||
import { CustomPasswordFieldWidget } from "@concepta/react-material-ui/dist/styles/CustomWidgets"; | ||
import { validatePasswordScore } from "@concepta/react-material-ui/dist/components/TextField/utils"; | ||
|
||
type PasswordUpdateForm = { | ||
oldPassword: string; | ||
newPassword: string; | ||
confirmNewPassword: string; | ||
}; | ||
|
||
export const widgets = { | ||
TextWidget: CustomTextFieldWidget, | ||
}; | ||
|
||
export const profileFormSchema: RJSFSchema = { | ||
type: "object", | ||
required: ["fullName", "nickname", "email"], | ||
properties: { | ||
fullName: { type: "string", title: "Full Name", minLength: 3 }, | ||
nickname: { type: "string", title: "Nickname", minLength: 3 }, | ||
email: { type: "string", title: "Email", minLength: 3, readOnly: true }, | ||
}, | ||
}; | ||
|
||
export const passwordChangeFormSchema: RJSFSchema = { | ||
type: "object", | ||
required: ["oldPassword", "newPassword", "confirmNewPassword"], | ||
properties: { | ||
oldPassword: { type: "string", title: "Current password" }, | ||
newPassword: { type: "string", title: "New password" }, | ||
confirmNewPassword: { type: "string", title: "Confirm new password" }, | ||
}, | ||
}; | ||
|
||
export const passwordChangeUiSchema: UiSchema = { | ||
oldPassword: { | ||
"ui:widget": CustomPasswordFieldWidget, | ||
}, | ||
newPassword: { | ||
"ui:widget": CustomPasswordFieldWidget, | ||
"ui:passwordStrengthConfig": { | ||
hideStrengthBar: false, | ||
hideRulesText: false, | ||
}, | ||
}, | ||
confirmNewPassword: { | ||
"ui:widget": CustomPasswordFieldWidget, | ||
}, | ||
}; | ||
|
||
export const customValidate: CustomValidator< | ||
PasswordUpdateForm, | ||
RJSFSchema, | ||
Record<string, unknown> | ||
> = (formData, errors) => { | ||
if (formData?.confirmNewPassword !== formData?.newPassword) { | ||
errors?.confirmNewPassword?.addError("Your passwords don't match."); | ||
} | ||
if (!validatePasswordScore(formData?.newPassword ?? "")) { | ||
errors?.newPassword?.addError( | ||
"Your password do not meet the security criteria." | ||
); | ||
} | ||
|
||
return errors; | ||
}; |
Oops, something went wrong.