Skip to content

fix: page templates date field required#992

Open
priscila-moneo wants to merge 7 commits into
masterfrom
fix/page-templates-date-field-required
Open

fix: page templates date field required#992
priscila-moneo wants to merge 7 commits into
masterfrom
fix/page-templates-date-field-required

Conversation

@priscila-moneo

@priscila-moneo priscila-moneo commented Jun 18, 2026

Copy link
Copy Markdown

ref: https://app.clickup.com/t/9014802374/86b9c2nd4

Summary by CodeRabbit

  • New Features
    • Global sponsor page templates now adapt the media request form by conditionally showing the upload deadline.
  • Bug Fixes
    • Upload deadline validation now correctly differs between global and non-global templates.
    • Stale/legacy upload_deadline values are cleared and omitted when the field is hidden.
    • Save/close interactions are safer while saving, and successful saves no longer automatically dismiss popups across pages.
    • Failed saves no longer trigger list refresh behavior.
  • Tests
    • Added/updated Jest coverage for global vs. non-global rendering, validation, normalization, and save-state guarding.

@coderabbitai

coderabbitai Bot commented Jun 18, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 8ec36ca6-ce52-4da1-b970-75519b4f778d

📥 Commits

Reviewing files that changed from the base of the PR and between 54c2287 and 4a79f21.

📒 Files selected for processing (2)
  • src/actions/page-template-actions.js
  • src/pages/sponsors-global/page-templates/page-template-list-page.js
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/pages/sponsors-global/page-templates/page-template-list-page.js

📝 Walkthrough

Walkthrough

The PR threads an isGlobal flag through page-template popup validation and media rendering, makes upload deadlines optional and hidden for global templates, removes missing deadlines during normalization, and coordinates save completion with popup state across page flows.

Changes

Global page template and save flow

