Skip to content

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

Merged
smarcet merged 4 commits intomasterfrom
fix/do_not_allow_blank_sponsor_fields_to_be_added
Feb 6, 2026
Merged

86b84dha5 - Do not allow blank sponsor fields to be added#772
smarcet merged 4 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 a localized validation message.
    • Form validation schema added for sponsor-user forms to enforce data types and required fields.
  • Bug Fixes
    • Improved display of input error messages so users see clear, user-friendly helper text.

@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

Adds a Yup validation schema to the sponsor-user Formik form, refactors sponsor input error handling to compute helperText from error objects/strings, and adds a new i18n key for missing sponsor validation 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 a Yup validationSchema to Formik enforcing types and required fields, including nested access_rights[].sponsor.id and access_rights[].sponsor.name with translated required messages.
Localization
src/i18n/en.json
Added sponsor_users.error_misssing_sponsor localization key used by validation messages.
Input Error Display
src/components/mui/formik-inputs/mui-sponsor-input.js
Changed helperText to use a computed errorMessage that handles string errors or extracts the first value from error objects instead of rendering the raw error prop.

Sequence Diagram(s)

sequenceDiagram
  participant User as User
  participant Formik as FormikForm
  participant Yup as YupValidator
  participant i18n as i18n
  participant Input as MUI_Sponsor_Input
  participant UI as TextField

  User->>Formik: submit form
  Formik->>Yup: validate(values, schema)
  Yup-->>Formik: validation result / errors
  alt validation error in access_rights.sponsor
    Formik->>i18n: resolve "sponsor_users.error_misssing_sponsor"
    Formik->>Input: pass error object/string
    Input->>Input: compute errorMessage (string or first object value)
    Input->>UI: render helperText = errorMessage
  else no validation errors
    Formik->>Input: pass no error
    Input->>UI: render helperText = ""
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Poem

🐇 I hopped through code with ears alert,
A missing sponsor spun my squirt,
I stitched a rule, a message bright —
Now forms approve by moonlit night. ✨

🚥 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 directly reflects the main change in the PR: adding validation to prevent blank sponsor fields from being submitted, which is implemented through Formik validation schema and error handling improvements across the three modified files.
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

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.

❤️ Share

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.

Copy link

@smarcet smarcet left a comment

Choose a reason for hiding this comment

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

LGTM

@smarcet smarcet merged commit 3aa6c73 into master Feb 6, 2026
9 checks passed
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