'use client' import { useState } from 'react' import { Button } from '../ui/button' import { Input } from '../ui/input' import { Label } from '../ui/label' import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '../ui/card' import { Loader2 } from 'lucide-react' export interface ProfileFormValues { firstName: string lastName: string email: string } export interface ProfileFormProps { initialValues: ProfileFormValues onSubmit: (values: { first_name: string; last_name: string }) => Promise disabled?: boolean } export function ProfileForm({ initialValues, onSubmit, disabled }: ProfileFormProps) { const [firstName, setFirstName] = useState(initialValues.firstName) const [lastName, setLastName] = useState(initialValues.lastName) const [saving, setSaving] = useState(false) const [error, setError] = useState(null) const [success, setSuccess] = useState(false) const hasChanges = firstName !== initialValues.firstName || lastName !== initialValues.lastName const handleSubmit = async (e: React.FormEvent) => { e.preventDefault() setError(null) setSuccess(false) setSaving(true) try { await onSubmit({ first_name: firstName.trim(), last_name: lastName.trim() }) setSuccess(true) setTimeout(() => setSuccess(false), 3000) } catch (err) { setError(err instanceof Error ? err.message : 'Failed to update profile') } finally { setSaving(false) } } return ( Profile Update your personal information.

Email cannot be changed.

setFirstName(e.target.value)} disabled={disabled || saving} placeholder="First name" />
setLastName(e.target.value)} disabled={disabled || saving} placeholder="Last name" />
{error && (

{error}

)} {success && (

Profile updated.

)}
) }