Skip to content

fix: adjust sponsor global quantity metafield initial value#774

Merged
smarcet merged 8 commits intomasterfrom
fix/sponsor-global-initial-quantity
Feb 4, 2026
Merged

fix: adjust sponsor global quantity metafield initial value#774
smarcet merged 8 commits intomasterfrom
fix/sponsor-global-initial-quantity

Conversation

@tomrndom
Copy link

@tomrndom tomrndom commented Feb 3, 2026

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

Signed-off-by: Tomás Castillo tcastilloboireau@gmail.com

Summary by CodeRabbit

  • Bug Fixes

    • Sponsor forms, form items and inventory dialogs now start with an empty meta-field list instead of a pre-filled placeholder.
    • List inputs maintain a single editable draft entry so the UI never appears completely empty when editing fields.
  • Refactor

    • Quantity field validation standardized across the app for consistent behavior.

Signed-off-by: Tomás Castillo <tcastilloboireau@gmail.com>
@coderabbitai
Copy link

coderabbitai bot commented Feb 3, 2026

📝 Walkthrough

Walkthrough

Default sponsor form meta_fields were changed from a pre-populated single empty field to an empty array across reducers, dialogs, and UI; AdditionalInputList now manages draft items with per-item _key; quantity validators were refactored to use positiveNumberValidation().

Changes

Cohort / File(s) Summary
Sponsor Form Reducers
src/reducers/sponsors/sponsor-form-items-list-reducer.js, src/reducers/sponsors/sponsor-customized-form-items-list-reducer.js, src/reducers/sponsors/sponsor-customized-form-reducer.js, src/reducers/sponsors/sponsor-forms-list-reducer.js
DEFAULT_STATE and RECEIVE handlers now default meta_fields to [] instead of a prefilled single empty-field object.
Reducer Tests
src/reducers/sponsors/__tests__/sponsor-form-items-list-reducer.test.js
Updated expectations to assert currentItem.meta_fields: [] where a default field object was previously expected.
UI Inputs
src/components/mui/formik-inputs/additional-input/additional-input-list.js, src/components/mui/formik-inputs/additional-input/additional-input.js
Added per-item _key draft handling and useEffect to ensure a draft item exists when metaFields is empty; render keys prefer _key (fallback to id); adjusted inner Grid alignment.
Component Tests
src/components/mui/__tests__/additional-input-list.test.js
Test updated to expect a single draft metafield rendered when meta_fields is empty, reflecting new UI initialization behavior.
Form Dialogs / Pages
src/pages/sponsors-global/form-templates/form-template-popup.js, src/pages/sponsors-global/form-templates/sponsor-inventory-popup.js
Dialog initialValues now set meta_fields to [] when missing/empty instead of inserting a default meta field object.
Validation Utilities
src/utils/yup.js
Replaced nullable number validators for minimum_quantity/maximum_quantity with positiveNumberValidation() while keeping conditional "Quantity" requirement.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • smarcet

Poem

"I'm a rabbit in the code, I clear the rows away,
I leave the fields all empty, ready for new play.
I tag each draft with keys that hop from line to line,
Quantity checks pruned tidy — forms will soon align.
Hop, hop, the inputs wake; the garden's set to sway."

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: adjust sponsor global quantity metafield initial value' directly relates to the main change: removing default meta_fields entries across multiple sponsor form reducers and components, changing empty array initialization behavior throughout the codebase.

✏️ 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/sponsor-global-initial-quantity

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

…, adjust test

Signed-off-by: Tomás Castillo <tcastilloboireau@gmail.com>
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: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (4)
src/reducers/sponsors/sponsor-customized-form-items-list-reducer.js (1)

128-138: ⚠️ Potential issue | 🟡 Minor

Inconsistent fallback meta_fields structure.

The fallback meta_fields object when item.meta_fields.length === 0 doesn't include minimum_quantity and maximum_quantity, unlike the DEFAULT_ITEM_ENTITY definition. This could cause inconsistent state shapes.

