86b84dha5 - Do not allow blank sponsor fields to be added#772
86b84dha5 - Do not allow blank sponsor fields to be added#772
Conversation
📝 WalkthroughWalkthroughThis change adds form validation to a sponsor user management form using yup, introduces error message handling for sponsor inputs, and adds a new localization string for sponsor validation errors. The validation schema defines required fields including mandatory sponsor selection with translated error messages. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Important Action Needed: IP Allowlist UpdateIf your organization protects your Git platform with IP whitelisting, please add the new CodeRabbit IP address to your allowlist:
Failure to add the new IP will result in interrupted reviews. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In
`@src/pages/sponsors/sponsor-users-list-page/components/edit-user-popup/sponsor-user-form.js`:
- Around line 41-48: The sponsor.id Yup schema currently uses
yup.number().required(...) which throws a type error when MuiSponsorInput passes
an empty string; update the sponsor.id schema in sponsor-user-form.js (the
sponsor: yup.object({...}) block for id) to add a transform that converts empty
strings to undefined (e.g., transform: (value) => value === "" ? undefined :
value) and chain a .typeError(...) with your translation key before
.required(...) so the localized error message is shown instead of the default
Yup message.
🧹 Nitpick comments (2)
src/i18n/en.json (1)
2677-2677: Fix the typo in the i18n key before it spreads.
error_misssing_sponsorlooks misspelled; consider renaming toerror_missing_sponsorand updating all usages (and other locales, if present) for consistency.🧩 Proposed rename
- "error_misssing_sponsor": "Sponsor is mandatory.", + "error_missing_sponsor": "Sponsor is mandatory.",src/components/mui/formik-inputs/mui-sponsor-input.js (1)
107-109: Make error message extraction deterministic and string-safe.If
erroris an object/array,Object.keys(error)[0]can resolve to a non-string value (rendering[object Object]). Consider aligning with the existing sponsor input pattern that explicitly checksid/nameand falls back to"".♻️ Suggested alignment
- const errorMessage = - error && (typeof error === "string" ? error : error[Object.keys(error)[0]]); + const errorMessage = + typeof error === "object" ? error?.id || error?.name || "" : error;Also applies to: 134-134
| sponsor: yup | ||
| .object({ | ||
| id: yup | ||
| .number() | ||
| .required(T.translate("sponsor_users.error_misssing_sponsor")), | ||
| name: yup | ||
| .string() | ||
| .required(T.translate("sponsor_users.error_misssing_sponsor")) |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
find . -type f -name "sponsor-user-form.js" | head -5Repository: fntechgit/summit-admin
Length of output: 242
🏁 Script executed:
cat -n ./src/pages/sponsors/sponsor-users-list-page/components/edit-user-popup/sponsor-user-form.js | head -80Repository: fntechgit/summit-admin
Length of output: 3136
🏁 Script executed:
cat -n ./src/pages/sponsors/sponsor-users-list-page/components/edit-user-popup/sponsor-user-form.js | tail -100Repository: fntechgit/summit-admin
Length of output: 3823
🏁 Script executed:
find . -type f -name "access-rights-lists*" -o -name "AccessRightsList*" 2>/dev/nullRepository: fntechgit/summit-admin
Length of output: 160
🏁 Script executed:
cat -n ./src/pages/sponsors/sponsor-users-list-page/components/edit-user-popup/access-rights-lists.jsRepository: fntechgit/summit-admin
Length of output: 2586
🏁 Script executed:
find . -type f -name "sponsor-section*" 2>/dev/nullRepository: fntechgit/summit-admin
Length of output: 156
🏁 Script executed:
cat -n ./src/pages/sponsors/sponsor-users-list-page/components/edit-user-popup/sponsor-section.jsRepository: fntechgit/summit-admin
Length of output: 2876
🏁 Script executed:
find . -type f -name "*mui-sponsor-input*" 2>/dev/nullRepository: fntechgit/summit-admin
Length of output: 178
🏁 Script executed:
cat -n ./src/components/mui/formik-inputs/mui-sponsor-input.jsRepository: fntechgit/summit-admin
Length of output: 5956
Handle empty string validation in sponsor.id field.
When the sponsor field is cleared, MuiSponsorInput sets { id: "", name: "" }. Yup's number() validator will throw a type error for the empty string, which appears before the required() validation runs, causing the untranslated default Yup error message to display instead of your custom translation.
Add a transform to convert empty strings to undefined and optionally a typeError handler to ensure the localized error message displays:
Suggested fix
- id: yup
- .number()
- .required(T.translate("sponsor_users.error_misssing_sponsor")),
+ id: yup
+ .number()
+ .transform((value, originalValue) =>
+ originalValue === "" ? undefined : value
+ )
+ .typeError(T.translate("sponsor_users.error_misssing_sponsor"))
+ .required(T.translate("sponsor_users.error_misssing_sponsor")),📝 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.
| sponsor: yup | |
| .object({ | |
| id: yup | |
| .number() | |
| .required(T.translate("sponsor_users.error_misssing_sponsor")), | |
| name: yup | |
| .string() | |
| .required(T.translate("sponsor_users.error_misssing_sponsor")) | |
| sponsor: yup | |
| .object({ | |
| id: yup | |
| .number() | |
| .transform((value, originalValue) => | |
| originalValue === "" ? undefined : value | |
| ) | |
| .typeError(T.translate("sponsor_users.error_misssing_sponsor")) | |
| .required(T.translate("sponsor_users.error_misssing_sponsor")), | |
| name: yup | |
| .string() | |
| .required(T.translate("sponsor_users.error_misssing_sponsor")) |
🤖 Prompt for AI Agents
In
`@src/pages/sponsors/sponsor-users-list-page/components/edit-user-popup/sponsor-user-form.js`
around lines 41 - 48, The sponsor.id Yup schema currently uses
yup.number().required(...) which throws a type error when MuiSponsorInput passes
an empty string; update the sponsor.id schema in sponsor-user-form.js (the
sponsor: yup.object({...}) block for id) to add a transform that converts empty
strings to undefined (e.g., transform: (value) => value === "" ? undefined :
value) and chain a .typeError(...) with your translation key before
.required(...) so the localized error message is shown instead of the default
Yup message.
ref: https://app.clickup.com/t/86b84dha5
86b84dha5 - Do not allow blank sponsor fields to be added
Changelog
Links
86b84dha5 - Do not allow blank sponsor fields to be added
Evidence
2026-02-03_10-40-26.mp4
Summary by CodeRabbit