From 25d6eb2fd7cc9d40ce7c6fe2790ce9e5176f27eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Castillo?= Date: Thu, 11 Jun 2026 17:26:51 -0300 Subject: [PATCH] fix: make managed forms dates optional, adjust payload MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Tomás Castillo --- src/actions/sponsor-forms-actions.js | 6 +- .../customized-form/customized-form.js | 61 ++++++++++++------- 2 files changed, 43 insertions(+), 24 deletions(-) diff --git a/src/actions/sponsor-forms-actions.js b/src/actions/sponsor-forms-actions.js index fe0d953b6..d60f994ce 100644 --- a/src/actions/sponsor-forms-actions.js +++ b/src/actions/sponsor-forms-actions.js @@ -912,8 +912,10 @@ export const normalizeSponsorCustomizedForm = (entity, summitTZ) => { ...normalizedEntity } = entity; - normalizedEntity.opens_at = moment.tz(opens_at, summitTZ).unix(); - normalizedEntity.expires_at = moment.tz(expires_at, summitTZ).unix(); + if (opens_at) + normalizedEntity.opens_at = moment.tz(opens_at, summitTZ).unix(); + if (expires_at) + normalizedEntity.expires_at = moment.tz(expires_at, summitTZ).unix(); Object.assign( normalizedEntity, diff --git a/src/pages/sponsors/sponsor-page/tabs/sponsor-forms-tab/components/customized-form/customized-form.js b/src/pages/sponsors/sponsor-page/tabs/sponsor-forms-tab/components/customized-form/customized-form.js index 5c40fbe7f..d166cd11e 100644 --- a/src/pages/sponsors/sponsor-page/tabs/sponsor-forms-tab/components/customized-form/customized-form.js +++ b/src/pages/sponsors/sponsor-page/tabs/sponsor-forms-tab/components/customized-form/customized-form.js @@ -18,7 +18,6 @@ import MuiFormikDatepicker from "openstack-uicore-foundation/lib/components/mui/ import { addIssAfterDateFieldValidator, formMetafieldsValidation, - opensAtValidation, requiredStringValidation, requiredHTMLValidation } from "../../../../../../../utils/yup"; @@ -60,27 +59,45 @@ const CustomizedForm = ({ const formik = useFormik( { initialValues: buildInitialValues(initialValues, summitTZ), - validationSchema: yup.object().shape({ - name: requiredStringValidation(), - code: requiredStringValidation(), - instructions: requiredHTMLValidation(), - opens_at: opensAtValidation(), - expires_at: yup - .date(T.translate("validation.date")) - .required(T.translate("validation.required")) - .isAfterDateField( - yup.ref("opens_at"), - T.translate("validation.after", { - field1: T.translate( - "edit_sponsor.forms_tab.customized_form.expires_at" - ), - field2: T.translate( - "edit_sponsor.forms_tab.customized_form.opens_at" - ) - }) - ), - meta_fields: formMetafieldsValidation() - }), + validationSchema: yup.object().shape( + { + name: requiredStringValidation(), + code: requiredStringValidation(), + instructions: requiredHTMLValidation(), + opens_at: yup + .date(T.translate("validation.date")) + .nullable() + .when("expires_at", { + is: (val) => !!val, + then: (schema) => + schema.required(T.translate("validation.required")), + otherwise: (schema) => schema.nullable() + }), + expires_at: yup + .date(T.translate("validation.date")) + .nullable() + .when("opens_at", { + is: (val) => !!val, + then: (schema) => + schema + .required(T.translate("validation.required")) + .isAfterDateField( + yup.ref("opens_at"), + T.translate("validation.after", { + field1: T.translate( + "edit_sponsor.forms_tab.customized_form.expires_at" + ), + field2: T.translate( + "edit_sponsor.forms_tab.customized_form.opens_at" + ) + }) + ), + otherwise: (schema) => schema.nullable() + }), + meta_fields: formMetafieldsValidation() + }, + [["opens_at", "expires_at"]] + ), onSubmit, enableReinitialize: true },