"use client"; import React from "react"; import {Button} from "@/components/ui/button"; import {Input} from "@/components/ui/input"; import {Badge} from "@/components/ui/badge"; import {Loader2} from "lucide-react"; import { Form, FormControl, FormDescription, FormField, FormItem, FormLabel, FormMessage, useZodForm } from "@/components/ui/form"; import {useMutation} from "@tanstack/react-query"; import {toast} from "sonner"; import {useRouter} from "next/navigation"; import {updateProfileSettingsAction} from "./profile.action"; import {User} from "@/db/schema/02_user"; import {ProfileSchema, ProfileSchemaType} from "./general.schema"; import {AvatarWithUpload} from "@/features/profile/avatar-with-upload"; interface ProfileGeneralProps { user: User; } export function ProfileGeneral({user}: ProfileGeneralProps) { const router = useRouter(); const profileForm = useZodForm({ schema: ProfileSchema, defaultValues: { name: user.name || "", role: user.role || "", }, }); const {mutate: updateProfile, isPending: isUpdatingProfile} = useMutation({ mutationFn: async (values: ProfileSchemaType) => { const result = await updateProfileSettingsAction({name: values.name}); const inner = result?.data; if (inner?.success) { toast.success("Profile updated successfully."); router.refresh(); profileForm.reset({name: values.name, role: values.role}); } else { toast.error("Failed to update profile."); } }, }); return (

Profile Settings

Manage your personal information and preferences.

updateProfile(values)}>
( Display Name This is your public display name )} />
( Role & Permissions
)} />
); } function RoleBadge({role}: { role: string }) { const variant = role === "admin" ? "default" : "secondary"; return ( {role} ); }