11import { useCallback , useMemo , useState } from "react"
2- import { Box , Button , Heading , ModalBody , Switch , useStyleConfig } from "@chakra-ui/react"
2+ import { Box , Button , Heading , ModalBody , Switch , useStyleConfig , useToast } from "@chakra-ui/react"
33import { ContinueButton } from "../../components/ContinueButton"
44import { useRsi } from "../../hooks/useRsi"
55import type { Meta } from "./types"
@@ -22,12 +22,14 @@ export const ValidationStep = <T extends string>({ initialData, file, onBack }:
2222 const styles = useStyleConfig (
2323 "ValidationStep" ,
2424 ) as ( typeof themeOverrides ) [ "components" ] [ "ValidationStep" ] [ "baseStyle" ]
25+ const toast = useToast ( )
2526
2627 const [ data , setData ] = useState < ( Data < T > & Meta ) [ ] > ( initialData )
2728
2829 const [ selectedRows , setSelectedRows ] = useState < ReadonlySet < number | string > > ( new Set ( ) )
2930 const [ filterByErrors , setFilterByErrors ] = useState ( false )
3031 const [ showSubmitAlert , setShowSubmitAlert ] = useState ( false )
32+ const [ isSubmitting , setSubmitting ] = useState ( false )
3133
3234 const updateData = useCallback (
3335 async ( rows : typeof data , indexes ?: number [ ] ) => {
@@ -96,9 +98,25 @@ export const ValidationStep = <T extends string>({ initialData, file, onBack }:
9698 } ,
9799 { validData : [ ] as Data < T > [ ] , invalidData : [ ] as Data < T > [ ] , all : data } ,
98100 )
99- onSubmit ( calculatedData , file )
100101 setShowSubmitAlert ( false )
101- onClose ( )
102+ setSubmitting ( true )
103+ onSubmit ( calculatedData , file )
104+ ?. then ( ( ) => {
105+ onClose ( )
106+ } )
107+ . catch ( ( err : Error ) => {
108+ toast ( {
109+ status : "error" ,
110+ variant : "left-accent" ,
111+ position : "bottom-left" ,
112+ title : `${ translations . alerts . submitError . title } ` ,
113+ description : err ?. message || `${ translations . alerts . submitError . defaultMessage } ` ,
114+ isClosable : true ,
115+ } )
116+ } )
117+ . finally ( ( ) => {
118+ setSubmitting ( false )
119+ } )
102120 }
103121 const onContinue = ( ) => {
104122 const invalidData = data . find ( ( value ) => {
@@ -153,6 +171,7 @@ export const ValidationStep = <T extends string>({ initialData, file, onBack }:
153171 />
154172 </ ModalBody >
155173 < ContinueButton
174+ isLoading = { isSubmitting }
156175 onContinue = { onContinue }
157176 onBack = { onBack }
158177 title = { translations . validationStep . nextButtonTitle }
0 commit comments