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.

improve bounty review UX & perf

Steven Tey76ee59b3ff27
diff --git a/apps/web/app/(ee)/api/bounties/[bountyId]/route.ts b/apps/web/app/(ee)/api/bounties/[bountyId]/route.ts
index f4d999fde5..33e6197a50 100644
--- a/apps/web/app/(ee)/api/bounties/[bountyId]/route.ts
+++ b/apps/web/app/(ee)/api/bounties/[bountyId]/route.ts
@@ -11,11 +11,7 @@ import { withWorkspace } from "@/lib/auth";
import { qstash } from "@/lib/cron";
import { WorkflowCondition } from "@/lib/types";
import { sendWorkspaceWebhook } from "@/lib/webhook/publish";
-import {
- BountySchema,
- BountySchemaExtended,
- updateBountySchema,
-} from "@/lib/zod/schemas/bounties";
+import { BountySchema, updateBountySchema } from "@/lib/zod/schemas/bounties";
import { prisma } from "@dub/prisma";
import { APP_DOMAIN_WITH_NGROK, arrayEqual } from "@dub/utils";
import { PartnerGroup, Prisma } from "@prisma/client";
@@ -29,12 +25,14 @@ export const GET = withWorkspace(
const programId = getDefaultProgramIdOrThrow(workspace);
+ console.time("getBountyWithDetails");
const bounty = await getBountyWithDetails({
bountyId,
programId,
});
+ console.timeEnd("getBountyWithDetails");
- return NextResponse.json(BountySchemaExtended.parse(bounty));
+ return NextResponse.json(BountySchema.parse(bounty));
},
{
requiredPlan: [
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/[bountyId]/bounty-info.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/[bountyId]/bounty-info.tsx
index 1d19869316..2dc82ec50c 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/[bountyId]/bounty-info.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/[bountyId]/bounty-info.tsx
@@ -6,6 +6,7 @@ import {
SubmissionsCountByStatus,
useBountySubmissionsCount,
} from "@/lib/swr/use-bounty-submissions-count";
+import { usePartnersCountBounty } from "@/lib/swr/use-partners-count-bounty";
import { BountyThumbnailImage } from "@/ui/partners/bounties/bounty-thumbnail-image";
import { formatDate, nFormatter, pluralize } from "@dub/utils";
import { CalendarDays, Gift, Users } from "lucide-react";
@@ -31,6 +32,9 @@ export function BountyInfo() {
return submissionsCount?.find((s) => s.status === "submitted")?.count ?? 0;
}, [submissionsCount]);
+ const { totalPartnersForBounty, loading: totalPartnersForBountyLoading } =
+ usePartnersCountBounty({ bounty });
+
if (loading) {
return <BountyInfoSkeleton />;
}
@@ -71,18 +75,28 @@ export function BountyInfo() {
<div className="flex items-center space-x-2">
<Users className="size-4 shrink-0" />
<div className="text-sm text-neutral-500">
- {totalSubmissions === undefined ? (
- <div className="h-5 w-32 animate-pulse rounded bg-neutral-200" />
+ {totalSubmissions === totalPartnersForBounty ? (
+ <>All</>
+ ) : (
+ <>
+ <span className="font-medium text-neutral-700">
+ {nFormatter(totalSubmissions ?? 0, {
+ full: true,
+ })}
+ </span>{" "}
+ of
+ </>
+ )}{" "}
+ {totalPartnersForBountyLoading ? (
+ <span className="inline-block h-4 w-8 animate-pulse rounded bg-neutral-200 align-middle" />
) : (
- <span className="font-medium text-neutral-700">
- {nFormatter(totalSubmissions, { full: true })}
- </span>
+ <>
+ <span className="font-medium text-neutral-700">
+ {nFormatter(totalPartnersForBounty, { full: true })}
+ </span>
+ </>
)}{" "}
- of{" "}
- <span className="font-medium text-neutral-700">
- {nFormatter(bounty.partnersCount, { full: true })}
- </span>{" "}
- {pluralize("partner", bounty.partnersCount ?? 0)}{" "}
+ {pluralize("partner", totalSubmissions ?? totalPartnersForBounty)}{" "}
{bounty.type === "performance" ? "completed" : "submitted"}
{readyForReviewSubmissions > 0 && (
<>
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 25af1dc88f..bcde7c9a0b 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
@@ -324,7 +324,7 @@ function BountySubmissionDetailsSheetContent({
</h2>
<div className="mt-2 flex flex-col gap-2">
{submission.urls?.map((url) => (
- <div className="relative">
+ <div className="relative" key={url}>
<div className="border-border-subtle block w-full rounded-lg border px-3 py-2 pr-12">
<a
href={url}
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 086b547277..436a5281dc 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
@@ -4,7 +4,7 @@ import {
} from "@/lib/swr/use-bounty-submissions-count";
import useGroups from "@/lib/swr/use-groups";
import useWorkspace from "@/lib/swr/use-workspace";
-import { BountyExtendedProps } from "@/lib/types";
+import { BountyProps } from "@/lib/types";
import { GroupColorCircle } from "@/ui/partners/groups/group-color-circle";
import { CircleDotted, useRouterStuff } from "@dub/ui";
import { Users6 } from "@dub/ui/icons";
@@ -15,7 +15,7 @@ import { BOUNTY_SUBMISSION_STATUS_BADGES } from "./bounty-submission-status-badg
export function useBountySubmissionFilters({
bounty,
}: {
- bounty?: BountyExtendedProps;
+ bounty?: BountyProps;
}) {
const { searchParamsObj, queryParams } = useRouterStuff();
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/add-edit-bounty-sheet.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/add-edit-bounty-sheet.tsx
index 1f8169db75..0b8a4e63c1 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/add-edit-bounty-sheet.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/add-edit-bounty-sheet.tsx
@@ -4,11 +4,7 @@ import { mutatePrefix } from "@/lib/swr/mutate";
import { useApiMutation } from "@/lib/swr/use-api-mutation";
import useProgram from "@/lib/swr/use-program";
import useWorkspace from "@/lib/swr/use-workspace";
-import {
- BountyExtendedProps,
- BountyProps,
- BountySubmissionRequirement,
-} from "@/lib/types";
+import { BountyProps, BountySubmissionRequirement } from "@/lib/types";
import { createBountySchema } from "@/lib/zod/schemas/bounties";
import { workflowConditionSchema } from "@/lib/zod/schemas/workflows";
import { useConfirmModal } from "@/ui/modals/confirm-modal";
@@ -47,7 +43,7 @@ import { z } from "zod";
type BountySheetProps = {
setIsOpen: Dispatch<SetStateAction<boolean>>;
- bounty?: BountyExtendedProps;
+ bounty?: BountyProps;
};
type FormData = z.infer<typeof createBountySchema>;
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/bounty-action-button.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/bounty-action-button.tsx
index 1f27590a3b..87b0832728 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/bounty-action-button.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/bounty-action-button.tsx
@@ -6,7 +6,7 @@ import {
useBountySubmissionsCount,
} from "@/lib/swr/use-bounty-submissions-count";
import useWorkspace from "@/lib/swr/use-workspace";
-import { BountyExtendedProps } from "@/lib/types";
+import { BountyProps } from "@/lib/types";
import { useConfirmModal } from "@/ui/modals/confirm-modal";
import { ThreeDots } from "@/ui/shared/icons";
import { Button, MenuItem, Popover } from "@dub/ui";
@@ -17,7 +17,7 @@ import { toast } from "sonner";
import { useBountySheet } from "./add-edit-bounty-sheet";
interface BountyActionButtonProps {
- bounty: BountyExtendedProps;
+ bounty: BountyProps;
className?: string;
buttonClassName?: string;
}
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 4a6b286e96..931506c9a8 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
@@ -1,41 +1,18 @@
import { getBountyRewardDescription } from "@/lib/partners/get-bounty-reward-description";
-import usePartnersCount from "@/lib/swr/use-partners-count";
+import { usePartnersCountBounty } from "@/lib/swr/use-partners-count-bounty";
import useWorkspace from "@/lib/swr/use-workspace";
import { BountyListProps } from "@/lib/types";
import { BountyThumbnailImage } from "@/ui/partners/bounties/bounty-thumbnail-image";
import { Calendar6, Gift, Users } from "@dub/ui/icons";
import { formatDate, nFormatter, pluralize } from "@dub/utils";
import Link from "next/link";
-import { useMemo } from "react";
export function BountyCard({ bounty }: { bounty: BountyListProps }) {
const { slug: workspaceSlug } = useWorkspace();
- const { partnersCount: groupCount } = usePartnersCount<
- | {
- groupId: string;
- _count: number;
- }[]
- | undefined
- >({
- groupBy: "groupId",
- });
-
- const totalPartnersForBounty = useMemo(() => {
- if (bounty.groups.length === 0) {
- // if no groups set, return all partners
- return groupCount?.reduce((acc, curr) => acc + curr._count, 0) ?? 0;
- }
-
- return (
- groupCount?.reduce((acc, curr) => {
- if (bounty.groups.some((group) => group.id === curr.groupId)) {
- return acc + curr._count;
- }
- return acc;
- }, 0) ?? 0
- );
- }, [groupCount, bounty.groups]);
+ const { totalPartnersForBounty, loading } = usePartnersCountBounty({
+ bounty,
+ });
return (
<div className="border-border-subtle hover:border-border-default relative cursor-pointer rounded-xl border bg-white p-5 transition-all hover:shadow-lg">
@@ -101,10 +78,19 @@ export function BountyCard({ bounty }: { bounty: BountyListProps }) {
of
</>
)}{" "}
- <span className="text-content-default">
- {nFormatter(totalPartnersForBounty, { full: true })}
- </span>{" "}
- {pluralize("partner", totalPartnersForBounty)}{" "}
+ {loading ? (
+ <span className="inline-block h-4 w-8 animate-pulse rounded bg-neutral-200 align-middle" />
+ ) : (
+ <>
+ <span className="text-content-default">
+ {nFormatter(totalPartnersForBounty, { full: true })}
+ </span>{" "}
+ </>
+ )}{" "}
+ {pluralize(
+ "partner",
+ bounty.submissionsCountData?.total || totalPartnersForBounty,
+ )}{" "}
{bounty.type === "performance" ? "completed" : "submitted"}
</div>
</div>
diff --git a/apps/web/lib/api/bounties/get-bounty-with-details.ts b/apps/web/lib/api/bounties/get-bounty-with-details.ts
index a368273314..f156b4f9ba 100644
--- a/apps/web/lib/api/bounties/get-bounty-with-details.ts
+++ b/apps/web/lib/api/bounties/get-bounty-with-details.ts
@@ -23,31 +23,6 @@ export const getBountyWithDetails = async ({
b.performanceScope,
wf.triggerConditions,
- -- Partners count
- COALESCE(
- (
- SELECT COUNT(pe.partnerId)
- FROM ProgramEnrollment pe
- WHERE pe.programId = ${programId} AND pe.status IN ('approved', 'invited')
- AND (
- -- If bounty has specific groups, count only partners in those groups
- EXISTS (
- SELECT 1
- FROM BountyGroup bg
- WHERE bg.bountyId = b.id AND bg.groupId = pe.groupId
- )
- OR
- -- If bounty has no groups, count all approved/invited partners
- NOT EXISTS (
- SELECT 1
- FROM BountyGroup bg
- WHERE bg.bountyId = b.id
- )
- )
- ),
- 0
- ) AS partners,
-
-- Bounty groups
COALESCE(
(
@@ -92,6 +67,5 @@ export const getBountyWithDetails = async ({
performanceScope,
performanceCondition,
groups: bounty.groups.filter((group) => group !== null) ?? [],
- partnersCount: Number(bounty.partners),
};
};
diff --git a/apps/web/lib/swr/use-bounty.ts b/apps/web/lib/swr/use-bounty.ts
index b93b749c56..bd3376c09a 100644
--- a/apps/web/lib/swr/use-bounty.ts
+++ b/apps/web/lib/swr/use-bounty.ts
@@ -1,14 +1,14 @@
import { fetcher } from "@dub/utils";
import { useParams } from "next/navigation";
import useSWR from "swr";
-import { BountyExtendedProps } from "../types";
+import { BountyProps } from "../types";
import useWorkspace from "./use-workspace";
export default function useBounty() {
const { id: workspaceId } = useWorkspace();
const { bountyId } = useParams<{ bountyId: string }>();
- const { data: bounty, error } = useSWR<BountyExtendedProps>(
+ const { data: bounty, error } = useSWR<BountyProps>(
workspaceId && bountyId
? `/api/bounties/${bountyId}?workspaceId=${workspaceId}`
: undefined,
diff --git a/apps/web/lib/swr/use-partners-count-bounty.ts b/apps/web/lib/swr/use-partners-count-bounty.ts
new file mode 100644
index 0000000000..4cd3684cde
--- /dev/null
+++ b/apps/web/lib/swr/use-partners-count-bounty.ts
@@ -0,0 +1,33 @@
+import { useMemo } from "react";
+import { BountyProps } from "../types";
+import usePartnersCount from "./use-partners-count";
+
+export function usePartnersCountBounty({ bounty }: { bounty?: BountyProps }) {
+ const { partnersCount: groupCount, loading } = usePartnersCount<
+ | {
+ groupId: string;
+ _count: number;
+ }[]
+ | undefined
+ >({
+ groupBy: "groupId",
+ });
+
+ const totalPartnersForBounty = useMemo(() => {
+ if (!bounty || bounty.groups.length === 0) {
+ // if no groups set, return all partners
+ return groupCount?.reduce((acc, curr) => acc + curr._count, 0) ?? 0;
+ }
+
+ return (
+ groupCount?.reduce((acc, curr) => {
+ if (bounty.groups.some((group) => group.id === curr.groupId)) {
+ return acc + curr._count;
+ }
+ return acc;
+ }, 0) ?? 0
+ );
+ }, [groupCount, bounty]);
+
+ return { totalPartnersForBounty, loading };
+}
diff --git a/apps/web/lib/types.ts b/apps/web/lib/types.ts
index b1dc45bfbe..e49bf22c85 100644
--- a/apps/web/lib/types.ts
+++ b/apps/web/lib/types.ts
@@ -31,7 +31,6 @@ import { WEBHOOK_TRIGGER_DESCRIPTIONS } from "./webhook/constants";
import {
BountyListSchema,
BountySchema,
- BountySchemaExtended,
BountySubmissionExtendedSchema,
getBountySubmissionsQuerySchema,
SUBMISSION_REQUIREMENTS,
@@ -584,7 +583,6 @@ export type PartnerCommentProps = z.infer<typeof PartnerCommentSchema>;
export type BountyProps = z.infer<typeof BountySchema>;
export type BountyListProps = z.infer<typeof BountyListSchema>;
-export type BountyExtendedProps = z.infer<typeof BountySchemaExtended>;
export type PartnerBountyProps = z.infer<typeof PartnerBountySchema>;
diff --git a/apps/web/lib/zod/schemas/bounties.ts b/apps/web/lib/zod/schemas/bounties.ts
index e5c4f43e40..0cdfabdedf 100644
--- a/apps/web/lib/zod/schemas/bounties.ts
+++ b/apps/web/lib/zod/schemas/bounties.ts
@@ -114,10 +114,6 @@ export const BountyListSchema = BountySchema.extend({
.optional(),
});
-export const BountySchemaExtended = BountySchema.extend({
- partnersCount: z.number().default(0),
-});
-
export const BountySubmissionSchema = z.object({
id: z.string(),
description: z.string().nullable(),
diff --git a/apps/web/ui/layout/sidebar/app-sidebar-nav.tsx b/apps/web/ui/layout/sidebar/app-sidebar-nav.tsx
index 92d65d6057..581469e629 100644
--- a/apps/web/ui/layout/sidebar/app-sidebar-nav.tsx
+++ b/apps/web/ui/layout/sidebar/app-sidebar-nav.tsx
@@ -5,7 +5,6 @@ import {
SubmissionsCountByStatus,
useBountySubmissionsCount,
} from "@/lib/swr/use-bounty-submissions-count";
-import useCustomersCount from "@/lib/swr/use-customers-count";
import { usePartnerMessagesCount } from "@/lib/swr/use-partner-messages-count";
import usePayoutsCount from "@/lib/swr/use-payouts-count";
import useProgram from "@/lib/swr/use-program";
@@ -537,9 +536,6 @@ export function AppSidebarNav({
});
const { canTrackConversions } = getPlanCapabilities(plan);
- const { data: customersCount } = useCustomersCount({
- enabled: canTrackConversions === true,
- });
return (
<SidebarNav
@@ -559,7 +555,7 @@ export function AppSidebarNav({
applicationsCount,
submittedBountiesCount,
unreadMessagesCount,
- showConversionGuides: canTrackConversions && customersCount === 0,
+ showConversionGuides: canTrackConversions,
partnerNetworkEnabled:
program && program.partnerNetworkEnabledAt !== null,
emailCampaignsEnabled: flags?.emailCampaigns,
diff --git a/apps/web/ui/partners/reject-bounty-submission-modal.tsx b/apps/web/ui/partners/reject-bounty-submission-modal.tsx
index 01c9ae0641..780d5a6016 100644
--- a/apps/web/ui/partners/reject-bounty-submission-modal.tsx
+++ b/apps/web/ui/partners/reject-bounty-submission-modal.tsx
@@ -7,7 +7,7 @@ import {
REJECT_BOUNTY_SUBMISSION_REASONS,
rejectBountySubmissionSchema,
} from "@/lib/zod/schemas/bounties";
-import { Button, Modal } from "@dub/ui";
+import { Button, Modal, useKeyboardShortcut } from "@dub/ui";
import { cn } from "@dub/utils";
import { useAction } from "next-safe-action/hooks";
import { useCallback, useMemo, useState } from "react";
@@ -43,7 +43,7 @@ const RejectBountySubmissionModal = ({
formState: { errors },
} = useForm<FormData>({
defaultValues: {
- rejectionReason: "didNotMeetCriteria",
+ rejectionReason: undefined,
rejectionNote: "",
},
});
@@ -63,6 +63,28 @@ const RejectBountySubmissionModal = ({
},
);
+ const handleReject = useCallback(async () => {
+ if (!workspace.id || !submission?.id) {
+ return;
+ }
+
+ const formData = getValues();
+
+ await rejectBountySubmission({
+ ...formData,
+ rejectionReason: formData.rejectionReason || "other",
+ workspaceId: workspace.id,
+ submissionId: submission.id,
+ });
+ }, [workspace.id, submission?.id, getValues, rejectBountySubmission]);
+
+ // Handle keyboard shortcut for Reject button
+ useKeyboardShortcut("r", handleReject, {
+ enabled: showModal,
+ sheet: true,
+ modal: true,
+ });
+
return (
<Modal showModal={showModal} setShowModal={setShowModal}>
<div className="border-b border-neutral-200 px-4 py-4 sm:px-6">
@@ -77,17 +99,22 @@ const RejectBountySubmissionModal = ({
className="text-content-emphasis text-sm font-medium"
>
Rejection reason
+ <span className="ml-1 font-normal text-neutral-500">
+ (optional)
+ </span>
</label>
<div className="relative mt-2 rounded-md shadow-sm">
<select
id="rejectionReason"
- {...register("rejectionReason", { required: true })}
+ {...register("rejectionReason")}
+ disabled={isPending}
className={cn(
"block w-full rounded-md border-neutral-300 text-neutral-900 focus:border-neutral-500 focus:outline-none focus:ring-neutral-500 sm:text-sm",
errors.rejectionReason &&
"border-red-600 focus:border-red-500 focus:ring-red-600",
)}
>
+ <option value="">Select a reason</option>
{Object.entries(REJECT_BOUNTY_SUBMISSION_REASONS).map(
([value, label]) => (
<option key={value} value={value}>
@@ -147,21 +174,10 @@ const RejectBountySubmissionModal = ({
type="button"
text="Reject"
variant="danger"
+ shortcut="R"
className="h-9 w-fit"
loading={isPending}
- onClick={async () => {
- if (!workspace.id || !submission?.id) {
- return;
- }
-
- const formData = getValues();
-
- await rejectBountySubmission({
- ...formData,
- workspaceId: workspace.id,
- submissionId: submission.id,
- });
- }}
+ onClick={handleReject}
/>
</div>
</div>
diff --git a/packages/ui/src/button.tsx b/packages/ui/src/button.tsx
index b29fa05e34..66b7adfe13 100644
--- a/packages/ui/src/button.tsx
+++ b/packages/ui/src/button.tsx
@@ -137,6 +137,7 @@ const Button = forwardRef<HTMLButtonElement, ButtonProps>(
variant === "secondary",
"bg-neutral-100 text-neutral-500 group-hover:bg-neutral-200":
variant === "outline",
+ "bg-red-400 text-white": variant === "danger",
"bg-red-100 text-red-600 group-hover:bg-red-500 group-hover:text-white":
variant === "danger-outline",
},