diff --git a/apps/web/src/components/form-sheet-rhf.tsx b/apps/web/src/components/form-sheet-rhf.tsx index e52f7d0..f336e37 100644 --- a/apps/web/src/components/form-sheet-rhf.tsx +++ b/apps/web/src/components/form-sheet-rhf.tsx @@ -1,3 +1,4 @@ +import { useEffect } from 'react' import type { ReactNode } from 'react' import { useForm, @@ -42,6 +43,14 @@ export function FormSheetRhf({ mode: 'onBlur', }) + // Re-sync form values when the sheet opens or defaultValues change (e.g. edit vs create). + useEffect(() => { + if (open) { + form.reset(defaultValues as DefaultValues) + } + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [open, defaultValues]) + const submit: SubmitHandler = (values) => onSubmit(values) return ( diff --git a/apps/web/src/components/select-field.tsx b/apps/web/src/components/select-field.tsx new file mode 100644 index 0000000..8c49680 --- /dev/null +++ b/apps/web/src/components/select-field.tsx @@ -0,0 +1,107 @@ +import * as React from 'react' +import { + Select as SelectPrimitive, + type SelectRootProps, +} from '@base-ui/react/select' + +import { cn } from '@cfdm/ui/lib/utils' +import { ChevronDownIcon, CheckIcon, ChevronUpIcon } from 'lucide-react' + +export interface SelectOption { + value: string + label: React.ReactNode +} + +interface SelectFieldProps extends Omit, 'items' | 'value' | 'onValueChange'> { + options: SelectOption[] + placeholder?: string + triggerClassName?: string + triggerId?: string + size?: 'sm' | 'default' + value?: string | null + onValueChange?: (value: string | null) => void +} + +export function SelectField({ + options, + placeholder, + triggerClassName, + triggerId, + size = 'default', + value, + onValueChange, + ...props +}: SelectFieldProps) { + const items = React.useMemo(() => options.map((o) => ({ value: o.value, label: o.label })), [options]) + + return ( + + + + } + /> + + + + + + + + + {options.map((opt) => ( + + + {opt.label} + + + } + > + + + + ))} + + + + + + + + + ) +} diff --git a/apps/web/src/routes/_auth/accounts.tsx b/apps/web/src/routes/_auth/accounts.tsx index 07f30ad..3ab56c8 100644 --- a/apps/web/src/routes/_auth/accounts.tsx +++ b/apps/web/src/routes/_auth/accounts.tsx @@ -18,7 +18,7 @@ import { FormSheet } from '@/components/form-sheet' import { FormField } from '@/components/form-field' import { Input } from '@cfdm/ui/components/input' import { Textarea } from '@cfdm/ui/components/textarea' -import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@cfdm/ui/components/select' +import { SelectField } from '@/components/select-field' import { LoadingButton } from '@/components/loading-button' import type { ProviderAccount, BillingMode } from '@/types/entities' @@ -191,12 +191,13 @@ function AccountsPage() { submitting={saveMut.isPending} > - + setForm({ ...form, providerId: v ?? '' })} + options={(snapshot?.providers ?? []).map((p) => ({ value: p.id, label: p.name }))} + /> setForm({ ...form, name: e.target.value })} /> @@ -212,13 +213,15 @@ function AccountsPage() { setForm({ ...form, apiCredentials: e.target.value })} /> - + setForm({ ...form, billingMode: (v ?? 'monthly') as BillingMode })} + options={[ + { value: 'monthly', label: billingModeLabel('monthly') }, + { value: 'daily', label: billingModeLabel('daily') }, + ]} + />