-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[BarClerk-553] - [Markup] Create Password reset page (#8)
- Loading branch information
1 parent
2abdd5d
commit df036e8
Showing
20 changed files
with
322 additions
and
84 deletions.
There are no files selected for viewing
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
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,13 @@ | ||
import React from "react"; | ||
|
||
const AdminAuthTemplate = ({ children, hasBorder = false }: any) => { | ||
return ( | ||
<main className="bg-barclerk-60 mobile:!bg-barclerk-30 min-h-screen h-full mobile:pb-20 mobile:pt-10 py-10 flex justify-center items-center px-10"> | ||
<div className={`bg-barclerk-30 p-20 mobile:p-0 rounded-3xl shadow-2xl mobile:shadow-none ${hasBorder && "!border-t-[15px] !border-barclerk-10 py-10 mobile:!border-none"}`}> | ||
{children} | ||
</div> | ||
</main> | ||
); | ||
}; | ||
|
||
export default AdminAuthTemplate; |
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
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,34 @@ | ||
import { | ||
getCookie, | ||
setCookie, | ||
deleteCookie | ||
} from "cookies-next"; | ||
import { Cookie } from "shared/types"; | ||
import React, { useState } from "react"; | ||
|
||
const useRememberMe = () => { | ||
const [rememberMe, setRememberMe] = useState<string>(""); | ||
|
||
const rememberedEmail: Cookie = getCookie('email') || ""; | ||
const isRemembered: Cookie = getCookie('isRemembered') || false; | ||
|
||
const onChangeRemember = (e: { target: any }) => { | ||
const { value, name } = e.target; | ||
if (name === "password") return; | ||
|
||
setRememberMe(value); | ||
if (isRemembered) return setCookie('email', value); | ||
} | ||
|
||
const onClickRemember = (e: { target: any }) => { | ||
const { checked } = e.target; | ||
|
||
setCookie('isRemembered', checked); | ||
if (!checked) return deleteCookie('email'); | ||
setCookie('email', rememberMe) | ||
} | ||
|
||
return { rememberedEmail, isRemembered, onChangeRemember, onClickRemember }; | ||
}; | ||
|
||
export default useRememberMe; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
|
||
/* eslint-disable @next/next/no-img-element */ | ||
import Router from "next/router"; | ||
import { Formik, Form } from "formik"; | ||
import React, { useState, useEffect } from "react"; | ||
|
||
import { | ||
ForgotPasswordFormSchema, | ||
ResetLinkSubmitFormSchema | ||
} from "shared/validation"; | ||
import Button from "components/atoms/Button"; | ||
import NextHead from "components/atoms/NextHead"; | ||
import { useAuthMethods } from "hooks/authMethods"; | ||
import CustomForm from "components/molecules/CustomForm"; | ||
import AdminAuthTemplate from "components/templates/AdminAuthTemplate"; | ||
|
||
const ForgotPassword = () => { | ||
const { state }: any = Router?.router || {}; | ||
const { user, verified } = state?.query || {}; | ||
const { handleSignInSubmit, ResetLinkSubmit } = useAuthMethods(); | ||
const [isPassHidden, setIsPassHidden] = useState<boolean>(true); | ||
const [isLinkClicked, setIsLinkClicked] = useState<boolean>(false); | ||
|
||
useEffect(() => { | ||
setIsLinkClicked((user && verified) ? true : false); | ||
}, [user, verified, isLinkClicked]); | ||
|
||
const setRequestResetLinkInitialValue = { | ||
email: "", | ||
}; | ||
const RequestResetLink = () => { | ||
return ( | ||
<Formik | ||
initialValues={setRequestResetLinkInitialValue} | ||
validationSchema={ResetLinkSubmitFormSchema} | ||
onSubmit={async ({ email }: { email: any; }) => { | ||
await ResetLinkSubmit(email); | ||
}} | ||
> | ||
{({ isSubmitting }): any => { | ||
return ( | ||
<Form > | ||
<div className="flex flex-col gap-4"> | ||
<CustomForm | ||
label="Email address" | ||
name="email" | ||
type="email" | ||
placeholder="[email protected]" | ||
/> | ||
</div> | ||
<div className="flex flex-row gap-3 mt-10 mb-5"> | ||
<Button | ||
value="Go Back" | ||
onClick={(e) => { | ||
e.preventDefault(); | ||
Router.push("/sign-in"); | ||
}} | ||
className="!bg-transparent !text-light !border-2 !border-barclerk-10 hover:!border-transparent hover:!bg-barclerk-10/70" | ||
/> | ||
<Button isSubmitting={isSubmitting} value="Continue" /> | ||
</div> | ||
</Form> | ||
); | ||
}} | ||
</Formik> | ||
); | ||
}; | ||
|
||
const setupNewPasswordInitialValue = { | ||
password: "", | ||
password_confirmation: "", | ||
}; | ||
const SetupNewPassword = ( | ||
<div className="flex flex-col"> | ||
<Formik | ||
initialValues={setupNewPasswordInitialValue} | ||
validationSchema={ForgotPasswordFormSchema} | ||
onSubmit={handleSignInSubmit} | ||
> | ||
{({ isSubmitting }): any => { | ||
return ( | ||
<Form className="-mt-3"> | ||
<div className="flex flex-col gap-3"> | ||
<CustomForm | ||
label="Password" | ||
name="password" | ||
type={isPassHidden ? "password" : "text"} | ||
placeholder="●●●●●●●" | ||
isPassHidden={isPassHidden} | ||
setIsPassHidden={setIsPassHidden} | ||
/> | ||
<CustomForm | ||
label="Confirm Password" | ||
name="password_confirmation" | ||
type={isPassHidden ? "password" : "text"} | ||
placeholder="●●●●●●●●" | ||
/> | ||
</div> | ||
<div className="flex flex-row gap-3 mt-10 mb-5"> | ||
<Button | ||
value="Go Back" | ||
onClick={(e) => { | ||
e.preventDefault(); | ||
Router.push("/forgot-password"); | ||
}} | ||
className="!bg-transparent !text-light !border-2 !border-barclerk-10 hover:!border-transparent hover:!bg-barclerk-10/70" | ||
/> | ||
<Button isSubmitting={isSubmitting} value="Continue" /> | ||
</div> | ||
</Form> | ||
); | ||
}} | ||
</Formik> | ||
</div> | ||
); | ||
|
||
return ( | ||
<> | ||
<NextHead title="BarClerk | Sign In" /> | ||
<AdminAuthTemplate hasBorder={true}> | ||
<div className="flex flex-col gap-10 w-[360px]"> | ||
<header className="flex flex-col items-center h-full justify-center"> | ||
<h1 className="text-[27px] font-semibold text-dark">{isLinkClicked ? "Setup your new password" : "Request password reset link"}</h1> | ||
</header> | ||
{isLinkClicked ? SetupNewPassword : <RequestResetLink />} | ||
</div> | ||
</AdminAuthTemplate> | ||
</> | ||
); | ||
}; | ||
|
||
export default ForgotPassword; |
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 |
---|---|---|
@@ -1,5 +1,14 @@ | ||
import Button from "components/atoms/Button"; | ||
import MaintenancePage from "components/templates/MaintenancePage"; | ||
import { useAuthMethods } from "hooks/authMethods"; | ||
|
||
export default function Home() { | ||
return <MaintenancePage /> | ||
const { handleAuthSignOut } = useAuthMethods(); | ||
return ( | ||
<div> | ||
<MaintenancePage /> | ||
<Button onClick={handleAuthSignOut} value="Temporary Logout Button" className="absolute top-10 right-10 max-w-[150px] rounded-lg" /> | ||
</div> | ||
) | ||
} | ||
|
Oops, something went wrong.