import { Box, Center, HStack, Image, Input, Stack, Text, VStack, } from "@chakra-ui/react"; import axios from "axios"; import { useState } from "react"; import { useNavigate } from "react-router-dom"; import logo from "../assets/logo.svg"; import { Button } from "../components/ui/button"; import { toaster, Toaster } from "../components/ui/toaster"; const SetNewPassword = () => { const [password, setPassword] = useState(""); const [confirmPassword, setConfirmPassword] = useState(""); const [isLoading, setIsLoading] = useState(false); const navigate = useNavigate(); const handlePasswordSubmit = async () => { // Validation if (password.length < 8) { toaster.create({ title: "Password must be at least 8 characters long", type: "error", }); return; } if (password !== confirmPassword) { toaster.create({ title: "Passwords do not match", type: "error", }); return; } setIsLoading(true); try { const res = await axios.post(`${import.meta.env.VITE_API_URL}/reset-password`, { password: password, confirm_password: confirmPassword, // id: id }); if (res.status === 200) { toaster.create({ title: "Password updated successfully", type: "success", }); navigate("/login"); // Redirect to login page } else { toaster.create({ title: res.data.message || "Failed to update password", type: "error", }); } } catch (error: any) { toaster.create({ title: error.response?.data?.message || "Something went wrong", type: "error", }); } finally { setIsLoading(false); } }; return (
Create a Password New password setPassword(e.target.value)} /> Confirm password setConfirmPassword(e.target.value)} />
); }; export default SetNewPassword;