Skip to content

Commit eef2b5f

Browse files
refactor: fetch email as search query in forgot password view
1 parent b2d30f0 commit eef2b5f

2 files changed

Lines changed: 18 additions & 11 deletions

File tree

packages/user/src/components/ForgotPasswordForm/index.tsx

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,23 @@
11
import { Provider, emailSchema } from "@prefabs.tech/react-form";
22
import { useTranslation } from "@prefabs.tech/react-i18n";
33
import React from "react";
4-
import { useLocation } from "react-router-dom";
54
import * as zod from "zod";
65

76
import { ForgotPasswordFormFields } from "./ForgotPasswordFormFields";
87

98
interface Properties {
109
handleSubmit: (email: string) => void;
1110
loading?: boolean;
11+
email?: string;
1212
}
1313

14-
export const ForgotPasswordForm = ({ handleSubmit, loading }: Properties) => {
14+
export const ForgotPasswordForm = ({
15+
handleSubmit,
16+
loading,
17+
email,
18+
}: Properties) => {
1519
const { t, i18n } = useTranslation("user");
1620

17-
const location = useLocation();
18-
19-
const searchParameters = new URLSearchParams(location.search);
20-
const email = searchParameters.get("email");
21-
2221
const ForgotPasswordFormSchema = zod.object({
2322
email: emailSchema({
2423
required: t("validation.messages.email"),
@@ -32,7 +31,7 @@ export const ForgotPasswordForm = ({ handleSubmit, loading }: Properties) => {
3231
onSubmit={(data) => handleSubmit(data.email)}
3332
validationTriggerKey={i18n.language}
3433
defaultValues={{
35-
email: email,
34+
email,
3635
}}
3736
>
3837
<ForgotPasswordFormFields loading={loading} />

packages/user/src/views/ForgotPassword.tsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
11
import { useTranslation } from "@prefabs.tech/react-i18n";
22
import { AuthPage } from "@prefabs.tech/react-ui";
33
import { useState } from "react";
4+
import { useSearchParams } from "react-router-dom";
45
import { toast } from "react-toastify";
56

7+
import { ForgotPasswordForm } from "../components/ForgotPasswordForm";
8+
69
import { AuthLinks } from "@/components/AuthLinks";
710
import { DEFAULT_PATHS } from "@/constants";
811
import { useConfig } from "@/hooks";
912
import { forgotPassword } from "@/supertokens";
1013
import { LinkType } from "@/types/types";
1114

12-
import { ForgotPasswordForm } from "../components/ForgotPasswordForm";
13-
1415
export const ForgotPassword = ({ centered = true }: { centered?: boolean }) => {
1516
const { t } = useTranslation("user");
1617
const [loading, setLoading] = useState<boolean>(false);
1718

19+
const [searchParameters] = useSearchParams();
20+
const email = searchParameters.get("email") ?? undefined;
21+
1822
const config = useConfig();
1923

2024
const links: Array<LinkType> = [
@@ -43,7 +47,11 @@ export const ForgotPassword = ({ centered = true }: { centered?: boolean }) => {
4347
className="forgot-password"
4448
title={t("forgotPassword.title")}
4549
>
46-
<ForgotPasswordForm handleSubmit={handleSubmit} loading={loading} />
50+
<ForgotPasswordForm
51+
handleSubmit={handleSubmit}
52+
loading={loading}
53+
email={email}
54+
/>
4755
<AuthLinks className="forgot-password" links={links} />
4856
</AuthPage>
4957
);

0 commit comments

Comments
 (0)