The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Skip removed partners in bulk approve instead of failing the batch
Rafic4fdfbad557c
diff --git a/apps/web/lib/actions/partners/bulk-approve-program-applications.ts b/apps/web/lib/actions/partners/bulk-approve-program-applications.tsindex 2e4ea1f006..7a9e4fe985 100644--- a/apps/web/lib/actions/partners/bulk-approve-program-applications.ts+++ b/apps/web/lib/actions/partners/bulk-approve-program-applications.ts@@ -121,22 +121,29 @@ export const bulkApproveProgramApplicationsAction = authActionClient]),);+ const ineligibleApplications: {+ applicationId: string;+ enrollmentStatus: ProgramEnrollmentStatus;+ }[] = [];+// Each application either creates an enrollment// OR approves an existing pending/rejected enrollment// OR moves an approved partner to the new group- const reviews = programApplications.map((application) => {+ const reviews = programApplications.flatMap((application) => {const partnerId = application.partnerId!;const enrollment = enrollmentsByPartnerId.get(partnerId);// Create a new enrollmentif (!enrollment) {- return {- application,- partnerId,- enrollmentId: createId({ prefix: "pge_" }),- enrollmentApplicationId: application.id,- action: "create" as const,- };+ return [+ {+ application,+ partnerId,+ enrollmentId: createId({ prefix: "pge_" }),+ enrollmentApplicationId: application.id,+ action: "create" as const,+ },+ ];}// Approve an existing pending/rejected enrollment@@ -147,23 +154,40 @@ export const bulkApproveProgramApplicationsAction = authActionClient// Move an approved partner to the new groupconst isApproved = enrollment.status === ProgramEnrollmentStatus.approved;- // e.g. invited, declined, deactivated, banned, or archived partners+ // Skip invited, declined, deactivated, banned, or archived partners so+ // they don't block the rest of the selectionif (!isPendingOrRejected && !isApproved) {- throw new DubApiError({- code: "bad_request",- message: `Application ${application.id} cannot be approved because the partner is ${enrollment.status}.`,+ ineligibleApplications.push({+ applicationId: application.id,+ enrollmentStatus: enrollment.status,});++ return [];}- return {- application,- partnerId,- enrollmentId: enrollment.id,- enrollmentApplicationId: enrollment.applicationId,- action: isApproved ? ("move" as const) : ("approve" as const),- };+ return [+ {+ application,+ partnerId,+ enrollmentId: enrollment.id,+ enrollmentApplicationId: enrollment.applicationId,+ action: isApproved ? ("move" as const) : ("approve" as const),+ },+ ];});+ if (reviews.length === 0) {+ const [ineligibleApplication] = ineligibleApplications;++ throw new DubApiError({+ code: "bad_request",+ message:+ ineligibleApplications.length === 1+ ? `Application ${ineligibleApplication.applicationId} cannot be approved because the partner is ${ineligibleApplication.enrollmentStatus}.`+ : "None of the selected applications can be approved.",+ });+ }+// Group reviews by actiontype Review = (typeof reviews)[number];diff --git a/apps/web/ui/modals/bulk-approve-program-applications-modal.tsx b/apps/web/ui/modals/bulk-approve-program-applications-modal.tsxindex 3c3963c516..04390e2722 100644--- a/apps/web/ui/modals/bulk-approve-program-applications-modal.tsx+++ b/apps/web/ui/modals/bulk-approve-program-applications-modal.tsx@@ -71,7 +71,7 @@ function BulkApproveProgramApplicationsModal({setShowBulkApproveProgramApplicationsModal(false);const { approvedCount, skippedCount } = data;toast.success(- `${approvedCount} ${pluralize("partner", approvedCount)} approved.${skippedCount > 0 ? ` ${skippedCount} skipped because ${pluralize("it was", skippedCount, { plural: "they were" })} already reviewed.` : ""}`,+ `${approvedCount} ${pluralize("partner", approvedCount)} approved.${skippedCount > 0 ? ` ${skippedCount} skipped because ${pluralize("it was", skippedCount, { plural: "they were" })} already reviewed or the partner was removed.` : ""}`,);await onConfirm?.();await mutatePrefix(["/api/partners", "/api/program-applications"]);