Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

Update only the groups whose lead form switch changed

Rafieaf0ecc93130
diff --git a/apps/web/lib/submitted-leads/update-submitted-lead-form-action.ts b/apps/web/lib/submitted-leads/update-submitted-lead-form-action.ts
index f0ceab786e..4dd553aeb6 100644
--- a/apps/web/lib/submitted-leads/update-submitted-lead-form-action.ts
+++ b/apps/web/lib/submitted-leads/update-submitted-lead-form-action.ts
@@ -12,7 +12,9 @@ import { throwIfNoPermission } from "../actions/throw-if-no-permission";
const schema = z.object({
workspaceId: z.string(),
referralFormData: submittedLeadFormSchema,
+ // Only the groups whose switch changed. All other groups keep their setting.
enabledGroupIds: z.array(z.string()),
+ disabledGroupIds: z.array(z.string()),
});
// Update the submitted lead form and the groups that can submit leads
@@ -20,7 +22,7 @@ export const updateSubmittedLeadFormAction = authActionClient
.inputSchema(schema)
.action(async ({ parsedInput, ctx }) => {
const { workspace } = ctx;
- const { referralFormData, enabledGroupIds } = parsedInput;
+ const { referralFormData, enabledGroupIds, disabledGroupIds } = parsedInput;
const programId = getDefaultProgramIdOrThrow(workspace);
@@ -70,7 +72,7 @@ export const updateSubmittedLeadFormAction = authActionClient
where: {
programId,
id: {
- notIn: enabledGroupIds,
+ in: disabledGroupIds,
},
},
data: {
diff --git a/apps/web/ui/submitted-leads/form-builder/edit-lead-form-sheet.tsx b/apps/web/ui/submitted-leads/form-builder/edit-lead-form-sheet.tsx
index 2e127a9c4c..6c42e4d482 100644
--- a/apps/web/ui/submitted-leads/form-builder/edit-lead-form-sheet.tsx
+++ b/apps/web/ui/submitted-leads/form-builder/edit-lead-form-sheet.tsx
@@ -143,7 +143,12 @@ function EditLeadFormSheetForm({
await executeAsync({
workspaceId,
- enabledGroupIds,
+ enabledGroupIds: enabledGroupIds.filter(
+ (id) => !initialState.enabledGroupIds.includes(id),
+ ),
+ disabledGroupIds: initialState.enabledGroupIds.filter(
+ (id) => !enabledGroupIds.includes(id),
+ ),
referralFormData: {
fields: fields.map((field, index) =>
fromLeadFormBuilderField(