2024-09-10 12:13:04 +05:30
|
|
|
import React, { useState } from 'react';
|
|
|
|
|
import { GenericModal } from "../atoms/GenericModal";
|
2024-09-12 22:27:32 +05:30
|
|
|
import { MenuItem, TextField, Typography, Box } from "@mui/material";
|
2024-09-10 12:13:04 +05:30
|
|
|
import { Dropdown } from "../atoms/DropdownMui";
|
|
|
|
|
import Button from "@mui/material/Button";
|
|
|
|
|
import { modalStyle } from "./AddWhereCondModal";
|
|
|
|
|
|
|
|
|
|
interface ScheduleSettingsProps {
|
|
|
|
|
isOpen: boolean;
|
|
|
|
|
handleStart: (settings: ScheduleSettings) => void;
|
|
|
|
|
handleClose: () => void;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface ScheduleSettings {
|
2024-09-12 22:17:30 +05:30
|
|
|
runEvery: number;
|
|
|
|
|
runEveryUnit: string;
|
|
|
|
|
startFrom: string;
|
|
|
|
|
atTime: string;
|
|
|
|
|
timezone: string;
|
2024-09-10 12:13:04 +05:30
|
|
|
}
|
|
|
|
|
|
2024-09-12 22:17:30 +05:30
|
|
|
export const ScheduleSettingsModal = ({ isOpen, handleStart, handleClose }: ScheduleSettingsProps) => {
|
|
|
|
|
const [settings, setSettings] = useState<ScheduleSettings>({
|
|
|
|
|
runEvery: 1,
|
|
|
|
|
runEveryUnit: 'hours',
|
|
|
|
|
startFrom: 'Monday',
|
|
|
|
|
atTime: '00:00',
|
|
|
|
|
timezone: 'UTC'
|
2024-09-10 12:13:04 +05:30
|
|
|
});
|
|
|
|
|
|
2024-09-12 22:17:30 +05:30
|
|
|
const handleChange = (field: keyof ScheduleSettings, value: string | number) => {
|
|
|
|
|
setSettings(prev => ({ ...prev, [field]: value }));
|
|
|
|
|
};
|
|
|
|
|
|
2024-09-10 12:13:04 +05:30
|
|
|
return (
|
|
|
|
|
<GenericModal
|
|
|
|
|
isOpen={isOpen}
|
|
|
|
|
onClose={handleClose}
|
|
|
|
|
modalStyle={modalStyle}
|
|
|
|
|
>
|
2024-09-12 22:27:32 +05:30
|
|
|
<Box sx={{
|
2024-09-10 12:13:04 +05:30
|
|
|
display: 'flex',
|
|
|
|
|
flexDirection: 'column',
|
|
|
|
|
alignItems: 'flex-start',
|
2024-09-12 22:27:32 +05:30
|
|
|
padding: '20px',
|
|
|
|
|
'& > *': { marginBottom: '20px' },
|
2024-09-10 12:13:04 +05:30
|
|
|
}}>
|
2024-09-12 22:27:32 +05:30
|
|
|
<Typography variant="h6">Schedule Settings</Typography>
|
|
|
|
|
|
|
|
|
|
<Box sx={{ display: 'flex', alignItems: 'center', width: '100%' }}>
|
|
|
|
|
<Typography sx={{ marginRight: '10px' }}>Run once every</Typography>
|
2024-09-12 22:17:30 +05:30
|
|
|
<TextField
|
|
|
|
|
type="number"
|
|
|
|
|
value={settings.runEvery}
|
|
|
|
|
onChange={(e) => handleChange('runEvery', parseInt(e.target.value))}
|
2024-09-12 22:27:32 +05:30
|
|
|
sx={{ width: '60px', marginRight: '10px' }}
|
2024-09-12 22:17:30 +05:30
|
|
|
/>
|
|
|
|
|
<Dropdown
|
|
|
|
|
label="unit"
|
|
|
|
|
id="runEveryUnit"
|
|
|
|
|
value={settings.runEveryUnit}
|
|
|
|
|
handleSelect={(e) => handleChange('runEveryUnit', e.target.value)}
|
|
|
|
|
>
|
|
|
|
|
<MenuItem value="minutes">minutes</MenuItem>
|
|
|
|
|
<MenuItem value="hours">hours</MenuItem>
|
|
|
|
|
<MenuItem value="days">days</MenuItem>
|
|
|
|
|
<MenuItem value="weeks">weeks</MenuItem>
|
|
|
|
|
<MenuItem value="months">months</MenuItem>
|
|
|
|
|
</Dropdown>
|
2024-09-12 22:27:32 +05:30
|
|
|
</Box>
|
2024-09-12 22:17:30 +05:30
|
|
|
|
2024-09-12 22:27:32 +05:30
|
|
|
<Box sx={{ width: '100%' }}>
|
|
|
|
|
<Typography sx={{ marginBottom: '5px' }}>Start from</Typography>
|
2024-09-12 22:17:30 +05:30
|
|
|
<Dropdown
|
2024-09-12 22:18:56 +05:30
|
|
|
label="start from"
|
2024-09-12 22:17:30 +05:30
|
|
|
id="startFrom"
|
|
|
|
|
value={settings.startFrom}
|
|
|
|
|
handleSelect={(e) => handleChange('startFrom', e.target.value)}
|
|
|
|
|
>
|
|
|
|
|
<MenuItem value="Monday">Monday</MenuItem>
|
|
|
|
|
<MenuItem value="Tuesday">Tuesday</MenuItem>
|
|
|
|
|
<MenuItem value="Wednesday">Wednesday</MenuItem>
|
|
|
|
|
<MenuItem value="Thursday">Thursday</MenuItem>
|
|
|
|
|
<MenuItem value="Friday">Friday</MenuItem>
|
|
|
|
|
<MenuItem value="Saturday">Saturday</MenuItem>
|
|
|
|
|
<MenuItem value="Sunday">Sunday</MenuItem>
|
|
|
|
|
</Dropdown>
|
2024-09-12 22:27:32 +05:30
|
|
|
</Box>
|
2024-09-12 22:17:30 +05:30
|
|
|
|
2024-09-12 22:27:32 +05:30
|
|
|
<Box sx={{ display: 'flex', alignItems: 'center', width: '100%' }}>
|
|
|
|
|
<Box sx={{ marginRight: '20px' }}>
|
|
|
|
|
<Typography sx={{ marginBottom: '5px' }}>At around</Typography>
|
|
|
|
|
<TextField
|
|
|
|
|
type="time"
|
|
|
|
|
value={settings.atTime}
|
|
|
|
|
onChange={(e) => handleChange('atTime', e.target.value)}
|
|
|
|
|
/>
|
|
|
|
|
</Box>
|
|
|
|
|
<Box>
|
|
|
|
|
<Typography sx={{ marginBottom: '5px' }}>Timezone</Typography>
|
|
|
|
|
<Dropdown
|
|
|
|
|
label="timezone"
|
|
|
|
|
id="timezone"
|
|
|
|
|
value={settings.timezone}
|
|
|
|
|
handleSelect={(e) => handleChange('timezone', e.target.value)}
|
|
|
|
|
>
|
|
|
|
|
<MenuItem value="UTC">UTC</MenuItem>
|
|
|
|
|
<MenuItem value="America/New_York">America/New_York</MenuItem>
|
|
|
|
|
<MenuItem value="Europe/London">Europe/London</MenuItem>
|
|
|
|
|
<MenuItem value="Asia/Tokyo">Asia/Tokyo</MenuItem>
|
|
|
|
|
<MenuItem value="Asia/Kolkata">Asia/Kolkata</MenuItem>
|
|
|
|
|
</Dropdown>
|
|
|
|
|
</Box>
|
|
|
|
|
</Box>
|
2024-09-12 22:17:30 +05:30
|
|
|
|
2024-09-12 22:27:32 +05:30
|
|
|
<Button variant="contained" onClick={() => handleStart(settings)}>Start</Button>
|
|
|
|
|
</Box>
|
2024-09-10 12:13:04 +05:30
|
|
|
</GenericModal>
|
|
|
|
|
);
|
|
|
|
|
}
|
2024-09-12 22:17:30 +05:30
|
|
|
|
|
|
|
|
export default ScheduleSettingsModal;
|