diff --git a/src/components/molecules/PairEditForm.tsx b/src/components/molecules/PairEditForm.tsx index 7ab9c381..aa3354ec 100644 --- a/src/components/molecules/PairEditForm.tsx +++ b/src/components/molecules/PairEditForm.tsx @@ -56,30 +56,30 @@ export const PairEditForm: FC = ( event.preventDefault(); let whereFromPair, whatFromPair; // validate where - whereFromPair = { - where: pairProps.where && pairProps.where !== '{"url":"","selectors":[""] }' - ? JSON.parse(pairProps.where) - : {}, - what: [], - }; - const validationError = Preprocessor.validateWorkflow({workflow: [whereFromPair]}); - setErrors({ ...errors, where: null }); + whereFromPair = { + where: pairProps.where && pairProps.where !== '{"url":"","selectors":[""] }' + ? JSON.parse(pairProps.where) + : {}, + what: [], + }; + const validationError = Preprocessor.validateWorkflow({ workflow: [whereFromPair] }); + setErrors({ ...errors, where: null }); if (validationError) { setErrors({ ...errors, where: validationError.message }); return; } // validate what - whatFromPair = { - where: {}, - what: pairProps.what && pairProps.what !== '[{"action":"","args":[""] }]' - ? JSON.parse(pairProps.what): [], - }; - const validationErrorWhat = Preprocessor.validateWorkflow({workflow: [whatFromPair]}); - setErrors({ ...errors, "what": null }); - if (validationErrorWhat) { - setErrors({ ...errors, what: validationErrorWhat.message }); - return; - } + whatFromPair = { + where: {}, + what: pairProps.what && pairProps.what !== '[{"action":"","args":[""] }]' + ? JSON.parse(pairProps.what) : [], + }; + const validationErrorWhat = Preprocessor.validateWorkflow({ workflow: [whatFromPair] }); + setErrors({ ...errors, "what": null }); + if (validationErrorWhat) { + setErrors({ ...errors, what: validationErrorWhat.message }); + return; + } //validate index const index = parseInt(pairProps?.index, 10); if (index > (numberOfPairs + 1)) { @@ -99,18 +99,18 @@ export const PairEditForm: FC = ( } else { setErrors({ ...errors, index: '' }); } - // submit the pair - onSubmitOfPair(pairProps.id + // submit the pair + onSubmitOfPair(pairProps.id ? { id: pairProps.id, where: whereFromPair?.where || {}, what: whatFromPair?.what || [], } : { - where: whereFromPair?.where || {}, - what: whatFromPair?.what || [], - } - , index); + where: whereFromPair?.where || {}, + what: whatFromPair?.what || [], + } + , index); }; return ( @@ -122,33 +122,33 @@ export const PairEditForm: FC = ( marginTop: "36px", }} > - Raw pair edit form: + Raw pair edit form: - - + +