Remove country selector from partner application form#3958
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
📝 WalkthroughWalkthroughCountry is made optional in schema and types, derived from x-vercel-ip-country in the server action (with local/CI "US" fallback), removed from the static application form in favor of group-managed dynamic fields, and submission now surfaces missing partner.country as a user-facing error. ChangesCountry Field Optionality and Dynamic Form Integration
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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.
Actionable comments posted: 0
🧹 Nitpick comments (1)
apps/web/lib/actions/partners/create-program-application.ts (1)
304-312: ⚡ Quick winPersist
ProgramApplication.countryexplicitly increateApplicationAndEnrollmentfor consistency.
prisma.programApplication.create(apps/web/lib/actions/partners/create-program-application.ts, lines 304-312) savescountryonly via...sanitizeData(data, group); it doesn’t explicitly set it frompartner.country. The logged-in partner UI appears to always submitcountry: partner.country, so divergence is unlikely for that path, but making the create write explicit prevents future callers/changes from leavingProgramApplication.countrynull while the response/events use partner data.♻️ Possible fix
prisma.programApplication.create({ data: { ...sanitizeData(data, group), + country: partner.country ?? data.country, id: applicationId, programId: program.id, groupId: group.id, }, }),🤖 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/actions/partners/create-program-application.ts` around lines 304 - 312, The program application create call currently relies on sanitizeData(data, group) to populate country, which can allow ProgramApplication.country to be null if callers change; update the prisma.programApplication.create data payload in createApplicationAndEnrollment (the block using prisma.programApplication.create and sanitizeData) to explicitly set country: partner.country (or the local partner variable) alongside id, programId, and groupId so the DB write always persists partner.country regardless of sanitizeData input.
🤖 Prompt for all review comments with 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.
Nitpick comments:
In `@apps/web/lib/actions/partners/create-program-application.ts`:
- Around line 304-312: The program application create call currently relies on
sanitizeData(data, group) to populate country, which can allow
ProgramApplication.country to be null if callers change; update the
prisma.programApplication.create data payload in createApplicationAndEnrollment
(the block using prisma.programApplication.create and sanitizeData) to
explicitly set country: partner.country (or the local partner variable)
alongside id, programId, and groupId so the DB write always persists
partner.country regardless of sanitizeData input.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: a2570a4c-feeb-43dc-ae5a-18c64ee239a9
📒 Files selected for processing (5)
apps/web/lib/actions/partners/create-program-application.tsapps/web/lib/zod/schemas/programs.tsapps/web/ui/partners/groups/design/application-form/program-application-form.tsxapps/web/ui/partners/groups/design/application-form/required-fields-preview.tsxapps/web/ui/partners/program-application-sheet.tsx
|
@coderabbitai full review |
✅ Actions performedFull review triggered. |
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
apps/web/ui/partners/groups/design/application-form/program-application-form.tsx (1)
199-210:⚠️ Potential issue | 🟡 Minor | ⚡ Quick winAdd optional chaining or fallback for
fieldsto prevent potential runtime error.Line 199 accesses
.fields.map(...)without guarding againstfieldsbeing undefined, whereas line 53-55 correctly usesgroup.applicationFormData?.fields ?? []. IfapplicationFormDatais defined butfieldsis undefined, this will throw a TypeError.🛡️ Proposed fix
- {group?.applicationFormData?.fields.map((field, index) => { + {(group.applicationFormData?.fields ?? []).map((field, index) => {🤖 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/ui/partners/groups/design/application-form/program-application-form.tsx` around lines 199 - 210, The map over group?.applicationFormData?.fields can throw if fields is undefined; update the rendering of ProgramApplicationFormField to iterate a safe array (e.g., group?.applicationFormData?.fields ?? []) or use optional chaining before .map so fields.map is only called when defined; locate the JSX that renders <ProgramApplicationFormField key={field.id} ... keyPath={`formData.fields.${index}`} onStatusChange={(loading) => handleFieldStatusChange(field.id, loading)} /> and change the source collection to a guarded expression (group?.applicationFormData?.fields ?? []) to prevent a TypeError.
🧹 Nitpick comments (1)
apps/web/lib/actions/partners/create-program-application.ts (1)
304-312: ⚡ Quick winReuse
sanitizedDatainstead of recomputing.
sanitizeData(data, group)is already computed at Line 262 (sanitizedData) and recomputed here. Reuse it to avoid the redundant call and prevent the two results from diverging.♻️ Proposed refactor
prisma.programApplication.create({ data: { - ...sanitizeData(data, group), + ...sanitizedData, id: applicationId, programId: program.id, groupId: group.id, }, }),🤖 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/actions/partners/create-program-application.ts` around lines 304 - 312, The create transaction is recomputing sanitizeData(data, group) instead of reusing the previously computed sanitizedData; update the prisma.programApplication.create call (inside the prisma.$transaction array) to spread sanitizedData rather than calling sanitizeData(data, group) again so the created application uses the same sanitizedData value that was computed earlier (ensure the variable sanitizedData is in scope where used).
🤖 Prompt for all review comments with 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.
Inline comments:
In `@apps/web/lib/actions/partners/create-program-application.ts`:
- Around line 408-416: The IP-derived country from headers() is being written
directly to Prisma and can be empty/invalid; import COUNTRY_CODES from
"`@dub/utils`" and validate/normalize the header value before persisting by
checking that headerList.get("x-vercel-ip-country") is a non-empty string
included in COUNTRY_CODES (e.g., uppercased/normalized to match entries); if
it’s invalid or empty, do not overwrite the already-validated country from
sanitizeData(data, group) (leave country undefined so the validated value or
schema default remains), and ensure the variable used in
prisma.programApplication.create({ data: { ...sanitizeData(...), country } })
only contains a validated value.
---
Outside diff comments:
In
`@apps/web/ui/partners/groups/design/application-form/program-application-form.tsx`:
- Around line 199-210: The map over group?.applicationFormData?.fields can throw
if fields is undefined; update the rendering of ProgramApplicationFormField to
iterate a safe array (e.g., group?.applicationFormData?.fields ?? []) or use
optional chaining before .map so fields.map is only called when defined; locate
the JSX that renders <ProgramApplicationFormField key={field.id} ...
keyPath={`formData.fields.${index}`} onStatusChange={(loading) =>
handleFieldStatusChange(field.id, loading)} /> and change the source collection
to a guarded expression (group?.applicationFormData?.fields ?? []) to prevent a
TypeError.
---
Nitpick comments:
In `@apps/web/lib/actions/partners/create-program-application.ts`:
- Around line 304-312: The create transaction is recomputing sanitizeData(data,
group) instead of reusing the previously computed sanitizedData; update the
prisma.programApplication.create call (inside the prisma.$transaction array) to
spread sanitizedData rather than calling sanitizeData(data, group) again so the
created application uses the same sanitizedData value that was computed earlier
(ensure the variable sanitizedData is in scope where used).
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 70baa20d-c6f4-45a3-8ef0-bb7f2de82abb
📒 Files selected for processing (5)
apps/web/lib/actions/partners/create-program-application.tsapps/web/lib/zod/schemas/programs.tsapps/web/ui/partners/groups/design/application-form/program-application-form.tsxapps/web/ui/partners/groups/design/application-form/required-fields-preview.tsxapps/web/ui/partners/program-application-sheet.tsx
Summary by CodeRabbit
New Features
Bug Fixes
Refactor