From 470ddc98c4fde9b7b881dd4b3c07289252bb2cb4 Mon Sep 17 00:00:00 2001 From: Yashas Date: Mon, 26 Oct 2026 16:44:29 +0530 Subject: [PATCH] Offer: valid-till is a date-time picker, never in the past Co-Authored-By: Claude Opus 5.5 --- src/screens/Enquiry.tsx | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/screens/Enquiry.tsx b/src/screens/Enquiry.tsx index 8a2f9c0..b4430a4 100644 --- a/src/screens/Enquiry.tsx +++ b/src/screens/Enquiry.tsx @@ -14,6 +14,12 @@ function fmtDateTime(v: string): string { if (!v || isNaN(d.getTime())) return ''; return d.toLocaleDateString('en-GB', { day: '2-digit', month: 'short', year: 'numeric' }) + ', ' + d.toTimeString().slice(0, 5); } +/** Now, in the datetime-local input's format, so a validity cannot be set in the past. */ +function nowLocal(): string { + const d = new Date(); + d.setMinutes(d.getMinutes() - d.getTimezoneOffset()); + return d.toISOString().slice(0, 16); +} /** A delivery window as the text the offer and the customer read: "12 Nov 2026, 06:00 - 12:00 IST". */ function fmtWindow(from: string, to: string): string { const a = fmtDateTime(from); @@ -248,18 +254,18 @@ function OpsForm({ e, onDone }: { e: Enquiry; onDone: () => void }) { function OfferForm({ e, onDone, revise, onCancel }: { e: Enquiry; onDone: () => void; revise: boolean; onCancel?: () => void }) { const { busy, error, ok, submit } = useSubmit(e, onDone); const [f, setF] = useState({ price: revise && e.price_usd_mt ? String(e.price_usd_mt) : '', basis: e.price_basis ?? `delivered ex-${e.supply_mode === 'pipeline' ? 'wharf' : 'barge'} ${e.port ?? ''}`.trim(), - valid: e.offer_valid_till ?? '', terms: e.payment_terms ?? '30 days from date of delivery', remarks: '' }); + valid: '', terms: e.payment_terms ?? '30 days from date of delivery', remarks: '' }); const [regret, setRegret] = useState(false); if (regret) return setRegret(false)} />; const sfx = revise ? 'revise' : 'offer'; return ( Your action}>
{ ev.preventDefault(); - const data: Record = { [`price_usd_mt__${sfx}`]: Number(f.price), [`offer_valid_till__${sfx}`]: f.valid, [`offer_remarks__${sfx}`]: f.remarks }; + const data: Record = { [`price_usd_mt__${sfx}`]: Number(f.price), [`offer_valid_till__${sfx}`]: fmtDateTime(f.valid) + ' IST', [`offer_remarks__${sfx}`]: f.remarks }; if (!revise) { data.price_basis__offer = f.basis; data.payment_terms__offer = f.terms; } submit(revise ? ACT.REVISE : ACT.OFFER, data); }}> setF({ ...f, price: x.target.value })} /> - setF({ ...f, valid: x.target.value })} /> + setF({ ...f, valid: x.target.value })} /> {!revise && setF({ ...f, basis: x.target.value })} />} {!revise && setF({ ...f, terms: x.target.value })} />}