Skip to content

Commit

Permalink
fixed mutating save action
Browse files Browse the repository at this point in the history
  • Loading branch information
Ducica committed Jan 9, 2024
1 parent 87e0b1e commit 2b6a220
Showing 1 changed file with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
"",
Expand Down

0 comments on commit 2b6a220

Please sign in to comment.