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.

Performance bounty submission filters

Tim Wilson10d8ee183485
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/[bountyId]/bounty-submissions-table.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/[bountyId]/bounty-submissions-table.tsx
index 45b75da9f0..98256a6f4b 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/[bountyId]/bounty-submissions-table.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/[bountyId]/bounty-submissions-table.tsx
@@ -67,14 +67,8 @@ export function BountySubmissionsTable() {
const sortBy = searchParams.get("sortBy") || "createdAt";
const sortOrder = searchParams.get("sortOrder") === "asc" ? "asc" : "desc";
- const {
- filters,
- activeFilters,
- onSelect,
- onRemove,
- onRemoveAll,
- isFiltered,
- } = useBountySubmissionFilters();
+ const { filters, activeFilters, onSelect, onRemove, onRemoveAll } =
+ useBountySubmissionFilters({ bounty });
const {
error,
@@ -369,10 +363,12 @@ export function BountySubmissionsTable() {
onSelect={onSelect}
onRemove={onRemove}
/>
- <SimpleDateRangePicker
- className="w-full sm:min-w-[200px] md:w-fit"
- defaultInterval="all"
- />
+ {bounty?.type === "submission" && (
+ <SimpleDateRangePicker
+ className="w-full sm:min-w-[200px] md:w-fit"
+ defaultInterval="all"
+ />
+ )}
</div>
<AnimatedSizeContainer height>
<div>
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/[bountyId]/use-bounty-submission-filters.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/[bountyId]/use-bounty-submission-filters.tsx
index 8bf3a5f69a..a6a60fbefe 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/[bountyId]/use-bounty-submission-filters.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/[bountyId]/use-bounty-submission-filters.tsx
@@ -1,13 +1,18 @@
import useGroups from "@/lib/swr/use-groups";
import useWorkspace from "@/lib/swr/use-workspace";
+import { BountyExtendedProps } from "@/lib/types";
import { GroupColorCircle } from "@/ui/partners/groups/group-color-circle";
import { CircleDotted, useRouterStuff } from "@dub/ui";
-import { Users6 } from "@dub/ui/icons";
+import { CircleCheck, CircleHalfDottedCheck, Users6 } from "@dub/ui/icons";
import { cn } from "@dub/utils";
import { useCallback, useMemo } from "react";
import { BOUNTY_SUBMISSION_STATUS_BADGES } from "./bounty-submission-status-badges";
-export function useBountySubmissionFilters() {
+export function useBountySubmissionFilters({
+ bounty,
+}: {
+ bounty?: BountyExtendedProps;
+}) {
const { slug } = useWorkspace();
const { searchParamsObj, queryParams } = useRouterStuff();
@@ -19,15 +24,33 @@ export function useBountySubmissionFilters() {
key: "status",
icon: CircleDotted,
label: "Status",
- options: Object.entries(BOUNTY_SUBMISSION_STATUS_BADGES).map(
- ([value, { label, icon: Icon, iconClassName }]) => ({
- value,
- label,
- icon: (
- <Icon className={cn("size-4 bg-transparent", iconClassName)} />
- ),
- }),
- ),
+ options:
+ bounty?.type === "submission"
+ ? Object.entries(BOUNTY_SUBMISSION_STATUS_BADGES).map(
+ ([value, { label, icon: Icon, iconClassName }]) => ({
+ value,
+ label,
+ icon: (
+ <Icon
+ className={cn("size-4 bg-transparent", iconClassName)}
+ />
+ ),
+ }),
+ )
+ : [
+ {
+ value: "approved",
+ label: "Completed",
+ icon: <CircleCheck className="size-4 text-green-600" />,
+ },
+ {
+ value: "pending",
+ label: "Incomplete",
+ icon: (
+ <CircleHalfDottedCheck className="size-4 text-orange-600" />
+ ),
+ },
+ ],
},
{
key: "groupId",
@@ -44,7 +67,7 @@ export function useBountySubmissionFilters() {
}) ?? null,
},
],
- [groups, slug],
+ [bounty, groups, slug],
);
const activeFilters = useMemo(() => {
diff --git a/apps/web/lib/api/bounties/get-partners-with-bounty-submission.ts b/apps/web/lib/api/bounties/get-partners-with-bounty-submission.ts
index 05011b78a6..cb56eee796 100644
--- a/apps/web/lib/api/bounties/get-partners-with-bounty-submission.ts
+++ b/apps/web/lib/api/bounties/get-partners-with-bounty-submission.ts
@@ -18,6 +18,7 @@ export async function getPartnersWithBountySubmission({
programId,
bountyId,
groupIds,
+ status,
}: BountySubmissionsQueryFilters & {
programId: string;
bountyId: string;
@@ -60,6 +61,7 @@ export async function getPartnersWithBountySubmission({
WHERE
pe.programId = ${programId}
${groupIds && groupIds.length > 0 ? Prisma.sql`AND pe.groupId IN (${Prisma.join(groupIds)})` : Prisma.sql``}
+ ${status ? (status === "approved" ? Prisma.sql`AND bs.status = ${status}` : Prisma.sql`AND bs.status IS NULL`) : Prisma.sql``}
GROUP BY
p.id, pe.partnerId, pe.groupId, pe.totalCommissions, pe.status, bountySubmissionId, bountySubmissionStatus, bountySubmissionCreatedAt, bountySubmissionUpdatedAt, metrics.totalLeads, metrics.totalConversions, metrics.totalSaleAmount
ORDER BY ${Prisma.raw(sortColumnsMap[sortBy])} ${Prisma.raw(sortOrder)}