Skip to content

Commit 7ecc1ee

Browse files
committed
canManageCustomers
1 parent 8d32d97 commit 7ecc1ee

3 files changed

Lines changed: 22 additions & 18 deletions

File tree

apps/web/lib/plan-capabilities.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ export const getPlanCapabilities = (
77
return {
88
canAddFolder: plan && !["free"].includes(plan),
99
canManageFolderPermissions: plan && !["free", "pro"].includes(plan), // default access level is write
10+
canManageCustomers: plan && !["free", "pro"].includes(plan),
1011
};
1112
};

apps/web/lib/swr/use-customers.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { fetcher } from "@dub/utils";
22
import useSWR from "swr";
33
import { z } from "zod";
4+
import { getPlanCapabilities } from "../plan-capabilities";
45
import { CustomerProps } from "../types";
56
import { getCustomersQuerySchemaExtended } from "../zod/schemas/customers";
67
import useWorkspace from "./use-workspace";
@@ -14,10 +15,11 @@ export default function useCustomers({
1415
query?: z.infer<typeof partialQuerySchema>;
1516
enabled?: boolean;
1617
} = {}) {
17-
const { id: workspaceId } = useWorkspace();
18+
const { id: workspaceId, plan } = useWorkspace();
19+
const { canManageCustomers } = getPlanCapabilities(plan);
1820

1921
const { data: customers, error } = useSWR<CustomerProps[]>(
20-
enabled && workspaceId
22+
enabled && workspaceId && canManageCustomers
2123
? `/api/customers?${new URLSearchParams({
2224
workspaceId: workspaceId,
2325
...query,

apps/web/ui/analytics/toggle.tsx

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
} from "@/lib/analytics/constants";
88
import { validDateRangeForPlan } from "@/lib/analytics/utils";
99
import { getStartEndDates } from "@/lib/analytics/utils/get-start-end-dates";
10+
import { getPlanCapabilities } from "@/lib/plan-capabilities";
1011
import useCustomer from "@/lib/swr/use-customer";
1112
import useCustomers from "@/lib/swr/use-customers";
1213
import useCustomersCount from "@/lib/swr/use-customers-count";
@@ -159,6 +160,7 @@ export default function Toggle({
159160
: "",
160161
},
161162
});
163+
const { canManageCustomers } = getPlanCapabilities(plan);
162164

163165
const {
164166
allDomains: domains,
@@ -414,21 +416,20 @@ export default function Toggle({
414416
? `/${slug}/customers/${selectedCustomerId}`
415417
: null;
416418
},
417-
options: customers?.map(({ id, email, name, avatar }) => {
418-
return {
419-
value: id,
420-
label: email ?? name,
421-
icon: (
422-
<img
423-
src={avatar || `${OG_AVATAR_URL}${id}`}
424-
alt={`${email} avatar`}
425-
className="size-4 rounded-full"
426-
/>
427-
),
428-
};
429-
}) ?? [
430-
{ value: selectedCustomerId, label: selectedCustomerId, icon: User },
431-
],
419+
options:
420+
customers?.map(({ id, email, name, avatar }) => {
421+
return {
422+
value: id,
423+
label: email ?? name,
424+
icon: (
425+
<img
426+
src={avatar || `${OG_AVATAR_URL}${id}`}
427+
alt={`${email} avatar`}
428+
className="size-4 rounded-full"
429+
/>
430+
),
431+
};
432+
}) ?? null,
432433
};
433434

434435
const filters: ComponentProps<typeof Filter.Select>["filters"] = useMemo(
@@ -450,7 +451,7 @@ export default function Toggle({
450451
: partnerPage
451452
? [LinkFilterItem, CustomerFilterItem]
452453
: [
453-
CustomerFilterItem,
454+
...(canManageCustomers ? [CustomerFilterItem] : []),
454455
...(flags?.linkFolders
455456
? [
456457
{

0 commit comments

Comments
 (0)