quivr/frontend/app/(auth)/recover-password/page.tsx
Mamadou DICKO b0514d6149
fix(i18n): update tests for french and spanish (#878)
* add libraries for traslation purposes

* Add button and service for language selection

* add spanish translation on login page

* add spanish translation on upload page

* Add spanish translations for explore page

* Add translations on user page

* Add translations for config page

* Add spanish translations on chat page

* add translations for brain page

* fix GUI and save on local storage

* fix (i18n) init and types

* fix (i18n): typos

* add translation on new brain modal

* add translations on metadata

* Add translations on home page

* fixes types

* fix(frontend-tests): use get by id instead of text

---------

Co-authored-by: Gustavo Maciel <gustavo_m13@outlook.com>
2023-08-07 14:13:41 +02:00

92 lines
2.8 KiB
TypeScript

/* eslint-disable */
"use client";
import { useState } from "react";
import Button from "@/lib/components/ui/Button";
import Card from "@/lib/components/ui/Card";
import Field from "@/lib/components/ui/Field";
import PageHeading from "@/lib/components/ui/PageHeading";
import { useSupabase } from "@/lib/context/SupabaseProvider";
import { useToast } from "@/lib/hooks/useToast";
import { redirectToLogin } from "@/lib/router/redirectToLogin";
import { useEventTracking } from "@/services/analytics/useEventTracking";
import { Suspense } from "react";
import { useTranslation } from "react-i18next";
export default function RecoverPassword() {
const { supabase, session } = useSupabase();
const [password, setPassword] = useState("");
const [isPending, setIsPending] = useState(false);
const { track } = useEventTracking();
const { t } = useTranslation(["translation", "updatePassword"]);
const { publish } = useToast();
function ChangePassword() {
const handleChangePassword = async () => {
void track("UPDATE_PASSWORD");
setIsPending(true);
const { error } = await supabase.auth.updateUser({
password: password,
});
if (error) {
console.error("Error while resetting password:", error.message);
publish({
variant: "danger",
text: `Error: ${error.message}`,
});
} else {
publish({
variant: "success",
text: t("passwordUpdated", { ns: "updatePassword" }),
});
}
setIsPending(false);
};
if (session?.user === undefined) {
redirectToLogin();
}
return (
<main>
<section className="min-h-[80vh] w-full h-full outline-none flex flex-col gap-5 items-center justify-center p-6">
<PageHeading title={t("title", { ns: "updatePassword" })} />
<Card className="max-w-md w-full p-5 sm:p-10 text-left">
<form
onSubmit={(e) => {
e.preventDefault();
handleChangePassword();
}}
className="flex flex-col gap-2"
>
<Field
name="New password"
required
type="password"
value={password}
onChange={(e) => setPassword(e.target.value)}
placeholder={t("newPassword", { ns: "updatePassword" })}
data-testid="password-field"
/>
<div className="flex flex-col items-center justify-center mt-2 gap-2">
<Button isLoading={isPending} data-testid="update-button">
{t("updateButton")}
</Button>
</div>
</form>
</Card>
</section>
</main>
);
}
return (
<Suspense fallback={"Loading..."}>
<ChangePassword />
</Suspense>
);
}