@@ -22,6 +22,8 @@ const TemplateForm = () => {
22
22
const [ fileload , setfileload ] = useState ( false ) ;
23
23
const [ percentage , setpercentage ] = useState ( 0 ) ;
24
24
const [ isAlert , setIsAlert ] = useState ( false ) ;
25
+ const [ isSubmit , setIsSubmit ] = useState ( false ) ;
26
+ const [ isErr , setIsErr ] = useState ( "" ) ;
25
27
const handleStrInput = ( e ) => {
26
28
setFormData ( { ...formData , [ e . target . name ] : e . target . value } ) ;
27
29
} ;
@@ -128,6 +130,7 @@ const TemplateForm = () => {
128
130
const dropboxCancel = async ( ) => { } ;
129
131
const handleSubmit = async ( e ) => {
130
132
e . preventDefault ( ) ;
133
+ setIsSubmit ( true ) ;
131
134
try {
132
135
const currentUser = Parse . User . current ( ) ;
133
136
const template = new Parse . Object ( templateCls ) ;
@@ -155,10 +158,6 @@ const TemplateForm = () => {
155
158
156
159
const res = await template . save ( ) ;
157
160
if ( res ) {
158
- setIsAlert ( true ) ;
159
- setTimeout ( ( ) => {
160
- setIsAlert ( false ) ;
161
- } , 1000 ) ;
162
161
setSigners ( [ ] ) ;
163
162
setFolder ( { ObjectId : "" , Name : "" } ) ;
164
163
setFormData ( {
@@ -175,7 +174,13 @@ const TemplateForm = () => {
175
174
}
176
175
} catch ( err ) {
177
176
console . log ( "err " , err ) ;
177
+ setIsErr ( true ) ;
178
+ } finally {
178
179
setIsAlert ( true ) ;
180
+ setTimeout ( ( ) => {
181
+ setIsAlert ( false ) ;
182
+ } , 1000 ) ;
183
+ setIsSubmit ( false ) ;
179
184
}
180
185
} ;
181
186
@@ -207,7 +212,13 @@ const TemplateForm = () => {
207
212
return (
208
213
< div className = "shadow-md rounded my-2 p-3 bg-[#ffffff] md:border-[1px] md:border-gray-600/50" >
209
214
< 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
+ ) }
211
222
< form onSubmit = { handleSubmit } >
212
223
< h1 className = "text-[20px] font-semibold mb-4" > New Template</ h1 >
213
224
{ fileload && (
@@ -302,8 +313,11 @@ const TemplateForm = () => {
302
313
< SelectFolder onSuccess = { handleFolder } folderCls = { templateCls } />
303
314
< div className = "flex items-center mt-3 gap-2 text-white" >
304
315
< 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`}
306
319
type = "submit"
320
+ disabled = { isSubmit }
307
321
>
308
322
Submit
309
323
</ button >
0 commit comments