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.

add bounty_submission.approved and rejected to audit logs, add View commissions button

Steven Tey93948821b08d
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/[bountyId]/bounty-submission-details-sheet.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/[bountyId]/bounty-submission-details-sheet.tsx
index ceb7740c51..09f6732232 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/[bountyId]/bounty-submission-details-sheet.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/[bountyId]/bounty-submission-details-sheet.tsx
@@ -213,33 +213,38 @@ function BountySubmissionDetailsSheetContent({
</div>
<div className="flex items-center justify-between gap-2 border-t border-neutral-200 p-5">
- <Button
- type="button"
- variant="danger"
- text="Reject"
- disabledTooltip={
- submission.status === "rejected"
- ? "Bounty submission already rejected."
- : undefined
- }
- disabled={
- isApprovingBountySubmission || submission.status === "approved"
- }
- onClick={() => setShowRejectModal(true)}
- />
+ {submission.status === "approved" ? (
+ <a
+ href={`/${workspaceSlug}/program/commissions?partnerId=${partner.id}&type=custom`}
+ target="_blank"
+ className="w-full"
+ >
+ <Button variant="secondary" text="View commissions" />
+ </a>
+ ) : (
+ <>
+ <Button
+ type="button"
+ variant="danger"
+ text="Reject"
+ disabledTooltip={
+ submission.status === "rejected"
+ ? "Bounty submission already rejected."
+ : undefined
+ }
+ disabled={isApprovingBountySubmission}
+ onClick={() => setShowRejectModal(true)}
+ />
- <Button
- type="submit"
- variant="primary"
- text="Approve"
- disabledTooltip={
- submission.status === "approved"
- ? "Bounty submission already approved."
- : undefined
- }
- loading={isApprovingBountySubmission}
- onClick={() => setShowApproveBountySubmissionModal(true)}
- />
+ <Button
+ type="submit"
+ variant="primary"
+ text="Approve"
+ loading={isApprovingBountySubmission}
+ onClick={() => setShowApproveBountySubmissionModal(true)}
+ />
+ </>
+ )}
</div>
</div>
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/page.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/page.tsx
index 79b1ef9ccd..02411256f7 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/page.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/page.tsx
@@ -7,11 +7,7 @@ export default function Page() {
return (
<PageContent
title="Bounties"
- titleInfo={{
- title:
- "Learn how partner commissions work on Dub, and how to create manual commissions or clawbacks.",
- href: "https://dub.co/help/article/partner-commissions-clawbacks",
- }}
+ // TODO: add title info & href
controls={<CreateBountyButton />}
>
<PageWidthWrapper>
diff --git a/apps/web/lib/actions/partners/approve-bounty-submission.ts b/apps/web/lib/actions/partners/approve-bounty-submission.ts
index 10f910c587..9f1183e6ad 100644
--- a/apps/web/lib/actions/partners/approve-bounty-submission.ts
+++ b/apps/web/lib/actions/partners/approve-bounty-submission.ts
@@ -1,7 +1,9 @@
"use server";
+import { recordAuditLog } from "@/lib/api/audit-logs/record-audit-log";
import { getDefaultProgramIdOrThrow } from "@/lib/api/programs/get-default-program-id-or-throw";
import { createPartnerCommission } from "@/lib/partners/create-partner-commission";
+import { BountySubmissionSchema } from "@/lib/zod/schemas/bounties";
import { sendEmail } from "@dub/email";
import BountyApproved from "@dub/email/templates/bounty-approved";
import { prisma } from "@dub/prisma";
@@ -77,26 +79,40 @@ export const approveBountySubmissionAction = authActionClient
if (partner.email) {
waitUntil(
- sendEmail({
- subject: "Bounty approved!",
- email: partner.email,
- variant: "notifications",
- react: BountyApproved({
+ Promise.allSettled([
+ recordAuditLog({
+ workspaceId: workspace.id,
+ programId: program.id,
+ action: "bounty_submission.approved",
+ description: `Bounty submission approved for ${partner.id}`,
+ actor: user,
+ targets: [
+ {
+ type: "bounty_submission",
+ id: submissionId,
+ metadata: BountySubmissionSchema.parse(bountySubmission),
+ },
+ ],
+ }),
+
+ sendEmail({
+ subject: "Bounty approved!",
email: partner.email,
- program: {
- name: program.name,
- slug: program.slug,
- supportEmail: program.supportEmail || "[email protected]",
- },
- bounty: {
- name: bounty.name,
- type: bounty.type,
- },
+ variant: "notifications",
+ react: BountyApproved({
+ email: partner.email,
+ program: {
+ name: program.name,
+ slug: program.slug,
+ supportEmail: program.supportEmail || "[email protected]",
+ },
+ bounty: {
+ name: bounty.name,
+ type: bounty.type,
+ },
+ }),
}),
- }),
+ ]),
);
}
-
- // TODO:
- // Record audit log
});
diff --git a/apps/web/lib/actions/partners/reject-bounty-submission.ts b/apps/web/lib/actions/partners/reject-bounty-submission.ts
index 793de2fac0..8f829140c9 100644
--- a/apps/web/lib/actions/partners/reject-bounty-submission.ts
+++ b/apps/web/lib/actions/partners/reject-bounty-submission.ts
@@ -1,7 +1,9 @@
"use server";
+import { recordAuditLog } from "@/lib/api/audit-logs/record-audit-log";
import { getDefaultProgramIdOrThrow } from "@/lib/api/programs/get-default-program-id-or-throw";
import {
+ BountySubmissionSchema,
REJECT_BOUNTY_SUBMISSION_REASONS,
rejectBountySubmissionSchema,
} from "@/lib/zod/schemas/bounties";
@@ -70,29 +72,42 @@ export const rejectBountySubmissionAction = authActionClient
if (partner.email) {
waitUntil(
- sendEmail({
- subject: "Bounty rejected",
- email: partner.email,
- variant: "notifications",
- react: BountyRejected({
+ Promise.allSettled([
+ recordAuditLog({
+ workspaceId: workspace.id,
+ programId: program.id,
+ action: "bounty_submission.rejected",
+ description: `Bounty submission rejected for ${partner.id}`,
+ actor: user,
+ targets: [
+ {
+ type: "bounty_submission",
+ id: submissionId,
+ metadata: BountySubmissionSchema.parse(bountySubmission),
+ },
+ ],
+ }),
+ sendEmail({
+ subject: "Bounty rejected",
email: partner.email,
- program: {
- name: program.name,
- slug: program.slug,
- supportEmail: program.supportEmail || "[email protected]",
- },
- bounty: {
- name: bounty.name,
- },
- submission: {
- rejectionReason:
- REJECT_BOUNTY_SUBMISSION_REASONS[rejectionReason],
- },
+ variant: "notifications",
+ react: BountyRejected({
+ email: partner.email,
+ program: {
+ name: program.name,
+ slug: program.slug,
+ supportEmail: program.supportEmail || "[email protected]",
+ },
+ bounty: {
+ name: bounty.name,
+ },
+ submission: {
+ rejectionReason:
+ REJECT_BOUNTY_SUBMISSION_REASONS[rejectionReason],
+ },
+ }),
}),
- }),
+ ]),
);
}
-
- // TODO:
- // Record audit log
});
diff --git a/apps/web/lib/api/audit-logs/schemas.ts b/apps/web/lib/api/audit-logs/schemas.ts
index 3e7376412c..04c48df71b 100644
--- a/apps/web/lib/api/audit-logs/schemas.ts
+++ b/apps/web/lib/api/audit-logs/schemas.ts
@@ -1,4 +1,7 @@
-import { BountySchema } from "@/lib/zod/schemas/bounties";
+import {
+ BountySchema,
+ BountySubmissionSchema,
+} from "@/lib/zod/schemas/bounties";
import { CommissionSchema } from "@/lib/zod/schemas/commissions";
import { DiscountSchema } from "@/lib/zod/schemas/discount";
import { GroupSchema } from "@/lib/zod/schemas/groups";
@@ -79,6 +82,8 @@ const actionSchema = z.enum([
"bounty.created",
"bounty.updated",
"bounty.deleted",
+ "bounty_submission.approved",
+ "bounty_submission.rejected",
]);
export const auditLogTarget = z.union([
@@ -168,6 +173,12 @@ export const auditLogTarget = z.union([
id: z.string(),
metadata: BountySchema,
}),
+
+ z.object({
+ type: z.literal("bounty_submission"),
+ id: z.string(),
+ metadata: BountySubmissionSchema,
+ }),
]);
export const recordAuditLogInputSchema = z.object({
diff --git a/apps/web/lib/zod/schemas/partner-profile.ts b/apps/web/lib/zod/schemas/partner-profile.ts
index e548f78220..3b8ba4210b 100644
--- a/apps/web/lib/zod/schemas/partner-profile.ts
+++ b/apps/web/lib/zod/schemas/partner-profile.ts
@@ -134,7 +134,9 @@ export const partnerNotificationTypes = z.enum([
"applicationApproved",
]);
-export const PartnerBountySchema = BountySchema.extend({
+export const PartnerBountySchema = BountySchema.omit({
+ groups: true,
+}).extend({
submission: BountySubmissionSchema.nullable(),
performanceCondition: workflowConditionSchema.nullable().default(null),
partner: z.object({