import { FC, useState } from 'react'; import { Alert, Box, styled, Typography } from '@mui/material'; import { Dialogue } from 'component/common/Dialogue/Dialogue'; import { APPLY_CHANGE_REQUEST } from 'component/providers/AccessProvider/permissions'; import PermissionButton from 'component/common/PermissionButton/PermissionButton'; import { DateTimePicker } from 'component/common/DateTimePicker/DateTimePicker'; import { getBrowserTimezone } from '../ChangeRequestReviewStatus/utils'; export interface ScheduleChangeRequestDialogProps { title: string; primaryButtonText: string; open: boolean; onConfirm: (selectedDate: Date) => void; onClose: () => void; projectId: string; environment: string; disabled?: boolean; scheduledAt?: string; } const StyledContainer = styled(Box)(({ theme }) => ({ display: 'flex', flexDirection: 'row', alignItems: 'center', gap: theme.spacing(2), })); export const ScheduleChangeRequestDialog: FC = ({ open, onConfirm, onClose, title, primaryButtonText, projectId, environment, disabled, scheduledAt, }) => { const [selectedDate, setSelectedDate] = useState( scheduledAt ? new Date(scheduledAt) : new Date(), ); const [error, setError] = useState(undefined); const timezone = getBrowserTimezone(); return ( onClose()} onClick={() => onConfirm(selectedDate)} permissionButton={ onConfirm(selectedDate)} projectId={projectId} permission={APPLY_CHANGE_REQUEST} environmentId={environment} disabled={disabled} > {primaryButtonText} } fullWidth > theme.spacing(2) }} > The time shown below is based on your browser's time zone. theme.spacing(4) }} > Select the date and time when these changes should be applied. If you change your mind later, you can reschedule the changes or apply the immediately. { setError(undefined); if (date < new Date()) { setError( `The time you provided (${date.toLocaleString()}) is not valid because it's in the past. Please select a time in the future.`, ); } setSelectedDate(date); }} min={new Date()} error={Boolean(error)} errorText={error} required /> Your browser's time zone is {timezone} ); };