From 2b6a2207f88691d4fb6dc7dac1d3e8c021d1399d Mon Sep 17 00:00:00 2001 From: ducica Date: Tue, 9 Jan 2024 12:47:41 +0100 Subject: [PATCH] fixed mutating save action --- .../theme/assets/semantic-ui/js/oarepo_ui/forms/hooks.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/oarepo_ui/theme/assets/semantic-ui/js/oarepo_ui/forms/hooks.js b/oarepo_ui/theme/assets/semantic-ui/js/oarepo_ui/forms/hooks.js index 9bb8f717..11f6b530 100644 --- a/oarepo_ui/theme/assets/semantic-ui/js/oarepo_ui/forms/hooks.js +++ b/oarepo_ui/theme/assets/semantic-ui/js/oarepo_ui/forms/hooks.js @@ -171,17 +171,18 @@ export const useDepositApiClient = ( setSubmitting(true); setIsSaving(true); - setValues(_omit(values, internalFieldsArray)); + // purge any existing errors in internal fields before making save action + const valuesWithoutInternalFields = _omit(values, internalFieldsArray); setErrors({}); try { - response = await apiClient.saveOrCreateDraft(values); + response = await apiClient.saveOrCreateDraft(valuesWithoutInternalFields); // when I am creating a new draft, it saves the response into formik's state, so that I would have access // to the draft and draft links in the app. I we don't do that then each time I click on save it will // create new draft, as I don't actually refresh the page, so the record from html is still empty. Invenio, // solves this by keeping record in the store, but the idea here is to not create some central state, // but use formik as some sort of auxiliary state. - if (!values.id) { + if (!valuesWithoutInternalFields.id) { window.history.replaceState( undefined, "",