Skip to content

86b84dha5 - Do not allow blank sponsor fields to be added#772

Open
ghost wants to merge 3 commits intomasterfrom
fix/do_not_allow_blank_sponsor_fields_to_be_added
Open

86b84dha5 - Do not allow blank sponsor fields to be added#772
ghost wants to merge 3 commits intomasterfrom
fix/do_not_allow_blank_sponsor_fields_to_be_added

Conversation

@ghost
Copy link

@ghost ghost commented Feb 3, 2026

ref: https://app.clickup.com/t/86b84dha5

86b84dha5 - Do not allow blank sponsor fields to be added

Changelog

  • Allow Sponsor dropdown to handle error objects (several errors) instead of a single one (a simple string).
  • Validate that user has selected an sponsor before saving.
  • Validate an use case when the user deleted the previously selected sponsor from the sponsor input.

Links

86b84dha5 - Do not allow blank sponsor fields to be added

Evidence

2026-02-03_10-40-26.mp4

Summary by CodeRabbit

  • New Features
    • Sponsor field is now mandatory with localized error validation.
    • Enhanced error message handling to display validation feedback more clearly.

@ghost ghost requested a review from smarcet February 3, 2026 13:55
@ghost ghost assigned smarcet and ghost Feb 3, 2026
@coderabbitai
Copy link

coderabbitai bot commented Feb 3, 2026

📝 Walkthrough

Walkthrough

This 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

Cohort / File(s) Summary
Sponsor User Form Validation
src/pages/sponsors/sponsor-users-list-page/components/edit-user-popup/sponsor-user-form.js
Added yup validation schema to Formik configuration with rules for user fields (id, name, email), access rights with nested sponsor object validation (id and name required), group assignments, and account status.
Localization and Error Display
src/i18n/en.json, src/components/mui/formik-inputs/mui-sponsor-input.js
Added new localization key sponsor_users.error_misssing_sponsor and improved error message handling in TextField component to process error objects and extract string values for helperText display.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Suggested reviewers

  • smarcet
  • romanetar

Poem

🐰 A sponsor must be chosen with care,
Validation rules now floating through the air,
Error messages translated just right,
The form now shines with newfound might! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the main objective of the changeset: preventing blank sponsor fields from being added by implementing validation and error handling for sponsor selection.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/do_not_allow_blank_sponsor_fields_to_be_added

Important

Action Needed: IP Allowlist Update

If your organization protects your Git platform with IP whitelisting, please add the new CodeRabbit IP address to your allowlist:

  • 136.113.208.247/32 (new)
  • 34.170.211.100/32
  • 35.222.179.152/32

Failure to add the new IP will result in interrupted reviews.


Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

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_sponsor looks misspelled; consider renaming to error_missing_sponsor and 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 error is 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 checks id/name and 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

Comment on lines +41 to +48
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"))
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

find . -type f -name "sponsor-user-form.js" | head -5

Repository: 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 -80

Repository: 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 -100

Repository: fntechgit/summit-admin

Length of output: 3823


🏁 Script executed:

find . -type f -name "access-rights-lists*" -o -name "AccessRightsList*" 2>/dev/null

Repository: 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.js

Repository: fntechgit/summit-admin

Length of output: 2586


🏁 Script executed:

find . -type f -name "sponsor-section*" 2>/dev/null

Repository: fntechgit/summit-admin

Length of output: 156


🏁 Script executed:

cat -n ./src/pages/sponsors/sponsor-users-list-page/components/edit-user-popup/sponsor-section.js

Repository: fntechgit/summit-admin

Length of output: 2876


🏁 Script executed:

find . -type f -name "*mui-sponsor-input*" 2>/dev/null

Repository: fntechgit/summit-admin

Length of output: 178


🏁 Script executed:

cat -n ./src/components/mui/formik-inputs/mui-sponsor-input.js

Repository: 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.

Suggested change
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant