diff --git a/apps/web/src/actions/accounts.ts b/apps/web/src/actions/accounts.ts index c159857..d77bc1d 100644 --- a/apps/web/src/actions/accounts.ts +++ b/apps/web/src/actions/accounts.ts @@ -172,8 +172,16 @@ export async function unpairAccountAction(formData: FormData): Promise { .update(whatsappAccounts) .set({ status: "unpaired", phoneNumber: null }) .where(eq(whatsappAccounts.id, accountId)); - // Wipe synced groups too — they belong to a different WA login now. - await db.delete(whatsappGroups).where(eq(whatsappGroups.accountId, accountId)); + // Soft-archive synced groups instead of DELETEing. Hard delete + // failed with "violates foreign key constraint + // reminder_targets_group_id_whatsapp_groups_id_fk" whenever any + // group had ever been used in a reminder, which aborted the + // unpair. Archived groups vanish from the picker; a re-pair flips + // them back via the on-conflict upsert in syncGroupsForAccount. + await db + .update(whatsappGroups) + .set({ isArchived: true }) + .where(eq(whatsappGroups.accountId, accountId)); revalidatePath("/accounts"); revalidatePath(`/accounts/${accountId}`); // eslint-disable-next-line @typescript-eslint/no-explicit-any