@@ -75,17 +75,25 @@ export const ValidationStep = <T extends string>({ initialData }: Props<T>) => {
7575
7676 const rowKeyGetter = useCallback ( ( row : Data < T > & Meta ) => row . __index , [ ] )
7777
78- const submitData = ( ) => {
79- const all = data . map ( ( { __index, __errors, ...value } ) => ( { ...value } ) ) as unknown as Data < T > [ ]
80- const validData = all . filter ( ( value , index ) => {
81- const originalValue = data [ index ]
82- if ( originalValue ?. __errors ) {
83- return ! Object . values ( originalValue . __errors ) ?. filter ( ( err ) => err . level === "error" ) . length
84- }
85- return true
86- } )
87- const invalidData = all . filter ( ( value ) => ! validData . includes ( value ) )
88- onSubmit ( { validData, invalidData, all : data } )
78+ const submitData = async ( ) => {
79+ const calculatedData = data . reduce (
80+ ( acc , value ) => {
81+ const { __index, __errors, ...values } = value
82+ if ( __errors ) {
83+ for ( const key in __errors ) {
84+ if ( __errors [ key ] . level === "error" ) {
85+ acc . invalidData . push ( values as unknown as Data < T > )
86+ return acc
87+ }
88+ }
89+ }
90+ acc . validData . push ( values as unknown as Data < T > )
91+ return acc
92+ } ,
93+ { validData : [ ] as Data < T > [ ] , invalidData : [ ] as Data < T > [ ] , all : data } ,
94+ )
95+ onSubmit ( calculatedData )
96+ setShowSubmitAlert ( false )
8997 onClose ( )
9098 }
9199 const onContinue = ( ) => {
@@ -104,14 +112,7 @@ export const ValidationStep = <T extends string>({ initialData }: Props<T>) => {
104112
105113 return (
106114 < >
107- < SubmitDataAlert
108- isOpen = { showSubmitAlert }
109- onClose = { ( ) => setShowSubmitAlert ( false ) }
110- onConfirm = { ( ) => {
111- setShowSubmitAlert ( false )
112- submitData ( )
113- } }
114- />
115+ < SubmitDataAlert isOpen = { showSubmitAlert } onClose = { ( ) => setShowSubmitAlert ( false ) } onConfirm = { submitData } />
115116 < ModalBody pb = { 0 } >
116117 < Box display = "flex" justifyContent = "space-between" alignItems = "center" mb = "2rem" flexWrap = "wrap" gap = "8px" >
117118 < Heading sx = { styles . heading } > { translations . validationStep . title } </ Heading >
0 commit comments