@@ -28,6 +28,7 @@ const NewRequest = ({ session }) => {
28
28
const wareID = router . query . id
29
29
const { dynamicForm, isLoadingInitialRequest, isInitialRequestError } = useInitializeRequest ( wareID , accessToken )
30
30
const oneWeekFromNow = addDays ( ( new Date ( ) ) , 7 ) . toISOString ( ) . slice ( 0 , 10 )
31
+ const disabled = session === null ? true : false
31
32
const initialFormData = { 'suppliers_identified' : 'Yes' }
32
33
const initialState = {
33
34
billingSameAsShipping : false ,
@@ -80,7 +81,6 @@ const NewRequest = ({ session }) => {
80
81
* using a guard clause with an early return inside the api methods also violates the react-hooks/rules-of-hooks rule.
81
82
*/
82
83
if ( session === undefined ) return pageLoading
83
- if ( session === null ) return unauthorizedUser
84
84
85
85
/**
86
86
* @param {object } event onChange event
@@ -169,45 +169,62 @@ const NewRequest = ({ session }) => {
169
169
}
170
170
171
171
return (
172
- < div className = 'container' >
173
- < Title title = { dynamicForm . name || '' } addClass = 'my-4' />
174
- { dynamicForm . schema ? (
175
- < Form
176
- formData = { formData }
177
- onChange = { e => setFormData ( e . formData ) }
178
- onSubmit = { handleSubmit }
179
- schema = { dynamicForm . schema }
180
- uiSchema = { dynamicForm . uiSchema }
181
- validator = { validator }
182
- >
183
- < StandardRequestOptions
184
- defaultRequiredDate = { oneWeekFromNow }
185
- requestForm = { requestForm }
186
- updateRequestForm = { updateRequestForm }
187
- buttonDisabled = { buttonDisabled }
188
- />
189
- </ Form >
190
- ) : (
191
- < BsForm
192
- onSubmit = { handleSubmit }
193
- id = { `new-${ wareID } -request-form` }
194
- noValidate
195
- validated = { validated }
196
- >
197
- < BlankRequestForm updateRequestForm = { updateRequestForm } />
198
- < StandardRequestOptions
199
- defaultRequiredDate = { oneWeekFromNow }
200
- requestForm = { requestForm }
201
- updateRequestForm = { updateRequestForm }
202
- buttonDisabled = { buttonDisabled }
203
- />
204
- </ BsForm >
205
- ) }
206
- </ div >
172
+ < >
173
+ { disabled &&
174
+ < Notice
175
+ addClass = 'mt-5'
176
+ alert = { {
177
+ body : [ 'To proceed with making a request, please log in to your account.' ] ,
178
+ title : 'Sign in required' ,
179
+ variant : 'info'
180
+ } }
181
+ dismissible = { false }
182
+ />
183
+ }
184
+ < div className = 'container' >
185
+ < Title title = { dynamicForm . name || '' } addClass = 'my-4' />
186
+ { dynamicForm . schema ? (
187
+ < Form
188
+ formData = { formData }
189
+ onChange = { e => setFormData ( e . formData ) }
190
+ onSubmit = { handleSubmit }
191
+ schema = { dynamicForm . schema }
192
+ uiSchema = { dynamicForm . uiSchema }
193
+ validator = { validator }
194
+ disabled = { disabled }
195
+ >
196
+ < StandardRequestOptions
197
+ defaultRequiredDate = { oneWeekFromNow }
198
+ requestForm = { requestForm }
199
+ updateRequestForm = { updateRequestForm }
200
+ buttonDisabled = { buttonDisabled || disabled }
201
+ disabled = { disabled }
202
+ />
203
+ </ Form >
204
+ ) : (
205
+ < BsForm
206
+ onSubmit = { handleSubmit }
207
+ id = { `new-${ wareID } -request-form` }
208
+ noValidate
209
+ validated = { validated }
210
+ disabled = { disabled }
211
+ >
212
+ < BlankRequestForm updateRequestForm = { updateRequestForm } />
213
+ < StandardRequestOptions
214
+ defaultRequiredDate = { oneWeekFromNow }
215
+ requestForm = { requestForm }
216
+ updateRequestForm = { updateRequestForm }
217
+ buttonDisabled = { buttonDisabled || disabled }
218
+ disabled = { disabled }
219
+ />
220
+ </ BsForm >
221
+ ) }
222
+ </ div >
223
+ </ >
207
224
)
208
225
}
209
226
210
- const StandardRequestOptions = ( { buttonDisabled, defaultRequiredDate, requestForm, updateRequestForm, } ) => {
227
+ const StandardRequestOptions = ( { buttonDisabled, defaultRequiredDate, requestForm, updateRequestForm, disabled } ) => {
211
228
return (
212
229
< >
213
230
< div className = 'row' >
@@ -217,20 +234,22 @@ const StandardRequestOptions = ({ buttonDisabled, defaultRequiredDate, requestFo
217
234
billingCountry = { requestForm . billing . country }
218
235
shippingCountry = { requestForm . shipping . country }
219
236
updateRequestForm = { updateRequestForm }
237
+ disabled = { disabled }
220
238
/>
221
239
</ div >
222
240
< div className = 'col' >
223
241
< AdditionalInfo
224
242
updateRequestForm = { updateRequestForm }
225
243
defaultRequiredDate = { defaultRequiredDate }
226
244
backgroundColor = { requestFormHeaderBg }
245
+ disabled = { disabled }
227
246
/>
228
247
</ div >
229
248
</ div >
230
249
< Button
231
250
addClass = 'btn btn-primary my-4 ms-auto d-block'
232
251
backgroundColor = { buttonBg }
233
- disabled = { buttonDisabled }
252
+ disabled = { buttonDisabled || disabled }
234
253
label = 'Initiate Request'
235
254
type = 'submit'
236
255
size = 'large'
@@ -241,16 +260,5 @@ const StandardRequestOptions = ({ buttonDisabled, defaultRequiredDate, requestFo
241
260
242
261
const pageLoading = < Loading wrapperClass = 'item-page mt-5' />
243
262
244
- const unauthorizedUser = (
245
- < Notice
246
- addClass = 'my-5'
247
- alert = { {
248
- body : [ 'Please log in to make new requests.' ] ,
249
- title : 'Unauthorized' ,
250
- variant : 'info'
251
- } }
252
- dismissible = { false }
253
- />
254
- )
255
263
256
264
export default NewRequest
0 commit comments