All blocks
Two-Column Form
Responsive two-column vendor onboarding and payout profile form with sectioned Fieldset cards, paired field grids, live inline validation, dirty-state tracking, settlement cadence controls, Reset and Save footer actions, and Toaster confirmation feedback.
Built withAlertBadgeButtonCardCheckboxFieldFieldsetGridHeadingIconInputLinkSegment GroupSelectSeparatorStackStatusSwitchTextTextareaToast
Vendor Onboarding · AP-4029Profile synced
Vendor Onboarding & Payout Profile
Configure legal entity details, tax identifiers, and automated settlement instructions for Meridian Ledger disbursements.
Install
1npx stylexblocks add form-two-columnSource
components/blocks/ui-sdk/form-two-column.tsx
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342import * as stylex from "@stylexjs/stylex";import { useCallback, useMemo, useState } from "react";import { Alert } from "#components/ui/ui-sdk/alert.tsx";import { Badge } from "#components/ui/ui-sdk/badge.tsx";import { Button } from "#components/ui/ui-sdk/button.tsx";import { Card } from "#components/ui/ui-sdk/card.tsx";import { Checkbox } from "#components/ui/ui-sdk/checkbox.tsx";import { Field } from "#components/ui/ui-sdk/field.tsx";import { Fieldset } from "#components/ui/ui-sdk/fieldset.tsx";import { Grid } from "#components/ui/ui-sdk/grid.tsx";import { Heading } from "#components/ui/ui-sdk/heading.tsx";import { Icon } from "#components/ui/ui-sdk/icon.tsx";import { Input } from "#components/ui/ui-sdk/input.tsx";import { Link } from "#components/ui/ui-sdk/link.tsx";import { SegmentGroup } from "#components/ui/ui-sdk/segment-group.tsx";import { Select } from "#components/ui/ui-sdk/select.tsx";import { Separator } from "#components/ui/ui-sdk/separator.tsx";import { HStack, VStack } from "#components/ui/ui-sdk/stack.tsx";import { Status } from "#components/ui/ui-sdk/status.tsx";import { Switch } from "#components/ui/ui-sdk/switch.tsx";import { Text } from "#components/ui/ui-sdk/text.tsx";import { Textarea } from "#components/ui/ui-sdk/textarea.tsx";import { Toast, Toaster } from "#components/ui/ui-sdk/toast.tsx";import { semanticColors } from "@stylexblocks/ui/semantic-tokens/colors.stylex.ts";import { semanticRadii } from "@stylexblocks/ui/semantic-tokens/radii.stylex.ts";import { accentPalette, amberPalette, emeraldPalette, redPalette,} from "@stylexblocks/ui/themes/palettes.ts";import { fonts } from "@stylexblocks/ui/tokens/fonts.stylex.ts";import { lineHeights } from "@stylexblocks/ui/tokens/line-heights.stylex.ts";import { spacing } from "@stylexblocks/ui/tokens/spacing.stylex.ts";import type { StyleOverrideProps } from "#lib/recipe-props.ts";
// ── Types ─────────────────────────────────────────────────────────────────────
export type PayoutCadence = "weekly" | "biweekly" | "monthly" | "net30";
export interface FormSelectOption { value: string; label: string;}
export interface VendorSupportChannel { label: string; email: string;}
export interface VendorPayoutValues { legalName: string; tradeName: string; taxId: string; entityType: string; country: string; contactEmail: string; currency: string; payoutCadence: PayoutCadence; routingOrIban: string; swiftBic: string; accountReference: string; remittanceNotes: string; autoRemittance: boolean; complianceConfirmed: boolean;}
export interface VendorPayoutSavePayload { values: VendorPayoutValues; updatedFields: Array<keyof VendorPayoutValues>; savedAt: string;}
export interface FormTwoColumnProps extends StyleOverrideProps { /** Eyebrow badge rendered above the page title. */ eyebrow?: string; /** Primary display heading for the onboarding form. */ title?: string; /** Supporting subtitle beneath the heading. */ description?: string; /** Optional overrides merged onto the default vendor payout profile values. */ initialValues?: Partial<VendorPayoutValues>; /** Legal entity classification options. */ entityTypeOptions?: FormSelectOption[]; /** Country and tax jurisdiction options. */ countryOptions?: FormSelectOption[]; /** Supported disbursement currency options. */ currencyOptions?: FormSelectOption[]; /** Operations support contacts shown in the bottom strip. */ supportChannels?: VendorSupportChannel[]; /** Called with the validated payout profile when saved. */ onSaveProfile?: (payload: VendorPayoutSavePayload) => void; /** Called when unsaved edits are discarded via Reset. */ onResetProfile?: () => void;}
type ValidatedFieldKey = | "legalName" | "taxId" | "entityType" | "country" | "contactEmail" | "currency" | "routingOrIban" | "swiftBic" | "remittanceNotes" | "complianceConfirmed";
type FormErrors = Partial<Record<ValidatedFieldKey, string>>;
// ── Container Queries ─────────────────────────────────────────────────────────
const STACK_SECTIONS = "@container form-two-column (max-width: 820px)";const STACK_FIELDS = "@container form-two-column (max-width: 540px)";
// ── Demo Data & Constants ─────────────────────────────────────────────────────
const DEFAULT_ENTITY_TYPE_OPTIONS: FormSelectOption[] = [ { value: "llc", label: "Limited Liability Company (LLC)" }, { value: "corporation", label: "Corporation (C-Corp / S-Corp)" }, { value: "partnership", label: "General or Limited Partnership" }, { value: "sole-proprietor", label: "Sole Proprietorship" }, { value: "non-profit", label: "Non-Profit Organization" }, { value: "foreign-entity", label: "Non-US Foreign Entity" },];
const DEFAULT_COUNTRY_OPTIONS: FormSelectOption[] = [ { value: "US", label: "United States" }, { value: "GB", label: "United Kingdom" }, { value: "DE", label: "Germany" }, { value: "NL", label: "Netherlands" }, { value: "CA", label: "Canada" }, { value: "SG", label: "Singapore" }, { value: "AU", label: "Australia" }, { value: "JP", label: "Japan" },];
const DEFAULT_CURRENCY_OPTIONS: FormSelectOption[] = [ { value: "USD", label: "USD — US Dollar (ACH / Fedwire)" }, { value: "EUR", label: "EUR — Euro (SEPA Credit)" }, { value: "GBP", label: "GBP — British Pound (Faster Payments)" }, { value: "CAD", label: "CAD — Canadian Dollar (EFT)" }, { value: "SGD", label: "SGD — Singapore Dollar (FAST)" }, { value: "AUD", label: "AUD — Australian Dollar (NPP)" },];
const DEFAULT_SUPPORT_CHANNELS: VendorSupportChannel[] = [ { label: "Accounts payable", email: "ap-ops@meridianledger.example" }, { label: "Tax & W-9 compliance", email: "tax-compliance@meridianledger.example" }, { label: "Treasury & wire desk", email: "treasury@meridianledger.example" },];
const CADENCE_OPTIONS: Array<{ value: PayoutCadence; label: string; cutoff: string }> = [ { value: "weekly", label: "Weekly", cutoff: "Batched every Friday · invoice approval cutoff Thu 17:00 UTC.", }, { value: "biweekly", label: "Bi-weekly", cutoff: "Disbursed on the 1st and 15th · cutoff 24 hours prior.", }, { value: "monthly", label: "Monthly", cutoff: "Consolidated on the last business day of each calendar month.", }, { value: "net30", label: "Net-30", cutoff: "Settled automatically 30 calendar days after invoice verification.", },];
const CURRENCY_RAIL_HINTS: Record<string, { placeholder: string; hint: string; rail: string }> = { USD: { placeholder: "021000021", hint: "9-digit ABA routing number for domestic ACH or Fedwire.", rail: "ACH / Fedwire", }, EUR: { placeholder: "DE89 3704 0044 0532 0130 00", hint: "Standard SEPA IBAN (15–34 alphanumeric characters).", rail: "SEPA Credit", }, GBP: { placeholder: "GB29 NWBK 6016 1331 9268 19", hint: "UK IBAN or 6-digit sort code and 8-digit account number.", rail: "Faster Payments", }, CAD: { placeholder: "003-21451-8901234", hint: "Institution, transit, and account number for Canadian EFT.", rail: "Canadian EFT", }, SGD: { placeholder: "7171-048-901234", hint: "MAS bank code and account number for FAST settlement.", rail: "FAST Transfer", }, AUD: { placeholder: "062-000 10482910", hint: "6-digit BSB code and account number for NPP transfers.", rail: "NPP / BECS", },};
const DEFAULT_VALUES: VendorPayoutValues = { legalName: "Alder & Pine Logistics LLC", tradeName: "Alder Freight", taxId: "US-84-3910482", entityType: "llc", country: "US", contactEmail: "ap@alderfreight.example", currency: "USD", payoutCadence: "biweekly", routingOrIban: "021000021", swiftBic: "CHASUS33XXX", accountReference: "Operating Treasury ••4819", remittanceNotes: "Include PO number and invoice batch ID in wire memo for automated ledger reconciliation.", autoRemittance: true, complianceConfirmed: true,};
const VALUE_KEYS = Object.keys(DEFAULT_VALUES) as Array<keyof VendorPayoutValues>;const EMAIL_PATTERN = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;const TAX_ID_PATTERN = /^[A-Z0-9][A-Z0-9\-\s]{4,22}[A-Z0-9]$/i;const SWIFT_PATTERN = /^[A-Z]{6}[A-Z0-9]{2}([A-Z0-9]{3})?$/i;const REMITTANCE_MAX_LENGTH = 240;
function formatSavedTime(date: Date): string { return date.toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" });}
function validateValues(values: VendorPayoutValues): FormErrors { const errors: FormErrors = {}; const legalName = values.legalName.trim(); const taxId = values.taxId.trim(); const contactEmail = values.contactEmail.trim(); const routingCompact = values.routingOrIban.replace(/[\s-]/g, ""); const swiftCompact = values.swiftBic.trim();
if (!legalName) { errors.legalName = "Enter the registered legal entity name."; } else if (legalName.length < 2) { errors.legalName = "Legal name must be at least 2 characters."; }
if (!taxId) { errors.taxId = "Enter a valid EIN, SSN, or VAT registration ID."; } else if (!TAX_ID_PATTERN.test(taxId)) { errors.taxId = "Use 6–24 letters, digits, or hyphens (e.g. US-84-3910482)."; }
if (!values.entityType) { errors.entityType = "Select the vendor legal entity classification."; }
if (!values.country) { errors.country = "Select the tax residency country."; }
if (!contactEmail) { errors.contactEmail = "Enter a primary accounts payable email address."; } else if (!EMAIL_PATTERN.test(contactEmail)) { errors.contactEmail = "Enter a valid email address (e.g. ap@company.com)."; }
if (!values.currency) { errors.currency = "Choose a settlement currency."; }
if (!routingCompact) { errors.routingOrIban = "Enter a bank routing number or IBAN."; } else if (routingCompact.length < 8) { errors.routingOrIban = "Routing number or IBAN must contain at least 8 characters."; } else if (!/^[A-Z0-9]+$/i.test(routingCompact)) { errors.routingOrIban = "Use letters, digits, spaces, or hyphens only."; }
if (swiftCompact && !SWIFT_PATTERN.test(swiftCompact)) { errors.swiftBic = "SWIFT / BIC must be 8 or 11 alphanumeric characters."; }
if (values.remittanceNotes.length > REMITTANCE_MAX_LENGTH) { errors.remittanceNotes = `Keep remittance notes within ${REMITTANCE_MAX_LENGTH} characters.`; }
if (!values.complianceConfirmed) { errors.complianceConfirmed = "Confirm tax accuracy and payout authorization before saving changes."; }
return errors;}
// ── Inline SVG Icons ──────────────────────────────────────────────────────────
function ShieldCheckIcon() { return ( <Icon size="sm" viewBox="0 0 20 20" fill="none" stroke="currentColor" strokeWidth="1.65" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true" > <path d="M10 2.5 4 5v4.5c0 3.7 2.55 6.2 6 7 3.45-.8 6-3.3 6-7V5l-6-2.5Z" /> <path d="m7.5 10.25 1.75 1.75 3.5-3.75" /> </Icon> );}
function BankBuildingIcon() { return ( <Icon size="sm" viewBox="0 0 20 20" fill="none" stroke="currentColor" strokeWidth="1.65" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true" > <path d="M3 7.5 10 3.5l7 4" /> <path d="M3 16.5h14" /> <path d="M5.25 10v4.25M8.4 10v4.25M11.6 10v4.25M14.75 10v4.25" /> </Icon> );}
function AlertCircleIcon() { return ( <Icon size="inherit" viewBox="0 0 20 20" fill="none" stroke="currentColor" strokeWidth="1.75" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true" > <circle cx="10" cy="10" r="8" /> <path d="M10 6.5v4" /> <circle cx="10" cy="13.5" r="0.6" fill="currentColor" stroke="none" /> </Icon> );}
function RotateCcwIcon() { return ( <Icon size="sm" viewBox="0 0 20 20" fill="none" stroke="currentColor" strokeWidth="1.65" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true" > <path d="M4.25 8.25a6 6 0 1 1 1.4 5.75" /> <path d="M4.25 4.25v4h4" /> </Icon> );}
function CheckIcon() { return ( <Icon size="sm" viewBox="0 0 20 20" fill="none" stroke="currentColor" strokeWidth="1.85" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true" > <path d="m4.75 10.5 3.5 3.5 7-7.75" /> </Icon> );}
// ── Styles ────────────────────────────────────────────────────────────────────
const styles = stylex.create({ root: { backgroundColor: semanticColors.bg, color: semanticColors.fg, containerName: "form-two-column", containerType: "inline-size", fontFamily: fonts.body, minHeight: "100%", overflowY: "auto", width: "100%", }, container: { marginInline: "auto", maxWidth: "68rem", paddingBlock: { default: spacing._10, [STACK_FIELDS]: spacing._6, }, paddingInline: { default: spacing._8, [STACK_SECTIONS]: spacing._6, [STACK_FIELDS]: spacing._4, }, width: "100%", }, headerTitleGroup: { maxWidth: "44rem", }, headingReset: { marginBlock: 0, }, pageDescription: { lineHeight: lineHeights.md, }, leadingSm: { lineHeight: lineHeights.sm, }, fullWidth: { width: "100%", }, sectionRow: { columnGap: { default: spacing._10, [STACK_SECTIONS]: spacing._6, }, rowGap: { default: spacing._6, [STACK_SECTIONS]: spacing._4, }, gridTemplateColumns: { default: "minmax(15rem, 19rem) minmax(0, 1fr)", [STACK_SECTIONS]: "minmax(0, 1fr)", }, width: "100%", }, sectionAside: { paddingTop: { default: spacing._1, [STACK_SECTIONS]: 0, }, }, asideCallout: { backgroundColor: semanticColors.bgMuted, borderColor: semanticColors.border, borderRadius: semanticRadii.panel, borderStyle: "solid", borderWidth: "1px", color: semanticColors.fgMuted, paddingBlock: spacing._3, paddingInline: spacing._3_5, }, asideCalloutIcon: { color: semanticColors.fgSubtle, display: "inline-flex", flexShrink: 0, marginTop: "0.125rem", }, cardGap5: { gap: spacing._5, }, fieldGridTwo: { gridTemplateColumns: { default: "repeat(2, minmax(0, 1fr))", [STACK_FIELDS]: "minmax(0, 1fr)", }, width: "100%", }, labelRow: { gap: spacing._2, justifyContent: "space-between", width: "100%", }, monoInput: { fontFamily: fonts.mono, }, requiredStar: { lineHeight: 1, }, segmentWrap: { maxWidth: "100%", overflowX: "auto", }, textarea: { minHeight: "5.25rem", resize: "vertical", }, switchPanel: { alignItems: "center", backgroundColor: semanticColors.bgMuted, borderColor: semanticColors.border, borderRadius: semanticRadii.panel, borderStyle: "solid", borderWidth: "1px", display: "flex", gap: spacing._4, justifyContent: "space-between", paddingBlock: spacing._3_5, paddingInline: spacing._4, width: "100%", }, checkboxRoot: { alignItems: "flex-start", display: "flex", width: "100%", }, checkboxControlOffset: { marginTop: "0.125rem", }, actionBar: { backgroundColor: semanticColors.bgPanel, borderColor: semanticColors.border, borderRadius: semanticRadii.panel, borderStyle: "solid", borderWidth: "1px", paddingBlock: spacing._3_5, paddingInline: spacing._4, width: "100%", }, actionButtons: { marginInlineStart: "auto", }, supportSection: { paddingTop: spacing._1, width: "100%", }, supportGrid: { columnGap: spacing._6, rowGap: spacing._4, gridTemplateColumns: { default: "repeat(3, minmax(0, 1fr))", [STACK_FIELDS]: "minmax(0, 1fr)", }, width: "100%", }, supportColumn: { alignItems: { default: "center", [STACK_FIELDS]: "flex-start", }, textAlign: { default: "center", [STACK_FIELDS]: "start", }, },});
// ── Component ─────────────────────────────────────────────────────────────────
/** * FormTwoColumn — structured two-column vendor onboarding and payout profile * form pairing left-column section guidance with right-column `Fieldset` cards, * responsive two-column field grids, live inline validation, dirty-state * tracking, Reset / Save footer actions, and `Toaster` confirmation feedback. */export function FormTwoColumn({ eyebrow = "Vendor Onboarding · AP-4029", title = "Vendor Onboarding & Payout Profile", description = "Configure legal entity details, tax identifiers, and automated settlement instructions for Meridian Ledger disbursements.", initialValues, entityTypeOptions = DEFAULT_ENTITY_TYPE_OPTIONS, countryOptions = DEFAULT_COUNTRY_OPTIONS, currencyOptions = DEFAULT_CURRENCY_OPTIONS, supportChannels = DEFAULT_SUPPORT_CHANNELS, onSaveProfile, onResetProfile, palette, style,}: FormTwoColumnProps) { const queue = useMemo(() => Toast.createToaster(), []);
const startingValues = useMemo<VendorPayoutValues>( () => ({ ...DEFAULT_VALUES, ...initialValues }), [initialValues], );
const [savedValues, setSavedValues] = useState<VendorPayoutValues>(startingValues); const [draft, setDraft] = useState<VendorPayoutValues>(startingValues); const [touched, setTouched] = useState<Partial<Record<ValidatedFieldKey, boolean>>>({}); const [attemptedSubmit, setAttemptedSubmit] = useState(false); const [lastSavedAt, setLastSavedAt] = useState<string | null>(null);
const allErrors = useMemo(() => validateValues(draft), [draft]);
const visibleErrors = useMemo<FormErrors>(() => { const out: FormErrors = {}; for (const [key, message] of Object.entries(allErrors) as Array< [ValidatedFieldKey, string | undefined] >) { if (message && (attemptedSubmit || touched[key])) { out[key] = message; } } return out; }, [allErrors, attemptedSubmit, touched]);
const visibleErrorCount = Object.keys(visibleErrors).length;
const modifiedFields = useMemo( () => VALUE_KEYS.filter((key) => draft[key] !== savedValues[key]), [draft, savedValues], ); const isDirty = modifiedFields.length > 0;
const updateField = useCallback( <K extends keyof VendorPayoutValues>(field: K, value: VendorPayoutValues[K]) => { setDraft((prev) => ({ ...prev, [field]: value })); }, [], );
const markTouched = useCallback((field: ValidatedFieldKey) => { setTouched((prev) => (prev[field] ? prev : { ...prev, [field]: true })); }, []);
const activeRail = CURRENCY_RAIL_HINTS[draft.currency] ?? CURRENCY_RAIL_HINTS.USD!; const activeCadence = CADENCE_OPTIONS.find((opt) => opt.value === draft.payoutCadence) ?? CADENCE_OPTIONS[1]!;
const handleReset = useCallback(() => { setDraft(savedValues); setTouched({}); setAttemptedSubmit(false); onResetProfile?.(); queue.info("Changes discarded", { description: "Restored the last saved vendor payout profile.", }); }, [onResetProfile, queue, savedValues]);
const handleSubmit = useCallback( (event: React.FormEvent<HTMLFormElement>) => { event.preventDefault(); setAttemptedSubmit(true);
const currentErrors = validateValues(draft); const errorEntries = Object.values(currentErrors).filter(Boolean); if (errorEntries.length > 0) { queue.error("Fix validation issues before saving", { description: errorEntries.length === 1 ? "1 field needs attention before the payout profile can be saved." : `${errorEntries.length} fields need attention before the payout profile can be saved.`, }); return; }
const normalized: VendorPayoutValues = { ...draft, legalName: draft.legalName.trim(), tradeName: draft.tradeName.trim(), taxId: draft.taxId.trim().toUpperCase(), contactEmail: draft.contactEmail.trim(), routingOrIban: draft.routingOrIban.trim().toUpperCase(), swiftBic: draft.swiftBic.trim().toUpperCase(), accountReference: draft.accountReference.trim(), remittanceNotes: draft.remittanceNotes.trim(), };
const changed = VALUE_KEYS.filter((key) => normalized[key] !== savedValues[key]); const timestamp = formatSavedTime(new Date());
setSavedValues(normalized); setDraft(normalized); setTouched({}); setAttemptedSubmit(false); setLastSavedAt(timestamp);
onSaveProfile?.({ values: normalized, updatedFields: changed, savedAt: timestamp, });
queue.success("Payout profile saved", { description: changed.length === 0 ? `${normalized.legalName} verified for ${normalized.currency} settlements (${timestamp}).` : `Updated ${changed.length} ${changed.length === 1 ? "field" : "fields"} for ${normalized.legalName} (${normalized.currency} · ${activeCadence.label}).`, }); }, [activeCadence.label, draft, onSaveProfile, queue, savedValues], );
const handleSupportLinkClick = useCallback( (channel: VendorSupportChannel) => (event: React.MouseEvent<HTMLAnchorElement>) => { event.preventDefault(); queue.info(`${channel.label} desk`, { description: `Reach ${channel.email} with vendor reference AP-4029 for priority routing.`, }); }, [queue], );
const headerStatus = visibleErrorCount > 0 ? ( <Status.Root size="sm" palette={redPalette}> <Status.Indicator /> <Text render={<span />} size="xs" tone="muted" tabular="true"> {visibleErrorCount === 1 ? "1 validation issue" : `${visibleErrorCount} validation issues`} </Text> </Status.Root> ) : isDirty ? ( <Status.Root size="sm" palette={amberPalette}> <Status.Indicator /> <Text render={<span />} size="xs" tone="muted" tabular="true"> {modifiedFields.length === 1 ? "1 unsaved change" : `${modifiedFields.length} unsaved changes`} </Text> </Status.Root> ) : ( <Status.Root size="sm" palette={emeraldPalette}> <Status.Indicator /> <Text render={<span />} size="xs" tone="muted" tabular="true"> {lastSavedAt ? `Saved at ${lastSavedAt}` : "Profile synced"} </Text> </Status.Root> );
return ( <VStack gap="0" palette={palette} style={[styles.root, style]}> <VStack render={<main />} gap="8" style={styles.container}> {/* Page Header */} <VStack render={<header />} gap="3"> <HStack wrap="wrap" justify="between" gap="3"> {eyebrow ? ( <Badge variant="subtle" size="sm" palette={accentPalette}> {eyebrow} </Badge> ) : null} {headerStatus} </HStack>
<VStack gap="1.5" style={styles.headerTitleGroup}> <Heading render={<h1 />} size="3xl" style={styles.headingReset}> {title} </Heading> <Text variant="muted" size="sm" style={styles.pageDescription}> {description} </Text> </VStack> </VStack>
<Separator decorative />
{/* Two-Column Sectioned Form */} <VStack render={<form noValidate onSubmit={handleSubmit} />} gap="8" style={styles.fullWidth} > {/* Section 1: Organization Details */} <Grid render={<section aria-labelledby="vendor-org-heading" />} align="start" style={styles.sectionRow} > <VStack gap="3" style={styles.sectionAside}> <HStack gap="2"> <Badge variant="outline" size="xs" palette={accentPalette}> 01 </Badge> <Heading id="vendor-org-heading" size="lg" style={styles.headingReset}> Organization details </Heading> </HStack> <Text variant="muted" size="sm"> Legal identity, tax classification, and primary billing contact printed on 1099, VAT statements, and remittance records. </Text> <HStack align="start" gap="2.5" style={styles.asideCallout}> <span {...stylex.props(styles.asideCalloutIcon)}> <ShieldCheckIcon /> </span> <VStack gap="1"> <Text render={<span />} size="xs" weight="medium"> Automated TIN verification </Text> <Text variant="muted" size="xs" style={styles.leadingSm}> Tax identifiers are matched against IRS / VIES registries before the first scheduled disbursement. </Text> </VStack> </HStack> </VStack>
<Card.Root variant="outline" size="lg"> <Card.Body style={styles.cardGap5}> <Fieldset.Root size="md"> <Fieldset.Legend>Legal entity & tax identity</Fieldset.Legend> <Fieldset.Content style={styles.cardGap5}> <Grid columns="2" gap="4" style={styles.fieldGridTwo}> <Field.Root required invalid={Boolean(visibleErrors.legalName)}> <Field.Label> Legal name <Field.RequiredIndicator /> </Field.Label> <Input autoComplete="organization" placeholder="Alder & Pine Logistics LLC" value={draft.legalName} onValueChange={(next) => { updateField("legalName", next); markTouched("legalName"); }} onBlur={() => markTouched("legalName")} /> {visibleErrors.legalName ? ( <Field.Error match>{visibleErrors.legalName}</Field.Error> ) : null} </Field.Root>
<Field.Root> <Field.Label style={styles.labelRow}> <span>Trade name / DBA</span> <Text render={<span />} size="xs" tone="subtle" weight="normal"> Optional </Text> </Field.Label> <Input placeholder="Alder Freight" value={draft.tradeName} onValueChange={(next) => updateField("tradeName", next)} /> </Field.Root> </Grid>
<Grid columns="2" gap="4" style={styles.fieldGridTwo}> <Field.Root required invalid={Boolean(visibleErrors.taxId)}> <Field.Label> Tax ID / VAT <Field.RequiredIndicator /> </Field.Label> <Input placeholder="US-84-3910482" value={draft.taxId} onValueChange={(next) => { updateField("taxId", next); markTouched("taxId"); }} onBlur={() => markTouched("taxId")} style={styles.monoInput} /> {visibleErrors.taxId ? ( <Field.Error match>{visibleErrors.taxId}</Field.Error> ) : ( <Field.Description>EIN, SSN, or EU/UK VAT registration.</Field.Description> )} </Field.Root>
<Field.Root required invalid={Boolean(visibleErrors.entityType)}> <Field.Label> Entity type <Field.RequiredIndicator /> </Field.Label> <Select.Root items={entityTypeOptions} value={draft.entityType || null} onValueChange={(next) => { updateField("entityType", next ?? ""); markTouched("entityType"); }} style={styles.fullWidth} > <Select.Control> <Select.Trigger onBlur={() => markTouched("entityType")}> <Select.Value placeholder="Select entity type" /> </Select.Trigger> <Select.IndicatorGroup> <Select.Icon /> </Select.IndicatorGroup> </Select.Control> <Select.Content> {entityTypeOptions.map((option) => ( <Select.Item key={option.value} value={option.value}> <Select.ItemText>{option.label}</Select.ItemText> <Select.ItemIndicator /> </Select.Item> ))} </Select.Content> </Select.Root> {visibleErrors.entityType ? ( <Field.Error match>{visibleErrors.entityType}</Field.Error> ) : null} </Field.Root> </Grid>
<Grid columns="2" gap="4" style={styles.fieldGridTwo}> <Field.Root required invalid={Boolean(visibleErrors.country)}> <Field.Label> Country / Jurisdiction <Field.RequiredIndicator /> </Field.Label> <Select.Root items={countryOptions} value={draft.country || null} onValueChange={(next) => { updateField("country", next ?? ""); markTouched("country"); }} style={styles.fullWidth} > <Select.Control> <Select.Trigger onBlur={() => markTouched("country")}> <Select.Value placeholder="Select country" /> </Select.Trigger> <Select.IndicatorGroup> <Select.Icon /> </Select.IndicatorGroup> </Select.Control> <Select.Content> {countryOptions.map((option) => ( <Select.Item key={option.value} value={option.value}> <Select.ItemText>{option.label}</Select.ItemText> <Select.ItemIndicator /> </Select.Item> ))} </Select.Content> </Select.Root> {visibleErrors.country ? ( <Field.Error match>{visibleErrors.country}</Field.Error> ) : null} </Field.Root>
<Field.Root required invalid={Boolean(visibleErrors.contactEmail)}> <Field.Label> Primary contact email <Field.RequiredIndicator /> </Field.Label> <Input type="email" autoComplete="email" placeholder="ap@alderfreight.example" value={draft.contactEmail} onValueChange={(next) => { updateField("contactEmail", next); markTouched("contactEmail"); }} onBlur={() => markTouched("contactEmail")} /> {visibleErrors.contactEmail ? ( <Field.Error match>{visibleErrors.contactEmail}</Field.Error> ) : null} </Field.Root> </Grid> </Fieldset.Content> </Fieldset.Root> </Card.Body> </Card.Root> </Grid>
<Separator decorative />
{/* Section 2: Settlement & Compliance */} <Grid render={<section aria-labelledby="vendor-settlement-heading" />} align="start" style={styles.sectionRow} > <VStack gap="3" style={styles.sectionAside}> <HStack gap="2"> <Badge variant="outline" size="xs" palette={accentPalette}> 02 </Badge> <Heading id="vendor-settlement-heading" size="lg" style={styles.headingReset}> Settlement & compliance </Heading> </HStack> <Text variant="muted" size="sm"> Define disbursement currency, payout cadence, and receiving bank coordinates. Updating routing details triggers a micro-deposit check. </Text>
<HStack align="start" gap="2.5" style={styles.asideCallout}> <span {...stylex.props(styles.asideCalloutIcon)}> <BankBuildingIcon /> </span> <VStack gap="1"> <Text render={<span />} size="xs" weight="medium"> Active settlement rail </Text> <HStack wrap="wrap" gap="1.5"> <Badge variant="subtle" size="xs" palette={accentPalette}> {draft.currency || "USD"} </Badge> <Badge variant="surface" size="xs"> {activeRail.rail} </Badge> <Badge variant="surface" size="xs"> {activeCadence.label} </Badge> </HStack> <Text variant="muted" size="xs" style={styles.leadingSm}> {activeCadence.cutoff} </Text> </VStack> </HStack> </VStack>
<Card.Root variant="outline" size="lg"> <Card.Body style={styles.cardGap5}> <Fieldset.Root size="md"> <Fieldset.Legend>Disbursement rails & authorization</Fieldset.Legend> <Fieldset.Content style={styles.cardGap5}> <Grid columns="2" gap="4" style={styles.fieldGridTwo}> <Field.Root required invalid={Boolean(visibleErrors.currency)}> <Field.Label> Settlement currency <Field.RequiredIndicator /> </Field.Label> <Select.Root items={currencyOptions} value={draft.currency || null} onValueChange={(next) => { updateField("currency", next ?? ""); markTouched("currency"); }} style={styles.fullWidth} > <Select.Control> <Select.Trigger onBlur={() => markTouched("currency")}> <Select.Value placeholder="Select currency" /> </Select.Trigger> <Select.IndicatorGroup> <Select.Icon /> </Select.IndicatorGroup> </Select.Control> <Select.Content> {currencyOptions.map((option) => ( <Select.Item key={option.value} value={option.value}> <Select.ItemText>{option.label}</Select.ItemText> <Select.ItemIndicator /> </Select.Item> ))} </Select.Content> </Select.Root> {visibleErrors.currency ? ( <Field.Error match>{visibleErrors.currency}</Field.Error> ) : null} </Field.Root>
<Field.Root required invalid={Boolean(visibleErrors.routingOrIban)}> <Field.Label> Routing number / IBAN <Field.RequiredIndicator /> </Field.Label> <Input placeholder={activeRail.placeholder} value={draft.routingOrIban} onValueChange={(next) => { updateField("routingOrIban", next); markTouched("routingOrIban"); }} onBlur={() => markTouched("routingOrIban")} style={styles.monoInput} /> {visibleErrors.routingOrIban ? ( <Field.Error match>{visibleErrors.routingOrIban}</Field.Error> ) : ( <Field.Description>{activeRail.hint}</Field.Description> )} </Field.Root> </Grid>
<VStack gap="2" style={styles.fullWidth}> <HStack render={<span id="vendor-payout-cadence-label" />} gap="1"> <Text render={<span />} variant="label" size="sm"> Payout cadence </Text> <Text render={<span />} size="sm" tone="error" style={styles.requiredStar} aria-hidden="true" > * </Text> </HStack> <div {...stylex.props(styles.segmentWrap)}> <SegmentGroup.Root size="sm" value={draft.payoutCadence} onValueChange={(next) => updateField("payoutCadence", next as PayoutCadence) } aria-labelledby="vendor-payout-cadence-label" > {CADENCE_OPTIONS.map((option) => ( <SegmentGroup.Item key={option.value} value={option.value}> {option.label} </SegmentGroup.Item> ))} </SegmentGroup.Root> </div> <Text variant="muted" size="xs" style={styles.leadingSm}> {activeCadence.cutoff} </Text> </VStack>
<Grid columns="2" gap="4" style={styles.fieldGridTwo}> <Field.Root invalid={Boolean(visibleErrors.swiftBic)}> <Field.Label style={styles.labelRow}> <span>SWIFT / BIC</span> <Text render={<span />} size="xs" tone="subtle" weight="normal"> Optional </Text> </Field.Label> <Input placeholder="CHASUS33XXX" value={draft.swiftBic} onValueChange={(next) => { updateField("swiftBic", next); markTouched("swiftBic"); }} onBlur={() => markTouched("swiftBic")} style={styles.monoInput} /> {visibleErrors.swiftBic ? ( <Field.Error match>{visibleErrors.swiftBic}</Field.Error> ) : ( <Field.Description>Required only for cross-border wires.</Field.Description> )} </Field.Root>
<Field.Root> <Field.Label style={styles.labelRow}> <span>Account reference</span> <Text render={<span />} size="xs" tone="subtle" weight="normal"> Optional </Text> </Field.Label> <Input placeholder="Operating Treasury ••4819" value={draft.accountReference} onValueChange={(next) => updateField("accountReference", next)} /> <Field.Description>Internal nickname shown on payout logs.</Field.Description> </Field.Root> </Grid>
<Field.Root invalid={Boolean(visibleErrors.remittanceNotes)}> <Field.Label style={styles.labelRow}> <span>Remittance notes</span> <Text render={<span />} size="xs" tone={ draft.remittanceNotes.length > REMITTANCE_MAX_LENGTH ? "error" : "subtle" } weight={ draft.remittanceNotes.length > REMITTANCE_MAX_LENGTH ? "medium" : "normal" } tabular="true" > {draft.remittanceNotes.length} / {REMITTANCE_MAX_LENGTH} </Text> </Field.Label> <Textarea rows={3} placeholder="Include PO references, cost center codes, or reconciliation instructions…" value={draft.remittanceNotes} onValueChange={(next) => { updateField("remittanceNotes", next); markTouched("remittanceNotes"); }} onBlur={() => markTouched("remittanceNotes")} style={styles.textarea} /> {visibleErrors.remittanceNotes ? ( <Field.Error match>{visibleErrors.remittanceNotes}</Field.Error> ) : ( <Field.Description> Appended to wire memos and automated ACH addenda records. </Field.Description> )} </Field.Root>
<Switch.Root size="md" palette={accentPalette} style={styles.switchPanel}> <VStack render={<span />} gap="0.5"> <Text render={<span />} size="sm" weight="medium"> Email PDF remittance advice </Text> <Text render={<span />} variant="muted" size="xs" style={styles.leadingSm} > Automatically deliver itemized invoice statements to{" "} {draft.contactEmail.trim() || "the primary contact"} on each payout. </Text> </VStack> <Switch.Control checked={draft.autoRemittance} onCheckedChange={(checked) => updateField("autoRemittance", checked)} /> </Switch.Root>
<Field.Root required invalid={Boolean(visibleErrors.complianceConfirmed)}> <Checkbox.Root size="md" palette={accentPalette} style={styles.checkboxRoot}> <Checkbox.Control checked={draft.complianceConfirmed} onCheckedChange={(next) => { updateField("complianceConfirmed", next === true); markTouched("complianceConfirmed"); }} style={styles.checkboxControlOffset} /> <Checkbox.Label> <VStack render={<span />} gap="0.5"> <Text render={<span />} size="sm" weight="medium"> Confirm tax accuracy & payout authorization </Text> <Text render={<span />} variant="muted" size="xs" weight="normal" style={styles.leadingSm} > I certify that the legal entity and tax ID above are accurate under W-9 / W-8BEN-E and authorize Meridian Ledger to initiate settlements to this bank account. </Text> </VStack> </Checkbox.Label> </Checkbox.Root> {visibleErrors.complianceConfirmed ? ( <Field.Error match>{visibleErrors.complianceConfirmed}</Field.Error> ) : null} </Field.Root> </Fieldset.Content> </Fieldset.Root> </Card.Body> </Card.Root> </Grid>
{/* Footer Action Bar */} <VStack gap="4" style={styles.fullWidth}> {attemptedSubmit && visibleErrorCount > 0 ? ( <Alert.Root status="error" variant="subtle" size="sm" palette={redPalette}> <Alert.Indicator> <AlertCircleIcon /> </Alert.Indicator> <Alert.Content> <Alert.Title> {visibleErrorCount === 1 ? "1 required field needs attention before saving." : `${visibleErrorCount} fields need attention before saving.`} </Alert.Title> </Alert.Content> </Alert.Root> ) : null}
<HStack wrap="wrap" justify="between" gap="4" style={styles.actionBar}> {isDirty ? ( <Status.Root size="sm" palette={amberPalette}> <Status.Indicator /> <Text render={<span />} size="xs" tone="muted" tabular="true"> {modifiedFields.length === 1 ? "1 unsaved change — reset or save to apply." : `${modifiedFields.length} unsaved changes — reset or save to apply.`} </Text> </Status.Root> ) : ( <Status.Root size="sm" palette={emeraldPalette}> <Status.Indicator /> <Text render={<span />} size="xs" tone="muted" tabular="true"> {lastSavedAt ? `All payout details saved at ${lastSavedAt}.` : "All payout details match the active disbursement profile."} </Text> </Status.Root> )}
<HStack wrap="wrap" gap="2.5" style={styles.actionButtons}> <Button type="button" variant="outline" size="md" disabled={!isDirty && !attemptedSubmit} onClick={handleReset} > <RotateCcwIcon /> Reset </Button> <Button type="submit" variant="solid" size="md" palette={accentPalette}> <CheckIcon /> Save payout profile </Button> </HStack> </HStack> </VStack> </VStack>
{/* Bottom Operations Contact Strip */} <VStack render={<footer />} gap="5" style={styles.supportSection}> <Separator decorative /> <Grid columns="3" style={styles.supportGrid}> {supportChannels.map((channel) => ( <VStack key={channel.label} gap="1" style={styles.supportColumn}> <Text render={<span />} variant="caption"> {channel.label} </Text> <Link href={`mailto:${channel.email}`} variant="underline" palette={accentPalette} onClick={handleSupportLinkClick(channel)} > {channel.email} </Link> </VStack> ))} </Grid> </VStack> </VStack>
<Toaster toaster={queue} /> </VStack> );}
Inspired by the Two-column Form template from Astryx (MIT License · Copyright (c) 2026 Meta Platforms, Inc.).