11/* istanbul ignore file */
2- import React , { createContext , useContext , useState , useRef } from 'react'
2+ import { createContext , useContext , useState , useRef , useEffect } from 'react'
33import { useDispatch , useSelector } from 'react-redux'
44import {
55 clearFileList ,
66 reinitializeSubmittedFiles ,
77 setStt ,
88} from '../../actions/reports'
99import { openFeedbackWidget } from '../../reducers/feedbackWidget'
10+ import { useSearchParams } from 'react-router-dom'
1011import { accountCanSelectStt } from '../../selectors/auth'
1112
1213const ReportsContext = createContext ( )
@@ -23,18 +24,63 @@ export const ReportsProvider = ({ isFra = false, children }) => {
2324 const dispatch = useDispatch ( )
2425 const canSelectStt = useSelector ( accountCanSelectStt )
2526
27+ // Search params
28+ const [ searchParams , setSearchParams ] = useSearchParams ( )
29+
2630 // Form state
27- const [ yearInputValue , setYearInputValue ] = useState ( '' )
28- const [ quarterInputValue , setQuarterInputValue ] = useState ( '' )
31+ const [ yearInputValue , setYearInputValue ] = useState (
32+ searchParams . get ( 'fy' ) || ''
33+ )
34+ const [ quarterInputValue , setQuarterInputValue ] = useState (
35+ searchParams . get ( 'q' ) || ''
36+ )
2937 const [ fileTypeInputValue , setFileTypeInputValue ] = useState (
30- isFra ? 'workOutcomesOfTanfExiters' : 'tanf'
38+ searchParams . get ( 'type' )
39+ ? searchParams . get ( 'type' )
40+ : isFra
41+ ? 'workOutcomesOfTanfExiters'
42+ : 'tanf'
43+ )
44+ const [ sttInputValue , setSttInputValue ] = useState (
45+ searchParams . get ( 'stt' ) || ''
46+ )
47+
48+ const [ selectedSubmissionTab , setSelectedSubmissionTab ] = useState (
49+ parseInt ( searchParams . get ( 'tab' ) ) || 1
3150 )
32- const [ sttInputValue , setSttInputValue ] = useState ( '' )
51+
3352 const [ pendingChange , setPendingChange ] = useState ( {
3453 type : null ,
3554 value : null ,
3655 } )
3756
57+ useEffect ( ( ) => {
58+ const newParams = new URLSearchParams ( )
59+ if ( yearInputValue ) {
60+ newParams . set ( 'fy' , yearInputValue )
61+ }
62+ if ( quarterInputValue ) {
63+ newParams . set ( 'q' , quarterInputValue )
64+ }
65+ if ( fileTypeInputValue ) {
66+ newParams . set ( 'type' , fileTypeInputValue )
67+ }
68+ if ( sttInputValue ) {
69+ newParams . set ( 'stt' , sttInputValue )
70+ }
71+ if ( selectedSubmissionTab ) {
72+ newParams . set ( 'tab' , selectedSubmissionTab )
73+ }
74+ setSearchParams ( newParams )
75+ } , [
76+ yearInputValue ,
77+ quarterInputValue ,
78+ fileTypeInputValue ,
79+ sttInputValue ,
80+ selectedSubmissionTab ,
81+ setSearchParams ,
82+ ] )
83+
3884 // Touched state for validation
3985 const [ yearTouched , setYearTouched ] = useState ( false )
4086 const [ quarterTouched , setQuarterTouched ] = useState ( false )
@@ -58,9 +104,6 @@ export const ReportsProvider = ({ isFra = false, children }) => {
58104 message : null ,
59105 } )
60106
61- // Tab state
62- const [ selectedSubmissionTab , setSelectedSubmissionTab ] = useState ( 1 )
63-
64107 // Refs
65108 const headerRef = useRef ( null )
66109 const alertRef = useRef ( null )
0 commit comments