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