-
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-550] - [FE] Integrate User Sign-In API (#7)
- Loading branch information
1 parent
9cbbd40
commit 2abdd5d
Showing
4 changed files
with
34 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,42 @@ | ||
/* eslint-disable @next/next/no-img-element */ | ||
import Link from "next/link"; | ||
import { Formik, Form } from "formik"; | ||
import { setCookie } from 'cookies-next'; | ||
import { setCookie, deleteCookie, getCookie } from 'cookies-next'; | ||
import React, { useState } from "react"; | ||
|
||
import { Cookie } from "shared/types"; | ||
import Button from "components/atoms/Button"; | ||
import NextHead from "components/atoms/NextHead"; | ||
import { useAuthMethods } from "hooks/authMethods"; | ||
import { SignInFormSchema } from "shared/validation"; | ||
import CustomForm from "components/molecules/CustomForm"; | ||
|
||
const SignIn = () => { | ||
const { handleSignInSubmit } = useAuthMethods(); | ||
const [isPassHidden, setIsPassHidden] = useState<boolean>(true); | ||
const [rememberMe, setRememberMe] = useState<string>(""); | ||
const isRemembered: Cookie = getCookie('isRemembered') || false; | ||
const rememberedEmail: Cookie = getCookie('email') || ""; | ||
|
||
const formikInitialValues = { | ||
email: "", | ||
password: "" | ||
}; | ||
|
||
const onClickRemember = (e: any) => { | ||
setCookie('isRemembered', e.target.checked); | ||
const onChangeRemember = (e: { target: any }) => { | ||
const { value, name } = e.target; | ||
if (name === "password") return; | ||
|
||
if (e.target.checked) { | ||
setCookie('email', formikInitialValues.email); | ||
} | ||
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 ( | ||
|
@@ -39,16 +53,17 @@ const SignIn = () => { | |
<Formik | ||
initialValues={formikInitialValues} | ||
validationSchema={SignInFormSchema} | ||
onSubmit={()=>{}} | ||
onSubmit={handleSignInSubmit} | ||
> | ||
{({ isSubmitting }): any => { | ||
return ( | ||
<Form> | ||
<div className="flex flex-col gap-4 "> | ||
<div className="flex flex-col gap-4" onChange={onChangeRemember}> | ||
<CustomForm | ||
label="Email address" | ||
name="email" | ||
type="email" | ||
defaultValue={rememberedEmail} | ||
placeholder="[email protected]" | ||
/> | ||
<CustomForm | ||
|
@@ -66,7 +81,7 @@ const SignIn = () => { | |
<input | ||
id="remember" | ||
type="checkbox" | ||
value="" | ||
defaultChecked={isRemembered} | ||
onClick={onClickRemember} | ||
className="h-3 w-3 rounded-sm border border-gray-300 bg-transparent" | ||
/> | ||
|
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