From e2061758513e77dd11ea95fd9db2a25b6b5982b5 Mon Sep 17 00:00:00 2001 From: ppranay20 Date: Sun, 9 Nov 2025 21:12:01 +0530 Subject: [PATCH 1/2] fix: error message not displaying when no actions --- .../[emailAccountId]/assistant/RuleForm.tsx | 82 +++++++++---------- 1 file changed, 37 insertions(+), 45 deletions(-) diff --git a/apps/web/app/(app)/[emailAccountId]/assistant/RuleForm.tsx b/apps/web/app/(app)/[emailAccountId]/assistant/RuleForm.tsx index f218a0b52..ba41057ad 100644 --- a/apps/web/app/(app)/[emailAccountId]/assistant/RuleForm.tsx +++ b/apps/web/app/(app)/[emailAccountId]/assistant/RuleForm.tsx @@ -158,10 +158,13 @@ export function RuleForm({ watch, setValue, control, - formState: { errors, isSubmitting, isSubmitted }, + formState , trigger, } = form; + const { errors, isSubmitting, isSubmitted } = formState; + + const { fields: conditionFields, append: appendCondition, @@ -285,23 +288,6 @@ export function RuleForm({ ) as CoreConditionType | undefined; }, [conditions]); - // biome-ignore lint/correctness/useExhaustiveDependencies: needed - useEffect(() => { - trigger("conditions"); - }, [conditions]); - - const actionErrors = useMemo(() => { - const actionErrors: string[] = []; - watch("actions")?.forEach((_, index) => { - const actionError = - errors?.actions?.[index]?.url?.root?.message || - errors?.actions?.[index]?.labelId?.root?.message || - errors?.actions?.[index]?.to?.root?.message; - if (actionError) actionErrors.push(actionError); - }); - return actionErrors; - }, [errors, watch]); - const conditionalOperator = watch("conditionalOperator"); const terminology = getEmailTerminology(provider); @@ -351,18 +337,48 @@ export function RuleForm({ setIsNameEditMode((prev: boolean) => !prev); } }, [alwaysEditMode]); + + function getErrorMessages(errors: any): string[] { + const messages: string[] = []; + + if (!errors) { + return messages; + } + + if (typeof errors.name?.message === 'string') { + messages.push(errors.name.message); + } + + const actionsMessage = errors.actions?.root?.message || errors.actions?.message; + + if (typeof actionsMessage === 'string') { + messages.push(actionsMessage); + } + + const conditionsMessage = errors.conditions?.root?.message || errors.conditions?.message; + + if (typeof conditionsMessage === 'string') { + messages.push(conditionsMessage); + } + + return messages; + } + + const errorMessages = useMemo(() => { + return getErrorMessages(errors); + }, [formState]); return (
- {isSubmitted && Object.keys(errors).length > 0 && ( + {isSubmitted && errorMessages.length > 0 && (
- {Object.values(errors).map((error) => ( -
  • {error.message}
  • + {errorMessages.map((message, index) => ( +
  • {message}
  • ))} } @@ -461,15 +477,6 @@ export function RuleForm({
    - {errors.conditions?.root?.message && ( -
    - -
    - )} -
    {conditionFields.map((condition, index) => (
    @@ -696,21 +703,6 @@ export function RuleForm({ )}
    - {actionErrors.length > 0 && ( -
    - - {actionErrors.map((error, index) => ( -
  • {error}
  • - ))} - - } - /> -
    - )} -
    {watch("actions")?.map((action, i) => isActionsEditMode ? ( From 1d3cbea7a24996f366d26b3fa5cf7789af556e10 Mon Sep 17 00:00:00 2001 From: ppranay20 Date: Mon, 10 Nov 2025 16:32:59 +0530 Subject: [PATCH 2/2] fix:added types in errors --- apps/web/app/(app)/[emailAccountId]/assistant/RuleForm.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/web/app/(app)/[emailAccountId]/assistant/RuleForm.tsx b/apps/web/app/(app)/[emailAccountId]/assistant/RuleForm.tsx index ba41057ad..bf69932fa 100644 --- a/apps/web/app/(app)/[emailAccountId]/assistant/RuleForm.tsx +++ b/apps/web/app/(app)/[emailAccountId]/assistant/RuleForm.tsx @@ -338,7 +338,7 @@ export function RuleForm({ } }, [alwaysEditMode]); - function getErrorMessages(errors: any): string[] { + function getErrorMessages(errors: FieldErrors): string[] { const messages: string[] = []; if (!errors) {