Files
parcer/src/components/molecules/ScheduleSettings.tsx

144 lines
4.6 KiB
TypeScript
Raw Normal View History

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-12 23:02:49 +05:30
const textStyle = {
2024-09-12 23:01:19 +05:30
width: '150px',
2024-09-12 23:16:12 +05:30
height: '52px',
2024-09-12 23:01:19 +05:30
marginRight: '10px',
};
2024-09-12 23:02:49 +05:30
const dropDownStyle = {
2024-09-12 23:01:19 +05:30
marginTop: '2px',
width: '150px',
height: '59px',
marginRight: '10px',
};
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 23:27:26 +05:30
<Typography variant="h6" sx={{ marginBottom: '20px' }}>Schedule Settings</Typography>
2024-09-12 22:27:52 +05:30
2024-09-12 22:27:32 +05:30
<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 23:02:49 +05:30
sx={textStyle}
2024-09-12 22:17:30 +05:30
/>
<Dropdown
2024-09-12 23:15:03 +05:30
label=""
2024-09-12 22:17:30 +05:30
id="runEveryUnit"
value={settings.runEveryUnit}
handleSelect={(e) => handleChange('runEveryUnit', e.target.value)}
2024-09-12 23:02:49 +05:30
sx={dropDownStyle}
2024-09-12 22:17:30 +05:30
>
<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 23:17:32 +05:30
<Box sx={{ display: 'flex', alignItems: 'center', width: '100%' }}>
2024-09-12 23:20:33 +05:30
<Typography sx={{ marginBottom: '5px', marginRight: '25px' }}>Start from</Typography>
2024-09-12 22:17:30 +05:30
<Dropdown
2024-09-12 23:15:03 +05:30
label=""
2024-09-12 22:17:30 +05:30
id="startFrom"
value={settings.startFrom}
handleSelect={(e) => handleChange('startFrom', e.target.value)}
2024-09-12 23:02:49 +05:30
sx={dropDownStyle}
2024-09-12 22:17:30 +05:30
>
<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)}
2024-09-12 23:02:49 +05:30
sx={textStyle}
2024-09-12 22:27:32 +05:30
/>
</Box>
<Box>
<Typography sx={{ marginBottom: '5px' }}>Timezone</Typography>
<Dropdown
2024-09-12 23:15:03 +05:30
label=""
2024-09-12 22:27:32 +05:30
id="timezone"
value={settings.timezone}
handleSelect={(e) => handleChange('timezone', e.target.value)}
2024-09-12 23:02:49 +05:30
sx={dropDownStyle}
2024-09-12 22:27:32 +05:30
>
<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 23:01:19 +05:30
<Button
variant="contained"
onClick={() => handleStart(settings)}
>
Start
</Button>
2024-09-12 22:27:32 +05:30
</Box>
2024-09-10 12:13:04 +05:30
</GenericModal>
);
}
2024-09-12 22:17:30 +05:30
export default ScheduleSettingsModal;