forked from coderdost/MERN-ecommerce-Frontend
-
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.
- Loading branch information
1 parent
07e4d53
commit 1fedc1a
Showing
9 changed files
with
170 additions
and
31 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
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,90 @@ | ||
import React, { useState } from 'react'; | ||
import { Link, Navigate } from 'react-router-dom'; | ||
import { checkUserAsync } from '../authSlice'; | ||
import { useForm } from 'react-hook-form'; | ||
|
||
export default function ForgotPassword() { | ||
const { | ||
register, | ||
handleSubmit, | ||
formState: { errors }, | ||
} = useForm(); | ||
|
||
console.log(errors); | ||
|
||
return ( | ||
<> | ||
<div className="flex min-h-full flex-1 flex-col justify-center px-6 py-12 lg:px-8"> | ||
<div className="sm:mx-auto sm:w-full sm:max-w-sm"> | ||
<img | ||
className="mx-auto h-10 w-auto" | ||
src="https://tailwindui.com/img/logos/mark.svg?color=indigo&shade=600" | ||
alt="Your Company" | ||
/> | ||
<h2 className="mt-10 text-center text-2xl font-bold leading-9 tracking-tight text-gray-900"> | ||
Enter email to reset password | ||
</h2> | ||
</div> | ||
|
||
<div className="mt-10 sm:mx-auto sm:w-full sm:max-w-sm"> | ||
<form | ||
noValidate | ||
onSubmit={handleSubmit((data) => { | ||
console.log(data); | ||
// TODO : implementation on backend with email | ||
})} | ||
className="space-y-6" | ||
|
||
> | ||
<div> | ||
<label | ||
htmlFor="email" | ||
className="block text-sm font-medium leading-6 text-gray-900" | ||
> | ||
Email address | ||
</label> | ||
<div className="mt-2"> | ||
<input | ||
id="email" | ||
{...register('email', { | ||
required: 'email is required', | ||
pattern: { | ||
value: /\b[\w\.-]+@[\w\.-]+\.\w{2,4}\b/gi, | ||
message: 'email not valid', | ||
}, | ||
})} | ||
type="email" | ||
className="block w-full rounded-md border-0 py-1.5 text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:ring-2 focus:ring-inset focus:ring-indigo-600 sm:text-sm sm:leading-6" | ||
/> | ||
{errors.email && ( | ||
<p className="text-red-500">{errors.email.message}</p> | ||
)} | ||
</div> | ||
</div> | ||
|
||
|
||
|
||
<div> | ||
<button | ||
type="submit" | ||
className="flex w-full justify-center rounded-md bg-indigo-600 px-3 py-1.5 text-sm font-semibold leading-6 text-white shadow-sm hover:bg-indigo-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600" | ||
> | ||
Send Email | ||
</button> | ||
</div> | ||
</form> | ||
|
||
<p className="mt-10 text-center text-sm text-gray-500"> | ||
Send me back to {' '} | ||
<Link | ||
to="/login" | ||
className="font-semibold leading-6 text-indigo-600 hover:text-indigo-500" | ||
> | ||
Login | ||
</Link> | ||
</p> | ||
</div> | ||
</div> | ||
</> | ||
); | ||
} |
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,23 @@ | ||
import { useEffect } from "react"; | ||
import { selectLoggedInUser, signOutAsync } from "../authSlice"; | ||
import { useDispatch, useSelector } from "react-redux"; | ||
import { Navigate } from "react-router-dom"; | ||
|
||
|
||
function Logout() { | ||
const dispatch = useDispatch(); | ||
const user = useSelector(selectLoggedInUser) | ||
|
||
useEffect(()=>{ | ||
dispatch(signOutAsync()) | ||
}) | ||
|
||
// but useEffect runs after render, so we have to delay navigate part | ||
return ( | ||
<> | ||
{!user && <Navigate to='/login' replace={true}></Navigate>} | ||
</> | ||
); | ||
} | ||
|
||
export default Logout; |
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,9 @@ | ||
import ForgotPassword from "../features/auth/components/ForgotPassword"; | ||
import Login from "../features/auth/components/Login"; | ||
function ForgotPasswordPage() { | ||
return ( <div> | ||
<ForgotPassword></ForgotPassword> | ||
</div> ); | ||
} | ||
|
||
export default ForgotPasswordPage; |