Skip to content

fix: page templates date field required#992

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

fix: page templates date field required#992
priscila-moneo wants to merge 2 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 their media request form based on template type.
  • Bug Fixes

    • The upload deadline field is hidden for global templates and remains required for non-global templates.
    • Media request data now avoids keeping outdated upload deadline values when they are not provided.
  • Tests

    • Added coverage to verify media modules normalize correctly when upload deadline values are missing or blank.

@coderabbitai

coderabbitai Bot commented Jun 18, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The PR threads an isGlobal flag through the sponsors global page template flow, makes the media upload-deadline field optional for global templates, and updates normalization and tests so media modules without a deadline do not retain one.

Changes

Global page template deadline flow

Layer / File(s) Summary
Popup global flag
src/pages/sponsors-global/page-templates/page-template-list-page.js, src/pages/sponsors-global/page-templates/page-template-popup/index.js
PageTemplatePopup receives isGlobal, uses it in Formik/Yup validation, forwards it to PageModules, and declares the new prop.
PageModules handoff
src/pages/sponsors-global/page-templates/page-template-popup/page-template-modules-form.js
PageModules accepts isGlobal = false, requires getAllMediaFileTypes, and passes showUploadDeadline={!isGlobal} to MediaRequestModule.
Media deadline toggle
src/utils/constants.js, src/pages/sponsors-global/page-templates/page-template-popup/modules/page-template-media-request-module.js
New column constants support MediaRequestModule, which switches the name-field span, conditionally renders the upload-deadline picker from showUploadDeadline, and declares that prop as optional.
Normalize missing deadlines
src/utils/page-template.js, src/utils/__tests__/page-template.test.js
normalizePageTemplateModules deletes upload_deadline when it is absent on media modules, and tests cover FILE and INPUT normalization cases.

Sequence Diagram(s)

sequenceDiagram
  participant PageTemplateListPage
  participant PageTemplatePopup
  participant useFormik
  participant mediaModuleSchema
  participant PageModules
  participant MediaRequestModule
  PageTemplateListPage->>PageTemplatePopup: isGlobal
  PageTemplatePopup->>useFormik: validationContext { isGlobal }
  useFormik->>mediaModuleSchema: validate upload_deadline
  mediaModuleSchema-->>PageTemplatePopup: upload_deadline required or nullable
  PageTemplatePopup->>PageModules: isGlobal
  PageModules->>MediaRequestModule: showUploadDeadline={!isGlobal}
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • fntechgit/summit-admin#862 — Shares the src/utils/page-template.js media-module normalization path and related tests around upload_deadline.

Suggested reviewers

  • smarcet

Poem

🐰 I hopped through templates, light and spry,
A global flag went floating by.
Deadlines tucked themselves away,
While modules danced in tidy array.
Thump thump! 🌿

🚥 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 accurately reflects the main change: adjusting the page template date field requirement.
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.

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

✨ 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.

<MediaRequestModule
baseName={name}
index={index}
isGlobal={isGlobal}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

at this point isGlobal means nothing, can we change it to showUploadDeadline={!isGlobal} instead ? and add a default to isGlobal

name: yup.string().required(T.translate("validation.required")),
type: yup.string().required(T.translate("validation.required")),
upload_deadline: yup.date().required(T.translate("validation.required")),
upload_deadline: yup.date().nullable(),

@smarcet smarcet Jun 24, 2026

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 this change makes upload_deadline optional for all consumers of the component, not just the global context.

The ticket required:

  • Global template -> hide the field + make it optional (correct)
  • Summit/sponsor template -> keep the field visible and still required (broken by this change)

The other two consumers of PageTemplatePopup - show-pages-list-page/index.js and sponsor-pages-tab/index.js - do not pass isGlobal, still render the date picker, but now allow the form to submit without a value because the validation is .nullable() instead of .required().

Suggested fix: make the schema conditional using Formik's validationContext:

// In useFormik:
validationContext: { isGlobal }

// In mediaModuleSchema:
upload_deadline: yup.date().when('$isGlobal', {
  is: true,
  then: (s) => s.nullable(),
  otherwise: (s) => s.required(T.translate("validation.required"))
})

@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.

Comment on lines 233 to 236
PageModules.propTypes = {
name: PropTypes.string
name: PropTypes.string,
isGlobal: PropTypes.bool
};
Signed-off-by: Priscila Moneo <priscila_moneo@hotmail.com.ar>
Signed-off-by: Priscila Moneo <priscila_moneo@hotmail.com.ar>
@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

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.

4 participants