"use client"; import InputField from "@/components/global/form-field/input-field"; import { Button } from "@/components/ui/button"; import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from "@/components/ui/dialog"; import { useChangePasswordMutation } from "@/features/auth/queries/auth.mutations"; import { changePasswordZodSchema, type IChangePasswordPayload, } from "@/features/auth/validators/change-password.validator"; import { zodResolver } from "@hookform/resolvers/zod"; import { Loader2 } from "lucide-react"; import { FormProvider, useForm } from "react-hook-form"; interface ChangePasswordDialogProps { open: boolean; onOpenChange: (open: boolean) => void; } export default function ChangePasswordDialog({ open, onOpenChange, }: ChangePasswordDialogProps) { const mutation = useChangePasswordMutation(); const form = useForm({ mode: "onTouched", resolver: zodResolver(changePasswordZodSchema), defaultValues: { currentPassword: "", newPassword: "", confirmPassword: "", }, }); async function onSubmit(values: IChangePasswordPayload) { try { await mutation.mutateAsync({ currentPassword: values.currentPassword, newPassword: values.newPassword, }); form.reset(); onOpenChange(false); } catch {} } return ( Change Password Enter your current password and choose a new one. Password must be at least 8 characters.
); }