diff --git a/apps/web/app/(app)/[emailAccountId]/assistant/settings/DraftReplies.tsx b/apps/web/app/(app)/[emailAccountId]/assistant/settings/DraftReplies.tsx index 86ed96b927..5643e9aba1 100644 --- a/apps/web/app/(app)/[emailAccountId]/assistant/settings/DraftReplies.tsx +++ b/apps/web/app/(app)/[emailAccountId]/assistant/settings/DraftReplies.tsx @@ -63,17 +63,15 @@ export function useDraftReplies() { async (enable: boolean) => { if (!data) return; - // Optimistically update the cache const optimisticData = data.map((rule) => { if (rule.systemType === SystemType.TO_REPLY) { return { ...rule, actions: enable - ? // Add DRAFT_EMAIL action if enabling - rule.actions.some( + ? rule.actions.some( (action) => action.type === ActionType.DRAFT_EMAIL, ) - ? rule.actions // Already has the action + ? rule.actions : [ ...rule.actions, { @@ -113,7 +111,6 @@ export function useDraftReplies() { enable, }); - // Revalidate to get the real data from server mutate(); return result; diff --git a/apps/web/utils/actions/rule.ts b/apps/web/utils/actions/rule.ts index c2e7ddf35e..007d491c2e 100644 --- a/apps/web/utils/actions/rule.ts +++ b/apps/web/utils/actions/rule.ts @@ -233,9 +233,6 @@ export const updateRuleSettingsAction = actionClient data: { instructions }, }); - revalidatePath(prefixPath(emailAccountId, `/assistant/rule/${id}`)); - revalidatePath(prefixPath(emailAccountId, "/assistant")); - revalidatePath(prefixPath(emailAccountId, "/automation")); revalidatePath(prefixPath(emailAccountId, "/reply-zero")); }, ); @@ -245,16 +242,33 @@ export const enableDraftRepliesAction = actionClient .schema(enableDraftRepliesBody) .action( async ({ ctx: { emailAccountId, provider }, parsedInput: { enable } }) => { - const rule = await toggleRule({ - emailAccountId, - enabled: enable, - systemType: SystemType.TO_REPLY, - provider, - ruleId: undefined, + let rule = await prisma.rule.findUnique({ + where: { + emailAccountId_systemType: { + emailAccountId, + systemType: SystemType.TO_REPLY, + }, + }, + include: { actions: true }, }); + if (!rule && !enable) { + return; + } + + // if rule doesn't exist, then toggle will create it + rule = + rule || + (await toggleRule({ + emailAccountId, + enabled: enable, + systemType: SystemType.TO_REPLY, + provider, + ruleId: undefined, + })); + if (enable) { - const alreadyDraftingReplies = rule?.actions?.find( + const alreadyDraftingReplies = rule.actions.find( (a) => a.type === ActionType.DRAFT_EMAIL, ); if (!alreadyDraftingReplies) { diff --git a/version.txt b/version.txt index 608ac5d846..839d54f2fe 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -v2.16.2 +v2.16.3