diff --git a/react/components/FormHandler.tsx b/react/components/FormHandler.tsx index fe413a4..295b763 100644 --- a/react/components/FormHandler.tsx +++ b/react/components/FormHandler.tsx @@ -36,7 +36,7 @@ export const FormHandler: FC<{ } dispatchSubmitAction({ type: 'SET_LOADING' }) - data = parseDateTimeFieldsData({ + const parsedData = parseDateTimeFieldsData({ data, properties: props.schema.properties, }) @@ -44,7 +44,7 @@ export const FormHandler: FC<{ await createDocumentMutation({ variables: { dataEntity: props.formProps.entity, - document: { document: data }, + document: { document: parsedData }, schema: props.formProps.schema, }, }) @@ -52,7 +52,7 @@ export const FormHandler: FC<{ dispatchSubmitAction({ type: 'SET_SUCCESS' }) }) .catch(e => { - setLastErrorFieldValues(data) + setLastErrorFieldValues(parsedData) if (e.graphQLErrors) { for (const graphqlError of e.graphQLErrors as GraphQLError[]) { diff --git a/react/logic/parseDateTimeFields.ts b/react/logic/parseDateTimeFields.ts index 175e44b..97fd7d3 100644 --- a/react/logic/parseDateTimeFields.ts +++ b/react/logic/parseDateTimeFields.ts @@ -7,11 +7,12 @@ export const parseDateTimeFieldsData = ({ data, properties, }: ParseDateTimeParams) => { + const parsedData = { ...data } Object.entries(properties).forEach(([propertyKey, property]) => { - if ((property as any)?.format === 'date-time' && data[propertyKey]) { - data[propertyKey] = new Date(data[propertyKey]).toISOString() + if ((property as any)?.format === 'date-time' && parsedData[propertyKey]) { + parsedData[propertyKey] = new Date(parsedData[propertyKey]).toISOString() } }) - return data + return parsedData }