import { useState } from "react" import { Button } from "@/components/ui/button" import { DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from "@/components/ui/dialog" import { Icons } from "@/components/Icons" import { type IUser } from "./type" import { useRouter } from "next/navigation" import useAxiosAuth from "@/lib/axios/useAxiosAuth" import { type ResponseData } from "@/types/types" import { toast } from "sonner" type Props = { data?: IUser onCancel?: () => any } export default function ResetPassword({ data, onCancel }: Props) { const [isLoading, setIsLoading] = useState(false) const router = useRouter() const axios = useAxiosAuth() const handleResetPassword = async () => { if (isLoading) return try { setIsLoading(true) const { data: res }: ResponseData = await axios.post('/user/reset-password', { nik: data?.nik }) setIsLoading(false) console.log(res) if (!res) return if (res.code === '00') { showSuccess(res.message) } else { showError(`Failed to reset password, ${res.message}`) } } catch (error: any) { console.log(error) showError(`Failed to reset password, (${error.response.data.code || error.response.status || '-'}) ${error.response.data.message || error.response.statusText || error.message}`) } } const showSuccess = (message: string) => { toast.success(message as string) router.refresh() onCancel!() }; const showError = (message?: string) => { setIsLoading(false) toast.error(message) }; return ( Confirm reset password This action will reset password for user {data?.fullname}, are you sure to continue this process? ) }