Proposed fix
             : [
                 {
                   name: "",
                   type: "Text",
                   is_required: false,
+                  minimum_quantity: 0,
+                  maximum_quantity: 0,
                   values: []
                 }
               ]
src/reducers/sponsors/sponsor-form-items-list-reducer.js (1)

115-125: ⚠️ Potential issue | 🟡 Minor

Inconsistent fallback meta_fields structure.

Same issue as in sponsor-customized-form-items-list-reducer.js — the fallback meta_fields when item.meta_fields.length === 0 is missing minimum_quantity and maximum_quantity.

Proposed fix
             : [
                 {
                   name: "",
                   type: "Text",
                   is_required: false,
+                  minimum_quantity: 0,
+                  maximum_quantity: 0,
                   values: []
                 }
               ]
src/reducers/sponsors/sponsor-forms-list-reducer.js (1)

136-146: ⚠️ Potential issue | 🟡 Minor

Inconsistent fallback meta_fields structure.

Same pattern as other reducers — the fallback meta_fields when form.meta_fields.length === 0 is missing minimum_quantity and maximum_quantity. Consider adding them for consistent state shape.

Proposed fix
             : [
                 {
                   name: "",
                   type: "Text",
                   is_required: false,
+                  minimum_quantity: 0,
+                  maximum_quantity: 0,
                   values: []
                 }
               ]
src/reducers/sponsors_inventory/inventory-item-reducer.js (1)

29-50: ⚠️ Potential issue | 🟠 Major

Avoid shared default meta_fields object across resets.

DEFAULT_ENTITY now contains a nested object/array, but reducer paths use shallow copies, so later mutations (e.g., updating metaField.values) can leak into the default and affect new forms. Use a factory function to create fresh defaults each time.

✅ Proposed fix
-export const DEFAULT_ENTITY = {
+const createDefaultMetaField = () => ({
+  name: "",
+  type: "Text",
+  is_required: false,
+  minimum_quantity: 0,
+  maximum_quantity: 0,
+  values: []
+});
+
+export const createDefaultEntity = () => ({
   id: 0,
   code: "",
   name: "",
   description: "",
   default_quantity: 0,
   quantity_limit_per_show: 0,
   quantity_limit_per_sponsor: 0,
   early_bird_rate: 0,
   standard_rate: 0,
   onsite_rate: 0,
   images: [],
-  meta_fields: [
-    {
-      name: "",
-      type: "Text",
-      is_required: false,
-      minimum_quantity: 0,
-      maximum_quantity: 0,
-      values: []
-    }
-  ]
-};
+  meta_fields: [createDefaultMetaField()]
+});
 
-const DEFAULT_STATE = {
-  entity: DEFAULT_ENTITY,
+const DEFAULT_STATE = {
+  entity: createDefaultEntity(),
   errors: {}
 };

Then update usages (e.g., RESET/RECEIVE/ADDED/UPDATED) to spread createDefaultEntity() instead of DEFAULT_ENTITY.

🧹 Nitpick comments (1)
src/reducers/sponsors/__tests__/sponsor-form-items-list-reducer.test.js (1)

198-204: Test expectation aligns with reducer inconsistency.

The expected meta_fields in this test doesn't include minimum_quantity and maximum_quantity, which matches the current reducer fallback behavior. If you fix the reducer's fallback (as suggested in the reducer review), update this expectation accordingly.

Signed-off-by: Tomás Castillo <tcastilloboireau@gmail.com>
@tomrndom tomrndom force-pushed the fix/sponsor-global-initial-quantity branch from 93dd620 to 51c7fea Compare February 4, 2026 14:24
Signed-off-by: Tomás Castillo <tcastilloboireau@gmail.com>
@tomrndom tomrndom requested a review from smarcet February 4, 2026 14:43
…ll cases

Signed-off-by: Tomás Castillo <tcastilloboireau@gmail.com>
Signed-off-by: Tomás Castillo <tcastilloboireau@gmail.com>
Signed-off-by: Tomás Castillo <tcastilloboireau@gmail.com>
Signed-off-by: Tomás Castillo <tcastilloboireau@gmail.com>
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 811f794 into master Feb 4, 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.

2 participants