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 group selector

Kiran K50eb319391f3
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/campaigns/[campaignId]/campaign-editor-skeleton.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/campaigns/[campaignId]/campaign-editor-skeleton.tsx
index e11227385d..6a3f03a32c 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/campaigns/[campaignId]/campaign-editor-skeleton.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/campaigns/[campaignId]/campaign-editor-skeleton.tsx
@@ -29,13 +29,13 @@ export function CampaignEditorSkeleton() {
<div className="h-7 w-full animate-pulse rounded-md bg-neutral-100" />
<span className={labelClassName}>To</span>
- <div />
+ <div className="h-7 w-full animate-pulse rounded-md bg-neutral-100" />
<span className={labelClassName}>Subject</span>
<div className="h-7 w-full animate-pulse rounded-md bg-neutral-100" />
- <span className={labelClassName}>Type</span>
- <div className="h-7 w-32 animate-pulse rounded-md bg-neutral-100" />
+ <span className={labelClassName}>Automation</span>
+ <div className="h-7 w-full animate-pulse rounded-md bg-neutral-100" />
</div>
<div className="mt-6">
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/campaigns/[campaignId]/campaign-editor.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/campaigns/[campaignId]/campaign-editor.tsx
index f14cadc559..22391e06bf 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/campaigns/[campaignId]/campaign-editor.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/campaigns/[campaignId]/campaign-editor.tsx
@@ -16,6 +16,7 @@ import { toast } from "sonner";
import { useDebouncedCallback } from "use-debounce";
import { CAMPAIGN_STATUS_BADGES } from "../campaign-status-badges";
import { CampaignControls } from "./campaign-controls";
+import { CampaignGroupsSelector } from "./campaign-groups-selector";
import { TransactionalCampaignLogic } from "./transactional-campaign-logic";
const inputClassName =
@@ -150,10 +151,17 @@ export function CampaignEditor({ campaign }: { campaign: Campaign }) {
/>
</label>
- <label className="contents">
- <span className={labelClassName}>To</span>
- <div />
- </label>
+ <span className={labelClassName}>To</span>
+ <Controller
+ control={control}
+ name="groupIds"
+ render={({ field }) => (
+ <CampaignGroupsSelector
+ selectedGroupIds={field.value ?? null}
+ setSelectedGroupIds={field.onChange}
+ />
+ )}
+ />
<label className="contents">
<span className={labelClassName}>Subject</span>
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/campaigns/[campaignId]/campaign-groups-selector.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/campaigns/[campaignId]/campaign-groups-selector.tsx
new file mode 100644
index 0000000000..02496a69d3
--- /dev/null
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/campaigns/[campaignId]/campaign-groups-selector.tsx
@@ -0,0 +1,106 @@
+"use client";
+
+import useGroups from "@/lib/swr/use-groups";
+import { GroupColorCircle } from "@/ui/partners/groups/group-color-circle";
+import { GroupsMultiSelect } from "@/ui/partners/groups/groups-multi-select";
+import { Popover, Users6 } from "@dub/ui";
+import { cn } from "@dub/utils";
+import { useMemo, useState } from "react";
+
+const MAX_DISPLAYED_GROUPS = 4;
+
+interface CampaignGroupsSelectorProps {
+ selectedGroupIds: string[] | null;
+ setSelectedGroupIds: (groupIds: string[] | null) => void;
+}
+
+export function CampaignGroupsSelector({
+ selectedGroupIds,
+ setSelectedGroupIds,
+}: CampaignGroupsSelectorProps) {
+ const { groups, loading } = useGroups();
+ const [isHovered, setIsHovered] = useState(false);
+ const [openPopover, setOpenPopover] = useState(false);
+
+ const selectedGroups = useMemo(() => {
+ if (!selectedGroupIds?.length || !groups) {
+ return null;
+ }
+
+ return groups.filter((group) => selectedGroupIds.includes(group.id));
+ }, [groups, selectedGroupIds]);
+
+ const displayAllGroups = !selectedGroupIds || selectedGroupIds.length === 0;
+
+ const plusCount = selectedGroups
+ ? Math.max(0, selectedGroups.length - MAX_DISPLAYED_GROUPS)
+ : 0;
+
+ return (
+ <Popover
+ content={
+ <div className="min-w-[440px] p-3">
+ <GroupsMultiSelect
+ selectedGroupIds={selectedGroupIds}
+ setSelectedGroupIds={setSelectedGroupIds}
+ />
+ </div>
+ }
+ align="start"
+ openPopover={openPopover}
+ setOpenPopover={setOpenPopover}
+ >
+ <div
+ className={cn(
+ "group relative flex min-h-[28px] w-full cursor-pointer items-center gap-2 rounded-lg p-1.5 text-sm transition-colors duration-150 hover:bg-neutral-100",
+ openPopover && "bg-neutral-100",
+ )}
+ onMouseEnter={() => setIsHovered(true)}
+ onMouseLeave={() => setIsHovered(false)}
+ onClick={() => setOpenPopover(true)}
+ >
+ {loading && selectedGroupIds?.length ? (
+ <div className="h-5 w-1/3 animate-pulse rounded bg-neutral-200" />
+ ) : displayAllGroups ? (
+ <div className="text-content-default flex items-center gap-1.5">
+ <Users6 className="size-3.5 shrink-0" />
+ <span>All groups</span>
+ </div>
+ ) : selectedGroups && selectedGroups.length > 0 ? (
+ <div className="flex min-w-0 flex-1 flex-wrap items-center gap-1.5">
+ {selectedGroups.slice(0, MAX_DISPLAYED_GROUPS).map((group) => (
+ <div
+ key={group.id}
+ className="flex h-5 min-w-0 items-center gap-1 rounded-md bg-neutral-200 px-1.5"
+ >
+ <GroupColorCircle group={group} />
+ <span className="text-content-default min-w-0 truncate text-sm font-medium">
+ {group.name}
+ </span>
+ </div>
+ ))}
+
+ {plusCount > 0 && (
+ <span className="flex items-center rounded-md bg-neutral-100 px-2 py-0.5 text-xs font-medium text-neutral-600">
+ +{plusCount}
+ </span>
+ )}
+ </div>
+ ) : null}
+
+ {(isHovered || openPopover) && (
+ <button
+ type="button"
+ className="ml-auto h-5 shrink-0 rounded-md bg-neutral-200 px-2 text-xs font-semibold text-neutral-700 transition-colors"
+ onClick={(e) => {
+ e.stopPropagation();
+ setOpenPopover(true);
+ }}
+ >
+ Edit
+ </button>
+ )}
+ </div>
+ </Popover>
+ );
+}
diff --git a/apps/web/lib/types.ts b/apps/web/lib/types.ts
index 86ebdf2492..0495e3920a 100644
--- a/apps/web/lib/types.ts
+++ b/apps/web/lib/types.ts
@@ -34,6 +34,7 @@ import {
SUBMISSION_REQUIREMENTS,
} from "./zod/schemas/bounties";
import {
+ CAMPAIGN_WORKFLOW_ATTRIBUTES,
CampaignListSchema,
CampaignSchema,
updateCampaignSchema,
@@ -643,3 +644,6 @@ export type CampaignList = z.infer<typeof CampaignListSchema>;
export type Campaign = z.infer<typeof CampaignSchema>;
export type UpdateCampaignFormData = z.infer<typeof updateCampaignSchema>;
+
+export type CampaignWorkflowAttribute =
+ (typeof CAMPAIGN_WORKFLOW_ATTRIBUTES)[number];
diff --git a/apps/web/lib/zod/schemas/campaigns.ts b/apps/web/lib/zod/schemas/campaigns.ts
index 9c5a1e4de2..ed7588d6a2 100644
--- a/apps/web/lib/zod/schemas/campaigns.ts
+++ b/apps/web/lib/zod/schemas/campaigns.ts
@@ -1,3 +1,4 @@
+import { CampaignWorkflowAttribute } from "@/lib/types";
import { CampaignStatus, CampaignType } from "@dub/prisma/client";
import { z } from "zod";
import { GroupSchema } from "./groups";
@@ -7,6 +8,15 @@ export const ALLOWED_ATTRIBUTE_VALUES_IN_DAYS = [0, 1, 3, 7, 14, 30];
export const EMAIL_TEMPLATE_VARIABLES = ["PartnerName", "PartnerEmail"];
+export const CAMPAIGN_WORKFLOW_ATTRIBUTES = ["partnerEnrolledDays"] as const;
+
+export const CAMPAIGN_WORKFLOW_ATTRIBUTE_LABELS: Record<
+ CampaignWorkflowAttribute,
+ string
+> = {
+ partnerEnrolledDays: "been in the program for",
+} as const;
+
export const CampaignSchema = z.object({
id: z.string(),
name: z.string(),
@@ -77,26 +87,3 @@ export const getCampaignsCountQuerySchema = getCampaignsQuerySchema
.extend({
groupBy: z.enum(["type", "status"]).optional(),
});
-
-// Workflow
-export const CAMPAIGN_WORKFLOW_ATTRIBUTES = [
- "totalLeads",
- "totalConversions",
- "totalSaleAmount",
- "totalCommissions",
- "partnerEnrolledDays",
-] as const;
-
-export type CampaignWorkflowAttribute =
- (typeof CAMPAIGN_WORKFLOW_ATTRIBUTES)[number];
-
-export const CAMPAIGN_WORKFLOW_ATTRIBUTE_LABELS: Record<
- CampaignWorkflowAttribute,
- string
-> = {
- totalLeads: "lead",
- totalConversions: "conversions",
- totalSaleAmount: "revenue",
- totalCommissions: "commissions",
- partnerEnrolledDays: "been in the program for",
-} as const;