"use client"; import { useActionState, useEffect } from "react"; import { toast } from "sonner"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { updateProfile, changePassword, type MeState } from "./actions"; function useToastOnDone(state: MeState, okMsg: string) { useEffect(() => { if (state.ok) toast.success(okMsg); else if (state.error) toast.error(state.error); }, [state, okMsg]); } export function ProfileForm({ nickname, username }: { nickname: string; username: string }) { const [state, action, pending] = useActionState(updateProfile, {}); useToastOnDone(state, "资料已更新"); return (
); } export function PasswordForm() { const [state, action, pending] = useActionState(changePassword, {}); useToastOnDone(state, "密码已修改"); return (
); }