import { useEffect, useMemo, useState, type FormEvent } from 'react'; import type { Customer, CustomerAddress } from '@model/shared'; import { changeCustomer, resolveCustomerConflict, type LocalAddress, type LocalCustomer, type LocalDelivery, type OutboxEntry } from './db'; type CustomerData = Omit; const windowLabels = { morning: 'בוקר', afternoon: 'צהריים', lateNight: 'לילה' } as const; const windowDefaults = { morning: ['08:00', '12:00'], afternoon: ['12:00', '17:00'], lateNight: ['20:00', '23:00'] } as const; function dataFromForm(form: HTMLFormElement): CustomerData { const fields = new FormData(form); const deliveryWindows = Object.fromEntries(Object.entries(windowDefaults).map(([key, defaults]) => [key, fields.get(`${key}Enabled`) === 'on' ? { start: String(fields.get(`${key}Start`) || defaults[0]), end: String(fields.get(`${key}End`) || defaults[1]) } : null])) as CustomerData['deliveryWindows']; return { name: String(fields.get('name') ?? ''), contactName: String(fields.get('contactName') ?? ''), phone: String(fields.get('phone') ?? ''), comments: String(fields.get('comments') ?? ''), deliveryWindows }; } function CustomerForm({ customer, busy, submit, cancel }: { customer?: LocalCustomer; busy: boolean; submit: (data: CustomerData) => Promise; cancel?: () => void }) { return
{ event.preventDefault(); void submit(dataFromForm(event.currentTarget)); }}>
חלונות מסירה מועדפים{(Object.keys(windowLabels) as Array).map(key => { const value = customer?.deliveryWindows[key]; const defaults = windowDefaults[key]; return
עד
; })}