import type { ResetPasswordRequest } from "@prisma/client"; import { debounce } from "lodash"; import type { GetServerSidePropsContext } from "next"; import { getCsrfToken } from "next-auth/react"; import { serverSideTranslations } from "next-i18next/serverSideTranslations"; import Link from "next/link"; import type { CSSProperties } from "react"; import React, { useMemo } from "react"; import dayjs from "@calcom/dayjs"; import { useLocale } from "@calcom/lib/hooks/useLocale"; import prisma from "@calcom/prisma"; import { Button, TextField } from "@calcom/ui"; import AuthContainer from "@components/ui/AuthContainer"; type Props = { id: string; resetPasswordRequest: ResetPasswordRequest; csrfToken: string; }; export default function Page({ resetPasswordRequest, csrfToken }: Props) { const { t } = useLocale(); const [loading, setLoading] = React.useState(false); const [, setError] = React.useState<{ message: string } | null>(null); const [success, setSuccess] = React.useState(false); const [password, setPassword] = React.useState(""); const submitChangePassword = async ({ password, requestId }: { password: string; requestId: string }) => { try { const res = await fetch("/api/auth/reset-password", { method: "POST", body: JSON.stringify({ requestId: requestId, password: password }), headers: { "Content-Type": "application/json", }, }); const json = await res.json(); if (!res.ok) { setError(json); } else { setSuccess(true); } return json; } catch (reason) { setError({ message: t("unexpected_error_try_again") }); } finally { setLoading(false); } }; const debouncedChangePassword = debounce(submitChangePassword, 250); const Success = () => { return ( <>
{t("request_is_expired_instructions")}