Skip to content
Snippets Groups Projects
Commit 290b0200 authored by Leonardo's avatar Leonardo
Browse files

chore: better error handling for errors on cron insight form

parent a9e55864
No related branches found
Tags v1.67.1
No related merge requests found
......@@ -13,8 +13,8 @@ type Props = {
handleSave: (insight: InsightModel, generateEmail: boolean) => void;
};
const FrequencyOptions = ['Hourly', 'Daily', 'Specific Day of the Week'] as const;
const FrequencyWeekDays = ['SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT'] as const;
const FrequencyOptions = ['Hourly', 'Daily', 'Specific Day of the Week'];
const FrequencyWeekDays = ['SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT'];
export function FormInsight(props: Props) {
const dispatch = useAppDispatch();
......@@ -105,12 +105,9 @@ export function FormInsight(props: Props) {
props.handleSave(updatedInsight, generateEmail);
};
const generateCronExpression = (
frequency: (typeof FrequencyOptions)[number],
minute: number,
hour: number,
dayOfWeek?: (typeof FrequencyWeekDays)[number],
) => {
const generateCronExpression = (frequency: string, minute: number, hour: number, dayOfWeek?: string) => {
setFrequency({ frequency, minute, hour, dayOfWeek });
let cron = '';
if (frequency === 'Hourly') {
......@@ -123,7 +120,12 @@ export function FormInsight(props: Props) {
throw new Error('Invalid frequency');
}
setFrequency({ frequency, minute, hour, dayOfWeek });
if (!cron || cron.toLowerCase().includes('nan')) {
console.error('Invalid cron expression', cron, frequency, minute, hour, dayOfWeek);
// dispatch(addError('Invalid cron expression'));
return;
}
setLocalInsight({ ...localInsight, frequency: cron });
};
......@@ -133,7 +135,7 @@ export function FormInsight(props: Props) {
return (
<div>
<h2 className="text-lg text-secondary-600 font-bold ">
<h2 className="text-lg text-secondary-600 font-bold">
{capitalizeFirstLetter(props.insight.type)} ID: {props.insight.id}
</h2>
<div className="p-2 flex flex-col gap-2">
......@@ -288,8 +290,8 @@ export function FormInsight(props: Props) {
label={'Frequency to trigger the ' + props.insight.type}
type="dropdown"
value={frequency.frequency}
onChange={value => generateCronExpression(String(value) as any, frequency.minute, frequency.hour, frequency.dayOfWeek)}
options={FrequencyOptions as any}
onChange={value => generateCronExpression(value as string, frequency.minute, frequency.hour, frequency.dayOfWeek)}
options={FrequencyOptions}
inline={false}
size="md"
info={'Select the frequency to trigger the ' + props.insight.type}
......@@ -323,8 +325,8 @@ export function FormInsight(props: Props) {
label="Day of Week"
type="dropdown"
value={frequency.dayOfWeek}
onChange={value => generateCronExpression(frequency.frequency, frequency.minute, frequency.hour, String(value) as any)}
options={FrequencyWeekDays as any}
onChange={value => generateCronExpression(frequency.frequency, frequency.minute, frequency.hour, value as string)}
options={FrequencyWeekDays}
inline={false}
size="md"
info={'Select the day of the week to trigger the ' + props.insight.type}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment