Skip to content

Commit fe470b2

Browse files
committed
#1310: Disables button if secure settings not set
1 parent fcb05cc commit fe470b2

2 files changed

Lines changed: 21 additions & 3 deletions

File tree

src/frontend/src/pages/FinancePage/ReimbursementRequestForm/ReimbursementFormView.tsx

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
FormLabel,
66
Grid,
77
IconButton,
8+
Link,
89
MenuItem,
910
Select,
1011
TextField,
@@ -27,9 +28,11 @@ import ReimbursementProductTable from './ReimbursementProductTable';
2728
import NERFailButton from '../../../components/NERFailButton';
2829
import NERSuccessButton from '../../../components/NERSuccessButton';
2930
import { ReimbursementRequestFormInput } from './ReimbursementRequestForm';
30-
import { useState } from 'react';
31+
import { useState, useEffect } from 'react';
3132
import { useToast } from '../../../hooks/toasts.hooks';
3233
import { expenseTypePipe } from '../../../utils/pipes';
34+
import { Link as RouterLink } from 'react-router-dom';
35+
import { routes } from '../../../utils/routes';
3336

3437
interface ReimbursementRequestFormViewProps {
3538
allVendors: Vendor[];
@@ -52,6 +55,7 @@ interface ReimbursementRequestFormViewProps {
5255
submitText: string;
5356
previousPage: string;
5457
setValue: UseFormSetValue<ReimbursementRequestFormInput>;
58+
hasSecureSettingsSet: boolean;
5559
}
5660

5761
const ReimbursementRequestFormView: React.FC<ReimbursementRequestFormViewProps> = ({
@@ -71,13 +75,21 @@ const ReimbursementRequestFormView: React.FC<ReimbursementRequestFormViewProps>
7175
watch,
7276
submitText,
7377
previousPage,
74-
setValue
78+
setValue,
79+
hasSecureSettingsSet
7580
}) => {
7681
const [datePickerOpen, setDatePickerOpen] = useState(false);
7782
const toast = useToast();
7883
const products = watch(`reimbursementProducts`);
7984
const calculatedTotalCost = products.reduce((acc, product) => acc + Number(product.cost), 0).toFixed(2);
8085

86+
useEffect(() => {
87+
if (!hasSecureSettingsSet) {
88+
//<Link component={RouterLink} to={routes.SETTINGS}> </Link>
89+
toast.warning('Your secure settings must be set to create a reimbursement request, you can set them here.', Infinity);
90+
}
91+
}, []);
92+
8193
const wbsElementAutocompleteOptions = allWbsElements.map((wbsElement) => ({
8294
label: wbsPipe(wbsElement.wbsNum) + ' - ' + wbsElement.wbsName,
8395
id: wbsPipe(wbsElement.wbsNum)
@@ -257,7 +269,7 @@ const ReimbursementRequestFormView: React.FC<ReimbursementRequestFormViewProps>
257269
<NERFailButton variant="contained" href={previousPage} sx={{ mx: 1 }}>
258270
Cancel
259271
</NERFailButton>
260-
<NERSuccessButton variant="contained" type="submit">
272+
<NERSuccessButton variant="contained" type="submit" disabled={!hasSecureSettingsSet}>
261273
{submitText}
262274
</NERSuccessButton>
263275
</Box>

src/frontend/src/pages/FinancePage/ReimbursementRequestForm/ReimbursementRequestForm.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { useAllProjects } from '../../../hooks/projects.hooks';
1515
import { useHistory } from 'react-router-dom';
1616
import { routes } from '../../../utils/routes';
1717
import { getAllWbsElements } from '../../../utils/reimbursement-request.utils';
18+
import { useCurrentUserSecureSettings } from '../../../hooks/users.hooks';
1819

1920
export interface ReimbursementRequestFormInput {
2021
vendorId: string;
@@ -120,6 +121,10 @@ const ReimbursementRequestForm: React.FC<ReimbursementRequestFormProps> = ({
120121
data: allProjects
121122
} = useAllProjects();
122123

124+
const { data } = useCurrentUserSecureSettings();
125+
const userSecureSettings = data ?? {};
126+
const hasSecureSettingsSet = Object.values(userSecureSettings).every((x) => x !== '') ? true : false;
127+
123128
const toast = useToast();
124129
const history = useHistory();
125130

@@ -181,6 +186,7 @@ const ReimbursementRequestForm: React.FC<ReimbursementRequestFormProps> = ({
181186
submitText={submitText}
182187
previousPage={previousPage}
183188
setValue={setValue}
189+
hasSecureSettingsSet={hasSecureSettingsSet}
184190
/>
185191
);
186192
};

0 commit comments

Comments
 (0)