@@ -22,6 +22,7 @@ import { useFormContext } from "react-hook-form";
22
22
23
23
import { TimeZoneCommand } from "@/components/time-zone-picker/time-zone-select" ;
24
24
25
+ import { getBrowserTimeZone } from "../../../utils/date-time-utils" ;
25
26
import { NewEventData } from "../types" ;
26
27
import MonthCalendar from "./month-calendar" ;
27
28
import { DateTimeOption } from "./types" ;
@@ -31,7 +32,6 @@ export type PollOptionsData = {
31
32
navigationDate : string ; // used to navigate to the right part of the calendar
32
33
duration : number ; // duration of the event in minutes
33
34
timeZone : string ;
34
- autoTimeZone : boolean ;
35
35
view : string ;
36
36
options : DateTimeOption [ ] ;
37
37
} ;
@@ -73,6 +73,7 @@ const PollOptionsForm = ({
73
73
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
74
74
const watchOptions = watch ( "options" , [ ] ) ! ;
75
75
const watchDuration = watch ( "duration" ) ;
76
+ const watchTimeZone = watch ( "timeZone" ) ;
76
77
77
78
const options = getValues ( "options" ) ;
78
79
const datesOnly =
@@ -148,6 +149,7 @@ const PollOptionsForm = ({
148
149
"options" ,
149
150
watchOptions . filter ( ( option ) => option . type === "date" ) ,
150
151
) ;
152
+ setValue ( "timeZone" , "" ) ;
151
153
dateOrTimeRangeDialog . dismiss ( ) ;
152
154
} }
153
155
>
@@ -159,6 +161,9 @@ const PollOptionsForm = ({
159
161
"options" ,
160
162
watchOptions . filter ( ( option ) => option . type === "timeSlot" ) ,
161
163
) ;
164
+ if ( ! watchTimeZone ) {
165
+ setValue ( "timeZone" , getBrowserTimeZone ( ) ) ;
166
+ }
162
167
dateOrTimeRangeDialog . dismiss ( ) ;
163
168
} }
164
169
variant = "primary"
@@ -210,7 +215,7 @@ const PollOptionsForm = ({
210
215
{ ! datesOnly ? (
211
216
< FormField
212
217
control = { form . control }
213
- name = "autoTimeZone "
218
+ name = "timeZone "
214
219
render = { ( { field } ) => (
215
220
< div
216
221
className = { cn (
@@ -219,24 +224,24 @@ const PollOptionsForm = ({
219
224
>
220
225
< div className = "flex h-9 items-center gap-x-2.5 p-2" >
221
226
< Switch
222
- id = "autoTimeZone "
227
+ id = "timeZone "
223
228
disabled = { disableTimeZoneChange }
224
229
checked = { ! ! field . value }
225
230
onCheckedChange = { ( checked ) => {
226
231
if ( checked ) {
227
- field . onChange ( true ) ;
232
+ field . onChange ( getBrowserTimeZone ( ) ) ;
228
233
} else {
229
- field . onChange ( false ) ;
234
+ field . onChange ( "" ) ;
230
235
}
231
236
} }
232
237
/>
233
- < Label htmlFor = "autoTimeZone " >
238
+ < Label htmlFor = "timeZone " >
234
239
< Trans
235
240
i18nKey = "autoTimeZone"
236
241
defaults = "Automatic Time Zone Conversion"
237
242
/>
238
243
</ Label >
239
- < Tooltip delayDuration = { 0 } >
244
+ < Tooltip >
240
245
< TooltipTrigger type = "button" >
241
246
< InfoIcon className = "text-muted-foreground size-4" />
242
247
</ TooltipTrigger >
@@ -249,36 +254,30 @@ const PollOptionsForm = ({
249
254
</ Tooltip >
250
255
</ div >
251
256
{ field . value ? (
252
- < FormField
253
- control = { form . control }
254
- name = "timeZone"
255
- render = { ( { field } ) => (
256
- < div >
257
- < Button
258
- disabled = { disableTimeZoneChange }
259
- onClick = { ( ) => {
260
- showTimeZoneCommandModal ( true ) ;
261
- } }
262
- variant = "ghost"
263
- >
264
- < GlobeIcon className = "text-muted-foreground size-4" />
265
- { field . value }
266
- </ Button >
267
- < CommandDialog
268
- open = { isTimeZoneCommandModalOpen }
269
- onOpenChange = { showTimeZoneCommandModal }
270
- >
271
- < TimeZoneCommand
272
- value = { field . value }
273
- onSelect = { ( newValue ) => {
274
- field . onChange ( newValue ) ;
275
- showTimeZoneCommandModal ( false ) ;
276
- } }
277
- />
278
- </ CommandDialog >
279
- </ div >
280
- ) }
281
- />
257
+ < div >
258
+ < Button
259
+ disabled = { disableTimeZoneChange }
260
+ onClick = { ( ) => {
261
+ showTimeZoneCommandModal ( true ) ;
262
+ } }
263
+ variant = "ghost"
264
+ >
265
+ < GlobeIcon className = "text-muted-foreground size-4" />
266
+ { field . value }
267
+ </ Button >
268
+ < CommandDialog
269
+ open = { isTimeZoneCommandModalOpen }
270
+ onOpenChange = { showTimeZoneCommandModal }
271
+ >
272
+ < TimeZoneCommand
273
+ value = { field . value }
274
+ onSelect = { ( newValue ) => {
275
+ field . onChange ( newValue ) ;
276
+ showTimeZoneCommandModal ( false ) ;
277
+ } }
278
+ />
279
+ </ CommandDialog >
280
+ </ div >
282
281
) : null }
283
282
</ div >
284
283
) }
0 commit comments