import { Button } from "@/components/ui/button" import { Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger, } from "@/components/ui/dialog" import { Input } from "@/components/ui/input" import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage, } from "@/components/ui/form" import { ScrollArea } from "@/components/ui/scroll-area" import { useForm } from "react-hook-form" import { z } from "zod" import { zodResolver } from "@hookform/resolvers/zod" import { getProfile, updateProfile } from "@/api/user" import { useState } from "react" import { useMainStore } from "@/hooks/useMainStore" import { toast } from "sonner" import { useTranslation } from "react-i18next"; const profileFormSchema = z.object({ original_password: z.string().min(5).max(72), new_password: z.string().min(8).max(72), }); export const ProfileCard = ({ className }: { className: string }) => { const { t } = useTranslation(); const form = useForm>({ resolver: zodResolver(profileFormSchema), defaultValues: { original_password: '', new_password: '', }, resetOptions: { keepDefaultValues: false, } }) const { setProfile } = useMainStore(); const [open, setOpen] = useState(false); const onSubmit = async (values: z.infer) => { try { await updateProfile(values); } catch (e) { toast(t("Error"), { description: `${e}`, }) return; } const profile = await getProfile(); setProfile(profile); setOpen(false); form.reset(); } return (
{t("UpdatePassword")}
( {t("OriginalPassword")} )} /> ( {t("NewPassword")} )} />
) }