From d3753614326fe267243fcddcb2e2fd3c6c6fa4fc Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Tue, 29 Oct 2024 01:09:20 +0530 Subject: [PATCH] feat: day of month handle --- src/components/molecules/ScheduleSettings.tsx | 210 ++++++++---------- 1 file changed, 98 insertions(+), 112 deletions(-) diff --git a/src/components/molecules/ScheduleSettings.tsx b/src/components/molecules/ScheduleSettings.tsx index fae240f9..bdcfaf01 100644 --- a/src/components/molecules/ScheduleSettings.tsx +++ b/src/components/molecules/ScheduleSettings.tsx @@ -1,6 +1,6 @@ import React, { useState, useEffect } from 'react'; import { GenericModal } from "../atoms/GenericModal"; -import { MenuItem, TextField, Typography, Box, Switch, FormControlLabel } from "@mui/material"; +import { MenuItem, TextField, Typography, Box } from "@mui/material"; import { Dropdown } from "../atoms/DropdownMui"; import Button from "@mui/material/Button"; import { validMomentTimezones } from '../../constants/const'; @@ -17,7 +17,8 @@ interface ScheduleSettingsProps { export interface ScheduleSettings { runEvery: number; runEveryUnit: string; - startFrom: string; + startFrom: string; + dayOfMonth?: string; atTimeStart?: string; atTimeEnd?: string; timezone: string; @@ -28,13 +29,13 @@ export const ScheduleSettingsModal = ({ isOpen, handleStart, handleClose, initia const [settings, setSettings] = useState({ runEvery: 1, runEveryUnit: 'HOURS', - startFrom: 'MONDAY', + startFrom: 'MONDAY', + dayOfMonth: '', atTimeStart: '00:00', atTimeEnd: '01:00', timezone: 'UTC' }); - // Load initial settings if provided useEffect(() => { if (initialSettings) { setSettings(initialSettings); @@ -66,20 +67,8 @@ export const ScheduleSettingsModal = ({ isOpen, handleStart, handleClose, initia 'MONTHS' ]; - const days = [ - 'MONDAY', - 'TUESDAY', - 'WEDNESDAY', - 'THURSDAY', - 'FRIDAY', - 'SATURDAY', - 'SUNDAY' - ]; - const { recordingId } = useGlobalInfoStore(); - console.log(`Recoridng ID Shculde: ${recordingId}`); - const deleteRobotSchedule = () => { if (recordingId) { deleteSchedule(recordingId); @@ -92,6 +81,7 @@ export const ScheduleSettingsModal = ({ isOpen, handleStart, handleClose, initia runEvery: 1, runEveryUnit: 'HOURS', startFrom: 'MONDAY', + dayOfMonth: '', atTimeStart: '00:00', atTimeEnd: '01:00', timezone: 'UTC' @@ -101,7 +91,6 @@ export const ScheduleSettingsModal = ({ isOpen, handleStart, handleClose, initia const getRobotSchedule = async () => { if (recordingId) { const scheduleData = await getSchedule(recordingId); - console.log(`Robot found schedule: ${JSON.stringify(scheduleData, null, 2)}`); setSchedule(scheduleData); } else { console.error('No recording id provided'); @@ -132,116 +121,113 @@ export const ScheduleSettingsModal = ({ isOpen, handleStart, handleClose, initia }}> Schedule Settings <> - { - (schedule !== null) ? ( - <> - Run every: {schedule.runEvery} {schedule.runEveryUnit.toLowerCase()} - Start from: {schedule.startFrom.charAt(0).toUpperCase() + schedule.startFrom.slice(1).toLowerCase()} - At around: {schedule.atTimeStart}, {schedule.timezone} Timezone - - - - - ) : ( - <> + {schedule !== null ? ( + <> + Run every: {schedule.runEvery} {schedule.runEveryUnit.toLowerCase()} + Start from: {schedule.startFrom.charAt(0).toUpperCase() + schedule.startFrom.slice(1).toLowerCase()} + On day: {schedule.dayOfMonth} + At around: {schedule.atTimeStart}, {schedule.timezone} Timezone + + + + + ) : ( + <> + + Run once every + handleChange('runEvery', parseInt(e.target.value))} + sx={textStyle} + inputProps={{ min: 1 }} + /> + handleChange('runEveryUnit', e.target.value)} + sx={dropDownStyle} + > + {units.map((unit) => ( + {unit} + ))} + + + + {settings.runEveryUnit === 'MONTHS' && ( - Run once every + On Day of the Month handleChange('runEvery', parseInt(e.target.value))} - sx={textStyle} - inputProps={{ min: 1 }} + type="number" + value={settings.dayOfMonth} + onChange={(e) => handleChange('dayOfMonth', e.target.value)} + sx={textStyle} + inputProps={{ min: 1, max: 31 }} /> - handleChange('runEveryUnit', e.target.value)} - sx={dropDownStyle} - > - {units.map((unit) => ( - {unit} - ))} - + )} + {['MINUTES', 'HOURS'].includes(settings.runEveryUnit) ? ( - Start from / On - handleChange('startFrom', e.target.value)} - sx={dropDownStyle} - > - {days.map((day) => ( - {day} - ))} - - - - {['MINUTES', 'HOURS'].includes(settings.runEveryUnit) ? ( - - - In Between - handleChange('atTimeStart', e.target.value)} - sx={textStyle} - /> - handleChange('atTimeEnd', e.target.value)} - sx={textStyle} - /> - - - ) : ( - - At Around + + In Between handleChange('atTimeStart', e.target.value)} sx={textStyle} /> + handleChange('atTimeEnd', e.target.value)} + sx={textStyle} + /> - )} - + + ) : ( - Timezone - handleChange('timezone', e.target.value)} - sx={dropDownStyle} - > - {validMomentTimezones.map((tz) => ( - {tz} - ))} - + At Around + handleChange('atTimeStart', e.target.value)} + sx={textStyle} + /> - - - - - - ) - } + )} + + + Timezone + handleChange('timezone', e.target.value)} + sx={dropDownStyle} + > + {validMomentTimezones.map((tz) => ( + {tz} + ))} + + + + + + + + )}