The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Flag partner through the rejected application modal (#3866)
Pedro Ladeira9b487f5b385b
diff --git a/apps/web/app/(ee)/api/partners/applications/reject/route.ts b/apps/web/app/(ee)/api/partners/applications/reject/route.tsindex 0a4922999c..c3ba4310ca 100644--- a/apps/web/app/(ee)/api/partners/applications/reject/route.ts+++ b/apps/web/app/(ee)/api/partners/applications/reject/route.ts@@ -7,8 +7,14 @@ import { NextResponse } from "next/server";// POST /api/partners/applications/reject – Reject a pending partner applicationexport const POST = withWorkspace(async ({ workspace, req, session }) => {- const { partnerId, rejectionReason, rejectionNote, allowImmediateReapply } =- rejectPartnerSchema.parse(await parseRequestBody(req));+ const {+ partnerId,+ rejectionReason,+ rejectionNote,+ allowImmediateReapply,+ flagForFraud,+ flagForFraudReason,+ } = rejectPartnerSchema.parse(await parseRequestBody(req));await rejectPartner({workspace,@@ -16,6 +22,8 @@ export const POST = withWorkspace(rejectionReason,rejectionNote,allowImmediateReapply,+ flagForFraud,+ flagForFraudReason,userId: session.user.id,});diff --git a/apps/web/lib/actions/partners/reject-partner-application.ts b/apps/web/lib/actions/partners/reject-partner-application.tsindex e67ab58e9f..ede95d8856 100644--- a/apps/web/lib/actions/partners/reject-partner-application.ts+++ b/apps/web/lib/actions/partners/reject-partner-application.ts@@ -15,8 +15,14 @@ export const rejectPartnerApplicationAction = authActionClient.inputSchema(inputSchema).action(async ({ parsedInput, ctx }) => {const { workspace, user } = ctx;- const { partnerId, rejectionReason, rejectionNote, allowImmediateReapply } =- parsedInput;+ const {+ partnerId,+ rejectionReason,+ rejectionNote,+ allowImmediateReapply,+ flagForFraud,+ flagForFraudReason,+ } = parsedInput;throwIfNoPermission({role: workspace.role,@@ -29,6 +35,8 @@ export const rejectPartnerApplicationAction = authActionClientrejectionReason,rejectionNote,allowImmediateReapply,+ flagForFraud,+ flagForFraudReason,userId: user.id,});});diff --git a/apps/web/lib/api/partners/applications/reject-partner.ts b/apps/web/lib/api/partners/applications/reject-partner.tsindex f446a05ce4..1d2721280e 100644--- a/apps/web/lib/api/partners/applications/reject-partner.ts+++ b/apps/web/lib/api/partners/applications/reject-partner.ts@@ -24,10 +24,27 @@ export async function rejectPartner({rejectionReason,rejectionNote,allowImmediateReapply,+ flagForFraud,+ flagForFraudReason,userId,}: RejectPartnerInput) {const programId = getDefaultProgramIdOrThrow(workspace);+ if (flagForFraud && allowImmediateReapply) {+ throw new DubApiError({+ code: "bad_request",+ message:+ "Cannot flag for fraud when allowing the partner to reapply immediately.",+ });+ }++ if (flagForFraud && (!flagForFraudReason || !flagForFraudReason.trim())) {+ throw new DubApiError({+ code: "bad_request",+ message: "Fraud reason is required when flagging for fraud.",+ });+ }+const programEnrollment = await prisma.programEnrollment.findUnique({where: {partnerId_programId: {@@ -111,6 +128,16 @@ export async function rejectPartner({discountId: null,},});++ if (flagForFraud && flagForFraudReason) {+ await tx.fraudAlert.create({+ data: {+ partnerId,+ programId,+ reason: flagForFraudReason,+ },+ });+ }});const { partner, program } = programEnrollment;diff --git a/apps/web/lib/zod/schemas/partners.ts b/apps/web/lib/zod/schemas/partners.tsindex 82b1ebce13..94b4d2dc6a 100644--- a/apps/web/lib/zod/schemas/partners.ts+++ b/apps/web/lib/zod/schemas/partners.ts@@ -904,33 +904,71 @@ export const PROGRAM_APPLICATION_REJECTION_NOTE_MAX_LENGTH = 500;// Max length for optional `flagForFraudReason` on `FraudAlert`export const MAX_FRAUD_REASON_LENGTH = 2000;-export const rejectPartnerSchema = z.object({- partnerId: z.string().describe("The ID of the partner to reject."),- rejectionReason: z- .enum(ProgramApplicationRejectionReason)- .optional()- .describe(- "The reason for rejecting the partner application. This will be shared with the partner via email.",- ),- rejectionNote: z- .string()- .max(PROGRAM_APPLICATION_REJECTION_NOTE_MAX_LENGTH)- .optional()- .transform((s) => {- const t = s?.trim();- return t === "" ? undefined : t;- })- .describe(- "Additional details about the rejection. This will be shared with the partner via email.",- ),- allowImmediateReapply: z- .boolean()- .optional()- .default(false)- .describe(- "When true, pending enrollment is removed so the partner can submit a new application immediately.",- ),-});+export const rejectPartnerSchema = z+ .object({+ partnerId: z.string().describe("The ID of the partner to reject."),+ rejectionReason: z+ .enum(ProgramApplicationRejectionReason)+ .optional()+ .describe(+ "The reason for rejecting the partner application. This will be shared with the partner via email.",+ ),+ rejectionNote: z+ .string()+ .max(PROGRAM_APPLICATION_REJECTION_NOTE_MAX_LENGTH)+ .optional()+ .transform((s) => {+ const t = s?.trim();+ return t === "" ? undefined : t;+ })+ .describe(+ "Additional details about the rejection. This will be shared with the partner via email.",+ ),+ allowImmediateReapply: z+ .boolean()+ .optional()+ .default(false)+ .describe(+ "When true, pending enrollment is removed so the partner can submit a new application immediately.",+ ),+ flagForFraud: z+ .boolean()+ .optional()+ .describe(+ "Whether to flag the partner for fraud review by the Dub team. Cannot be combined with allowImmediateReapply.",+ ),+ flagForFraudReason: z+ .string()+ .max(MAX_FRAUD_REASON_LENGTH)+ .optional()+ .transform((s) => {+ const t = s?.trim();+ return t === "" ? undefined : t;+ })+ .describe(+ "The reason for flagging the partner for fraud. Required when flagForFraud is true.",+ ),+ })+ .superRefine((data, ctx) => {+ if (data.allowImmediateReapply && data.flagForFraud) {+ ctx.addIssue({+ code: "custom",+ message:+ "Cannot flag for fraud when allowing the partner to reapply immediately.",+ path: ["flagForFraud"],+ });+ }+ if (+ data.flagForFraud &&+ (!data.flagForFraudReason || !data.flagForFraudReason.trim())+ ) {+ ctx.addIssue({+ code: "custom",+ message: "Fraud reason is required when flagging for fraud.",+ path: ["flagForFraudReason"],+ });+ }+ });export const bulkRejectPartnersSchema = z.object({workspaceId: z.string(),diff --git a/apps/web/ui/modals/reject-partner-application-modal.tsx b/apps/web/ui/modals/reject-partner-application-modal.tsxindex 92e4e5abc2..6af522b808 100644--- a/apps/web/ui/modals/reject-partner-application-modal.tsx+++ b/apps/web/ui/modals/reject-partner-application-modal.tsx@@ -5,18 +5,23 @@ import {} from "@/lib/partners/program-application-rejection";import useWorkspace from "@/lib/swr/use-workspace";import { PartnerProps } from "@/lib/types";-import { PROGRAM_APPLICATION_REJECTION_NOTE_MAX_LENGTH } from "@/lib/zod/schemas/partners";+import {+ MAX_FRAUD_REASON_LENGTH,+ PROGRAM_APPLICATION_REJECTION_NOTE_MAX_LENGTH,+} from "@/lib/zod/schemas/partners";import { PartnerAvatar } from "@/ui/partners/partner-avatar";import { ProgramApplicationRejectionReason } from "@dub/prisma/client";import {Button,- Checkbox,Combobox,ComboboxOption,+ InfoTooltip,Modal,+ Switch,useKeyboardShortcut,} from "@dub/ui";import { cn } from "@dub/utils";+import { motion } from "motion/react";import { useAction } from "next-safe-action/hooks";import {Dispatch,@@ -55,7 +60,6 @@ export function RejectPartnerApplicationModal({confirmShortcutOptions,}: RejectPartnerApplicationModalProps) {const { id: workspaceId } = useWorkspace();- const allowReapplyCheckboxId = useId();const allowImmediateReapplyOutcomeRef = useRef(false);const [selectedReason, setSelectedReason] = useState<ComboboxOption | null>(@@ -63,12 +67,18 @@ export function RejectPartnerApplicationModal({);const [rejectionNote, setRejectionNote] = useState("");const [allowImmediateReapply, setAllowImmediateReapply] = useState(false);+ const [flagForFraud, setFlagForFraud] = useState(false);+ const [flagForFraudReason, setFlagForFraudReason] = useState("");+ const fraudReasonFieldId = useId();+ const fraudReasonCounterId = useId();useEffect(() => {if (!showRejectPartnerApplicationModal) {setSelectedReason(null);setRejectionNote("");setAllowImmediateReapply(false);+ setFlagForFraud(false);+ setFlagForFraudReason("");}}, [showRejectPartnerApplicationModal]);@@ -93,12 +103,20 @@ export function RejectPartnerApplicationModal({const handleConfirm = useCallback(async () => {if (!workspaceId || !partner) return;+ if (flagForFraud && !flagForFraudReason.trim()) {+ toast.error("Fraud reason is required when flagging for fraud.");+ return;+ }+allowImmediateReapplyOutcomeRef.current = allowImmediateReapply;await rejectPartnerApplication({workspaceId,partnerId: partner.id,allowImmediateReapply,+ ...(flagForFraud+ ? { flagForFraud: true, flagForFraudReason: flagForFraudReason.trim() }+ : {}),...(selectedReason && {rejectionReason:selectedReason.value as ProgramApplicationRejectionReason,@@ -112,6 +130,8 @@ export function RejectPartnerApplicationModal({selectedReason,rejectionNote,allowImmediateReapply,+ flagForFraud,+ flagForFraudReason,]);const handleClose = useCallback(() => {@@ -208,27 +228,105 @@ export function RejectPartnerApplicationModal({</p></div>- <div className="flex flex-col gap-1.5">- <div className="flex gap-2">- <Checkbox- id={allowReapplyCheckboxId}+ <div>+ <div className="flex items-center justify-between">+ <div className="flex items-center gap-2">+ <span+ className={cn(+ "text-sm font-medium text-neutral-900",+ flagForFraud && "text-neutral-400",+ )}+ >+ Allow partner to reapply immediately+ </span>+ <InfoTooltip content="This will skip the 30 day waiting period and allow the partner to resubmit another application." />+ </div>+ <Switchchecked={allowImmediateReapply}- onCheckedChange={(checked) =>- setAllowImmediateReapply(checked === true)+ disabled={isPending || flagForFraud}+ disabledTooltip={+ flagForFraud+ ? 'Turn off "Flag partner for potential fraud" to allow immediate reapply.'+ : undefined}- disabled={isPending}+ fn={(checked: boolean) => {+ setAllowImmediateReapply(checked);+ if (checked) {+ setFlagForFraud(false);+ setFlagForFraudReason("");+ }+ }}/>- <label- htmlFor={allowReapplyCheckboxId}- className="select-none text-sm font-medium text-neutral-700"- >- Allow partner to reapply immediately- </label></div>- <p className="pl-7 text-xs text-neutral-500">- This will skip the 30 day waiting period and allow the partner to- resubmit another application.- </p>+ </div>++ <div>+ <div className="flex items-center justify-between">+ <div className="flex items-center gap-2">+ <span className="text-sm font-medium text-neutral-900">+ Flag partner for potential fraud+ </span>+ <InfoTooltip content="This will report the partner to our fraud team, and if deemed fraudulent, they will be banned from the network." />+ </div>+ <Switch+ checked={flagForFraud}+ disabled={isPending || allowImmediateReapply}+ disabledTooltip={+ allowImmediateReapply+ ? 'Turn off "Allow partner to reapply immediately" to flag for fraud.'+ : undefined+ }+ fn={(checked: boolean) => {+ setFlagForFraud(checked);+ if (checked) {+ setAllowImmediateReapply(false);+ }+ }}+ />+ </div>+ <motion.div+ initial={false}+ animate={{+ height: flagForFraud ? "auto" : 0,+ opacity: flagForFraud ? 1 : 0,+ }}+ transition={{ duration: 0.2, ease: [0.4, 0, 0.2, 1] }}+ className="overflow-hidden"+ inert={!flagForFraud}+ >+ <div className="mt-1 p-px">+ <textarea+ id={fraudReasonFieldId}+ aria-describedby={fraudReasonCounterId}+ className={cn(+ "mt-1.5 block w-full rounded-md border border-neutral-300 bg-white text-neutral-900 placeholder-neutral-400 focus:border-neutral-500 focus:outline-none focus:ring-1 focus:ring-neutral-500 sm:text-sm",+ )}+ placeholder="Describe the suspected fraudulent activity..."+ rows={3}+ maxLength={MAX_FRAUD_REASON_LENGTH}+ value={flagForFraudReason}+ onChange={(e) => setFlagForFraudReason(e.target.value)}+ disabled={isPending}+ />+ <p+ id={fraudReasonCounterId}+ className="mt-1 block text-right text-xs tabular-nums text-neutral-400"+ >+ <span className="sr-only">+ {flagForFraudReason.length} of {MAX_FRAUD_REASON_LENGTH}{" "}+ characters entered.{" "}+ {Math.max(+ 0,+ MAX_FRAUD_REASON_LENGTH - flagForFraudReason.length,+ )}{" "}+ characters remaining.+ </span>+ <span aria-hidden="true">+ {flagForFraudReason.length}/{MAX_FRAUD_REASON_LENGTH}+ </span>+ </p>+ </div>+ </motion.div></div></div>)}