Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | 540x 540x 4x 4x 540x 540x 115x 540x 540x 145x 540x 540x | import { RootState } from "@redux/types/store";
import { createSelector, createSlice, PayloadAction } from "@reduxjs/toolkit";
import { MerchantData } from "@hooks/enterprise-api/account/types";
import { SelectorOption } from "components/common/TableFilters/SelectorOption";
import { TransactionsState } from "./types";
const initialState: TransactionsState = {
selectedMerchant: {},
selectedEnterprises: {},
selectedDate: {},
};
const merchantFiltersSlice = createSlice({
name: "merchantFilters",
initialState,
reducers: {
setSelectedMerchant: (
state: TransactionsState,
action: PayloadAction<{ queryKey: string; value: MerchantData | null }>,
) => {
const { queryKey, value } = action.payload;
state.selectedMerchant[queryKey] = value;
},
setSelectedEnterprises: (
state: TransactionsState,
action: PayloadAction<{
queryKey: string;
value: SelectorOption[] | null;
}>,
) => {
const { queryKey, value } = action.payload;
state.selectedEnterprises[queryKey] = value;
},
setSelectedDate: (
state: TransactionsState,
action: PayloadAction<{ queryKey: string; value: string }>,
) => {
const { queryKey, value } = action.payload;
state.selectedDate[queryKey] = value;
},
},
});
export const { setSelectedMerchant, setSelectedDate, setSelectedEnterprises } =
merchantFiltersSlice.actions;
export const selectSelectedMerchant = (state: RootState, queryKey: string) =>
state.merchantFilters?.selectedMerchant?.[queryKey];
export const selectSelectedEnterprises = (state: RootState, queryKey: string) =>
state.merchantFilters?.selectedEnterprises?.[queryKey];
export const selectDateFilter = (state: RootState, queryKey: string) =>
state.merchantFilters?.selectedDate?.[queryKey];
const selectSelectedEnterprisesByKey = (state: RootState) =>
state.merchantFilters?.selectedEnterprises;
export const createSelectEnterprisesForQueryKey = () =>
createSelector(
[
selectSelectedEnterprisesByKey,
(_: RootState, queryKey: string) => queryKey,
],
(selectedEnterprisesMap, queryKey) =>
selectedEnterprisesMap?.[queryKey] ?? [],
);
export default merchantFiltersSlice.reducer;
|