Layer / File(s) Summary
Popup validation and save state
src/pages/sponsors-global/page-templates/page-template-list-page.js, src/pages/sponsors-global/page-templates/page-template-popup/index.js, src/pages/sponsors-global/page-templates/page-template-popup/__tests__/page-template-popup.test.js
PageTemplatePopup receives isGlobal, applies contextual validation, prevents closing and duplicate submission while saving, and handles resolved or rejected saves.
Global media-module rendering
src/pages/sponsors-global/page-templates/page-template-popup/page-template-modules-form.js, src/pages/sponsors-global/page-templates/page-template-popup/modules/*, src/utils/constants.js, src/pages/sponsors-global/page-templates/page-template-popup/__tests__/page-template-module-form.test.js
Global state controls upload-deadline visibility, stale-value cleanup, responsive field sizing, and shared component wiring.
Deadline normalization
src/utils/page-template.js, src/utils/__tests__/page-template.test.js
Media-module normalization deletes missing upload_deadline values, with FILE and INPUT cases tested.
Save handler integration
src/actions/page-template-actions.js, src/pages/sponsors/show-pages-list-page/index.js, src/pages/sponsors/sponsor-page/tabs/sponsor-pages-tab/index.js, src/pages/sponsors/**/__tests__/*
Save failures are rethrown, page lists refresh after successful saves, and popup closure is delegated to the popup save flow.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant PageTemplateListPage
  participant PageTemplatePopup
  participant PageModules
  participant MediaRequestModule
  participant savePageTemplate
  PageTemplateListPage->>PageTemplatePopup: pass isGlobal
  PageTemplatePopup->>PageModules: pass isGlobal
  PageModules->>MediaRequestModule: pass showUploadDeadline={!isGlobal}
  PageTemplatePopup->>savePageTemplate: save entity
  savePageTemplate-->>PageTemplatePopup: resolve or reject save
  PageTemplateListPage->>PageTemplateListPage: refresh page templates
Loading

Possibly related PRs

Suggested reviewers: santipalenque, tomrndom, smarcet

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title matches the main change: adjusting the page template date field requiredness.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/page-templates-date-field-required

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.

Comment thread src/pages/sponsors-global/page-templates/page-template-popup/index.js Outdated

@smarcet smarcet left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@priscila-moneo please review

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses cases where upload_deadline was being treated as a required field for page template MEDIA modules (notably for global templates), by omitting it from the payload when unset and updating the UI/validation to allow it to be absent.

Changes:

  • Update module normalization to remove upload_deadline from the outgoing payload when it is null/undefined.
  • Relax form validation for upload_deadline and hide the deadline field for global templates in the MEDIA module UI.
  • Add/adjust constants and unit tests to cover the new normalization behavior.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/utils/page-template.js Omits upload_deadline from normalized MEDIA modules when unset.
src/utils/constants.js Adds grid column constants used by the updated MEDIA module layout.
src/utils/tests/page-template.test.js Adds coverage ensuring upload_deadline is omitted when null/undefined.
src/pages/sponsors-global/page-templates/page-template-popup/page-template-modules-form.js Threads isGlobal into MEDIA module rendering.
src/pages/sponsors-global/page-templates/page-template-popup/modules/page-template-media-request-module.js Hides the deadline field for global templates and adjusts layout sizing.
src/pages/sponsors-global/page-templates/page-template-popup/index.js Makes upload_deadline nullable in schema and passes isGlobal down.
src/pages/sponsors-global/page-templates/page-template-list-page.js Marks the popup usage as isGlobal.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@priscila-moneo
priscila-moneo force-pushed the fix/page-templates-date-field-required branch from 3d3d139 to 26b5622 Compare June 25, 2026 15:36
@priscila-moneo
priscila-moneo requested a review from smarcet June 25, 2026 15:38

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

♻️ Duplicate comments (1)
src/pages/sponsors-global/page-templates/page-template-popup/index.js (1)

125-127: 🎯 Functional Correctness | 🔴 Critical

validationContext is not a Formik option; global template submission is blocked.

useFormik (v2.4.6) ignores validationContext, so the Yup schema resolves $isGlobal to undefined. This forces upload_deadline to remain .required() even when the field is hidden for global templates, preventing form submission.

Replace validationSchema with a custom validate function to inject the context:

🛠️ Fix: Inject context via custom validate
  const formik = useFormik({
    initialValues: pageTemplate,
-   validationContext: { isGlobal },
-   validationSchema: yup.object().shape({
-     code: yup.string().required(T.translate("validation.required")),
-     name: yup.string().required(T.translate("validation.required")),
-     ...(showSponsorships && {
-       sponsorship_types: yup
-         .array()
-         .min(1, T.translate("validation.required"))
-     }),
-     modules: yup.array().of(moduleSchema)
-   }),
+   validate: (values) =>
+     validationSchema
+       .validate(values, { abortEarly: false, context: { isGlobal } })
+       .then(() => ({}))
+       .catch((err) => yupToFormErrors(err)),
  });

Define validationSchema containing the moduleSchema logic before this hook.

Ensure yupToFormErrors is imported.

🤖 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 `@src/pages/sponsors-global/page-templates/page-template-popup/index.js` around
lines 125 - 127, useFormik is currently passing validationContext, which Formik
ignores, so the Yup schema in this popup cannot receive isGlobal and global
template submission stays blocked. Update the page-template-popup form hook to
replace validationSchema usage with a custom validate function that runs the
existing moduleSchema validation with context, and convert Yup errors with
yupToFormErrors so hidden global-only fields like upload_deadline do not remain
required. Keep the fix localized to the useFormik setup in the page template
popup component and preserve the current moduleSchema logic.
🤖 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.

Duplicate comments:
In `@src/pages/sponsors-global/page-templates/page-template-popup/index.js`:
- Around line 125-127: useFormik is currently passing validationContext, which
Formik ignores, so the Yup schema in this popup cannot receive isGlobal and
global template submission stays blocked. Update the page-template-popup form
hook to replace validationSchema usage with a custom validate function that runs
the existing moduleSchema validation with context, and convert Yup errors with
yupToFormErrors so hidden global-only fields like upload_deadline do not remain
required. Keep the fix localized to the useFormik setup in the page template
popup component and preserve the current moduleSchema logic.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 32cffde2-ea83-41d3-9605-c42134967c97

📥 Commits

Reviewing files that changed from the base of the PR and between d3f018b and 26b5622.

📒 Files selected for processing (7)
  • src/pages/sponsors-global/page-templates/page-template-list-page.js
  • src/pages/sponsors-global/page-templates/page-template-popup/index.js
  • src/pages/sponsors-global/page-templates/page-template-popup/modules/page-template-media-request-module.js
  • src/pages/sponsors-global/page-templates/page-template-popup/page-template-modules-form.js
  • src/utils/__tests__/page-template.test.js
  • src/utils/constants.js
  • src/utils/page-template.js

@smarcet
smarcet requested a review from santipalenque July 17, 2026 16:01
}),
modules: yup.array().of(moduleSchema)
}),
validate: (values) => {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@tomrndom Switching from the declarative validationSchema prop to this manual validate callback was necessary to pass context: { isGlobal } into Yup, but it also drops Formik's built-in prepareDataForValidation step (which normalizes '' to undefined before validation runs) for every field in the form, not just upload_deadline. I checked this repo's yup (1.7.1): .required() still rejects '' directly, so required-field enforcement isn't broken. But non-required numeric fields cleared to '' (e.g. max_file_size) now surface as a Yup type-cast error ("must be a number type... cast from the value """) instead of Formik's normalized "required" message - a behavior change to every field's validation UX as a side effect of this fix, and it isn't called out or tested.

Suggested fix: coerce '' to undefined on values before calling validationSchema.validateSync(...), mirroring Formik's prepareDataForValidation, so cleared fields keep producing the same "required" error message they did before this refactor.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@tomrndom why don't we just add a hidden field with the isGlobal value ? then we can just have normal conditional validation . I think thats more straight forward

priscila-moneo and others added 4 commits July 17, 2026 17:55
Signed-off-by: Priscila Moneo <priscila_moneo@hotmail.com.ar>
Signed-off-by: Priscila Moneo <priscila_moneo@hotmail.com.ar>
Signed-off-by: Tomás Castillo <tcastilloboireau@gmail.com>
Signed-off-by: Tomás Castillo <tcastilloboireau@gmail.com>
@tomrndom
tomrndom force-pushed the fix/page-templates-date-field-required branch from aefd24b to 49f0b0a Compare July 17, 2026 20:56
}),
modules: yup.array().of(moduleSchema)
}),
validate: (values) => {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@tomrndom why don't we just add a hidden field with the isGlobal value ? then we can just have normal conditional validation . I think thats more straight forward

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 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 `@src/pages/sponsors-global/page-templates/page-template-list-page.js`:
- Line 117: Update both save branches in the page-template save action to
rethrow API errors or remove their terminal catch, ensuring the promise returned
through handleSavePageTemplate remains rejected when saving fails. Preserve
successful-save behavior while preventing the popup from closing or resetting
after an error.
🪄 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: 9fd626ec-b13d-4ed8-b146-0ebe6eda56a0

📥 Commits

Reviewing files that changed from the base of the PR and between aefd24b and 54c2287.

📒 Files selected for processing (15)
  • src/pages/sponsors-global/page-templates/page-template-list-page.js
  • src/pages/sponsors-global/page-templates/page-template-popup/__tests__/page-template-module-form.test.js
  • src/pages/sponsors-global/page-templates/page-template-popup/__tests__/page-template-popup.test.js
  • src/pages/sponsors-global/page-templates/page-template-popup/index.js
  • src/pages/sponsors-global/page-templates/page-template-popup/modules/page-template-document-download-module.js
  • src/pages/sponsors-global/page-templates/page-template-popup/modules/page-template-info-module.js
  • src/pages/sponsors-global/page-templates/page-template-popup/modules/page-template-media-request-module.js
  • src/pages/sponsors-global/page-templates/page-template-popup/page-template-modules-form.js
  • src/pages/sponsors/show-pages-list-page/__tests__/show-pages-list-page.test.js
  • src/pages/sponsors/show-pages-list-page/index.js
  • src/pages/sponsors/sponsor-page/tabs/sponsor-pages-tab/__tests__/sponsor-pages-tab.test.js
  • src/pages/sponsors/sponsor-page/tabs/sponsor-pages-tab/index.js
  • src/utils/__tests__/page-template.test.js
  • src/utils/constants.js
  • src/utils/page-template.js
🚧 Files skipped from review as they are similar to previous changes (13)
  • src/pages/sponsors/sponsor-page/tabs/sponsor-pages-tab/tests/sponsor-pages-tab.test.js
  • src/pages/sponsors/show-pages-list-page/tests/show-pages-list-page.test.js
  • src/pages/sponsors/show-pages-list-page/index.js
  • src/pages/sponsors/sponsor-page/tabs/sponsor-pages-tab/index.js
  • src/pages/sponsors-global/page-templates/page-template-popup/modules/page-template-document-download-module.js
  • src/utils/tests/page-template.test.js
  • src/pages/sponsors-global/page-templates/page-template-popup/modules/page-template-info-module.js
  • src/pages/sponsors-global/page-templates/page-template-popup/tests/page-template-popup.test.js
  • src/pages/sponsors-global/page-templates/page-template-popup/page-template-modules-form.js
  • src/utils/page-template.js
  • src/pages/sponsors-global/page-templates/page-template-popup/tests/page-template-module-form.test.js
  • src/pages/sponsors-global/page-templates/page-template-popup/modules/page-template-media-request-module.js
  • src/pages/sponsors-global/page-templates/page-template-popup/index.js

Comment thread src/pages/sponsors-global/page-templates/page-template-list-page.js Outdated
Signed-off-by: Tomás Castillo <tcastilloboireau@gmail.com>
@smarcet
smarcet requested review from santipalenque and smarcet July 20, 2026 20:51
Comment thread src/pages/sponsors-global/page-templates/page-template-list-page.js Outdated
Comment thread src/pages/sponsors-global/page-templates/page-template-list-page.js

@smarcet smarcet left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@tomrndom please review comments

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

@santipalenque santipalenque left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LGTM

})
.catch((err) => {
console.error(err);
throw err;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

you are already returning the promise so this throw is redundant

})
.catch((err) => {
console.error(err);
throw err;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

you are already returning the promise so this throw is redundant

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.

5 participants