From 7c798a063c3dc1f783fd31c7c8b90cc6b60ec6bb Mon Sep 17 00:00:00 2001 From: James Grugett Date: Sun, 28 Aug 2022 00:35:22 -0500 Subject: [PATCH] Improve edit close date UI --- web/components/contract/contract-details.tsx | 35 ++++++++++++++------ 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/web/components/contract/contract-details.tsx b/web/components/contract/contract-details.tsx index 354f4394..7705b538 100644 --- a/web/components/contract/contract-details.tsx +++ b/web/components/contract/contract-details.tsx @@ -191,7 +191,7 @@ export function ContractDetails(props: { )} @@ -277,14 +276,22 @@ function EditableCloseDate(props: { const [isEditingCloseTime, setIsEditingCloseTime] = useState(false) const [closeDate, setCloseDate] = useState( - closeTime && dayJsCloseTime.format('YYYY-MM-DDTHH:mm') + closeTime && dayJsCloseTime.format('YYYY-MM-DD') ) + const [closeHoursMinutes, setCloseHoursMinutes] = useState( + closeTime && dayJsCloseTime.format('HH:mm') + ) + + const newCloseTime = closeDate + ? dayjs(`${closeDate}T${closeHoursMinutes}`).valueOf() + : undefined const isSameYear = dayJsCloseTime.isSame(dayJsNow, 'year') const isSameDay = dayJsCloseTime.isSame(dayJsNow, 'day') const onSave = () => { - const newCloseTime = dayjs(closeDate).valueOf() + if (!newCloseTime) return + if (newCloseTime === closeTime) setIsEditingCloseTime(false) else if (newCloseTime > Date.now()) { const content = contract.description @@ -309,16 +316,24 @@ function EditableCloseDate(props: { return ( <> {isEditingCloseTime ? ( -
+ e.stopPropagation()} - onChange={(e) => setCloseDate(e.target.value || '')} + onChange={(e) => setCloseDate(e.target.value)} min={Date.now()} value={closeDate} /> -
+ e.stopPropagation()} + onChange={(e) => setCloseHoursMinutes(e.target.value)} + min="00:00" + value={closeHoursMinutes} + /> + ) : ( Date.now() ? 'Trading ends:' : 'Trading ended:'} @@ -342,7 +357,7 @@ function EditableCloseDate(props: { color={'gray-white'} onClick={() => setIsEditingCloseTime(true)} > - Edit + ))}