From 2667a5753b5fa7e51e232729422d4e16171fb218 Mon Sep 17 00:00:00 2001 From: SKairinos Date: Fri, 12 Jul 2024 16:49:40 +0000 Subject: [PATCH] quick save --- src/pages/resetPassword/EmailForm.tsx | 57 +++++++++++++++++++ src/pages/resetPassword/PasswordForm.tsx | 67 +++++++++++++++++++++++ src/pages/resetPassword/ResetPassword.tsx | 52 ++++++++++++++++++ src/router/paths.ts | 8 +-- src/router/routes/authentication.tsx | 4 +- 5 files changed, 181 insertions(+), 7 deletions(-) create mode 100644 src/pages/resetPassword/EmailForm.tsx create mode 100644 src/pages/resetPassword/PasswordForm.tsx create mode 100644 src/pages/resetPassword/ResetPassword.tsx diff --git a/src/pages/resetPassword/EmailForm.tsx b/src/pages/resetPassword/EmailForm.tsx new file mode 100644 index 0000000..de8e833 --- /dev/null +++ b/src/pages/resetPassword/EmailForm.tsx @@ -0,0 +1,57 @@ +import { Send as SendIcon } from "@mui/icons-material" +import { Stack, Typography } from "@mui/material" +import { type FC } from "react" + +import * as form from "codeforlife/components/form" +import { LinkButton } from "codeforlife/components/router" + +import { useLazyRequestPasswordResetQuery } from "../../api/user" +import { paths } from "../../router" + +export interface EmailFormProps {} + +const EmailForm: FC = () => { + const [requestPasswordReset, result] = useLazyRequestPasswordResetQuery() + + return result.isSuccess ? ( + + + Thank you + + + + If you have entered a valid email address, you will receive a link + enabling you to reset your password. + + Back to homepage + + ) : ( + + + Reset password + + + Please enter your email address + + + We will send an email with a link to reset your password. + + { + requestPasswordReset(values) + }} + > + + + + Cancel + + Reset password + + + + ) +} + +export default EmailForm diff --git a/src/pages/resetPassword/PasswordForm.tsx b/src/pages/resetPassword/PasswordForm.tsx new file mode 100644 index 0000000..0d8e2db --- /dev/null +++ b/src/pages/resetPassword/PasswordForm.tsx @@ -0,0 +1,67 @@ +import { CheckCircleOutline as CheckCircleOutlineIcon } from "@mui/icons-material" +import { Stack, Typography } from "@mui/material" +import { type FC } from "react" + +import * as form from "codeforlife/components/form" +import { LinkButton } from "codeforlife/components/router" + +import { useResetPasswordMutation } from "../../api/user" +// import CflPasswordFields from "../../features/cflPasswordFields/CflPasswordFields" +import { paths } from "../../router" + +export interface PasswordFormProps { + userType: "teacher" | "independent" + userId: number + token: string +} + +const PasswordForm: FC = ({ userType, userId, token }) => { + const [resetPassword, result] = useResetPasswordMutation() + + return result.isSuccess ? ( + + + Your password has been reset + + + Please log in. + + OK + + + ) : ( + + + Password Reset + + + Please enter a new password and confirm it in the box below to reset + your account’s password. + + + resetPassword([userId, { token, password }]) + } + > + {/* */} + + + Cancel + + Reset password + + + + ) +} + +export default PasswordForm diff --git a/src/pages/resetPassword/ResetPassword.tsx b/src/pages/resetPassword/ResetPassword.tsx new file mode 100644 index 0000000..bf5a3c6 --- /dev/null +++ b/src/pages/resetPassword/ResetPassword.tsx @@ -0,0 +1,52 @@ +import { type FC, useEffect } from "react" +import * as yup from "yup" + +import * as page from "codeforlife/components/page" +import { useNavigate, useParams } from "codeforlife/hooks" +import { ThemedBox } from "codeforlife/theme" + +import { themeOptions } from "../../app/theme" +import { paths } from "../../router" +import EmailForm from "./EmailForm" +import PasswordForm from "./PasswordForm" + +export interface ResetPasswordProps {} + +const ResetPassword: FC = () => { + const navigate = useNavigate() + + const params = useParams({ + userType: yup + .string() + .oneOf(["teacher", "independent"] as const) + .required(), + userId: yup.number(), + token: yup.string(), + }) + + useEffect(() => { + if (!params) navigate(paths.error.type.pageNotFound._) + }, [navigate, params]) + + if (!params) return <> + + return ( + + + + {params.userId && params.token ? ( + + ) : ( + + )} + + + + ) +} + +export default ResetPassword diff --git a/src/router/paths.ts b/src/router/paths.ts index ab6c8ed..564b03e 100644 --- a/src/router/paths.ts +++ b/src/router/paths.ts @@ -12,11 +12,9 @@ const paths = _("", { }), indy: _("/independent"), }), - resetPassword: _("/reset-password", { - userType: _("/:userType", { - teacher: _({ userType: "teacher" }), - indy: _({ userType: "independent" }), - }), + resetPassword: _("/reset-password/:userType/:userId?/:token?", { + teacher: _({ userType: "teacher" }), + indy: _({ userType: "independent" }), }), teacher: _("/teacher", { onboarding: _("/onboarding"), diff --git a/src/router/routes/authentication.tsx b/src/router/routes/authentication.tsx index 8affeab..e38fe3d 100644 --- a/src/router/routes/authentication.tsx +++ b/src/router/routes/authentication.tsx @@ -3,7 +3,7 @@ import { Route } from "react-router-dom" import EmailVerification from "../../pages/emailVerification/EmailVerification" import Login from "../../pages/login/Login" // import Register from '../../pages/register/Register' -// import ResetPassword from '../../pages/resetPassword/ResetPassword' +import ResetPassword from "../../pages/resetPassword/ResetPassword" import paths from "../paths" const authentication = ( @@ -33,7 +33,7 @@ const authentication = ( path={paths.register.emailVerification.userType._} element={} /> - {/* } /> */} + } /> {/* } /> */} )