feat: modify to handle minutes

This commit is contained in:
karishmas6
2024-10-22 18:25:32 +05:30
parent 3675920d5d
commit a368ea2cd0

View File

@@ -16,7 +16,8 @@ export interface ScheduleSettings {
runEvery: number; runEvery: number;
runEveryUnit: string; runEveryUnit: string;
startFrom: string; startFrom: string;
atTime: string; atTimeStart?: string; // Start time for "In Between"
atTimeEnd?: string; // End time for "In Between"
timezone: string; timezone: string;
} }
@@ -25,7 +26,8 @@ export const ScheduleSettingsModal = ({ isOpen, handleStart, handleClose }: Sche
runEvery: 1, runEvery: 1,
runEveryUnit: 'HOURS', runEveryUnit: 'HOURS',
startFrom: 'MONDAY', startFrom: 'MONDAY',
atTime: '00:00', atTimeStart: '00:00',
atTimeEnd: '01:00', // Default end time
timezone: 'UTC' timezone: 'UTC'
}); });
@@ -33,8 +35,6 @@ export const ScheduleSettingsModal = ({ isOpen, handleStart, handleClose }: Sche
setSettings(prev => ({ ...prev, [field]: value })); setSettings(prev => ({ ...prev, [field]: value }));
}; };
console.log(`Settings:`, settings);
const textStyle = { const textStyle = {
width: '150px', width: '150px',
height: '52px', height: '52px',
@@ -49,11 +49,12 @@ export const ScheduleSettingsModal = ({ isOpen, handleStart, handleClose }: Sche
}; };
const units = [ const units = [
'MINUTES',
'HOURS', 'HOURS',
'DAYS', 'DAYS',
'WEEKS', 'WEEKS',
'MONTHS' 'MONTHS'
] ];
const days = [ const days = [
'MONDAY', 'MONDAY',
@@ -63,7 +64,7 @@ export const ScheduleSettingsModal = ({ isOpen, handleStart, handleClose }: Sche
'FRIDAY', 'FRIDAY',
'SATURDAY', 'SATURDAY',
'SUNDAY' 'SUNDAY'
] ];
return ( return (
<GenericModal <GenericModal
@@ -117,41 +118,59 @@ export const ScheduleSettingsModal = ({ isOpen, handleStart, handleClose }: Sche
</Dropdown> </Dropdown>
</Box> </Box>
<Box sx={{ display: 'flex', alignItems: 'center', width: '100%' }}> {/* Conditional rendering based on the selected runEveryUnit */}
<Box sx={{ marginRight: '20px' }}> {['MINUTES', 'HOURS'].includes(settings.runEveryUnit) ? (
<Typography sx={{ marginBottom: '5px' }}>At around</Typography> <Box sx={{ display: 'flex', alignItems: 'center', width: '100%' }}>
<Box sx={{ marginRight: '20px' }}>
<Typography sx={{ marginBottom: '5px' }}>In Between</Typography>
<TextField
type="time"
value={settings.atTimeStart}
onChange={(e) => handleChange('atTimeStart', e.target.value)}
sx={textStyle}
/>
<TextField
type="time"
value={settings.atTimeEnd}
onChange={(e) => handleChange('atTimeEnd', e.target.value)}
sx={textStyle}
/>
</Box>
</Box>
) : (
<Box sx={{ display: 'flex', alignItems: 'center', width: '100%' }}>
<Typography sx={{ marginBottom: '5px', marginRight: '10px' }}>At Around</Typography>
<TextField <TextField
type="time" type="time"
value={settings.atTime} value={settings.atTimeStart}
onChange={(e) => handleChange('atTime', e.target.value)} onChange={(e) => handleChange('atTimeStart', e.target.value)}
sx={textStyle} sx={textStyle}
/> />
</Box> </Box>
<Box> )}
<Typography sx={{ marginBottom: '5px' }}>Timezone</Typography>
<Dropdown <Box sx={{ display: 'flex', alignItems: 'center', width: '100%' }}>
label="" <Typography sx={{ marginRight: '10px' }}>Timezone</Typography>
id="timezone" <Dropdown
value={settings.timezone} label=""
handleSelect={(e) => handleChange('timezone', e.target.value)} id="timezone"
sx={dropDownStyle} value={settings.timezone}
> handleSelect={(e) => handleChange('timezone', e.target.value)}
{validMomentTimezones.map((tz) => ( sx={dropDownStyle}
<MenuItem key={tz} value={tz}>{tz}</MenuItem> >
))} {validMomentTimezones.map((tz) => (
</Dropdown> <MenuItem key={tz} value={tz}>{tz}</MenuItem>
</Box> ))}
</Dropdown>
</Box> </Box>
<Button <Button
variant="contained" variant="contained"
onClick={() => handleStart(settings)} onClick={() => handleStart(settings)}
> >
Save Schedule
</Button> </Button>
</Box> </Box>
</GenericModal> </GenericModal>
); );
} };
export default ScheduleSettingsModal;