Skip to content

Commit

Permalink
feat: onSubmit ready
Browse files Browse the repository at this point in the history
  • Loading branch information
GeorgeZhang2035 committed Jul 26, 2024
1 parent cc16c41 commit 106e5dc
Showing 1 changed file with 17 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,22 +79,34 @@ const SheetOperatorEditorForm: FC<SheetOperatorEditorFormProp> = ({
React.FormHTMLAttributes<HTMLFormElement>,
HTMLFormElement
>['onSubmit'] = (e) => {
console.log(selectedOperators)
e.preventDefault()
const targetGroup = existedGroups.find(
({ name: exsitedName }) => exsitedName === name,
) || { name, opers: [] }
const deleteArray: number[] = []
const opers = selectedOperators.map(({ groupName, operName }) => {
if (groupName) {
const targetGroup = existedGroups.find(({ name }) => name === groupName)
return existedGroups
.find(({ name }) => name === groupName)
?.opers?.find(({ name }) => name === operName)
const { opers: otherGroupOpers, ...rest } = existedGroups.find(
({ name }) => name === groupName,
) || { name: groupName, opers: [] }
const targetIndex =
otherGroupOpers?.findIndex(
({ name: otherOpersName }) => otherOpersName === operName,
) || -1
const target = otherGroupOpers?.splice(targetIndex, 1)[0]
submitGroup({ ...rest, opers: otherGroupOpers }, undefined, true)
return target
} else {
const index = existedOperators.findIndex(
({ name }) => name === operName,
)
deleteArray.push(index)
removeOperator(deleteArray)
return existedOperators[index]
}
})
}) as Group['opers']
submitGroup({ ...targetGroup, opers }, undefined, true)
}

const onReset = () => {
Expand Down

0 comments on commit 106e5dc

Please sign in to comment.