Skip to content

Commit 3f455b6

Browse files
authored
Merge pull request #3657 from Northeastern-Electric-Racing/#3209-SABO-number-limit
#3209 sabo number limit
2 parents a048d4a + 7e01601 commit 3f455b6

4 files changed

Lines changed: 29 additions & 8 deletions

File tree

src/frontend/src/pages/FinancePage/FinanceComponents/ReimbursementRequestInfo.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,14 @@ import { Link as RouterLink, useLocation } from 'react-router-dom';
1414
import { useState } from 'react';
1515
import { isGuest, ReimbursementRequest } from 'shared';
1616
import { ReimbursementRequestRow, ReimbursementStatusType } from 'shared/src/types/reimbursement-requests-types';
17-
import { undefinedPipe, fullNamePipe, centsToDollar, datePipe, dateUndefinedPipe } from '../../../utils/pipes';
17+
import {
18+
undefinedPipe,
19+
fullNamePipe,
20+
centsToDollar,
21+
datePipe,
22+
dateUndefinedPipe,
23+
formatSaboIdPipe
24+
} from '../../../utils/pipes';
1825
import {
1926
createReimbursementRequestRowData,
2027
vendorDescendingComparator,
@@ -291,7 +298,7 @@ const ReimbursementRequestInfo = ({
291298
{currentTab !== 0 && <TableCell align="center">{fullNamePipe(row.submitter)}</TableCell>}
292299
<TableCell align="center">{`$${centsToDollar(row.amount)}`}</TableCell>
293300
<TableCell align="center">{undefinedPipe(row.identifier)}</TableCell>
294-
<TableCell align="center">{undefinedPipe(row.saboId)}</TableCell>
301+
<TableCell align="center">{formatSaboIdPipe(row.saboId)}</TableCell>
295302
<TableCell align="center">{datePipe(row.dateSubmitted)}</TableCell>
296303
<TableCell align="center">{dateUndefinedPipe(row.dateSubmittedToSabo)}</TableCell>
297304
{currentTab === 1 && <TableCell align="center">{fullNamePipe(row.financeMemberAssigned)}</TableCell>}

src/frontend/src/pages/FinancePage/ReimbursementRequestDetailPage/AddSABONumberModal.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,15 @@ import ReactHookTextField from '../../../components/ReactHookTextField';
77
import { useSetSaboNumber } from '../../../hooks/finance.hooks';
88
import { useToast } from '../../../hooks/toasts.hooks';
99

10-
const schema = yup.object().shape({
10+
const schema = yup.object({
1111
saboNumber: yup
1212
.number()
1313
.typeError('The SABO number should be a valid number')
14-
.required()
15-
.test('length', 'The SABO number must be at least 5 digits', (num) => String(num).length >= 5)
14+
.required('The SABO number is required')
15+
.test('exact-5-digits', 'The SABO number must be exactly 5 digits', function () {
16+
const original = this.originalValue?.toString().trim();
17+
return /^\d{5}$/.test(original || '');
18+
})
1619
});
1720

1821
interface AddSABONumberModalProps {

src/frontend/src/pages/FinancePage/ReimbursementRequestDetailPage/ReimbursementRequestDetailsView.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* See the LICENSE file in the repository root folder for details.
44
*/
55

6-
import { accountCodePipe, displayEnum } from '../../../utils/pipes';
6+
import { accountCodePipe, displayEnum, formatSaboIdPipe } from '../../../utils/pipes';
77
import { Assignment, ChangeCircle, Edit, Pending } from '@mui/icons-material';
88
import CheckIcon from '@mui/icons-material/Check';
99
import CloseIcon from '@mui/icons-material/Close';
@@ -40,7 +40,7 @@ import {
4040
} from '../../../hooks/finance.hooks';
4141
import { useToast } from '../../../hooks/toasts.hooks';
4242
import { useCurrentUser } from '../../../hooks/users.hooks';
43-
import { centsToDollar, fullNamePipe, undefinedPipe } from '../../../utils/pipes';
43+
import { centsToDollar, fullNamePipe } from '../../../utils/pipes';
4444
import {
4545
imageDownloadUrl,
4646
imageFileUrl,
@@ -479,7 +479,7 @@ const ReimbursementRequestDetailsView: React.FC<ReimbursementRequestDetailsViewP
479479
},
480480
{ content: `$${centsToDollar(reimbursementRequest.totalCost)}` },
481481
{ content: reimbursementRequest.vendor.name },
482-
{ content: `${undefinedPipe(reimbursementRequest.saboId)}` },
482+
{ content: `${formatSaboIdPipe(reimbursementRequest.saboId)}` },
483483
{
484484
content: refundSourceNames.join(', ')
485485
},

src/frontend/src/utils/pipes.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,3 +209,14 @@ export const labelPipe = (label: string) => {
209209

210210
return result;
211211
};
212+
213+
// Pad SABO ID with leading zeroes
214+
export const formatSaboIdPipe = (saboId: number | undefined): string => {
215+
if (saboId === undefined || saboId === null) return undefinedPipe(saboId as any);
216+
const str = String(saboId);
217+
// Only pad if it's shorter than 5
218+
if (str.length < 5) {
219+
return str.padStart(5, '0');
220+
}
221+
return str;
222+
};

0 commit comments

Comments
 (0)