Skip to content

Commit

Permalink
Avoid reasign properties
Browse files Browse the repository at this point in the history
  • Loading branch information
igorbrasileiro committed Aug 3, 2021
1 parent 3d8806c commit 4e7ce63
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
6 changes: 3 additions & 3 deletions react/components/FormHandler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,23 @@ export const FormHandler: FC<{
}
dispatchSubmitAction({ type: 'SET_LOADING' })

data = parseDateTimeFieldsData({
const parsedData = parseDateTimeFieldsData({
data,
properties: props.schema.properties,
})

await createDocumentMutation({
variables: {
dataEntity: props.formProps.entity,
document: { document: data },
document: { document: parsedData },
schema: props.formProps.schema,
},
})
.then(() => {
dispatchSubmitAction({ type: 'SET_SUCCESS' })
})
.catch(e => {
setLastErrorFieldValues(data)
setLastErrorFieldValues(parsedData)

if (e.graphQLErrors) {
for (const graphqlError of e.graphQLErrors as GraphQLError[]) {
Expand Down
7 changes: 4 additions & 3 deletions react/logic/parseDateTimeFields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 4e7ce63

Please sign in to comment.