Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I97 edit profile reset password #100

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions context/AuthContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { auth } from "firebase.config";
import {
createUserWithEmailAndPassword,
onAuthStateChanged,
sendPasswordResetEmail,
signInWithEmailAndPassword,
signOut,
} from "firebase/auth";
Expand Down Expand Up @@ -46,9 +47,13 @@ export const AuthContextProvider = ({ children }) => {
setUser(null);
await signOut(auth);
};

const resetPassword = (email) => {
return sendPasswordResetEmail(auth, email);
};
return (
<AuthContext.Provider value={{ user, login, signup, logout }}>
<AuthContext.Provider
value={{ user, login, signup, logout, resetPassword }}
>
{loading ? null : children}
</AuthContext.Provider>
);
Expand Down
4 changes: 2 additions & 2 deletions data/products.json
Original file line number Diff line number Diff line change
Expand Up @@ -595,8 +595,8 @@
"condition": "New",
"seller": {
"id": 88888888,
"displayName": "Umut Polat",
"email": "studentstoretemp@gmail.com",
"displayName": "Nouh Rastanawi",
"email": "studentstoretemp@gmaill.com",
"image": "https://www.random-name-generator.com/images/faces/male-white/37.jpg?ezimgfmt=rs:148x143/rscb1/ng:webp/ngcb1"
},
"requestedBuyers": [],
Expand Down
43 changes: 38 additions & 5 deletions src/components/EditProfile/EditProfile.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,20 @@ import { updateProfile } from "firebase/auth";
import { useRouter } from "next/router";
import { useTranslation } from "next-i18next";
import * as React from "react";
import { useRef } from "react";
import { toast, ToastContainer } from "react-toastify";
import { injectStyle } from "react-toastify/dist/inject-style";

import Button from "../button";
import Input from "../input";
import { useAuth } from "../../../context/AuthContext";
if (typeof window !== "undefined") {
injectStyle();
}

export default function EditProfile() {
const emailRef = useRef(null);
const { resetPassword } = useAuth();
const { t } = useTranslation("profile");
const router = useRouter();

Expand All @@ -34,6 +38,20 @@ export default function EditProfile() {
.catch(() => {});
};

const resetUserPassword = async (event) => {
event.preventDefault();

await resetPassword(emailRef.current.value)
.then(() => {
toast.success(
t(
"Check your inbox we Sent you a link to reset your password"
) + "!"
);
})
.catch(() => {});
};

return (
<div className='mt-4 flex flex-wrap justify-center self-center'>
<div className='w-3/4'>
Expand All @@ -49,12 +67,18 @@ export default function EditProfile() {
placeholder={t("name")}
required
/>
<Input type='email' placeholder='email' />
<Input type='password' placeholder={t("password")} />
<Input
type='password'
placeholder={t("confirm-new-password")}
<input
className=' inputtabfont my-3.5 block w-full rounded-lg
border border-gray-300 bg-gray-50 p-2.5
text-center text-xl text-hadrisblue
placeholder-hadrisblue focus:border-blue-500 focus:ring-purple'
id='email'
name='email'
type='email'
placeholder='Enter Email to Reset Your password'
ref={emailRef}
/>

<div className='flex h-48 items-stretch'>
<Input type='text' placeholder={t("address")} />
</div>
Expand All @@ -68,6 +92,15 @@ export default function EditProfile() {
handleClick={updateInfo}
/>
</a>

<a>
<Button
buttonStyle='saveChanges'
type='button'
text='reset password'
handleClick={resetUserPassword}
/>
</a>
<ToastContainer />
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,10 @@ exports[`renders correctly 1`] = `
<input
className=" inputtabfont my-3.5 block w-full rounded-lg border border-gray-300 bg-gray-50 p-2.5 text-center text-xl text-hadrisblue placeholder-hadrisblue focus:border-blue-500 focus:ring-purple"
id="email"
placeholder="email"
required={true}
name="email"
placeholder="Enter Email to Reset Your password"
type="email"
/>
<input
className=" inputtabfont my-3.5 block w-full rounded-lg border border-gray-300 bg-gray-50 p-2.5 text-center text-xl text-hadrisblue placeholder-hadrisblue focus:border-blue-500 focus:ring-purple"
id="password"
placeholder="password"
required={true}
type="password"
/>
<input
className=" inputtabfont my-3.5 block w-full rounded-lg border border-gray-300 bg-gray-50 p-2.5 text-center text-xl text-hadrisblue placeholder-hadrisblue focus:border-blue-500 focus:ring-purple"
id="password"
placeholder="confirm-new-password"
required={true}
type="password"
/>
<div
className="flex h-48 items-stretch"
>
Expand All @@ -60,6 +46,15 @@ exports[`renders correctly 1`] = `
save-changes
</button>
</a>
<a>
<button
className="h-12 w-56 lg:h-14 lg:w-64 m-1 p-1 px-2 hover:bg-purple hover:shadow-lg rounded-lg border-2 bg-pumpkin font-md text-[17px] text-white shadow-sm"
onClick={[Function]}
type="button"
>
reset password
</button>
</a>
<div
className="Toastify"
/>
Expand Down