-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Add domain validation to the group additional links #2878
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
WalkthroughAdds a domain-format validator and integrates it into Zod schema and a modal form; the modal now normalizes domains, uses per-field errors (setError/clearErrors/formState.errors) for invalid or duplicate domains, and passes field errors to the Input component. Changes
Sequence Diagram(s)sequenceDiagram
actor User
participant Modal as Add/Edit Link Modal
participant Form as react-hook-form
participant Validator as isValidDomainFormat
User->>Modal: Type domain
Modal->>Form: setValue + clearErrors('domain')
User->>Modal: Submit
Modal->>Modal: normalize domain (trim, toLowerCase)
Modal->>Validator: isValidDomainFormat(domainNormalized)
alt Invalid format
Modal->>Form: setError('domain', { message: "Please enter a valid domain (eg: acme.com)." })
Form-->>User: Render field error via Input
else Valid format
Modal->>Modal: check for duplicates (compare normalized)
alt Duplicate found
Modal->>Form: setError('domain', { message: "Domain already exists" })
Form-->>User: Render field error via Input
else No duplicate
Modal->>Modal: proceed with submission (persist)
Modal-->>User: success / close
end
end
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested reviewers
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
🧹 Nitpick comments (3)
apps/web/lib/zod/schemas/groups.ts (1)
28-30: Normalize the domain in-schema to avoid dupes and casing/whitespace issues.Add trim + lowercase before refine so both UI and API get consistent, canonical domains.
domain: z - .string() - .min(1, "domain is required") + .string() + .trim() + .toLowerCase() + .min(1, "domain is required") .refine((v) => isValidDomainFormat(v), { message: "Please enter a valid domain (eg: acme.com).", }),apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/groups/[groupSlug]/links/add-edit-group-additional-link-modal.tsx (2)
40-53: Use zodResolver with additionalPartnerLinkSchema to DRY validation and apply schema transforms.This centralizes messages and picks up the schema’s trim/lowercase transform automatically.
} = useForm<PartnerGroupAdditionalLink>({ + resolver: zodResolver(additionalPartnerLinkSchema), defaultValues: { domain: link?.domain || "", validationMode: link?.validationMode || "domain", }, });Add imports (outside this hunk):
import { zodResolver } from "@hookform/resolvers/zod"; import { additionalPartnerLinkSchema } from "@/lib/zod/schemas/groups";
131-134: Mark the field dirty on change (helps form UX/state).- setValue("domain", e.target.value); + setValue("domain", e.target.value, { shouldDirty: true }); clearErrors("domain");
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/groups/[groupSlug]/links/add-edit-group-additional-link-modal.tsx(3 hunks)apps/web/lib/api/domains/is-valid-domain.ts(1 hunks)apps/web/lib/zod/schemas/groups.ts(2 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/groups/[groupSlug]/links/add-edit-group-additional-link-modal.tsx (2)
apps/web/lib/types.ts (1)
PartnerGroupAdditionalLink(550-552)apps/web/lib/api/domains/is-valid-domain.ts (1)
isValidDomainFormat(11-13)
apps/web/lib/zod/schemas/groups.ts (1)
apps/web/lib/api/domains/is-valid-domain.ts (1)
isValidDomainFormat(11-13)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: build
🔇 Additional comments (3)
apps/web/lib/zod/schemas/groups.ts (1)
1-1: Good swap to a single source of truth for format validation.apps/web/lib/api/domains/is-valid-domain.ts (1)
11-13: LGTM: clean, focused format-only validator.Separates format check from product restrictions without changing behavior.
apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/groups/[groupSlug]/links/add-edit-group-additional-link-modal.tsx (1)
138-139: LGTM: error wired to form state.
...board)/[slug]/(ee)/program/groups/[groupSlug]/links/add-edit-group-additional-link-modal.tsx
Outdated
Show resolved
Hide resolved
...board)/[slug]/(ee)/program/groups/[groupSlug]/links/add-edit-group-additional-link-modal.tsx
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (2)
apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/groups/[groupSlug]/links/add-edit-group-additional-link-modal.tsx (2)
40-53: Optional: register domain field (or use Controller) for better RHF stateCurrent watch/setValue works, but registering the domain (or using Controller) will keep touched/dirty/validation state in sync without manual handling.
138-141: Mark domain as dirty on changeKeeps formState accurate for navigation guards and UI prompts.
- setValue("domain", e.target.value); + setValue("domain", e.target.value, { shouldDirty: true }); clearErrors("domain");
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/groups/[groupSlug]/links/add-edit-group-additional-link-modal.tsx(3 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/groups/[groupSlug]/links/add-edit-group-additional-link-modal.tsx (2)
apps/web/lib/types.ts (1)
PartnerGroupAdditionalLink(550-552)apps/web/lib/api/domains/is-valid-domain.ts (1)
isValidDomainFormat(11-13)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: build
🔇 Additional comments (4)
apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/groups/[groupSlug]/links/add-edit-group-additional-link-modal.tsx (4)
3-3: LGTM: using the domain-format validatorImport and usage look correct.
58-69: Nice: normalize before validating and write back canonical valueThis addresses earlier feedback and avoids false negatives.
145-145: LGTM: piping field error to InputPassing
errors.domain?.messageis consistent with the manual validation above.
70-79: Normalize duplicate check (case/whitespace-insensitive) and standardize error typeAs written, “Acme.com” and “acme.com” can coexist. Compare normalized values and use the same manual error type used above.
Apply:
- const existingDomains = additionalLinks.map((l) => l.domain); + const existingDomains = additionalLinks.map( + (l) => (l.domain || "").trim().toLowerCase(), + ); - if ( - existingDomains.includes(domainNormalized) && - domainNormalized !== link?.domain - ) { + if ( + existingDomains.includes(domainNormalized) && + domainNormalized !== link?.domain?.trim().toLowerCase() + ) { setError("domain", { - type: "value", + type: "manual", message: `Domain ${domainNormalized} has already been added as a link domain`, }); }
Summary by CodeRabbit
New Features
Bug Fixes