import { Box, Center, HStack, IconButton, 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"; import { InputGroup } from "../components/ui/input-group"; import { LuEye, LuEyeOff } from "react-icons/lu"; const SetNewPassword = () => { const [password, setPassword] = useState(""); const [confirmPassword, setConfirmPassword] = useState(""); const [isLoading, setIsLoading] = useState(false); const navigate = useNavigate(); const queryParams = new URLSearchParams(window.location.search); const id = queryParams.get("id"); const [showOldPassword, setShowOldPassword] = useState(false); const [showNewPassword, setShowNewPassword] = useState(false); 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}/update-password`, { password: password, confirm_password: confirmPassword, id: Number(id), } ); if (res.data.status === "success") { 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 setShowOldPassword(!showOldPassword)} // _hover={{ bg: "transparent" }} bg={"transparent"} color={"#000"} height={"fit-content"} mr={2} > {showOldPassword ? : } } > setPassword(e.target.value)} size={"sm"} /> Confirm password setShowNewPassword(!showNewPassword)} bg={"transparent"} color={"#000"} mr={2} > {showNewPassword ? : } } > setConfirmPassword(e.target.value)} size={"sm"} />
); }; export default SetNewPassword;