Skip to content

Commit

Permalink
LF-4746 Create and use action to reset date range
Browse files Browse the repository at this point in the history
  • Loading branch information
kathyavini committed Mar 7, 2025
1 parent f6cf506 commit a5f8a30
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
7 changes: 7 additions & 0 deletions packages/webapp/src/containers/Finances/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
SET_SELECTED_EXPENSE_TYPE,
SET_SELECTED_SALE,
UPDATE_SALE,
RESET_DATE_RANGE,
} from './constants';

export const setSalesInState = (sales) => {
Expand Down Expand Up @@ -144,6 +145,12 @@ export const setDateRange = (rangeObj) => {
};
};

export const resetDateRange = () => {
return {
type: RESET_DATE_RANGE,
};
};

export const setIsFetchingData = (isFetching) => {
return {
type: SET_IS_FETCHING_DATA,
Expand Down
1 change: 1 addition & 0 deletions packages/webapp/src/containers/Finances/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export const ADD_EXPENSES = 'ADD_EXPENSES';
export const DELETE_EXPENSES = 'DELETE_EXPENSES';
export const ADD_REMOVE_EXPENSE = 'ADD_REMOVE_EXPENSE';
export const SET_DATE_RANGE = 'SET_DATE_RANGE';
export const RESET_DATE_RANGE = 'RESET_DATE_RANGE';
export const UPDATE_SALE = 'UPDATE_SALE';
export const DELETE_EXPENSE = 'DELETE_EXPENSE';
export const SET_IS_FETCHING_DATA = 'SET_IS_FETCHING_DATA';
Expand Down
5 changes: 5 additions & 0 deletions packages/webapp/src/containers/Finances/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import {
SET_CROP_SALES_IN_STATE,
SET_DATE_RANGE,
RESET_DATE_RANGE,
SET_EXPENSE,
SET_EXPENSE_DETAIL_DATE,
SET_EXPENSE_TYPE,
Expand Down Expand Up @@ -71,6 +72,10 @@ function financeReducer(state = initialState, action) {
return Object.assign({}, state, {
date_range: { ...state.date_range, ...action.rangeObj },
});
case RESET_DATE_RANGE:
return Object.assign({}, state, {
date_range: initialState.date_range,
});
case SET_IS_FETCHING_DATA:
return Object.assign({}, state, {
isFetchingData: action.isFetching,
Expand Down
5 changes: 2 additions & 3 deletions packages/webapp/src/containers/saga.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,7 @@ import {
import { getFencesSuccess, onLoadingFenceFail, onLoadingFenceStart } from './fenceSlice';
import { getFieldsSuccess, onLoadingFieldFail, onLoadingFieldStart } from './fieldSlice';
import { resetTasksFilter } from './filterSlice';
import { setDateRange, setIsFetchingData } from './Finances/actions.js';
import { DateRangeOptions } from '../components/DateRangeSelector/types';
import { resetDateRange, setIsFetchingData } from './Finances/actions.js';
import { getGardensSuccess, onLoadingGardenFail, onLoadingGardenStart } from './gardenSlice';
import { getGatesSuccess, onLoadingGateFail, onLoadingGateStart } from './gateSlice';
import {
Expand Down Expand Up @@ -622,7 +621,7 @@ export function* fetchAllSaga() {

export function* clearOldFarmStateSaga() {
yield put(resetTasks());
yield put(setDateRange({ option: DateRangeOptions.YEAR_TO_DATE }));
yield put(resetDateRange());

yield put(
api.util.invalidateTags([
Expand Down

0 comments on commit a5f8a30

Please # to comment.