Skip to content

Commit d2d396b

Browse files
committed
- removed unnecessary conditionals
- updated validation so that 2024 is the only valid fy for pia
1 parent 9990022 commit d2d396b

File tree

1 file changed

+31
-38
lines changed

1 file changed

+31
-38
lines changed

tdrs-frontend/src/components/Reports/ReportsContext.jsx

Lines changed: 31 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -71,57 +71,49 @@ const validateUrlParams = (searchParams, isFra, sttList) => {
7171
let hasInvalidParam = false
7272

7373
// Validate fiscal year (must be a valid year between 2021 and current fiscal year)
74-
if (fiscalYear) {
75-
const year = parseInt(fiscalYear, 10)
76-
const currentFiscalYear = getCurrentFiscalYear()
77-
const minYear = 2021
78-
if (!isNaN(year) && year >= minYear && year <= currentFiscalYear) {
79-
validatedFy = fiscalYear
80-
} else {
81-
hasInvalidParam = true
82-
}
74+
// For program-integrity-audit, only 2024 is allowed
75+
const year = parseInt(fiscalYear, 10)
76+
const currentFiscalYear = getCurrentFiscalYear()
77+
const minYear = type === 'program-integrity-audit' ? 2024 : 2021
78+
const maxYear = type === 'program-integrity-audit' ? 2024 : currentFiscalYear
79+
if (!isNaN(year) && year >= minYear && year <= maxYear) {
80+
validatedFy = fiscalYear
81+
} else {
82+
hasInvalidParam = true
8383
}
8484

8585
// Validate quarter (must be Q1, Q2, Q3, or Q4)
86-
if (quarter) {
87-
if (VALID_QUARTERS.includes(quarter)) {
88-
validatedQ = quarter
89-
} else {
90-
hasInvalidParam = true
91-
}
86+
if (VALID_QUARTERS.includes(quarter)) {
87+
validatedQ = quarter
88+
} else {
89+
hasInvalidParam = true
9290
}
9391

9492
// Validate file type
95-
if (type) {
96-
const validTypes = isFra ? VALID_FILE_TYPES.fra : VALID_FILE_TYPES.reports
97-
if (validTypes.includes(type)) {
98-
validatedType = type
99-
} else {
100-
hasInvalidParam = true
101-
}
93+
const validTypes = isFra ? VALID_FILE_TYPES.fra : VALID_FILE_TYPES.reports
94+
if (validTypes.includes(type)) {
95+
validatedType = type
96+
} else {
97+
hasInvalidParam = true
10298
}
10399

104100
// Validate STT (must exist in the STT list if provided)
105-
if (stt) {
106-
if (sttList && sttList.length > 0) {
107-
if (sttList.some((s) => s?.name === stt)) {
108-
validatedStt = stt
109-
} else {
110-
hasInvalidParam = true
111-
}
112-
} else {
113-
// STT list not loaded yet, keep the value for now
101+
if (sttList && sttList.length > 0) {
102+
if (sttList.some((s) => s?.name === stt)) {
114103
validatedStt = stt
104+
} else {
105+
hasInvalidParam = true
115106
}
107+
} else {
108+
// STT list not loaded yet, keep the value for now
109+
validatedStt = stt
116110
}
117111

118112
// Validate tab (must be 1 or 2)
119-
if (tab) {
120-
if (tab === '1' || tab === '2') {
121-
validatedTab = parseInt(tab, 10)
122-
} else {
123-
hasInvalidParam = true
124-
}
113+
if (tab === '1' || tab === '2') {
114+
validatedTab = parseInt(tab, 10)
115+
} else {
116+
hasInvalidParam = true
125117
}
126118

127119
return {
@@ -143,7 +135,8 @@ export const ReportsProvider = ({ isFra = false, children }) => {
143135
const [searchParams, setSearchParams] = useSearchParams()
144136
const [hasValidatedParams, setHasValidatedParams] = useState(false)
145137

146-
// Get validated params (without STT validation since list may not be loaded)
138+
// Get validated params (without STT validation since it will never be loaded since we have to wait for fetchSTTs to
139+
// run.
147140
const validatedParams = useMemo(
148141
() => validateUrlParams(searchParams, isFra, []),
149142
[searchParams, isFra]

0 commit comments

Comments
 (0)