"use client"; import { useState } from "react"; import { Input } from "@/components/ui/input"; import { Button } from "@/components/ui/button"; import Swal from "sweetalert2"; import withReactContent from "sweetalert2-react-content"; import { useRouter } from "next/navigation"; import { forgotPassword } from "@/service/auth"; const MySwal = withReactContent(Swal); export default function ForgotPass() { const [username, setUsername] = useState(""); const [loading, setLoading] = useState(false); const router = useRouter(); const handleForgot = async (e: React.FormEvent) => { e.preventDefault(); if (!username.trim()) { MySwal.fire({ icon: "warning", title: "Oops...", text: "Username tidak boleh kosong!", }); return; } setLoading(true); try { const payload = { username }; const res = await forgotPassword(payload); if (!res.error) { MySwal.fire({ icon: "success", title: "Berhasil!", text: "Instruksi reset password telah dikirim ke EMAIL Anda.", timer: 2500, timerProgressBar: true, showConfirmButton: false, }); setTimeout(() => { router.push("/auth"); }, 3000); setUsername(""); } else { MySwal.fire({ icon: "error", title: "Gagal", text: res.message || "Gagal mengirim instruksi reset password.", }); } } catch (err) { console.error(err); MySwal.fire({ icon: "error", title: "Error", text: "Terjadi kesalahan pada sistem.", }); } finally { setLoading(false); } }; return (
setUsername(e.target.value)} className="w-full h-11 px-4 text-base border-gray-300 focus:border-blue-500 focus:ring-2 focus:ring-blue-400 focus:outline-none transition-all duration-200" />

Masukkan username yang terdaftar untuk menerima tautan reset.

); } // "use client"; // import { useState } from "react"; // import { Input } from "@/components/ui/input"; // import { Button } from "@/components/ui/button"; // import Swal from "sweetalert2"; // import withReactContent from "sweetalert2-react-content"; // import { useRouter } from "next/navigation"; // import { forgotPassword } from "@/service/auth"; // pastikan path sesuai // const MySwal = withReactContent(Swal); // export default function ForgotPass() { // const [username, setUsername] = useState(""); // const [loading, setLoading] = useState(false); // const router = useRouter(); // const handleForgot = async (e: React.FormEvent) => { // e.preventDefault(); // if (!username.trim()) { // MySwal.fire({ // icon: "warning", // title: "Oops...", // text: "Username tidak boleh kosong!", // }); // return; // } // setLoading(true); // try { // const payload = { username }; // const res = await forgotPassword(payload); // if (!res.error) { // MySwal.fire({ // icon: "success", // title: "Berhasil!", // text: "Instruksi reset password telah dikirim ke EMAIL Anda.", // timer: 2500, // timerProgressBar: true, // showConfirmButton: false, // }); // setTimeout(() => { // router.push("/auth"); // }, 3000); // setUsername(""); // } else { // MySwal.fire({ // icon: "error", // title: "Gagal", // text: res.message || "Gagal mengirim instruksi reset password.", // }); // } // } catch (err) { // console.error(err); // MySwal.fire({ // icon: "error", // title: "Error", // text: "Terjadi kesalahan pada sistem.", // }); // } finally { // setLoading(false); // } // }; // return ( //
//
// // setUsername(e.target.value)} // className="w-full h-11" // /> //
// //
// ); // }