diff --git a/frontend/src/employee-frontend/components/fee-decisions/FeeDecisionFilters.tsx b/frontend/src/employee-frontend/components/fee-decisions/FeeDecisionFilters.tsx index 9d64e04102..0061154636 100755 --- a/frontend/src/employee-frontend/components/fee-decisions/FeeDecisionFilters.tsx +++ b/frontend/src/employee-frontend/components/fee-decisions/FeeDecisionFilters.tsx @@ -1,14 +1,8 @@ -// SPDX-FileCopyrightText: 2017-2024 City of Espoo +// SPDX-FileCopyrightText: 2017-2022 City of Espoo // // SPDX-License-Identifier: LGPL-2.1-or-later -import React, { - Fragment, - useCallback, - useContext, - useEffect, - useState -} from 'react' +import React, { Fragment, useContext, useEffect } from 'react' import { useMemo } from 'react' import { wrapResult } from 'lib-common/api' @@ -24,10 +18,7 @@ import { Gap } from 'lib-components/white-space' import { getUnits } from '../../generated/api-clients/daycare' import { getFinanceDecisionHandlers } from '../../generated/api-clients/pis' import { useTranslation } from '../../state/i18n' -import { - FeeDecisionSearchFilters, - InvoicingUiContext -} from '../../state/invoicing-ui' +import { InvoicingUiContext } from '../../state/invoicing-ui' import { AreaFilter, FeeDecisionDifferenceFilter, @@ -42,23 +33,14 @@ import { const getUnitsResult = wrapResult(getUnits) const getFinanceDecisionHandlersResult = wrapResult(getFinanceDecisionHandlers) -const emptyFilters: FeeDecisionSearchFilters = { - searchTerms: '', - distinctiveDetails: [], - statuses: ['DRAFT'], - area: [], - startDate: undefined, - endDate: LocalDate.todayInSystemTz(), - searchByStartDate: false, - financeDecisionHandlerId: undefined, - difference: [] -} - function FeeDecisionFilters() { - const { i18n } = useTranslation() - const { - feeDecisions: { setConfirmedSearchFilters }, + feeDecisions: { + searchFilters, + setSearchFilters, + confirmSearchFilters, + clearSearchFilters + }, shared: { units, setUnits, @@ -68,23 +50,7 @@ function FeeDecisionFilters() { } } = useContext(InvoicingUiContext) - const [searchFilters, _setSearchFilters] = - useState(emptyFilters) - const setSearchFilters = useCallback( - (value: React.SetStateAction) => { - _setSearchFilters(value) - setConfirmedSearchFilters(undefined) - }, - [setConfirmedSearchFilters] - ) - const clearSearchFilters = useCallback(() => { - _setSearchFilters(emptyFilters) - setConfirmedSearchFilters(undefined) - }, [setConfirmedSearchFilters]) - const confirmSearchFilters = useCallback( - () => setConfirmedSearchFilters(searchFilters), - [searchFilters, setConfirmedSearchFilters] - ) + const { i18n } = useTranslation() useEffect(() => { void getUnitsResult({ areaIds: null, type: 'DAYCARE', from: null }).then( diff --git a/frontend/src/employee-frontend/components/income-statements/IncomeStatementFilters.tsx b/frontend/src/employee-frontend/components/income-statements/IncomeStatementFilters.tsx index fad58608f8..029d8acb62 100644 --- a/frontend/src/employee-frontend/components/income-statements/IncomeStatementFilters.tsx +++ b/frontend/src/employee-frontend/components/income-statements/IncomeStatementFilters.tsx @@ -1,8 +1,8 @@ -// SPDX-FileCopyrightText: 2017-2024 City of Espoo +// SPDX-FileCopyrightText: 2017-2022 City of Espoo // // SPDX-License-Identifier: LGPL-2.1-or-later -import React, { Fragment, useCallback, useContext, useState } from 'react' +import React, { Fragment, useCallback, useContext } from 'react' import { ProviderType } from 'lib-common/generated/api-types/daycare' import { DaycareId } from 'lib-common/generated/api-types/shared' @@ -13,10 +13,7 @@ import { Label } from 'lib-components/typography' import { Gap } from 'lib-components/white-space' import { useTranslation } from '../../state/i18n' -import { - IncomeStatementSearchFilters, - InvoicingUiContext -} from '../../state/invoicing-ui' +import { InvoicingUiContext } from '../../state/invoicing-ui' import { renderResult } from '../async-rendering' import { AreaFilter, @@ -27,45 +24,23 @@ import { } from '../common/Filters' import { unitFilterQuery } from '../unit/queries' -const emptyFilters: IncomeStatementSearchFilters = { - area: [], - unit: undefined, - providerTypes: [], - sentStartDate: undefined, - sentEndDate: undefined, - placementValidDate: undefined -} - export default React.memo(function IncomeStatementsFilters() { - const { i18n } = useTranslation() - const { - incomeStatements: { setConfirmedSearchFilters }, + incomeStatements: { + searchFilters, + setSearchFilters, + clearSearchFilters, + confirmSearchFilters + }, shared: { availableAreas } } = useContext(InvoicingUiContext) - const [searchFilters, _setSearchFilters] = - useState(emptyFilters) - const setSearchFilters = useCallback( - (value: React.SetStateAction) => { - _setSearchFilters(value) - setConfirmedSearchFilters(undefined) - }, - [setConfirmedSearchFilters] - ) - const clearSearchFilters = useCallback(() => { - _setSearchFilters(emptyFilters) - setConfirmedSearchFilters(undefined) - }, [setConfirmedSearchFilters]) - const confirmSearchFilters = useCallback( - () => setConfirmedSearchFilters(searchFilters), - [searchFilters, setConfirmedSearchFilters] - ) - const unitsResult = useQueryResult( unitFilterQuery({ areaIds: null, type: 'DAYCARE', from: null }) ) + const { i18n } = useTranslation() + const toggleArea = useCallback( (code: string) => () => { setSearchFilters((old) => diff --git a/frontend/src/employee-frontend/components/invoices/InvoiceFilters.tsx b/frontend/src/employee-frontend/components/invoices/InvoiceFilters.tsx index 5eb0f3994f..c6bbb273d9 100644 --- a/frontend/src/employee-frontend/components/invoices/InvoiceFilters.tsx +++ b/frontend/src/employee-frontend/components/invoices/InvoiceFilters.tsx @@ -1,14 +1,8 @@ -// SPDX-FileCopyrightText: 2017-2024 City of Espoo +// SPDX-FileCopyrightText: 2017-2022 City of Espoo // // SPDX-License-Identifier: LGPL-2.1-or-later -import React, { - Fragment, - useCallback, - useContext, - useEffect, - useState -} from 'react' +import React, { Fragment, useCallback, useContext, useEffect } from 'react' import { wrapResult } from 'lib-common/api' import { @@ -21,10 +15,7 @@ import { Gap } from 'lib-components/white-space' import { getUnits } from '../../generated/api-clients/daycare' import { useTranslation } from '../../state/i18n' -import { - InvoiceSearchFilters, - InvoicingUiContext -} from '../../state/invoicing-ui' +import { InvoicingUiContext } from '../../state/invoicing-ui' import { AreaFilter, Filters, @@ -36,41 +27,18 @@ import { const getUnitsResult = wrapResult(getUnits) -const emptyFilters: InvoiceSearchFilters = { - searchTerms: '', - distinctiveDetails: [], - area: [], - status: 'DRAFT', - startDate: undefined, - endDate: undefined, - useCustomDatesForInvoiceSending: false -} - export default React.memo(function InvoiceFilters() { - const { i18n } = useTranslation() - const { - invoices: { setConfirmedSearchFilters }, + invoices: { + searchFilters, + setSearchFilters, + confirmSearchFilters, + clearSearchFilters + }, shared: { units, setUnits, availableAreas } } = useContext(InvoicingUiContext) - const [searchFilters, _setSearchFilters] = - useState(emptyFilters) - const setSearchFilters = useCallback( - (value: React.SetStateAction) => { - _setSearchFilters(value) - setConfirmedSearchFilters(undefined) - }, - [setConfirmedSearchFilters] - ) - const clearSearchFilters = useCallback(() => { - _setSearchFilters(emptyFilters) - setConfirmedSearchFilters(undefined) - }, [setConfirmedSearchFilters]) - const confirmSearchFilters = useCallback( - () => setConfirmedSearchFilters(searchFilters), - [searchFilters, setConfirmedSearchFilters] - ) + const { i18n } = useTranslation() useEffect(() => { void getUnitsResult({ areaIds: null, type: 'DAYCARE', from: null }).then( diff --git a/frontend/src/employee-frontend/components/invoices/InvoicesPage.tsx b/frontend/src/employee-frontend/components/invoices/InvoicesPage.tsx index 4102aa6572..06331c72b5 100755 --- a/frontend/src/employee-frontend/components/invoices/InvoicesPage.tsx +++ b/frontend/src/employee-frontend/components/invoices/InvoicesPage.tsx @@ -29,10 +29,7 @@ import { Label } from 'lib-components/typography' import { Gap } from 'lib-components/white-space' import { useTranslation } from '../../state/i18n' -import { - InvoiceSearchFilters, - InvoicingUiContext -} from '../../state/invoicing-ui' +import { InvoicingUiContext } from '../../state/invoicing-ui' import { renderResult } from '../async-rendering' import Actions from './Actions' @@ -157,9 +154,8 @@ export default React.memo(function InvoicesPage() { /> ))} - {showModal && searchFilters ? ( + {showModal ? ( { closeModal() @@ -174,19 +170,21 @@ export default React.memo(function InvoicesPage() { }) const Modal = React.memo(function Modal({ - searchFilters, onClose, onSendDone, checkedInvoices, fullAreaSelection }: { - searchFilters: InvoiceSearchFilters onClose: () => void onSendDone: () => void checkedInvoices: Set fullAreaSelection: boolean }) { const { i18n } = useTranslation() + const { + invoices: { searchFilters } + } = useContext(InvoicingUiContext) + const [invoiceDate, setInvoiceDate] = useState(LocalDate.todayInSystemTz()) const [dueDate, setDueDate] = useState( LocalDate.todayInSystemTz().addBusinessDays(10) diff --git a/frontend/src/employee-frontend/components/payments/PaymentFilters.tsx b/frontend/src/employee-frontend/components/payments/PaymentFilters.tsx index 64cab43a53..4aec6169df 100644 --- a/frontend/src/employee-frontend/components/payments/PaymentFilters.tsx +++ b/frontend/src/employee-frontend/components/payments/PaymentFilters.tsx @@ -1,15 +1,9 @@ -// SPDX-FileCopyrightText: 2017-2024 City of Espoo +// SPDX-FileCopyrightText: 2017-2022 City of Espoo // // SPDX-License-Identifier: LGPL-2.1-or-later import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' -import React, { - Fragment, - useCallback, - useContext, - useEffect, - useState -} from 'react' +import React, { Fragment, useCallback, useContext, useEffect } from 'react' import { wrapResult } from 'lib-common/api' import { @@ -29,50 +23,24 @@ import { fasExclamationTriangle } from 'lib-icons' import { getUnits } from '../../generated/api-clients/daycare' import { useTranslation } from '../../state/i18n' -import { - InvoicingUiContext, - PaymentSearchFilters -} from '../../state/invoicing-ui' +import { InvoicingUiContext } from '../../state/invoicing-ui' import { AreaFilter, Filters, UnitFilter } from '../common/Filters' import { FlexRow } from '../common/styled/containers' const getUnitsResult = wrapResult(getUnits) -const emptyFilters: PaymentSearchFilters = { - searchTerms: '', - area: [], - unit: null, - distinctions: [], - status: 'DRAFT', - paymentDateStart: null, - paymentDateEnd: null -} - export default React.memo(function PaymentFilters() { - const { i18n } = useTranslation() - const { - payments: { setConfirmedSearchFilters }, + payments: { + searchFilters, + setSearchFilters, + confirmSearchFilters, + clearSearchFilters + }, shared: { units, setUnits, availableAreas } } = useContext(InvoicingUiContext) - const [searchFilters, _setSearchFilters] = - useState(emptyFilters) - const setSearchFilters = useCallback( - (value: React.SetStateAction) => { - _setSearchFilters(value) - setConfirmedSearchFilters(undefined) - }, - [setConfirmedSearchFilters] - ) - const clearSearchFilters = useCallback(() => { - _setSearchFilters(emptyFilters) - setConfirmedSearchFilters(undefined) - }, [setConfirmedSearchFilters]) - const confirmSearchFilters = useCallback( - () => setConfirmedSearchFilters(searchFilters), - [searchFilters, setConfirmedSearchFilters] - ) + const { i18n } = useTranslation() useEffect(() => { void getUnitsResult({ areaIds: null, type: 'DAYCARE', from: null }).then( diff --git a/frontend/src/employee-frontend/components/voucher-value-decisions/VoucherValueDecisionFilters.tsx b/frontend/src/employee-frontend/components/voucher-value-decisions/VoucherValueDecisionFilters.tsx index b2fe0f65d3..24cd6a3d42 100755 --- a/frontend/src/employee-frontend/components/voucher-value-decisions/VoucherValueDecisionFilters.tsx +++ b/frontend/src/employee-frontend/components/voucher-value-decisions/VoucherValueDecisionFilters.tsx @@ -1,14 +1,8 @@ -// SPDX-FileCopyrightText: 2017-2024 City of Espoo +// SPDX-FileCopyrightText: 2017-2022 City of Espoo // // SPDX-License-Identifier: LGPL-2.1-or-later -import React, { - Fragment, - useCallback, - useContext, - useEffect, - useState -} from 'react' +import React, { Fragment, useCallback, useContext, useEffect } from 'react' import { useMemo } from 'react' import { wrapResult } from 'lib-common/api' @@ -24,10 +18,7 @@ import { Gap } from 'lib-components/white-space' import { getUnits } from '../../generated/api-clients/daycare' import { getFinanceDecisionHandlers } from '../../generated/api-clients/pis' import { useTranslation } from '../../state/i18n' -import { - InvoicingUiContext, - ValueDecisionSearchFilters -} from '../../state/invoicing-ui' +import { InvoicingUiContext } from '../../state/invoicing-ui' import { AreaFilter, Filters, @@ -42,22 +33,14 @@ import { const getUnitsResult = wrapResult(getUnits) const getFinanceDecisionHandlersResult = wrapResult(getFinanceDecisionHandlers) -const emptyFilters: ValueDecisionSearchFilters = { - searchTerms: '', - distinctiveDetails: [], - statuses: ['DRAFT'], - area: [], - difference: [], - startDate: undefined, - endDate: LocalDate.todayInSystemTz(), - searchByStartDate: false -} - export default React.memo(function VoucherValueDecisionFilters() { - const { i18n } = useTranslation() - const { - valueDecisions: { setConfirmedSearchFilters }, + valueDecisions: { + searchFilters, + setSearchFilters, + confirmSearchFilters, + clearSearchFilters + }, shared: { units, setUnits, @@ -67,23 +50,7 @@ export default React.memo(function VoucherValueDecisionFilters() { } } = useContext(InvoicingUiContext) - const [searchFilters, _setSearchFilters] = - useState(emptyFilters) - const setSearchFilters = useCallback( - (value: React.SetStateAction) => { - _setSearchFilters(value) - setConfirmedSearchFilters(undefined) - }, - [setConfirmedSearchFilters] - ) - const clearSearchFilters = useCallback(() => { - _setSearchFilters(emptyFilters) - setConfirmedSearchFilters(undefined) - }, [setConfirmedSearchFilters]) - const confirmSearchFilters = useCallback( - () => setConfirmedSearchFilters(searchFilters), - [searchFilters, setConfirmedSearchFilters] - ) + const { i18n } = useTranslation() useEffect(() => { void getFinanceDecisionHandlersResult().then(setFinanceDecisionHandlers) diff --git a/frontend/src/employee-frontend/state/invoicing-ui.tsx b/frontend/src/employee-frontend/state/invoicing-ui.tsx index 67229e4f30..54489cdf29 100644 --- a/frontend/src/employee-frontend/state/invoicing-ui.tsx +++ b/frontend/src/employee-frontend/state/invoicing-ui.tsx @@ -39,7 +39,7 @@ import { areaQuery } from '../components/unit/queries' import { UserContext } from './user' -export interface FeeDecisionSearchFilters { +interface FeeDecisionSearchFilters { searchTerms: string area: string[] unit?: DaycareId @@ -55,13 +55,14 @@ export interface FeeDecisionSearchFilters { interface FeeDecisionSearchFilterState { page: number setPage: (p: number) => void + searchFilters: FeeDecisionSearchFilters + setSearchFilters: Dispatch> confirmedSearchFilters: FeeDecisionSearchFilters | undefined - setConfirmedSearchFilters: ( - filters: FeeDecisionSearchFilters | undefined - ) => void + confirmSearchFilters: () => void + clearSearchFilters: () => void } -export interface ValueDecisionSearchFilters { +interface ValueDecisionSearchFilters { searchTerms: string area: string[] unit?: DaycareId @@ -77,10 +78,11 @@ export interface ValueDecisionSearchFilters { interface ValueDecisionSearchFilterState { page: number setPage: (p: number) => void + searchFilters: ValueDecisionSearchFilters + setSearchFilters: Dispatch> confirmedSearchFilters: ValueDecisionSearchFilters | undefined - setConfirmedSearchFilters: ( - filters: ValueDecisionSearchFilters | undefined - ) => void + confirmSearchFilters: () => void + clearSearchFilters: () => void } export interface InvoiceSearchFilters { @@ -97,8 +99,11 @@ export interface InvoiceSearchFilters { interface InvoiceSearchFilterState { page: number setPage: (p: number) => void + searchFilters: InvoiceSearchFilters + setSearchFilters: Dispatch> confirmedSearchFilters: InvoiceSearchFilters | undefined - setConfirmedSearchFilters: (filters: InvoiceSearchFilters | undefined) => void + confirmSearchFilters: () => void + clearSearchFilters: () => void } export interface PaymentSearchFilters { @@ -114,8 +119,11 @@ export interface PaymentSearchFilters { interface PaymentSearchFilterState { page: number setPage: (p: number) => void + searchFilters: PaymentSearchFilters + setSearchFilters: Dispatch> confirmedSearchFilters: PaymentSearchFilters | undefined - setConfirmedSearchFilters: (filters: PaymentSearchFilters | undefined) => void + confirmSearchFilters: () => void + clearSearchFilters: () => void } export interface IncomeStatementSearchFilters { @@ -130,10 +138,11 @@ export interface IncomeStatementSearchFilters { interface IncomeStatementSearchFilterState { page: number setPage: (p: number) => void + searchFilters: IncomeStatementSearchFilters + setSearchFilters: Dispatch> confirmedSearchFilters: IncomeStatementSearchFilters | undefined - setConfirmedSearchFilters: ( - filters: IncomeStatementSearchFilters | undefined - ) => void + confirmSearchFilters: () => void + clearSearchFilters: () => void } export interface FinanceDecisionHandlerOption { @@ -162,32 +171,89 @@ const defaultState: UiState = { feeDecisions: { page: 1, setPage: () => undefined, + searchFilters: { + searchTerms: '', + distinctiveDetails: [], + statuses: ['DRAFT'], + area: [], + startDate: undefined, + endDate: LocalDate.todayInSystemTz(), + searchByStartDate: false, + financeDecisionHandlerId: undefined, + difference: [] + }, + setSearchFilters: () => undefined, confirmedSearchFilters: undefined, - setConfirmedSearchFilters: () => undefined + confirmSearchFilters: () => undefined, + clearSearchFilters: () => undefined }, valueDecisions: { page: 1, setPage: () => undefined, + searchFilters: { + searchTerms: '', + distinctiveDetails: [], + statuses: ['DRAFT'], + area: [], + difference: [], + startDate: undefined, + endDate: LocalDate.todayInSystemTz(), + searchByStartDate: false + }, + setSearchFilters: () => undefined, confirmedSearchFilters: undefined, - setConfirmedSearchFilters: () => undefined + confirmSearchFilters: () => undefined, + clearSearchFilters: () => undefined }, invoices: { page: 1, setPage: () => undefined, + searchFilters: { + searchTerms: '', + distinctiveDetails: [], + area: [], + status: 'DRAFT', + startDate: undefined, + endDate: undefined, + useCustomDatesForInvoiceSending: false + }, + setSearchFilters: () => undefined, confirmedSearchFilters: undefined, - setConfirmedSearchFilters: () => undefined + confirmSearchFilters: () => undefined, + clearSearchFilters: () => undefined }, payments: { page: 1, setPage: () => undefined, + searchFilters: { + searchTerms: '', + area: [], + unit: null, + distinctions: [], + status: 'DRAFT', + paymentDateStart: null, + paymentDateEnd: null + }, + setSearchFilters: () => undefined, confirmedSearchFilters: undefined, - setConfirmedSearchFilters: () => undefined + confirmSearchFilters: () => undefined, + clearSearchFilters: () => undefined }, incomeStatements: { page: 1, setPage: () => undefined, + searchFilters: { + area: [], + unit: undefined, + providerTypes: [], + sentStartDate: undefined, + sentEndDate: undefined, + placementValidDate: undefined + }, + setSearchFilters: () => undefined, confirmedSearchFilters: undefined, - setConfirmedSearchFilters: () => undefined + clearSearchFilters: () => undefined, + confirmSearchFilters: () => undefined }, shared: { units: Loading.of(), @@ -217,6 +283,26 @@ export const InvoicingUIContextProvider = React.memo( ] = useState( defaultState.feeDecisions.confirmedSearchFilters ) + const [feeDecisionSearchFilters, _setFeeDecisionSearchFilters] = + useState( + defaultState.feeDecisions.searchFilters + ) + const setFeeDecisionSearchFilters = useCallback( + (value: React.SetStateAction) => { + _setFeeDecisionSearchFilters(value) + setConfirmedFeeDecisionSearchFilters(undefined) + }, + [] + ) + const confirmFeeDecisionSearchFilters = useCallback(() => { + setConfirmedFeeDecisionSearchFilters(feeDecisionSearchFilters) + setFeeDecisionPage(defaultState.feeDecisions.page) + }, [feeDecisionSearchFilters]) + const clearFeeDecisionSearchFilters = useCallback( + () => + setFeeDecisionSearchFilters(defaultState.feeDecisions.searchFilters), + [setFeeDecisionSearchFilters] + ) const [valueDecisionPage, setValueDecisionPage] = useState( defaultState.valueDecisions.page @@ -227,6 +313,28 @@ export const InvoicingUIContextProvider = React.memo( ] = useState( defaultState.valueDecisions.confirmedSearchFilters ) + const [valueDecisionSearchFilters, _setValueDecisionSearchFilters] = + useState( + defaultState.valueDecisions.searchFilters + ) + const setValueDecisionSearchFilters = useCallback( + (value: React.SetStateAction) => { + _setValueDecisionSearchFilters(value) + setConfirmedValueDecisionSearchFilters(undefined) + }, + [] + ) + const confirmValueDecisionSearchFilters = useCallback(() => { + setConfirmedValueDecisionSearchFilters(valueDecisionSearchFilters) + setValueDecisionPage(defaultState.valueDecisions.page) + }, [valueDecisionSearchFilters]) + const clearValueDecisionSearchFilters = useCallback( + () => + setValueDecisionSearchFilters( + defaultState.valueDecisions.searchFilters + ), + [setValueDecisionSearchFilters] + ) const [invoicePage, setInvoicePage] = useState( defaultState.invoices.page @@ -235,6 +343,23 @@ export const InvoicingUIContextProvider = React.memo( useState( defaultState.invoices.confirmedSearchFilters ) + const [invoiceSearchFilters, _setInvoiceSearchFilters] = + useState(defaultState.invoices.searchFilters) + const setInvoiceSearchFilters = useCallback( + (value: React.SetStateAction) => { + _setInvoiceSearchFilters(value) + setConfirmedInvoiceSearchFilters(undefined) + }, + [] + ) + const confirmInvoiceSearchFilters = useCallback(() => { + setConfirmedInvoiceSearchFilters(invoiceSearchFilters) + setInvoicePage(defaultState.invoices.page) + }, [invoiceSearchFilters]) + const clearInvoiceSearchFilters = useCallback( + () => setInvoiceSearchFilters(defaultState.invoices.searchFilters), + [setInvoiceSearchFilters] + ) const [paymentPage, setPaymentPage] = useState( defaultState.payments.page @@ -243,6 +368,23 @@ export const InvoicingUIContextProvider = React.memo( useState( defaultState.payments.confirmedSearchFilters ) + const [paymentSearchFilters, _setPaymentSearchFilters] = + useState(defaultState.payments.searchFilters) + const setPaymentSearchFilters = useCallback( + (value: React.SetStateAction) => { + _setPaymentSearchFilters(value) + setConfirmedPaymentSearchFilters(undefined) + }, + [] + ) + const confirmPaymentSearchFilters = useCallback(() => { + setConfirmedPaymentSearchFilters(paymentSearchFilters) + setPaymentPage(defaultState.payments.page) + }, [paymentSearchFilters]) + const clearPaymentSearchFilters = useCallback( + () => setPaymentSearchFilters(defaultState.payments.searchFilters), + [setPaymentSearchFilters] + ) const [incomeStatementPage, setIncomeStatementPage] = useState( defaultState.incomeStatements.page @@ -253,6 +395,26 @@ export const InvoicingUIContextProvider = React.memo( ] = useState( defaultState.incomeStatements.confirmedSearchFilters ) + const [incomeStatementSearchFilters, _setIncomeStatementSearchFilters] = + useState( + defaultState.incomeStatements.searchFilters + ) + const setIncomeStatementSearchFilters = useCallback( + (value: React.SetStateAction) => { + _setIncomeStatementSearchFilters(value) + setConfirmedIncomeStatementSearchFilters(undefined) + }, + [] + ) + const confirmIncomeStatementSearchFilters = useCallback(() => { + setConfirmedIncomeStatementSearchFilters(incomeStatementSearchFilters) + setIncomeStatementPage(defaultState.incomeStatements.page) + }, [incomeStatementSearchFilters]) + const clearIncomeStatementSearchFilters = useCallback(() => { + setIncomeStatementSearchFilters( + defaultState.incomeStatements.searchFilters + ) + }, [setIncomeStatementSearchFilters]) const [units, setUnits] = useState>( defaultState.shared.units @@ -280,32 +442,47 @@ export const InvoicingUIContextProvider = React.memo( feeDecisions: { page: feeDecisionPage, setPage: setFeeDecisionPage, + searchFilters: feeDecisionSearchFilters, confirmedSearchFilters: confirmedFeeDecisionSearchFilters, - setConfirmedSearchFilters: setConfirmedFeeDecisionSearchFilters + setSearchFilters: setFeeDecisionSearchFilters, + confirmSearchFilters: confirmFeeDecisionSearchFilters, + clearSearchFilters: clearFeeDecisionSearchFilters }, valueDecisions: { page: valueDecisionPage, setPage: setValueDecisionPage, + searchFilters: valueDecisionSearchFilters, confirmedSearchFilters: confirmedValueDecisionSearchFilters, - setConfirmedSearchFilters: setConfirmedValueDecisionSearchFilters + setSearchFilters: setValueDecisionSearchFilters, + confirmSearchFilters: confirmValueDecisionSearchFilters, + clearSearchFilters: clearValueDecisionSearchFilters }, invoices: { page: invoicePage, setPage: setInvoicePage, + searchFilters: invoiceSearchFilters, confirmedSearchFilters: confirmedInvoiceSearchFilters, - setConfirmedSearchFilters: setConfirmedInvoiceSearchFilters + setSearchFilters: setInvoiceSearchFilters, + confirmSearchFilters: confirmInvoiceSearchFilters, + clearSearchFilters: clearInvoiceSearchFilters }, payments: { page: paymentPage, setPage: setPaymentPage, + searchFilters: paymentSearchFilters, confirmedSearchFilters: confirmedPaymentSearchFilters, - setConfirmedSearchFilters: setConfirmedPaymentSearchFilters + setSearchFilters: setPaymentSearchFilters, + confirmSearchFilters: confirmPaymentSearchFilters, + clearSearchFilters: clearPaymentSearchFilters }, incomeStatements: { page: incomeStatementPage, setPage: setIncomeStatementPage, + searchFilters: incomeStatementSearchFilters, + setSearchFilters: setIncomeStatementSearchFilters, confirmedSearchFilters: confirmedIncomeStatementSearchFilters, - setConfirmedSearchFilters: setConfirmedIncomeStatementSearchFilters + clearSearchFilters: clearIncomeStatementSearchFilters, + confirmSearchFilters: confirmIncomeStatementSearchFilters }, shared: { units, @@ -317,15 +494,35 @@ export const InvoicingUIContextProvider = React.memo( }), [ feeDecisionPage, + feeDecisionSearchFilters, confirmedFeeDecisionSearchFilters, + setFeeDecisionSearchFilters, + confirmFeeDecisionSearchFilters, + clearFeeDecisionSearchFilters, valueDecisionPage, + valueDecisionSearchFilters, confirmedValueDecisionSearchFilters, + setValueDecisionSearchFilters, + confirmValueDecisionSearchFilters, + clearValueDecisionSearchFilters, invoicePage, + invoiceSearchFilters, confirmedInvoiceSearchFilters, + setInvoiceSearchFilters, + confirmInvoiceSearchFilters, + clearInvoiceSearchFilters, paymentPage, + paymentSearchFilters, confirmedPaymentSearchFilters, + setPaymentSearchFilters, + confirmPaymentSearchFilters, + clearPaymentSearchFilters, incomeStatementPage, + incomeStatementSearchFilters, confirmedIncomeStatementSearchFilters, + setIncomeStatementSearchFilters, + clearIncomeStatementSearchFilters, + confirmIncomeStatementSearchFilters, units, financeDecisionHandlers, availableAreas,