Skip to content

Commit 38c43c1

Browse files
time placeholder
1 parent 770a41c commit 38c43c1

2 files changed

Lines changed: 39 additions & 15 deletions

File tree

src/app/components/CreateEventModal.tsx

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,30 @@ type CreateEventFormState = {
2222
description: string
2323
}
2424

25-
const initialFormState: CreateEventFormState = {
26-
orgId: '',
27-
title: '',
28-
location: '',
29-
eventTime: '',
30-
description: '',
25+
function getCurrentDateTimeInputValue() {
26+
const now = new Date()
27+
now.setSeconds(0, 0)
28+
29+
const timezoneOffset = now.getTimezoneOffset()
30+
const localDate = new Date(now.getTime() - timezoneOffset * 60_000)
31+
return localDate.toISOString().slice(0, 16)
32+
}
33+
34+
function createInitialFormState(): CreateEventFormState {
35+
return {
36+
orgId: '',
37+
title: '',
38+
location: '',
39+
eventTime: getCurrentDateTimeInputValue(),
40+
description: '',
41+
}
3142
}
3243

3344
function toEventTimeISOString(value: string) {
34-
if (!value) return undefined
45+
if (!value) return null
3546

3647
const date = new Date(value)
37-
return Number.isNaN(date.getTime()) ? undefined : date.toISOString()
48+
return Number.isNaN(date.getTime()) ? null : date.toISOString()
3849
}
3950

4051
/**
@@ -54,18 +65,29 @@ export function CreateEventModal({ isOpen, onClose, onCreated }: CreateEventModa
5465
isLoading: isLoadingMyOrganizations,
5566
error: myOrganizationsError,
5667
} = useUserOrganizations(organizations, user?.uid, isAuthed, isOpen ? 1 : 0)
57-
const [formState, setFormState] = useState<CreateEventFormState>(initialFormState)
68+
const [formState, setFormState] = useState<CreateEventFormState>(() => createInitialFormState())
5869
const [isSubmitting, setIsSubmitting] = useState(false)
5970
const [error, setError] = useState<string | null>(null)
6071

6172
useEffect(() => {
6273
if (!isOpen) {
63-
setFormState(initialFormState)
74+
setFormState(createInitialFormState())
6475
setIsSubmitting(false)
6576
setError(null)
6677
return
6778
}
6879

80+
setFormState((current) => {
81+
if (current.eventTime.length > 0) {
82+
return current
83+
}
84+
85+
return {
86+
...current,
87+
eventTime: getCurrentDateTimeInputValue(),
88+
}
89+
})
90+
6991
const onKeyDown = (event: KeyboardEvent) => {
7092
if (event.key === 'Escape' && !isSubmitting) {
7193
onClose()

src/shared/models/event.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ export type Event = {
22
eid: string
33
title: string
44
location: string
5-
event_time: string
5+
event_time: string | null
66
description: string
77
date_created?: string
88
date_modified?: string
@@ -18,10 +18,12 @@ export type EventRegistration = {
1818

1919
export type CreateEventPayload = {
2020
org_id: string
21-
} & Partial<Pick<Event, 'title' | 'location' | 'event_time' | 'description'>>
21+
} & Partial<Pick<Event, 'title' | 'location' | 'description'>> & {
22+
event_time?: Event['event_time']
23+
}
2224

23-
export type UpdateEventPayload = Partial<
24-
Pick<Event, 'title' | 'location' | 'event_time' | 'description'>
25-
>
25+
export type UpdateEventPayload = Partial<Pick<Event, 'title' | 'location' | 'description'>> & {
26+
event_time?: Event['event_time']
27+
}
2628

2729
export type ListEventsResponse = Event[]

0 commit comments

Comments
 (0)