From 42c432eb0ea9112ef28652d75cc784c3b3dd79fd Mon Sep 17 00:00:00 2001 From: Nick O'Ferrall Date: Thu, 25 Apr 2024 11:46:19 +0100 Subject: [PATCH] fix: can update gcal start datetime (#9668) --- .../components/GcalModal/DateTimePickers.tsx | 27 ++-------------- .../components/GcalModal/GcalModal.tsx | 27 ++++++++++++++-- .../components/GcalModal/GcalSettings.tsx | 31 ++++++++++++++----- 3 files changed, 51 insertions(+), 34 deletions(-) diff --git a/packages/client/modules/userDashboard/components/GcalModal/DateTimePickers.tsx b/packages/client/modules/userDashboard/components/GcalModal/DateTimePickers.tsx index 4348f8099bb..55a6425c050 100644 --- a/packages/client/modules/userDashboard/components/GcalModal/DateTimePickers.tsx +++ b/packages/client/modules/userDashboard/components/GcalModal/DateTimePickers.tsx @@ -42,39 +42,18 @@ const timePickerStyles = { type Props = { startValue: Dayjs - setStart: (newValue: Dayjs) => void endValue: Dayjs - setEnd: (newValue: Dayjs) => void + handleChangeStart: (date: Dayjs | null, time: Dayjs | null) => void + handleChangeEnd: (date: Dayjs | null, time: Dayjs | null) => void } const DateTimePickers = (props: Props) => { - const {startValue, setStart, endValue, setEnd} = props + const {startValue, endValue, handleChangeStart, handleChangeEnd} = props const timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone const date = new Date() const dateTimeString = date.toLocaleString('en-US', {timeZone: timeZone, timeZoneName: 'short'}) const timeZoneShort = dateTimeString.split(' ').pop() - const handleChangeStart = (date: Dayjs | null, time: Dayjs | null) => { - if (date && time) { - const newValue = date.hour(time.hour()).minute(time.minute()) - setStart(newValue) - setEnd(newValue.add(1, 'hour')) - } - } - - const handleChangeEnd = (date: Dayjs | null, time: Dayjs | null) => { - if (date && time) { - const newValue = date.hour(time.hour()).minute(time.minute()) - if (newValue.isAfter(startValue)) { - setEnd(newValue) - } else { - const newStartValue = newValue.subtract(1, 'hour') - setStart(newStartValue) - setEnd(newValue) - } - } - } - const handleMouseDown = (e: React.MouseEvent) => { // prevent gcal modal from closing when clicking datetime pickers e.stopPropagation() diff --git a/packages/client/modules/userDashboard/components/GcalModal/GcalModal.tsx b/packages/client/modules/userDashboard/components/GcalModal/GcalModal.tsx index 21b77a164ab..98bef3b7751 100644 --- a/packages/client/modules/userDashboard/components/GcalModal/GcalModal.tsx +++ b/packages/client/modules/userDashboard/components/GcalModal/GcalModal.tsx @@ -1,7 +1,7 @@ import styled from '@emotion/styled' import {Close} from '@mui/icons-material' import graphql from 'babel-plugin-relay/macro' -import dayjs from 'dayjs' +import dayjs, {Dayjs} from 'dayjs' import React, {useEffect, useState} from 'react' import {useFragment} from 'react-relay' import {GcalModal_team$key} from '../../../../__generated__/GcalModal_team.graphql' @@ -204,6 +204,27 @@ const GcalModal = (props: Props) => { setVideoType(option) } + const handleChangeStart = (date: Dayjs | null, time: Dayjs | null) => { + if (date && time) { + const newValue = date.hour(time.hour()).minute(time.minute()) + setStart(newValue) + setEnd(newValue.add(1, 'hour')) + } + } + + const handleChangeEnd = (date: Dayjs | null, time: Dayjs | null) => { + if (date && time) { + const newValue = date.hour(time.hour()).minute(time.minute()) + if (newValue.isAfter(start)) { + setEnd(newValue) + } else { + const newStartValue = newValue.subtract(1, 'hour') + setStart(newStartValue) + setEnd(newValue) + } + } + } + return ( @@ -234,8 +255,8 @@ const GcalModal = (props: Props) => { diff --git a/packages/client/modules/userDashboard/components/GcalModal/GcalSettings.tsx b/packages/client/modules/userDashboard/components/GcalModal/GcalSettings.tsx index ce464d188e3..48e6d0d39d3 100644 --- a/packages/client/modules/userDashboard/components/GcalModal/GcalSettings.tsx +++ b/packages/client/modules/userDashboard/components/GcalModal/GcalSettings.tsx @@ -1,6 +1,6 @@ import styled from '@emotion/styled' import graphql from 'babel-plugin-relay/macro' -import dayjs from 'dayjs' +import dayjs, {Dayjs} from 'dayjs' import React, {useEffect, useState} from 'react' import {useFragment} from 'react-relay' import {GcalModal_team$key} from '../../../../__generated__/GcalModal_team.graphql' @@ -35,7 +35,6 @@ const GcalSettings = (props: Props) => { const {invitees, start, end, videoType} = settings const [rawInvitees, setRawInvitees] = useState(invitees.join(', ')) const [inviteAll, setInviteAll] = useState(true) - const [inviteError, setInviteError] = useState(null) const setInvitees = (invitees: string[]) => { @@ -45,11 +44,24 @@ const GcalSettings = (props: Props) => { onSettingsChanged({...settings, videoType}) } - const setStart = (start: dayjs.Dayjs) => { - onSettingsChanged({...settings, start}) + const handleChangeStart = (date: Dayjs | null, time: Dayjs | null) => { + if (date && time) { + const newStart = date.hour(time.hour()).minute(time.minute()) + const newEnd = newStart.add(1, 'hour') + onSettingsChanged({...settings, start: newStart, end: newEnd}) + } } - const setEnd = (end: dayjs.Dayjs) => { - onSettingsChanged({...settings, end}) + + const handleChangeEnd = (date: Dayjs | null, time: Dayjs | null) => { + if (date && time) { + const startValue = settings.start + const newEnd = date.hour(time.hour()).minute(time.minute()) + let newStart = startValue + if (newEnd.isBefore(startValue) || newEnd.isSame(startValue)) { + newStart = newEnd.subtract(1, 'hour') + } + onSettingsChanged({...settings, start: newStart, end: newEnd}) + } } const team = useFragment( @@ -135,7 +147,12 @@ const GcalSettings = (props: Props) => { return (
- +