Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,29 @@ export function PageClient() {
};

const isValid = useMemo(() => {
const { name, url, domain, logo, type, amountInCents, amountInPercentage } =
data;
const {
name,
url,
domain,
logo,
type,
amountInCents,
amountInPercentage,
supportEmail,
} = data;

const hasAmount =
type === "flat" ? amountInCents != null : amountInPercentage != null;

if (!name || !url || !domain || !logo || !type || !hasAmount) {
if (
!name ||
!url ||
!domain ||
!logo ||
!type ||
!hasAmount ||
!supportEmail
) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,18 @@ import { getPlanCapabilities } from "@/lib/plan-capabilities";
import useProgram from "@/lib/swr/use-program";
import useWorkspace from "@/lib/swr/use-workspace";
import { ProgramProps } from "@/lib/types";
import { updateProgramSchema } from "@/lib/zod/schemas/programs";
import { usePartnersUpgradeModal } from "@/ui/partners/partners-upgrade-modal";
import { Button, CrownSmall, Switch, TooltipContent } from "@dub/ui";
import { useAction } from "next-safe-action/hooks";
import { Controller, useForm } from "react-hook-form";
import { toast } from "sonner";
import { mutate } from "swr";
import * as z from "zod/v4";
import { SettingsRow } from "../program-settings-row";

type FormData = Pick<
ProgramProps,
z.infer<typeof updateProgramSchema>,
"supportEmail" | "helpUrl" | "termsUrl" | "messagingEnabledAt"
>;

Expand Down Expand Up @@ -57,7 +59,7 @@ export function ProgramHelpAndSupportContent({
} = useForm<FormData>({
mode: "onBlur",
defaultValues: {
supportEmail: program?.supportEmail,
supportEmail: program?.supportEmail || undefined,
helpUrl: program?.helpUrl,
termsUrl: program?.termsUrl,
messagingEnabledAt: program?.messagingEnabledAt,
Expand Down
21 changes: 12 additions & 9 deletions apps/web/lib/zod/schemas/program-onboarding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
import { parseUrlSchema } from "./utils";

// Getting started
export const programInfoSchema = z.object({
const programInfoSchema = z.object({
name: z.string().max(100),
logo: z.string(),
domain: z.string(),
Expand All @@ -20,7 +20,7 @@ export const programInfoSchema = z.object({
});

// Configure rewards
export const programRewardSchema = z.object({
const programRewardSchema = z.object({
defaultRewardType: z.enum(["lead", "sale"]).default("lead"),
type: z.enum(RewardStructure).nullish(),
amountInCents: FLAT_REWARD_AMOUNT_SCHEMA.nullish(),
Expand All @@ -29,7 +29,7 @@ export const programRewardSchema = z.object({
});

// Invite partners
export const programInvitePartnersSchema = z.object({
const programInvitePartnersSchema = z.object({
partners: z
.array(
z.object({
Expand All @@ -47,13 +47,16 @@ export const programInvitePartnersSchema = z.object({
});

// Help and support
export const programSupportSchema = updateProgramSchema.pick({
supportEmail: true,
helpUrl: true,
termsUrl: true,
});
const programSupportSchema = updateProgramSchema
.pick({
helpUrl: true,
termsUrl: true,
})
.extend({
supportEmail: z.email().max(255),
});

export const onboardingStepSchema = z.enum([
const onboardingStepSchema = z.enum([
"get-started",
"configure-reward",
"invite-partners",
Expand Down
2 changes: 1 addition & 1 deletion apps/web/lib/zod/schemas/programs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export const updateProgramSchema = z.object({
.refine((val) => ALLOWED_MIN_PAYOUT_AMOUNTS.includes(val), {
message: `Minimum payout amount must be one of ${ALLOWED_MIN_PAYOUT_AMOUNTS.join(", ")}`,
}),
supportEmail: z.email().max(255).nullish(),
supportEmail: z.email().max(255).optional(), // Support email is required for a program

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Fix contradictory inline comment for supportEmail.

The schema is optional() here, but the comment says “required,” which misstates this specific contract and can mislead future edits.

Suggested clarification
-  supportEmail: z.email().max(255).optional(), // Support email is required for a program
+  supportEmail: z.email().max(255).optional(), // Required during onboarding; optional in update schema (often consumed via .partial())
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
supportEmail: z.email().max(255).optional(), // Support email is required for a program
supportEmail: z.email().max(255).optional(), // Required during onboarding; optional in update schema (often consumed via .partial())
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/web/lib/zod/schemas/programs.ts` at line 106, The inline comment for the
supportEmail field in the programs schema contradicts the actual schema
definition. The field is marked as optional() but the comment states "Support
email is required for a program," which is incorrect and misleading. Update the
comment on the supportEmail field to accurately reflect that the field is
optional, not required, or clarify the intent if this is intentional and the
optional requirement is conditional.

helpUrl: z.httpUrl().max(500).nullish(),
termsUrl: z.httpUrl().max(500).nullish(),
messagingEnabledAt: z.coerce.date().nullish(),
Expand Down
2 changes: 1 addition & 1 deletion apps/web/ui/partners/program-onboarding-form-wrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export function ProgramOnboardingFormWrapper({
partners: programOnboarding.partners?.length
? programOnboarding.partners
: [{ email: "" }],
supportEmail: programOnboarding.supportEmail || null,
supportEmail: programOnboarding.supportEmail,
helpUrl: programOnboarding.helpUrl || null,
termsUrl: programOnboarding.termsUrl || null,
...values,
Expand Down
Loading