@@ -2,7 +2,7 @@ import React, { useContext, useState, useEffect } from 'react';
22import Box from '@mui/material/Box' ;
33import Drawer from '@mui/material/Drawer' ;
44import Divider from '@mui/material/Divider' ;
5- import { Grid } from '@mui/material' ;
5+ import { Grid , MenuItem } from '@mui/material' ;
66import { MetHeader3 , MetLabel , PrimaryButton , SecondaryButton } from 'components/common' ;
77import { useForm , FormProvider , SubmitHandler } from 'react-hook-form' ;
88import { yupResolver } from '@hookform/resolvers/yup' ;
@@ -13,13 +13,11 @@ import ControlledTextField from 'components/common/ControlledInputComponents/Con
1313import { openNotification } from 'services/notificationService/notificationSlice' ;
1414import { postEvent , patchEvent , PatchEventProps } from 'services/widgetService/EventService' ;
1515import { Event , EVENT_TYPE } from 'models/event' ;
16- import { formatToUTC , formatDate } from 'components/common/dateHelper' ;
16+ import { formatDate } from 'components/common/dateHelper' ;
1717import { formEventDates } from './utils' ;
18- import dayjs from 'dayjs' ;
19- import tz from 'dayjs/plugin/timezone' ;
2018import { updatedDiff } from 'deep-object-diff' ;
21-
22- dayjs . extend ( tz ) ;
19+ import ControlledSelect from 'components/common/ControlledInputComponents/ControlledSelect' ;
20+ import { TIMEZONE_OPTIONS , TIMEZONES } from 'constants/timezones' ;
2321
2422const schema = yup
2523 . object ( {
@@ -35,6 +33,7 @@ const schema = yup
3533 date : yup . string ( ) . defined ( ) . required ( 'Date cannot be empty' ) ,
3634 time_from : yup . string ( ) . required ( 'Time from cannot be empty' ) ,
3735 time_to : yup . string ( ) . required ( 'Time to cannot be empty' ) ,
36+ timezone : yup . string ( ) . oneOf ( Object . values ( TIMEZONES ) ) . defined ( ) . default ( TIMEZONES . CANADA_PACIFIC ) ,
3837 } )
3938 . required ( ) ;
4039
@@ -53,8 +52,8 @@ const InPersonEventFormDrawer = () => {
5352 } = useContext ( EventsContext ) ;
5453 const [ isCreating , setIsCreating ] = useState ( false ) ;
5554 const eventItemToEdit = eventToEdit ? eventToEdit . event_items [ 0 ] : null ;
56- const startDate = dayjs ( eventItemToEdit ? eventItemToEdit ? .start_date : '' ) . tz ( 'US/Pacific' ) ;
57- const endDate = dayjs ( eventItemToEdit ? eventItemToEdit ? .end_date : '' ) . tz ( 'US/Pacific' ) ;
55+ const startDate = eventItemToEdit ? new Date ( eventItemToEdit . start_date ) : null ;
56+ const endDate = eventItemToEdit ? new Date ( eventItemToEdit . end_date ) : null ;
5857 const methods = useForm < InPersonEventForm > ( {
5958 resolver : yupResolver ( schema ) ,
6059 } ) ;
@@ -70,8 +69,12 @@ const InPersonEventFormDrawer = () => {
7069 methods . setValue ( 'location_name' , eventItemToEdit ?. location_name || '' ) ;
7170 methods . setValue ( 'location_address' , eventItemToEdit ?. location_address || '' ) ;
7271 methods . setValue ( 'date' , eventItemToEdit ? formatDate ( eventItemToEdit . start_date ) : '' ) ;
73- methods . setValue ( 'time_from' , pad ( startDate . hour ( ) ) + ':' + pad ( startDate . minute ( ) ) || '' ) ;
74- methods . setValue ( 'time_to' , pad ( endDate . hour ( ) ) + ':' + pad ( endDate . minute ( ) ) || '' ) ;
72+ methods . setValue (
73+ 'time_from' ,
74+ startDate ? pad ( startDate . getHours ( ) ) + ':' + pad ( startDate . getMinutes ( ) ) || '' : '' ,
75+ ) ;
76+ methods . setValue ( 'time_to' , endDate ? pad ( endDate . getHours ( ) ) + ':' + pad ( endDate . getMinutes ( ) ) || '' : '' ) ;
77+ methods . setValue ( 'timezone' , eventItemToEdit ?. timezone || TIMEZONES . CANADA_PACIFIC ) ;
7578 } , [ eventToEdit ] ) ;
7679
7780 const { handleSubmit, reset } = methods ;
@@ -86,8 +89,8 @@ const InPersonEventFormDrawer = () => {
8689 } ) as PatchEventProps ;
8790
8891 await patchEvent ( widget . id , eventToEdit . id , eventItemToEdit . id , {
89- start_date : formatToUTC ( dateFrom ) ,
90- end_date : formatToUTC ( dateTo ) ,
92+ start_date : dateFrom ,
93+ end_date : dateTo ,
9194 ...eventUpdatesToPatch ,
9295 } ) ;
9396
@@ -98,7 +101,7 @@ const InPersonEventFormDrawer = () => {
98101
99102 const createEvent = async ( data : InPersonEventForm ) => {
100103 const validatedData = await schema . validate ( data ) ;
101- const { description, location_address, location_name, date, time_from, time_to } = validatedData ;
104+ const { description, location_address, location_name, date, time_from, time_to, timezone } = validatedData ;
102105 const { dateFrom, dateTo } = formEventDates ( date , time_from , time_to ) ;
103106 if ( widget ) {
104107 const createdWidgetEvent = await postEvent ( widget . id , {
@@ -109,8 +112,9 @@ const InPersonEventFormDrawer = () => {
109112 description : description ,
110113 location_name : location_name ,
111114 location_address : location_address ,
112- start_date : formatToUTC ( dateFrom ) ,
113- end_date : formatToUTC ( dateTo ) ,
115+ timezone : timezone ,
116+ start_date : dateFrom ,
117+ end_date : dateTo ,
114118 } ,
115119 ] ,
116120 } ) ;
@@ -250,6 +254,26 @@ const InPersonEventFormDrawer = () => {
250254 size = "small"
251255 />
252256 </ Grid >
257+ < Grid item >
258+ < MetLabel sx = { { marginBottom : '2px' } } > Timezone</ MetLabel >
259+ < ControlledSelect
260+ name = "timezone"
261+ variant = "outlined"
262+ label = " "
263+ InputLabelProps = { {
264+ shrink : false ,
265+ } }
266+ fullWidth
267+ size = "small"
268+ defaultValue = { TIMEZONES . CANADA_PACIFIC }
269+ >
270+ { TIMEZONE_OPTIONS . map ( ( option ) => (
271+ < MenuItem key = { option . value } value = { option . value } >
272+ { option . label }
273+ </ MenuItem >
274+ ) ) }
275+ </ ControlledSelect >
276+ </ Grid >
253277 < Grid
254278 item
255279 xs = { 12 }
0 commit comments