Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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,
{
Expand Down Expand Up @@ -113,7 +111,6 @@ export function useDraftReplies() {
enable,
});

// Revalidate to get the real data from server
mutate();

return result;
Expand Down
34 changes: 24 additions & 10 deletions apps/web/utils/actions/rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
},
);
Expand All @@ -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 =
Comment thread
elie222 marked this conversation as resolved.
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) {
Expand Down
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v2.16.2
v2.16.3
Loading