Skip to content

Commit 42c11ff

Browse files
authored
Merge pull request #4139 from LiteFarmOrg/LF-5265-old-farms-note-data-persists-after-switching-farms-to-a-newly-invited-farm
LF-5265 Old farm's note data persists after switching farms to a newly invited farm
2 parents 1c78130 + 882d8fd commit 42c11ff

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

packages/webapp/src/containers/ChooseFarm/saga.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import {
2828
spotlightLoading,
2929
} from '../showedSpotlightSlice';
3030
import { createAction } from '@reduxjs/toolkit';
31-
import { axios, getHeader } from '../saga';
31+
import { axios, clearOldFarmStateSaga, getHeader } from '../saga';
3232
import history from '../../history';
3333
import { startInvitationFlowOnChooseFarmScreen } from './chooseFarmFlowSlice';
3434

@@ -57,6 +57,7 @@ export function* patchUserFarmStatusWithIDTokenSaga({ payload: userFarm }) {
5757
const header = getHeader(user_id, farm_id);
5858
const result = yield call(axios.patch, patchUserFarmStatusWithIdTokenUrl(farm_id), {}, header);
5959
const { user: resUserFarm } = result.data;
60+
yield call(clearOldFarmStateSaga);
6061
yield put(acceptInvitationSuccess(resUserFarm));
6162
yield put(startInvitationFlowOnChooseFarmScreen(resUserFarm.farm_id));
6263
history.push('/consent');

packages/webapp/src/containers/saga.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -690,9 +690,14 @@ export function* selectFarmAndFetchAllSaga({ payload: farm }) {
690690
try {
691691
yield call(selectFarmSaga, { payload: farm });
692692
const userFarm = yield select(userFarmSelector);
693-
if (!userFarm.has_consent) return history.push('/consent');
694-
history.push({ pathname: '/' });
695693
yield call(clearOldFarmStateSaga);
694+
if (!userFarm.has_consent) {
695+
// has_consent is derived in the userFarmSelector from DB has_consent && consent_version === CONSENT_VERSION
696+
// Reachable when CONSENT_VERSION was bumped and the user hasn't re-accepted, or when an admin has changed the user's role (userFarmController.updateRole resets has_consent but leaves status='Active')
697+
// Status 'Invited' farms do not use selectFarmAndFetchAllSaga, but instead use patchUserFarmStatusWithIdTokenUrl
698+
return history.push('/consent');
699+
}
700+
history.push({ pathname: '/' });
696701
yield call(fetchAllSaga);
697702
} catch (e) {
698703
console.error('failed to fetch farm info', e);

0 commit comments

Comments
 (0)