From 932a5cde1676fb14b1dfde08570322dc12824617 Mon Sep 17 00:00:00 2001 From: Qiyun Dai Date: Wed, 11 Dec 2024 16:04:36 -0600 Subject: [PATCH 1/2] small refactor --- .../event-creation-form/event-creation-form.js | 18 +++++++++--------- .../series-creation-form.js | 18 ++++++++++++------ 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/ecc/blocks/event-creation-form/event-creation-form.js b/ecc/blocks/event-creation-form/event-creation-form.js index d0337f17..3cb3f620 100644 --- a/ecc/blocks/event-creation-form/event-creation-form.js +++ b/ecc/blocks/event-creation-form/event-creation-form.js @@ -440,26 +440,26 @@ async function save(props, toPublish = false) { let resp = props.response; - const onSave = async () => { + if (!resp.eventId) { + resp = await createEvent(quickFilter(props.payload)); + props.eventDataResp = { ...props.eventDataResp, ...resp }; + updateDashboardLink(props); if (resp?.eventId) await handleEventUpdate(props); if (!resp.error) { showSaveSuccessMessage(props); } - }; - - if (!resp.eventId) { - resp = await createEvent(quickFilter(props.payload)); - props.eventDataResp = { ...props.eventDataResp, ...resp }; - updateDashboardLink(props); - await onSave(); } else if (!toPublish) { resp = await updateEvent( getFilteredCachedResponse().eventId, getJoinedData(), ); props.eventDataResp = { ...props.eventDataResp, ...resp }; - await onSave(); + if (resp?.eventId) await handleEventUpdate(props); + + if (!resp.error) { + showSaveSuccessMessage(props); + } } else if (toPublish) { resp = await publishEvent( getFilteredCachedResponse().eventId, diff --git a/ecc/blocks/series-creation-form/series-creation-form.js b/ecc/blocks/series-creation-form/series-creation-form.js index efa331dc..cea3ce6d 100644 --- a/ecc/blocks/series-creation-form/series-creation-form.js +++ b/ecc/blocks/series-creation-form/series-creation-form.js @@ -402,25 +402,31 @@ async function save(props, toPublish = false) { let resp = props.response; const onSave = async () => { - if (resp?.seriesId) await handleSeriesUpdate(props); - if (!resp.error) { - showSaveSuccessMessage(props); - } }; if (!resp.seriesId) { resp = await createSeries(quickFilter(props.payload)); props.response = { ...props.response, ...resp }; updateDashboardLink(props); - await onSave(); + + if (resp?.seriesId) await handleSeriesUpdate(props); + + if (!resp.error) { + showSaveSuccessMessage(props); + } } else if (!toPublish) { resp = await updateSeries( resp.seriesId, getJoinedData(), ); props.response = { ...props.response, ...resp }; - await onSave(); + + if (resp?.seriesId) await handleSeriesUpdate(props); + + if (!resp.error) { + showSaveSuccessMessage(props); + } } else if (toPublish) { resp = await publishSeries( resp.seriesId, From cd10f3302b465f94e67fc3d854abcdae67534781 Mon Sep 17 00:00:00 2001 From: Qiyun Dai Date: Wed, 11 Dec 2024 16:11:51 -0600 Subject: [PATCH 2/2] set status to draft on POST --- ecc/scripts/esp-controller.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ecc/scripts/esp-controller.js b/ecc/scripts/esp-controller.js index e2cb7f9c..ab13c302 100644 --- a/ecc/scripts/esp-controller.js +++ b/ecc/scripts/esp-controller.js @@ -810,7 +810,7 @@ export async function getSeriesById(seriesId) { export async function createSeries(seriesData) { const { host } = API_CONFIG.esp[getEventServiceEnv()]; - const raw = JSON.stringify(seriesData); + const raw = JSON.stringify({ ...seriesData, seriesStatus: 'draft' }); const options = await constructRequestOptions('POST', raw); try {