Skip to content

Commit

Permalink
- MVP of limiting submission boxes based on what an stt should be sub…
Browse files Browse the repository at this point in the history
…mitting
  • Loading branch information
elipe17 committed Nov 20, 2024
1 parent dcda51a commit f152968
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 10 deletions.
9 changes: 7 additions & 2 deletions tdrs-frontend/src/actions/reports.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,13 @@ export const SET_SELECTED_YEAR = 'SET_SELECTED_YEAR'
export const SET_SELECTED_QUARTER = 'SET_SELECTED_QUARTER'
export const SET_FILE_TYPE = 'SET_FILE_TYPE'

export const setStt = (stt) => (dispatch) => {
dispatch({ type: SET_SELECTED_STT, payload: { stt } })
export const setStt = (stt) => async (dispatch) => {
const URL = `${process.env.REACT_APP_BACKEND_URL}/stts/${stt}`
const { data } = await axiosInstance.get(URL, {
withCredentials: true,
})
const newUploadSections = Object.keys(data.filenames)
dispatch({ type: SET_SELECTED_STT, payload: { stt, newUploadSections } })
}
export const setYear = (year) => (dispatch) => {
dispatch({ type: SET_SELECTED_YEAR, payload: { year } })
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import React from 'react'
import PropTypes from 'prop-types'
import classNames from 'classnames'
import { useDispatch, useSelector } from 'react-redux'
import { fileUploadSections } from '../../reducers/reports'
import Paginator from '../Paginator'
import { getAvailableFileList } from '../../actions/reports'
import { useEffect } from 'react'
Expand Down Expand Up @@ -64,6 +62,9 @@ const SubmissionHistory = ({ filterValues }) => {
const dispatch = useDispatch()
const [hasFetchedFiles, setHasFetchedFiles] = useState(false)
const { files } = useSelector((state) => state.reports)
const fileUploadSections = useSelector(
(state) => state.reports.fileUploadSections
)

useEffect(() => {
if (!hasFetchedFiles) {
Expand Down
7 changes: 6 additions & 1 deletion tdrs-frontend/src/components/UploadReport/UploadReport.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import Button from '../Button'
import FileUpload from '../FileUpload'
import { submit } from '../../actions/reports'
import { useEventLogger } from '../../utils/eventLogger'
import { fileUploadSections } from '../../reducers/reports'

function UploadReport({ handleCancel, stt }) {
// The currently selected year from the reportingYears dropdown
Expand All @@ -20,6 +19,12 @@ function UploadReport({ handleCancel, stt }) {

// The set of uploaded files in our Redux state
const files = useSelector((state) => state.reports.submittedFiles)

// The set of sections the STT can report for
const fileUploadSections = useSelector(
(state) => state.reports.fileUploadSections
)

// The logged in user in our Redux state
const user = useSelector((state) => state.auth.user)

Expand Down
11 changes: 6 additions & 5 deletions tdrs-frontend/src/reducers/reports.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const getFile = (files, section) =>
.sort((a, b) => b.id - a.id)
.find((currentFile) => currentFile.section.includes(section))

export const fileUploadSections = [
export const defaultFileUploadSections = [
'Active Case Data',
'Closed Case Data',
'Aggregate Data',
Expand Down Expand Up @@ -73,7 +73,8 @@ export const serializeApiDataFile = (dataFile) => ({

const initialState = {
files: [],
submittedFiles: fileUploadSections.map((section) => ({
fileUploadSections: defaultFileUploadSections,
submittedFiles: defaultFileUploadSections.map((section) => ({
section,
fileName: null,
error: null,
Expand Down Expand Up @@ -116,7 +117,7 @@ const reports = (state = initialState, action) => {
...state,
isLoadingCurrentSubmission: false,
currentSubmissionError: null,
submittedFiles: fileUploadSections.map((section) => {
submittedFiles: state.fileUploadSections.map((section) => {
const file = getFile(data, section)
if (file) {
return serializeApiDataFile(file)
Expand Down Expand Up @@ -201,8 +202,8 @@ const reports = (state = initialState, action) => {
return { ...state, year }
}
case SET_SELECTED_STT: {
const { stt } = payload
return { ...state, stt }
const { stt, newUploadSections } = payload
return { ...state, stt, fileUploadSections: newUploadSections }
}
case SET_SELECTED_QUARTER: {
const { quarter } = payload
Expand Down

0 comments on commit f152968

Please sign in to comment.