Skip to content

Commit 16eaa34

Browse files
authored
Merge pull request #234 from scientist-softserv/239-disable-button
239 page loading after request creation + disable button
2 parents 763d344 + 0d7540f commit 16eaa34

File tree

1 file changed

+37
-28
lines changed

1 file changed

+37
-28
lines changed

pages/requests/new/[ware].js

Lines changed: 37 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ const NewRequest = () => {
5858
const [formData, setFormData] = useState(initialFormData)
5959
const [createRequestError, setCreateRequestError] = useState(undefined)
6060
const [createdRequestUUID, setCreatedRequestUUID] = useState(undefined)
61+
const [buttonDisabled, setButtonDisabled] = useState(false)
62+
const [formSubmitting, setFormSubmitting] = useState(false)
6163

6264
/**
6365
* @param {object} event onChange event
@@ -80,13 +82,15 @@ const NewRequest = () => {
8082
}
8183

8284
const handleSubmit = async (event) => {
85+
setButtonDisabled(true)
8386
if (!event.formData) {
8487
// these steps are needed for requests without a dynamic form
8588
// but error on the event resulting from the react json form
8689
event.preventDefault()
8790
event.stopPropagation()
8891
setValidated(true)
8992
}
93+
setFormSubmitting(true)
9094

9195
if (requestForm.billingSameAsShipping === true) Object.assign(requestForm.billing, requestForm.shipping)
9296

@@ -110,7 +114,7 @@ const NewRequest = () => {
110114
}, [createdRequestUUID])
111115

112116
// TODO(alishaevn): use react bs placeholder component
113-
if (isLoadingInitialRequest || !wareID) return <Loading wrapperClass='item-page mt-5' />
117+
if (isLoadingInitialRequest || !wareID || formSubmitting) return <Loading wrapperClass='item-page mt-5' />
114118

115119
if (!session) {
116120
return (
@@ -165,6 +169,7 @@ const NewRequest = () => {
165169
defaultRequiredDate={oneWeekFromNow}
166170
requestForm={requestForm}
167171
updateRequestForm={updateRequestForm}
172+
buttonDisabled={buttonDisabled}
168173
/>
169174
</Form>
170175
) : (
@@ -179,40 +184,44 @@ const NewRequest = () => {
179184
defaultRequiredDate={oneWeekFromNow}
180185
requestForm={requestForm}
181186
updateRequestForm={updateRequestForm}
187+
buttonDisabled={buttonDisabled}
182188
/>
183189
</BsForm>
184190
)}
185191
</div>
186192
)
187193
}
188194

189-
const StandardRequestOptions = ({ defaultRequiredDate, requestForm, updateRequestForm, }) => (
190-
<>
191-
<div className='row'>
192-
<div className='col'>
193-
<ShippingDetails
194-
backgroundColor={requestFormHeaderBg}
195-
billingCountry={requestForm.billing.country}
196-
shippingCountry={requestForm.shipping.country}
197-
updateRequestForm={updateRequestForm}
198-
/>
199-
</div>
200-
<div className='col'>
201-
<AdditionalInfo
202-
updateRequestForm={updateRequestForm}
203-
defaultRequiredDate={defaultRequiredDate}
204-
backgroundColor={requestFormHeaderBg}
205-
/>
195+
const StandardRequestOptions = ({ buttonDisabled, defaultRequiredDate, requestForm, updateRequestForm, }) => {
196+
return (
197+
<>
198+
<div className='row'>
199+
<div className='col'>
200+
<ShippingDetails
201+
backgroundColor={requestFormHeaderBg}
202+
billingCountry={requestForm.billing.country}
203+
shippingCountry={requestForm.shipping.country}
204+
updateRequestForm={updateRequestForm}
205+
/>
206+
</div>
207+
<div className='col'>
208+
<AdditionalInfo
209+
updateRequestForm={updateRequestForm}
210+
defaultRequiredDate={defaultRequiredDate}
211+
backgroundColor={requestFormHeaderBg}
212+
/>
213+
</div>
206214
</div>
207-
</div>
208-
<Button
209-
addClass='btn btn-primary my-4 ms-auto d-block'
210-
backgroundColor={buttonBg}
211-
label='Initiate Request'
212-
type='submit'
213-
size='large'
214-
/>
215-
</>
216-
)
215+
<Button
216+
addClass='btn btn-primary my-4 ms-auto d-block'
217+
backgroundColor={buttonBg}
218+
disabled={buttonDisabled}
219+
label='Initiate Request'
220+
type='submit'
221+
size='large'
222+
/>
223+
</>
224+
)
225+
}
217226

218227
export default NewRequest

0 commit comments

Comments
 (0)