'use client'; import { useState } from 'react'; import { Loader2, Pencil } from 'lucide-react'; import { toast } from 'sonner'; import { TimezoneCombobox } from '@/components/shared/timezone-combobox'; import { formatTimezoneLabel } from '@/lib/i18n/timezones'; import type { CountryCode } from '@/lib/i18n/countries'; import { cn } from '@/lib/utils'; interface InlineTimezoneFieldProps { value: string | null | undefined; onSave: (next: string | null) => Promise; /** Optional country to surface "Suggested" zones in the picker. */ countryHint?: CountryCode | null; emptyText?: string; disabled?: boolean; className?: string; 'data-testid'?: string; } export function InlineTimezoneField({ value, onSave, countryHint, emptyText = '—', disabled, className, 'data-testid': testId, }: InlineTimezoneFieldProps) { const [editing, setEditing] = useState(false); const [saving, setSaving] = useState(false); async function commit(next: string | null) { if (next === (value ?? null)) { setEditing(false); return; } setSaving(true); try { await onSave(next); setEditing(false); } catch (err) { toast.error(err instanceof Error ? err.message : 'Failed to save'); } finally { setSaving(false); } } if (editing) { return (
void commit(tz)} countryHint={countryHint ?? undefined} data-testid={testId} /> {saving && }
); } const display = value ? formatTimezoneLabel(value) : null; return ( ); }