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.

remove payouts.read, add partner_profile.update permission

Steven Teycd07421a1c0d
diff --git a/apps/web/app/(ee)/api/partner-profile/payouts/count/route.ts b/apps/web/app/(ee)/api/partner-profile/payouts/count/route.ts
index 65e2c7c4fe..fea09ab733 100644
--- a/apps/web/app/(ee)/api/partner-profile/payouts/count/route.ts
+++ b/apps/web/app/(ee)/api/partner-profile/payouts/count/route.ts
@@ -1,5 +1,4 @@
import { withPartnerProfile } from "@/lib/auth/partner";
-import { throwIfNoPermission } from "@/lib/auth/partner-user-permissions";
import { payoutsCountQuerySchema } from "@/lib/zod/schemas/payouts";
import { prisma } from "@dub/prisma";
import { PayoutStatus, Prisma } from "@dub/prisma/client";
@@ -11,11 +10,6 @@ export const GET = withPartnerProfile(
const { programId, groupBy, status } =
payoutsCountQuerySchema.parse(searchParams);
- throwIfNoPermission({
- role: partnerUser.role,
- permission: "payouts.read",
- });
-
const where: Prisma.PayoutWhereInput = {
partnerId: partner.id,
...(programId && { programId }),
diff --git a/apps/web/app/(ee)/api/partner-profile/payouts/route.ts b/apps/web/app/(ee)/api/partner-profile/payouts/route.ts
index d127ba34eb..dcc72a3aba 100644
--- a/apps/web/app/(ee)/api/partner-profile/payouts/route.ts
+++ b/apps/web/app/(ee)/api/partner-profile/payouts/route.ts
@@ -1,5 +1,4 @@
import { withPartnerProfile } from "@/lib/auth/partner";
-import { throwIfNoPermission } from "@/lib/auth/partner-user-permissions";
import {
PartnerPayoutResponseSchema,
payoutsQuerySchema,
@@ -9,34 +8,25 @@ import { NextResponse } from "next/server";
import z from "zod";
// GET /api/partner-profile/payouts - get all payouts for a partner
-export const GET = withPartnerProfile(
- async ({ partner, searchParams, partnerUser }) => {
- const { programId, status, sortBy, sortOrder, page, pageSize } =
- payoutsQuerySchema.parse(searchParams);
+export const GET = withPartnerProfile(async ({ partner, searchParams }) => {
+ const { programId, status, sortBy, sortOrder, page, pageSize } =
+ payoutsQuerySchema.parse(searchParams);
- throwIfNoPermission({
- role: partnerUser.role,
- permission: "payouts.read",
- });
+ const payouts = await prisma.payout.findMany({
+ where: {
+ partnerId: partner.id,
+ ...(programId && { programId }),
+ ...(status && { status }),
+ },
+ include: {
+ program: true,
+ },
+ skip: (page - 1) * pageSize,
+ take: pageSize,
+ orderBy: {
+ [sortBy]: sortOrder,
+ },
+ });
- const payouts = await prisma.payout.findMany({
- where: {
- partnerId: partner.id,
- ...(programId && { programId }),
- ...(status && { status }),
- },
- include: {
- program: true,
- },
- skip: (page - 1) * pageSize,
- take: pageSize,
- orderBy: {
- [sortBy]: sortOrder,
- },
- });
-
- return NextResponse.json(
- z.array(PartnerPayoutResponseSchema).parse(payouts),
- );
- },
-);
+ return NextResponse.json(z.array(PartnerPayoutResponseSchema).parse(payouts));
+});
diff --git a/apps/web/app/(ee)/partners.dub.co/(dashboard)/auth.tsx b/apps/web/app/(ee)/partners.dub.co/(dashboard)/auth.tsx
index 9c5aca1361..9d25990992 100644
--- a/apps/web/app/(ee)/partners.dub.co/(dashboard)/auth.tsx
+++ b/apps/web/app/(ee)/partners.dub.co/(dashboard)/auth.tsx
@@ -1,6 +1,5 @@
"use client";
-import { hasPermission } from "@/lib/auth/partner-user-permissions";
import usePartnerProfile from "@/lib/swr/use-partner-profile";
import useRefreshSession from "@/lib/swr/use-refresh-session";
import LayoutLoader from "@/ui/layout/layout-loader";
@@ -42,13 +41,5 @@ export function PartnerProfileAuth({ children }: { children: ReactNode }) {
redirect("/onboarding");
}
- const canAccessPayouts = partner
- ? hasPermission(partner.role, "payouts.read")
- : undefined;
-
- if (pathname.endsWith("/payouts") && canAccessPayouts === false) {
- redirect("/");
- }
-
return children;
}
diff --git a/apps/web/app/(ee)/partners.dub.co/(dashboard)/payouts/payout-stats.tsx b/apps/web/app/(ee)/partners.dub.co/(dashboard)/payouts/payout-stats.tsx
index 2bfa3d1a39..a30f47043f 100644
--- a/apps/web/app/(ee)/partners.dub.co/(dashboard)/payouts/payout-stats.tsx
+++ b/apps/web/app/(ee)/partners.dub.co/(dashboard)/payouts/payout-stats.tsx
@@ -1,6 +1,5 @@
"use client";
-import { hasPermission } from "@/lib/auth/partner-user-permissions";
import usePartnerPayoutsCount from "@/lib/swr/use-partner-payouts-count";
import usePartnerProfile from "@/lib/swr/use-partner-profile";
import { PayoutsCount } from "@/lib/types";
@@ -173,10 +172,6 @@ export function PayoutStats() {
const topRowStats = payoutStats.slice(0, 3);
const bottomRowStats = payoutStats.slice(3);
- if (partner && !hasPermission(partner.role, "payouts.read")) {
- return null;
- }
-
return (
<>
{/* Mobile: 3 on top, 2 on bottom */}
diff --git a/apps/web/app/(ee)/partners.dub.co/(dashboard)/profile/about-you-form.tsx b/apps/web/app/(ee)/partners.dub.co/(dashboard)/profile/about-you-form.tsx
index 2fa57e9a8d..bdc6ebcb89 100644
--- a/apps/web/app/(ee)/partners.dub.co/(dashboard)/profile/about-you-form.tsx
+++ b/apps/web/app/(ee)/partners.dub.co/(dashboard)/profile/about-you-form.tsx
@@ -1,4 +1,5 @@
import { updatePartnerProfileAction } from "@/lib/actions/partners/update-partner-profile";
+import { hasPermission } from "@/lib/auth/partner-user-permissions";
import {
industryInterests,
monthlyTrafficAmounts,
@@ -25,6 +26,9 @@ type AboutYouFormData = {
};
export function AboutYouForm({ partner }: { partner?: PartnerProps }) {
+ const disabled = partner
+ ? !hasPermission(partner.role, "partner_profile.update")
+ : true;
const {
register,
control,
@@ -92,6 +96,7 @@ export function AboutYouForm({ partner }: { partner?: PartnerProps }) {
<ReactTextareaAutosize
className={cn(
"block w-full rounded-md focus:outline-none sm:text-sm",
+ disabled && "cursor-not-allowed bg-neutral-50 text-neutral-400",
errors.description
? "border-red-300 pr-10 text-red-900 placeholder-red-300 focus:border-red-500 focus:ring-red-500"
: "border-neutral-300 text-neutral-900 placeholder-neutral-400 focus:border-neutral-500 focus:ring-neutral-500",
@@ -100,6 +105,7 @@ export function AboutYouForm({ partner }: { partner?: PartnerProps }) {
minRows={3}
maxRows={10}
maxLength={MAX_PARTNER_DESCRIPTION_LENGTH}
+ disabled={disabled}
onKeyDown={handleKeyDown}
{...register("description")}
/>
@@ -155,7 +161,10 @@ export function AboutYouForm({ partner }: { partner?: PartnerProps }) {
</div>
<Button
text={`${field.value.length ? "Edit" : "Add"} interests`}
- onClick={() => setShowIndustryInterestsModal(true)}
+ onClick={() =>
+ !disabled && setShowIndustryInterestsModal(true)
+ }
+ disabled={disabled}
variant="secondary"
className="h-8 w-fit rounded-lg px-3"
/>
@@ -174,7 +183,8 @@ export function AboutYouForm({ partner }: { partner?: PartnerProps }) {
render={({ field }) => (
<RadioGroup
value={field.value}
- onValueChange={(value) => field.onChange(value)}
+ onValueChange={(value) => !disabled && field.onChange(value)}
+ disabled={disabled}
className="flex flex-col gap-4"
>
{monthlyTrafficAmounts.map(({ id, label }) => (
@@ -197,6 +207,7 @@ export function AboutYouForm({ partner }: { partner?: PartnerProps }) {
<Button
text="Save changes"
className="h-8 w-fit px-2.5"
+ disabled={disabled}
loading={isSubmitting}
/>
</div>
diff --git a/apps/web/app/(ee)/partners.dub.co/(dashboard)/profile/how-you-work-form.tsx b/apps/web/app/(ee)/partners.dub.co/(dashboard)/profile/how-you-work-form.tsx
index 9ff5dbb49b..c311e95435 100644
--- a/apps/web/app/(ee)/partners.dub.co/(dashboard)/profile/how-you-work-form.tsx
+++ b/apps/web/app/(ee)/partners.dub.co/(dashboard)/profile/how-you-work-form.tsx
@@ -1,4 +1,5 @@
import { updatePartnerProfileAction } from "@/lib/actions/partners/update-partner-profile";
+import { hasPermission } from "@/lib/auth/partner-user-permissions";
import { PartnerProps } from "@/lib/types";
import { Button, Check2 } from "@dub/ui";
import { useAction } from "next-safe-action/hooks";
@@ -21,6 +22,9 @@ type HowYouWorkFormData = {
};
export function HowYouWorkForm({ partner }: { partner?: PartnerProps }) {
+ const disabled = partner
+ ? !hasPermission(partner.role, "partner_profile.update")
+ : true;
const {
control,
handleSubmit,
@@ -86,14 +90,19 @@ export function HowYouWorkForm({ partner }: { partner?: PartnerProps }) {
{preferredEarningStructures.map((earningStructure) => (
<label
key={earningStructure.id}
- className="ring-border-subtle hover:bg-bg-muted flex cursor-pointer select-none items-center gap-2.5 rounded-full bg-white px-4 py-3 ring-1 transition-all duration-100 ease-out"
+ className={cn(
+ "ring-border-subtle hover:bg-bg-muted flex cursor-pointer select-none items-center gap-2.5 rounded-full bg-white px-4 py-3 ring-1 transition-all duration-100 ease-out",
+ disabled && "cursor-not-allowed opacity-50",
+ )}
>
<input
type="checkbox"
className="sr-only"
+ disabled={disabled}
checked={field.value.includes(earningStructure.id)}
onChange={(e) =>
- e.target.checked
+ !disabled &&
+ (e.target.checked
? field.onChange([
...field.value,
earningStructure.id,
@@ -102,7 +111,7 @@ export function HowYouWorkForm({ partner }: { partner?: PartnerProps }) {
field.value.filter(
(id) => id !== earningStructure.id,
),
- )
+ ))
}
/>
<div
@@ -147,14 +156,19 @@ export function HowYouWorkForm({ partner }: { partner?: PartnerProps }) {
{salesChannels.map((salesChannel) => (
<label
key={salesChannel.id}
- className="ring-border-subtle hover:bg-bg-muted flex cursor-pointer select-none items-center gap-2.5 rounded-full bg-white px-4 py-3 ring-1 transition-all duration-100 ease-out"
+ className={cn(
+ "ring-border-subtle hover:bg-bg-muted flex cursor-pointer select-none items-center gap-2.5 rounded-full bg-white px-4 py-3 ring-1 transition-all duration-100 ease-out",
+ disabled && "cursor-not-allowed opacity-50",
+ )}
>
<input
type="checkbox"
className="sr-only"
+ disabled={disabled}
checked={field.value.includes(salesChannel.id)}
onChange={(e) =>
- e.target.checked
+ !disabled &&
+ (e.target.checked
? field.onChange([
...field.value,
salesChannel.id,
@@ -163,7 +177,7 @@ export function HowYouWorkForm({ partner }: { partner?: PartnerProps }) {
field.value.filter(
(id) => id !== salesChannel.id,
),
- )
+ ))
}
/>
<div
@@ -197,6 +211,7 @@ export function HowYouWorkForm({ partner }: { partner?: PartnerProps }) {
<Button
text="Save changes"
className="h-8 w-fit px-2.5"
+ disabled={disabled}
loading={isSubmitting}
/>
</div>
diff --git a/apps/web/app/(ee)/partners.dub.co/(dashboard)/profile/page-client.tsx b/apps/web/app/(ee)/partners.dub.co/(dashboard)/profile/page-client.tsx
index d3aa2eec05..d075f92171 100644
--- a/apps/web/app/(ee)/partners.dub.co/(dashboard)/profile/page-client.tsx
+++ b/apps/web/app/(ee)/partners.dub.co/(dashboard)/profile/page-client.tsx
@@ -1,6 +1,7 @@
"use client";
import { updatePartnerProfileAction } from "@/lib/actions/partners/update-partner-profile";
+import { hasPermission } from "@/lib/auth/partner-user-permissions";
import usePartnerProfile from "@/lib/swr/use-partner-profile";
import { PartnerProps } from "@/lib/types";
import { PageContent } from "@/ui/layout/page-content";
@@ -77,6 +78,10 @@ function Controls({
},
);
+ const disabled = partner
+ ? !hasPermission(partner.role, "partner_profile.update")
+ : true;
+
const [isOpen, setIsOpen] = useState(false);
const { MergePartnerAccountsModal, setShowMergePartnerAccountsModal } =
@@ -131,8 +136,9 @@ function Controls({
<span className="text-sm font-medium">Discoverable</span>
<Switch
checked={!!partner.discoverableAt}
+ disabled={disabled}
fn={(checked: boolean) => {
- if (!partner) return;
+ if (!partner || disabled) return;
update(
() =>
@@ -159,10 +165,18 @@ function Controls({
<div className="w-full p-2 md:w-56">
<button
onClick={() => {
- setShowMergePartnerAccountsModal(true);
- setIsOpen(false);
+ if (!disabled) {
+ setShowMergePartnerAccountsModal(true);
+ setIsOpen(false);
+ }
}}
- className="w-full rounded-md p-2 hover:bg-neutral-100 active:bg-neutral-200"
+ disabled={disabled}
+ className={cn(
+ "w-full rounded-md p-2",
+ disabled
+ ? "cursor-not-allowed bg-neutral-50 text-neutral-400"
+ : "hover:bg-neutral-100 active:bg-neutral-200",
+ )}
>
<div className="flex items-center gap-2 text-left">
<Users2 className="size-4 shrink-0" />
diff --git a/apps/web/app/(ee)/partners.dub.co/(dashboard)/profile/profile-details-form.tsx b/apps/web/app/(ee)/partners.dub.co/(dashboard)/profile/profile-details-form.tsx
index d30c1aa3f8..de8269236f 100644
--- a/apps/web/app/(ee)/partners.dub.co/(dashboard)/profile/profile-details-form.tsx
+++ b/apps/web/app/(ee)/partners.dub.co/(dashboard)/profile/profile-details-form.tsx
@@ -1,4 +1,5 @@
import { updatePartnerProfileAction } from "@/lib/actions/partners/update-partner-profile";
+import { hasPermission } from "@/lib/auth/partner-user-permissions";
import { mutatePrefix } from "@/lib/swr/mutate";
import usePartnerPayoutsCount from "@/lib/swr/use-partner-payouts-count";
import { PartnerProps, PayoutsCount } from "@/lib/types";
@@ -41,6 +42,9 @@ type BasicInfoFormData = {
};
export function ProfileDetailsForm({ partner }: { partner?: PartnerProps }) {
+ const disabled = partner
+ ? !hasPermission(partner.role, "partner_profile.update")
+ : true;
const basicInfoFormRef = useRef<HTMLFormElement>(null);
const onlinePresenceFormRef = useRef<HTMLFormElement>(null);
@@ -87,7 +91,11 @@ export function ProfileDetailsForm({ partner }: { partner?: PartnerProps }) {
description="Your core details, and information that's required to set up your Dub Partner account."
>
<FormProvider {...basicInfoForm}>
- <BasicInfoForm partner={partner} formRef={basicInfoFormRef} />
+ <BasicInfoForm
+ partner={partner}
+ formRef={basicInfoFormRef}
+ disabled={disabled}
+ />
</FormProvider>
</SettingsRow>
@@ -108,11 +116,14 @@ export function ProfileDetailsForm({ partner }: { partner?: PartnerProps }) {
<Button
text="Save changes"
className="h-8 w-fit px-2.5"
+ disabled={disabled}
loading={
basicInfoForm.formState.isSubmitting ||
onlinePresenceForm.formState.isSubmitting
}
onClick={() => {
+ if (disabled) return;
+
if (
partner?.stripeConnectId &&
(basicInfoForm.formState.dirtyFields.country ||
@@ -134,9 +145,11 @@ export function ProfileDetailsForm({ partner }: { partner?: PartnerProps }) {
function BasicInfoForm({
partner,
formRef,
+ disabled,
}: {
partner?: PartnerProps;
formRef: RefObject<HTMLFormElement | null>;
+ disabled: boolean;
}) {
const {
register,
@@ -223,6 +236,7 @@ function BasicInfoForm({
variant="plain"
imageSrc={field.value || `${OG_AVATAR_URL}${partner?.name}`}
readFile
+ disabled={disabled}
onChange={({ src }) => field.onChange(src)}
content={null}
maxFileSizeMB={2}
@@ -252,8 +266,10 @@ function BasicInfoForm({
<div>
<input
type="text"
+ disabled={disabled}
className={cn(
"block w-full rounded-md focus:outline-none sm:text-sm",
+ disabled && "cursor-not-allowed bg-neutral-50 text-neutral-400",
errors.name
? "border-red-300 pr-10 text-red-900 placeholder-red-300 focus:border-red-500 focus:ring-red-500"
: "border-neutral-300 text-neutral-900 placeholder-neutral-400 focus:border-neutral-500 focus:ring-neutral-500",
@@ -269,8 +285,10 @@ function BasicInfoForm({
<span className="text-sm font-medium text-neutral-800">Email</span>
<input
type="email"
+ disabled={disabled}
className={cn(
"block w-full rounded-md focus:outline-none sm:text-sm",
+ disabled && "cursor-not-allowed bg-neutral-50 text-neutral-400",
errors.email
? "border-red-300 pr-10 text-red-900 placeholder-red-300 focus:border-red-500 focus:ring-red-500"
: "border-neutral-300 text-neutral-900 placeholder-neutral-400 focus:border-neutral-500 focus:ring-neutral-500",
@@ -292,10 +310,13 @@ function BasicInfoForm({
value={field.value || ""}
onChange={field.onChange}
error={errors.country ? true : false}
+ disabled={disabled || completedPayoutsCount > 0}
disabledTooltip={
- completedPayoutsCount > 0
- ? "Since you've already received payouts on Dub, you cannot change your country. If you need to update your country, please contact support."
- : undefined
+ disabled
+ ? "You don't have permission to update this field"
+ : completedPayoutsCount > 0
+ ? "Since you've already received payouts on Dub, you cannot change your country. If you need to update your country, please contact support."
+ : undefined
}
/>
)}
@@ -308,12 +329,16 @@ function BasicInfoForm({
</span>
<DynamicTooltipWrapper
tooltipProps={
- completedPayoutsCount > 0
+ disabled
? {
- content:
- "Since you've already received payouts on Dub, you cannot change your profile type. If you need to update your profile type, please contact support.",
+ content: "You don't have permission to update this field",
}
- : undefined
+ : completedPayoutsCount > 0
+ ? {
+ content:
+ "Since you've already received payouts on Dub, you cannot change your profile type. If you need to update your profile type, please contact support.",
+ }
+ : undefined
}
>
<LayoutGroup>
@@ -331,17 +356,18 @@ function BasicInfoForm({
]}
selected={profileType}
selectAction={(option: "individual" | "company") => {
- if (completedPayoutsCount === 0) {
+ if (!disabled && completedPayoutsCount === 0) {
setValue("profileType", option);
}
}}
className={cn(
"flex w-full items-center gap-0.5 rounded-lg border-neutral-300 bg-neutral-100 p-0.5",
- completedPayoutsCount > 0 && "cursor-not-allowed",
+ (disabled || completedPayoutsCount > 0) &&
+ "cursor-not-allowed",
)}
optionClassName={cn(
"h-9 flex items-center justify-center rounded-lg flex-1",
- completedPayoutsCount > 0 &&
+ (disabled || completedPayoutsCount > 0) &&
"pointer-events-none text-neutral-400",
)}
indicatorClassName="bg-white"
@@ -374,13 +400,15 @@ function BasicInfoForm({
<div>
<input
type="text"
+ disabled={disabled || completedPayoutsCount > 0}
className={cn(
"block w-full rounded-md focus:outline-none sm:text-sm",
+ (disabled || completedPayoutsCount > 0) &&
+ "cursor-not-allowed bg-neutral-50 text-neutral-400",
errors.companyName
? "border-red-300 pr-10 text-red-900 placeholder-red-300 focus:border-red-500 focus:ring-red-500"
: "border-neutral-300 text-neutral-900 placeholder-neutral-400 focus:border-neutral-500 focus:ring-neutral-500",
)}
- disabled={completedPayoutsCount > 0}
{...register("companyName", {
required: profileType === "company",
})}
diff --git a/apps/web/lib/actions/partners/update-partner-profile.ts b/apps/web/lib/actions/partners/update-partner-profile.ts
index 83b05e5351..f391355534 100644
--- a/apps/web/lib/actions/partners/update-partner-profile.ts
+++ b/apps/web/lib/actions/partners/update-partner-profile.ts
@@ -1,6 +1,7 @@
"use server";
import { confirmEmailChange } from "@/lib/auth/confirm-email-change";
+import { throwIfNoPermission } from "@/lib/auth/partner-user-permissions";
import { qstash } from "@/lib/cron";
import { getPartnerDiscoveryRequirements } from "@/lib/partners/discoverability";
import { storage } from "@/lib/storage";
@@ -45,7 +46,13 @@ const updatePartnerProfileSchema = z
export const updatePartnerProfileAction = authPartnerActionClient
.schema(updatePartnerProfileSchema)
.action(async ({ ctx, parsedInput }) => {
- const { partner } = ctx;
+ const { partner, partnerUser } = ctx;
+
+ throwIfNoPermission({
+ role: partnerUser.role,
+ permission: "partner_profile.update",
+ });
+
const {
name,
email: newEmail,
diff --git a/apps/web/lib/api/tokens/scopes.ts b/apps/web/lib/api/tokens/scopes.ts
index 0c149414d7..e6e25442f6 100644
--- a/apps/web/lib/api/tokens/scopes.ts
+++ b/apps/web/lib/api/tokens/scopes.ts
@@ -296,7 +296,7 @@ export const validateScopesForWorkspaceRole = (
};
// Get the scopes for a role
-export const getScopesForWorkspaceRole = (role: WorkspaceRole) => {
+export const getScopesForRole = (role: WorkspaceRole) => {
return ROLE_SCOPES_MAP[role];
};
diff --git a/apps/web/lib/auth/partner-user-permissions.ts b/apps/web/lib/auth/partner-user-permissions.ts
index 3f095cfb9f..d4e25d02c7 100644
--- a/apps/web/lib/auth/partner-user-permissions.ts
+++ b/apps/web/lib/auth/partner-user-permissions.ts
@@ -9,7 +9,7 @@ const PERMISSIONS = [
"user_invites.create",
"user_invites.delete",
"user_invites.update",
- "payouts.read",
+ "partner_profile.update",
"payout_settings.update",
] as const;
@@ -20,7 +20,7 @@ const ROLE_PERMISSIONS: Record<PartnerRole, Permission[]> = {
"user_invites.create",
"user_invites.delete",
"user_invites.update",
- "payouts.read",
+ "partner_profile.update",
"payout_settings.update",
],
member: [],
diff --git a/apps/web/lib/swr/use-partner-payouts-count.ts b/apps/web/lib/swr/use-partner-payouts-count.ts
index ae479b339d..f5b117dcf2 100644
--- a/apps/web/lib/swr/use-partner-payouts-count.ts
+++ b/apps/web/lib/swr/use-partner-payouts-count.ts
@@ -1,21 +1,18 @@
import { useRouterStuff } from "@dub/ui";
import { fetcher } from "@dub/utils";
+import { useSession } from "next-auth/react";
import useSWR from "swr";
-import { hasPermission } from "../auth/partner-user-permissions";
import { PayoutsCount } from "../types";
-import usePartnerProfile from "./use-partner-profile";
export default function usePartnerPayoutsCount<T>(
opts?: Record<string, string>,
) {
- const { partner } = usePartnerProfile();
-
+ const { data: session } = useSession();
+ const partnerId = session?.user?.["defaultPartnerId"];
const { getQueryString } = useRouterStuff();
const { data: payoutsCount, error } = useSWR<PayoutsCount[]>(
- partner &&
- partner.id &&
- hasPermission(partner.role, "payouts.read") &&
+ partnerId &&
`/api/partner-profile/payouts/count${getQueryString(opts, {
include: ["programId"],
})}`,
diff --git a/apps/web/ui/layout/sidebar/partners-sidebar-nav.tsx b/apps/web/ui/layout/sidebar/partners-sidebar-nav.tsx
index cf3e4ee37d..8768c02310 100644
--- a/apps/web/ui/layout/sidebar/partners-sidebar-nav.tsx
+++ b/apps/web/ui/layout/sidebar/partners-sidebar-nav.tsx
@@ -1,11 +1,9 @@
"use client";
-import usePartnerProfile from "@/lib/swr/use-partner-profile";
import usePartnerProgramBounties from "@/lib/swr/use-partner-program-bounties";
import useProgramEnrollment from "@/lib/swr/use-program-enrollment";
import useProgramEnrollmentsCount from "@/lib/swr/use-program-enrollments-count";
import { useProgramMessagesCount } from "@/lib/swr/use-program-messages-count";
-import { PartnerProps } from "@/lib/types";
import { useRouterStuff } from "@dub/ui";
import {
Bell,
@@ -36,7 +34,6 @@ import { SidebarNav, SidebarNavAreas, SidebarNavGroups } from "./sidebar-nav";
type SidebarNavData = {
pathname: string;
queryString?: string;
- partner?: PartnerProps;
programSlug?: string;
isUnapproved: boolean;
invitationsCount?: number;
@@ -46,7 +43,6 @@ type SidebarNavData = {
const NAV_GROUPS: SidebarNavGroups<SidebarNavData> = ({
pathname,
- partner,
unreadMessagesCount,
}) => [
{
@@ -57,26 +53,22 @@ const NAV_GROUPS: SidebarNavGroups<SidebarNavData> = ({
href: "/programs",
active: pathname.startsWith("/programs"),
},
- ...(partner?.role === "member"
- ? []
- : [
- {
- name: "Payouts",
- description:
- "View all your upcoming and previous payouts for all your programs.",
- icon: MoneyBills2,
- href: "/payouts",
- active: pathname.startsWith("/payouts"),
- },
- {
- name: "Partner profile",
- description:
- "Build a great partner profile and get noticed in our partner network.",
- icon: SquareUserSparkle2,
- href: "/profile",
- active: pathname.startsWith("/profile"),
- },
- ]),
+ {
+ name: "Payouts",
+ description:
+ "View all your upcoming and previous payouts for all your programs.",
+ icon: MoneyBills2,
+ href: "/payouts",
+ active: pathname.startsWith("/payouts"),
+ },
+ {
+ name: "Partner profile",
+ description:
+ "Build a great partner profile and get noticed in our partner network.",
+ icon: SquareUserSparkle2,
+ href: "/profile",
+ active: pathname.startsWith("/profile"),
+ },
{
name: "Messages",
description: "Chat with programs you're enrolled in",
@@ -282,7 +274,6 @@ export function PartnersSidebarNav({
toolContent?: ReactNode;
newsContent?: ReactNode;
}) {
- const { partner } = usePartnerProfile();
const { programSlug } = useParams() as {
programSlug?: string;
};
@@ -331,7 +322,6 @@ export function PartnersSidebarNav({
data={{
pathname,
queryString: getQueryString(),
- partner,
programSlug: programSlug || "",
isUnapproved:
!!programEnrollment && programEnrollment.status !== "approved",
diff --git a/apps/web/ui/layout/sidebar/payout-stats.tsx b/apps/web/ui/layout/sidebar/payout-stats.tsx
index 3b99133ecf..c689e27b8a 100644
--- a/apps/web/ui/layout/sidebar/payout-stats.tsx
+++ b/apps/web/ui/layout/sidebar/payout-stats.tsx
@@ -1,6 +1,5 @@
"use client";
-import { hasPermission } from "@/lib/auth/partner-user-permissions";
import usePartnerPayoutsCount from "@/lib/swr/use-partner-payouts-count";
import usePartnerProfile from "@/lib/swr/use-partner-profile";
import { PayoutsCount } from "@/lib/types";
@@ -25,10 +24,6 @@ export const PayoutStats = memo(() => {
groupBy: "status",
});
- if (partner && !hasPermission(partner.role, "payouts.read")) {
- return null;
- }
-
return (
<AnimatedSizeContainer height>
<div className="border-border-default grid gap-3 border-t p-3">
diff --git a/apps/web/ui/partners/online-presence-form.tsx b/apps/web/ui/partners/online-presence-form.tsx
index cecf6377db..df3a2aa88f 100644
--- a/apps/web/ui/partners/online-presence-form.tsx
+++ b/apps/web/ui/partners/online-presence-form.tsx
@@ -2,6 +2,7 @@
import { parseActionError } from "@/lib/actions/parse-action-errors";
import { updateOnlinePresenceAction } from "@/lib/actions/partners/update-online-presence";
+import { hasPermission } from "@/lib/auth/partner-user-permissions";
import {
sanitizeSocialHandle,
sanitizeWebsite,
@@ -100,6 +101,11 @@ export const OnlinePresenceForm = forwardRef<
ref,
) => {
const form = formProp ?? useOnlinePresenceForm({ partner });
+ const { partner: currentPartner } = usePartnerProfile();
+
+ const disabled = currentPartner
+ ? !hasPermission(currentPartner.role, "partner_profile.update")
+ : true;
const {
register,
@@ -189,6 +195,7 @@ export const OnlinePresenceForm = forwardRef<
property="website"
verifiedAtField="websiteVerifiedAt"
icon={Globe}
+ disabled={disabled}
onVerifyClick={async () => {
try {
const result =
@@ -219,8 +226,11 @@ export const OnlinePresenceForm = forwardRef<
input={
<input
type="text"
+ disabled={disabled}
className={cn(
"block w-full rounded-md focus:outline-none sm:text-sm",
+ disabled &&
+ "cursor-not-allowed bg-neutral-50 text-neutral-400",
errors.website
? "border-red-300 pr-10 text-red-900 placeholder-red-300 focus:border-red-500 focus:ring-red-500"
: "border-neutral-300 text-neutral-900 placeholder-neutral-400 focus:border-neutral-500 focus:ring-neutral-500",
@@ -239,6 +249,7 @@ export const OnlinePresenceForm = forwardRef<
prefix="@"
verifiedAtField="youtubeVerifiedAt"
icon={YouTube}
+ disabled={disabled}
onVerifyClick={() =>
startVerification("youtube", getValues("youtube"))
}
@@ -253,8 +264,11 @@ export const OnlinePresenceForm = forwardRef<
</span>
<input
type="text"
+ disabled={disabled}
className={cn(
"block w-full rounded-none rounded-r-md pl-7 focus:outline-none sm:text-sm",
+ disabled &&
+ "cursor-not-allowed bg-neutral-50 text-neutral-400",
errors.youtube
? "border-red-300 pr-10 text-red-900 placeholder-red-300 focus:border-red-500 focus:ring-red-500"
: "border-neutral-300 text-neutral-900 placeholder-neutral-400 focus:border-neutral-500 focus:ring-neutral-500",
@@ -274,6 +288,7 @@ export const OnlinePresenceForm = forwardRef<
prefix="@"
verifiedAtField="twitterVerifiedAt"
icon={Twitter}
+ disabled={disabled}
onVerifyClick={() =>
startVerification("twitter", getValues("twitter"))
}
@@ -284,8 +299,11 @@ export const OnlinePresenceForm = forwardRef<
</span>
<input
type="text"
+ disabled={disabled}
className={cn(
"block w-full rounded-none rounded-r-md focus:outline-none sm:text-sm",
+ disabled &&
+ "cursor-not-allowed bg-neutral-50 text-neutral-400",
errors.twitter
? "border-red-300 pr-10 text-red-900 placeholder-red-300 focus:border-red-500 focus:ring-red-500"
: "border-neutral-300 text-neutral-900 placeholder-neutral-400 focus:border-neutral-500 focus:ring-neutral-500",
@@ -305,6 +323,7 @@ export const OnlinePresenceForm = forwardRef<
prefix="in/"
verifiedAtField="linkedinVerifiedAt"
icon={LinkedIn}
+ disabled={disabled}
onVerifyClick={() =>
startVerification("linkedin", getValues("linkedin"))
}
@@ -316,8 +335,11 @@ export const OnlinePresenceForm = forwardRef<
</span>
<input
type="text"
+ disabled={disabled}
className={cn(
"block w-full rounded-none rounded-r-md focus:outline-none sm:text-sm",
+ disabled &&
+ "cursor-not-allowed bg-neutral-50 text-neutral-400",
errors.linkedin
? "border-red-300 pr-10 text-red-900 placeholder-red-300 focus:border-red-500 focus:ring-red-500"
: "border-neutral-300 text-neutral-900 placeholder-neutral-400 focus:border-neutral-500 focus:ring-neutral-500",
@@ -337,6 +359,7 @@ export const OnlinePresenceForm = forwardRef<
prefix="@"
verifiedAtField="instagramVerifiedAt"
icon={Instagram}
+ disabled={disabled}
onVerifyClick={() =>
startVerification("instagram", getValues("instagram"))
}
@@ -348,8 +371,11 @@ export const OnlinePresenceForm = forwardRef<
</span>
<input
type="text"
+ disabled={disabled}
className={cn(
"block w-full rounded-none rounded-r-md focus:outline-none sm:text-sm",
+ disabled &&
+ "cursor-not-allowed bg-neutral-50 text-neutral-400",
errors.instagram
? "border-red-300 pr-10 text-red-900 placeholder-red-300 focus:border-red-500 focus:ring-red-500"
: "border-neutral-300 text-neutral-900 placeholder-neutral-400 focus:border-neutral-500 focus:ring-neutral-500",
@@ -369,6 +395,7 @@ export const OnlinePresenceForm = forwardRef<
prefix="@"
verifiedAtField="tiktokVerifiedAt"
icon={TikTok}
+ disabled={disabled}
onVerifyClick={() =>
startVerification("tiktok", getValues("tiktok"))
}
@@ -382,8 +409,11 @@ export const OnlinePresenceForm = forwardRef<
</span>
<input
type="text"
+ disabled={disabled}
className={cn(
"block w-full rounded-none rounded-r-md pl-7 focus:outline-none sm:text-sm",
+ disabled &&
+ "cursor-not-allowed bg-neutral-50 text-neutral-400",
errors.tiktok
? "border-red-300 pr-10 text-red-900 placeholder-red-300 focus:border-red-500 focus:ring-red-500"
: "border-neutral-300 text-neutral-900 placeholder-neutral-400 focus:border-neutral-500 focus:ring-neutral-500",
@@ -403,6 +433,7 @@ export const OnlinePresenceForm = forwardRef<
type="submit"
text="Continue"
className="mt-6"
+ disabled={disabled}
loading={isSubmitting || isSubmitSuccessful}
/>
)}
@@ -480,12 +511,14 @@ function VerifyButton({
icon: Icon,
onClick,
disabledTooltip,
+ disabled: formDisabled = false,
}: {
property: keyof OnlinePresenceFormData;
verifiedAtField: string;
icon: Icon;
onClick: () => Promise<boolean>;
disabledTooltip?: string;
+ disabled?: boolean;
}) {
const { control, getFieldState } = useFormContext<OnlinePresenceFormData>();
const value = useWatch({ control, name: property });
@@ -513,8 +546,11 @@ function VerifyButton({
)
}
loading={isSaving || loading}
- disabled={!value || getFieldState(property).invalid || isVerified}
+ disabled={
+ formDisabled || !value || getFieldState(property).invalid || isVerified
+ }
onClick={async () => {
+ if (formDisabled) return;
setIsSaving(true);
const redirecting = await onClick();
@@ -537,6 +573,7 @@ function FormRow({
onVerifyClick,
verifyDisabledTooltip,
variant,
+ disabled = false,
}: {
label: string;
input: ReactNode;
@@ -548,6 +585,7 @@ function FormRow({
onVerifyClick: () => Promise<boolean>;
verifyDisabledTooltip?: string;
variant: "onboarding" | "settings";
+ disabled?: boolean;
}) {
const { partner } = usePartnerProfile();
const { control, setValue } = useFormContext<OnlinePresenceFormData>();
@@ -614,6 +652,7 @@ function FormRow({
icon={Icon}
onClick={onVerifyClick}
disabledTooltip={verifyDisabledTooltip}
+ disabled={disabled}
/>
</div>
</label>