"use client"; import type { z } from "zod"; import { ActionButton } from "@/components/ui/action-button"; import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage, } from "@/components/ui/form"; import { Input } from "@/components/ui/input"; import { toast } from "@/components/ui/use-toast"; import { api } from "@/lib/trpc"; import { zodResolver } from "@hookform/resolvers/zod"; import { useForm } from "react-hook-form"; import { zChangePasswordSchema } from "@hoarder/shared/types/users"; export function ChangePassword() { const form = useForm>({ resolver: zodResolver(zChangePasswordSchema), defaultValues: { currentPassword: "", newPassword: "", newPasswordConfirm: "", }, }); const mutator = api.users.changePassword.useMutation({ onSuccess: () => { toast({ description: "Password changed successfully" }); form.reset(); }, onError: (e) => { if (e.data?.code == "UNAUTHORIZED") { toast({ description: "Your current password is incorrect", variant: "destructive", }); } else { toast({ description: "Something went wrong", variant: "destructive" }); } }, }); async function onSubmit(value: z.infer) { mutator.mutate({ currentPassword: value.currentPassword, newPassword: value.newPassword, }); } return (
Change Password
{ return ( Current Password ); }} /> { return ( New Password ); }} /> { return ( Confirm New Password ); }} /> Save
); }