Skip to content

Commit 979b719

Browse files
authored
Merge pull request #359 from scientist-softserv/345-disable-request-form
Show disabled form for logged out users
2 parents b26d96d + 408f54b commit 979b719

File tree

3 files changed

+55
-44
lines changed

3 files changed

+55
-44
lines changed

pages/requests/new/[ware].js

Lines changed: 53 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ const NewRequest = ({ session }) => {
3131
const { ware } = useOneWare(wareID, accessToken)
3232
const { dynamicForm, isLoadingInitialRequest, isInitialRequestError } = useInitializeRequest(wareID, accessToken)
3333
const oneWeekFromNow = addDays((new Date()), 7).toISOString().slice(0, 10)
34+
const disabled = session === null ? true : false
3435
const initialFormData = { 'suppliers_identified': 'Yes' }
3536
const initialState = {
3637
billingSameAsShipping: false,
@@ -83,7 +84,6 @@ const NewRequest = ({ session }) => {
8384
* using a guard clause with an early return inside the api methods also violates the react-hooks/rules-of-hooks rule.
8485
*/
8586
if (session === undefined) return pageLoading
86-
if (session === null) return unauthorizedUser
8787

8888
/**
8989
* @param {object} event onChange event
@@ -172,52 +172,61 @@ const NewRequest = ({ session }) => {
172172
}
173173

174174
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
187208
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}
191213
>
214+
<BlankRequestForm updateRequestForm={updateRequestForm} />
192215
<StandardRequestOptions
193216
defaultRequiredDate={oneWeekFromNow}
194217
requestForm={requestForm}
195218
updateRequestForm={updateRequestForm}
196-
buttonDisabled={buttonDisabled}
219+
buttonDisabled={buttonDisabled || disabled}
220+
disabled={disabled}
197221
/>
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+
</>
217226
)
218227
}
219228

220-
const StandardRequestOptions = ({ buttonDisabled, defaultRequiredDate, requestForm, updateRequestForm, }) => {
229+
const StandardRequestOptions = ({ buttonDisabled, defaultRequiredDate, requestForm, updateRequestForm, disabled }) => {
221230
return (
222231
<>
223232
<div className='row'>
@@ -227,20 +236,22 @@ const StandardRequestOptions = ({ buttonDisabled, defaultRequiredDate, requestFo
227236
billingCountry={requestForm.billing.country}
228237
shippingCountry={requestForm.shipping.country}
229238
updateRequestForm={updateRequestForm}
239+
disabled={disabled}
230240
/>
231241
</div>
232242
<div className='col'>
233243
<AdditionalInfo
234244
updateRequestForm={updateRequestForm}
235245
defaultRequiredDate={defaultRequiredDate}
236246
backgroundColor={requestFormHeaderBg}
247+
disabled={disabled}
237248
/>
238249
</div>
239250
</div>
240251
<Button
241252
addClass='btn btn-primary my-4 ms-auto d-block'
242253
backgroundColor={buttonBg}
243-
disabled={buttonDisabled}
254+
disabled={buttonDisabled || disabled}
244255
label='Initiate Request'
245256
type='submit'
246257
size='large'
@@ -251,12 +262,12 @@ const StandardRequestOptions = ({ buttonDisabled, defaultRequiredDate, requestFo
251262

252263
const pageLoading = <Loading wrapperClass='item-page mt-5' />
253264

254-
const unauthorizedUser = (
265+
const SignInRequired = () => (
255266
<Notice
256-
addClass='my-5'
267+
addClass='mt-5'
257268
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',
260271
variant: 'info'
261272
}}
262273
dismissible={false}

utils/api/requests.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ export const useFiles = (id, accessToken) => {
119119
}
120120

121121
export const useInitializeRequest = (id, accessToken) => {
122-
const { data, error } = useSWR(accessToken ? [`/wares/${id}/quote_groups/new.json`, accessToken] : null)
122+
const { data, error } = useSWR(id ? [`/wares/${id}/quote_groups/new.json`, accessToken] : null)
123123
let dynamicForm = { name: data?.name }
124124
let dynamicFormInfo = data?.dynamic_forms[0]
125125

utils/theme/theme.module.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ $secondary: #936AAA;
55
$light: #F2F2F2;
66
$dark: #070818;
77
$success: #B0E298;
8-
$info: #FFFBA6;
8+
$info: #8eb3fc;
99
$warning: #E9DF00;
1010
$danger: #D20000;
1111
$black: #000000;

0 commit comments

Comments
 (0)