Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(gcal): gcal date UI/UX #8696

Merged
merged 19 commits into from
Sep 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React, {useEffect, useState} from 'react'
import graphql from 'babel-plugin-relay/macro'
import {useDialogState} from '../../ui/Dialog/useDialogState'
import SecondaryButton from '../SecondaryButton'
import GcalModal from '../../modules/userDashboard/components/GcalModal/GcalModal'
import {CreateGcalEventInput} from '../../__generated__/StartRetrospectiveMutation.graphql'
Expand All @@ -10,6 +9,7 @@ import {useFragment} from 'react-relay'
import {ScheduleMeetingButton_team$key} from '~/__generated__/ScheduleMeetingButton_team.graphql'
import {ScheduleMeetingButton_viewer$key} from '~/__generated__/ScheduleMeetingButton_viewer.graphql'
import {MenuMutationProps} from '../../hooks/useMutationProps'
import useModal from '../../hooks/useModal'

type Props = {
mutationProps: MenuMutationProps
Expand All @@ -20,13 +20,11 @@ type Props = {

const ScheduleMeetingButton = (props: Props) => {
const {mutationProps, handleStartActivity, teamRef, viewerRef} = props
const {
isOpen: isScheduleDialogOpen,
open: openScheduleDialog,
close: closeScheduleDialog
} = useDialogState()
const atmosphere = useAtmosphere()
const [hasStartedGcalAuthTeamId, setHasStartedGcalAuthTeamId] = useState<null | string>(null)
const {togglePortal: toggleModal, modalPortal} = useModal({
id: 'createGcalEventModal'
})
const {submitting} = mutationProps

const viewer = useFragment(
Expand Down Expand Up @@ -72,7 +70,7 @@ const ScheduleMeetingButton = (props: Props) => {

const handleClick = () => {
if (viewerGcalIntegration?.auth) {
openScheduleDialog()
toggleModal()
} else if (cloudProvider) {
const {clientId, id: providerId} = cloudProvider
GcalClientManager.openOAuth(atmosphere, providerId, clientId, teamId, mutationProps)
Expand All @@ -82,7 +80,7 @@ const ScheduleMeetingButton = (props: Props) => {

useEffect(() => {
if (hasStartedGcalAuth && viewerGcalIntegration?.auth) {
openScheduleDialog()
toggleModal()
}
}, [hasStartedGcalAuth, viewerGcalIntegration])

Expand All @@ -92,12 +90,13 @@ const ScheduleMeetingButton = (props: Props) => {
<SecondaryButton onClick={handleClick} waiting={submitting} className='h-14'>
<div className='text-lg'>Schedule</div>
</SecondaryButton>
<GcalModal
closeModal={closeScheduleDialog}
isOpen={isScheduleDialogOpen}
handleStartActivityWithGcalEvent={handleStartActivity}
teamRef={team}
/>
{modalPortal(
<GcalModal
closeModal={toggleModal}
handleStartActivityWithGcalEvent={handleStartActivity}
teamRef={team}
/>
)}
</>
)
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
import React from 'react'
import {Dayjs} from 'dayjs'
import {LocalizationProvider} from '@mui/x-date-pickers/LocalizationProvider'
import {AdapterDayjs} from '@mui/x-date-pickers/AdapterDayjs'
import {DatePicker, TimePicker} from '@mui/x-date-pickers'
import {PALETTE} from '../../../../styles/paletteV3'

const customStyles = {
width: '100%',
'& .MuiOutlinedInput-root': {
'&:hover .MuiOutlinedInput-notchedOutline, &.Mui-focused .MuiOutlinedInput-notchedOutline, &.focus-within .MuiOutlinedInput-notchedOutline':
{
borderColor: PALETTE.SLATE_400,
borderWidth: '1px'
},
'&.Mui-focused': {
outline: 'none'
}
},
'& label': {
color: PALETTE.SLATE_600,
'&.Mui-focused': {
color: PALETTE.SLATE_600
}
},
'& .MuiPickersDay-dayWithMargin': {
'&:hover, &:focus': {
borderColor: PALETTE.SLATE_400,
outline: 'none'
}
},
'& .MuiPickersCalendarHeader-switchHeader button:focus': {
outline: 'none',
color: PALETTE.SLATE_600
}
}

const timePickerStyles = {
...customStyles,
width: '50%'
}

type Props = {
startValue: Dayjs
setStart: (newValue: Dayjs) => void
endValue: Dayjs
setEnd: (newValue: Dayjs) => void
}

const DateTimePickers = (props: Props) => {
const {startValue, setStart, endValue, setEnd} = 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<HTMLDivElement, MouseEvent>) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-1 Why is this needed, please add a comment

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated! 👍

// prevent gcal modal from closing when clicking datetime pickers
e.stopPropagation()
}

return (
<LocalizationProvider dateAdapter={AdapterDayjs}>
<div className='w flex flex-col justify-between space-y-4 pt-3'>
<div className='flex space-x-2' onMouseDown={handleMouseDown}>
<DatePicker
label={`Meeting Start Date`}
value={startValue}
onChange={(date) => handleChangeStart(date, startValue)}
format='MMMM D, YYYY'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+2 I like we've used an unambiguous format

sx={customStyles}
/>
<TimePicker
label={`Start Time (${timeZoneShort})`}
value={startValue}
onChange={(time) => handleChangeStart(startValue, time)}
sx={timePickerStyles}
/>
</div>
<div className='flex space-x-2' onMouseDown={handleMouseDown}>
<DatePicker
label={`Meeting End Date`}
value={endValue}
onChange={(date) => handleChangeEnd(date, endValue)}
format='MMMM D, YYYY'
sx={customStyles}
/>
<TimePicker
label={`End Time (${timeZoneShort})`}
value={endValue}
onChange={(time) => handleChangeEnd(endValue, time)}
sx={timePickerStyles}
/>
</div>
</div>
</LocalizationProvider>
)
}

export default DateTimePickers
Loading