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.

Refactor bounty submissions and partners data structure

Kiran K2f7bf7625db0
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/bounty-card.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/bounty-card.tsx
index 6d2a4020f8..22fa7bb141 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/bounty-card.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/bounty-card.tsx
@@ -16,6 +16,9 @@ export function BountyCard({ bounty }: { bounty: BountyExtendedProps }) {
const [isMenuOpen, setIsMenuOpen] = useState(false);
const { id: workspaceId, slug: workspaceSlug } = useWorkspace();
+ const { pending = 0, approved = 0, rejected = 0 } = bounty.submissions;
+ const totalSubmissions = pending + approved + rejected;
+
const { confirmModal: deleteModal, setShowConfirmModal: setShowDeleteModal } =
useConfirmModal({
title: "Delete bounty",
@@ -59,7 +62,7 @@ export function BountyCard({ bounty }: { bounty: BountyExtendedProps }) {
<BountyThumbnailImage bounty={bounty} />
</div>
- <PendingSubmissionsBadge count={bounty.submissionsCount} />
+ {pending > 0 && <PendingSubmissionsBadge count={pending} />}
</div>
<div className="flex flex-col gap-1.5">
@@ -83,13 +86,8 @@ export function BountyCard({ bounty }: { bounty: BountyExtendedProps }) {
<div className="text-content-subtle flex items-center gap-2 text-sm font-medium">
<Users className="size-3.5" />
<div className="h-5">
- <span className="text-content-default">
- {bounty.submissionsCount}
- </span>{" "}
- of{" "}
- <span className="text-content-default">
- {bounty.partnersCount}
- </span>{" "}
+ <span className="text-content-default">{totalSubmissions}</span>{" "}
+ of <span className="text-content-default">{bounty.partners}</span>{" "}
partners completed
</div>
</div>
diff --git a/apps/web/lib/api/bounties/get-bounties.ts b/apps/web/lib/api/bounties/get-bounties.ts
index bb6680289a..516d24c0cd 100644
--- a/apps/web/lib/api/bounties/get-bounties.ts
+++ b/apps/web/lib/api/bounties/get-bounties.ts
@@ -52,7 +52,7 @@ export async function getBounties(filters: BountyFilters) {
)
),
0
- ) as partnersCount,
+ ) AS partners,
-- Bounty groups
COALESCE(
@@ -62,17 +62,22 @@ export async function getBounties(filters: BountyFilters) {
WHERE bountyId = b.id
),
JSON_ARRAY()
- ) as groups,
+ ) AS groups,
- -- Bounty submissions count
+ -- Bounty submissions count by status
COALESCE(
(
- SELECT COUNT(bs.id)
- FROM BountySubmission bs
- WHERE bs.bountyId = b.id
- ),
- 0
- ) AS submissions
+ SELECT JSON_OBJECT(
+ 'pending', COALESCE(SUM(status = 'pending'), 0),
+ 'approved', COALESCE(SUM(status = 'approved'), 0),
+ 'rejected', COALESCE(SUM(status = 'rejected'), 0)
+ )
+ FROM BountySubmission
+ WHERE bountyId = b.id
+ ),
+ JSON_OBJECT('pending', 0, 'approved', 0, 'rejected', 0)
+ ) AS submissions
+
FROM Bounty b
LEFT JOIN BountyGroup bg ON bg.bountyId = b.id
LEFT JOIN ProgramEnrollment pe ON pe.groupId = bg.groupId AND pe.status IN ('approved', 'invited')
@@ -97,9 +102,9 @@ export async function getBounties(filters: BountyFilters) {
rewardAmount: bounty.rewardAmount,
submissionRequirements: bounty.submissionRequirements,
performanceCondition,
- partnersCount: Number(bounty.partnersCount),
- submissionsCount: Number(bounty.submissions),
groups: bounty.groups.filter((group) => group !== null),
+ partners: Number(bounty.partners),
+ submissions: bounty.submissions,
};
});
diff --git a/apps/web/lib/types.ts b/apps/web/lib/types.ts
index a1e04dcc18..d5195e7529 100644
--- a/apps/web/lib/types.ts
+++ b/apps/web/lib/types.ts
@@ -6,7 +6,6 @@ import {
} from "@/lib/zod/schemas/partner-profile";
import { DirectorySyncProviders } from "@boxyhq/saml-jackson";
import {
- BountySubmissionStatus,
CommissionStatus,
FolderUserRole,
Link,
diff --git a/apps/web/lib/zod/schemas/bounties.ts b/apps/web/lib/zod/schemas/bounties.ts
index 94fc485836..09a705a7b4 100644
--- a/apps/web/lib/zod/schemas/bounties.ts
+++ b/apps/web/lib/zod/schemas/bounties.ts
@@ -47,6 +47,12 @@ export const updateBountySchema = createBountySchema.omit({
type: true,
});
+export const BountySubmissionFileSchema = z.object({
+ url: z.string(),
+ fileName: z.string(),
+ size: z.number(),
+});
+
export const BountySchema = z.object({
id: z.string(),
name: z.string().nullable(),
@@ -59,18 +65,6 @@ export const BountySchema = z.object({
performanceCondition: workflowConditionSchema.nullable().default(null),
});
-export const BountySchemaExtended = BountySchema.extend({
- groups: z.array(GroupSchema.pick({ id: true })).nullable(),
- partnersCount: z.number().default(0),
- submissionsCount: z.number().default(0),
-});
-
-export const BountySubmissionFileSchema = z.object({
- url: z.string(),
- fileName: z.string(),
- size: z.number(),
-});
-
const BountySubmissionSchema = z.object({
id: z.string(),
description: z.string().nullable(),
@@ -84,6 +78,12 @@ const BountySubmissionSchema = z.object({
rejectionNote: z.string().nullable(),
});
+export const BountySchemaExtended = BountySchema.extend({
+ groups: z.array(GroupSchema.pick({ id: true })).nullable(),
+ partners: z.number().default(0),
+ submissions: z.record(z.nativeEnum(BountySubmissionStatus), z.number()),
+});
+
export const BountySubmissionExtendedSchema = z.object({
submission: BountySubmissionSchema.nullable(),
partner: EnrolledPartnerSchema.pick({