@@ -22,6 +22,8 @@ const TemplateForm = () => {
2222 const [ fileload , setfileload ] = useState ( false ) ;
2323 const [ percentage , setpercentage ] = useState ( 0 ) ;
2424 const [ isAlert , setIsAlert ] = useState ( false ) ;
25+ const [ isSubmit , setIsSubmit ] = useState ( false ) ;
26+ const [ isErr , setIsErr ] = useState ( "" ) ;
2527 const handleStrInput = ( e ) => {
2628 setFormData ( { ...formData , [ e . target . name ] : e . target . value } ) ;
2729 } ;
@@ -128,6 +130,7 @@ const TemplateForm = () => {
128130 const dropboxCancel = async ( ) => { } ;
129131 const handleSubmit = async ( e ) => {
130132 e . preventDefault ( ) ;
133+ setIsSubmit ( true ) ;
131134 try {
132135 const currentUser = Parse . User . current ( ) ;
133136 const template = new Parse . Object ( templateCls ) ;
@@ -155,10 +158,6 @@ const TemplateForm = () => {
155158
156159 const res = await template . save ( ) ;
157160 if ( res ) {
158- setIsAlert ( true ) ;
159- setTimeout ( ( ) => {
160- setIsAlert ( false ) ;
161- } , 1000 ) ;
162161 setSigners ( [ ] ) ;
163162 setFolder ( { ObjectId : "" , Name : "" } ) ;
164163 setFormData ( {
@@ -175,7 +174,13 @@ const TemplateForm = () => {
175174 }
176175 } catch ( err ) {
177176 console . log ( "err " , err ) ;
177+ setIsErr ( true ) ;
178+ } finally {
178179 setIsAlert ( true ) ;
180+ setTimeout ( ( ) => {
181+ setIsAlert ( false ) ;
182+ } , 1000 ) ;
183+ setIsSubmit ( false ) ;
179184 }
180185 } ;
181186
@@ -207,7 +212,13 @@ const TemplateForm = () => {
207212 return (
208213 < div className = "shadow-md rounded my-2 p-3 bg-[#ffffff] md:border-[1px] md:border-gray-600/50" >
209214 < Title title = "New Template" />
210- { isAlert && < Alert type = "success" > Template created successfully!</ Alert > }
215+ { isAlert && (
216+ < Alert type = { isErr ? "danger" : "success" } >
217+ { isErr
218+ ? "Something went wrong please try again!"
219+ : "Template created successfully!" }
220+ </ Alert >
221+ ) }
211222 < form onSubmit = { handleSubmit } >
212223 < h1 className = "text-[20px] font-semibold mb-4" > New Template</ h1 >
213224 { fileload && (
@@ -302,8 +313,11 @@ const TemplateForm = () => {
302313 < SelectFolder onSuccess = { handleFolder } folderCls = { templateCls } />
303314 < div className = "flex items-center mt-3 gap-2 text-white" >
304315 < button
305- className = "bg-[#1ab6ce] rounded-sm shadow-md text-[14px] font-semibold uppercase text-white py-1.5 px-2.5 focus:outline-none"
316+ className = { `${
317+ isSubmit && "cursor-progress"
318+ } bg-[#1ab6ce] rounded-sm shadow-md text-[14px] font-semibold uppercase text-white py-1.5 px-2.5 focus:outline-none`}
306319 type = "submit"
320+ disabled = { isSubmit }
307321 >
308322 Submit
309323 </ button >
0 commit comments