import { Button } from "../ui/button"; import { Input } from "../ui/input"; import { Label } from "../ui/label"; import { Loader2 } from "lucide-react"; import { FaRegEye, FaRegEyeSlash } from "react-icons/fa"; import { toast } from "sonner"; import { t } from "@/utils"; import { resetPasswordApi, userSignUpApi } from "@/utils/api"; import { useState } from "react"; const ResetPasswordScreen = ({ formattedNumber, countryCode, onSuccess, onCancel, FirebaseId, }) => { const [newPassword, setNewPassword] = useState(""); const [isPasswordVisible, setIsPasswordVisible] = useState(false); const [resetPasswordLoader, setResetPasswordLoader] = useState(false); const handleResetPassword = async (e) => { e.preventDefault(); if (!newPassword) { toast.error(t("passwordRequired")); return; } if (newPassword.length < 6) { toast.error(t("passwordTooShort")); return; } setResetPasswordLoader(true); try { // Step 1: Get token by calling userSignUpApi const loginResponse = await userSignUpApi.userSignup({ mobile: formattedNumber, country_code: countryCode, type: "phone", firebase_id: FirebaseId, }); // Extract token from response const token = loginResponse?.data?.token; if (!token) { toast.error(t("errorOccurred")); return; } const response = await resetPasswordApi.resetPassword({ number: formattedNumber, country_code: countryCode, new_password: newPassword, token: token, }); if (response?.data?.error === false) { toast.success(response?.data?.message); onSuccess(); // Go back to login screen } else { toast.error(response?.data?.message); } } catch (error) { console.log(error); toast.error(t("errorOccurred")); } finally { setResetPasswordLoader(false); } }; return (
setNewPassword(e.target.value)} required />
{onCancel && ( )}
); }; export default ResetPasswordScreen;