From bf3916353cba55306ff490f5000e2545cf03bcad Mon Sep 17 00:00:00 2001 From: Shekar Siri Date: Fri, 25 Nov 2022 20:51:42 +0100 Subject: [PATCH] fix(ui) - activeSite id from path --- frontend/app/Router.js | 3 ++- frontend/app/duck/site.js | 9 ++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/frontend/app/Router.js b/frontend/app/Router.js index 1e4f4b4b7..6a4aea446 100644 --- a/frontend/app/Router.js +++ b/frontend/app/Router.js @@ -126,8 +126,9 @@ class Router extends React.Component { } fetchInitialData = async () => { + const siteIdFromPath = parseInt(window.location.pathname.split("/")[1]) await this.props.fetchUserInfo() - await this.props.fetchSiteList() + await this.props.fetchSiteList(siteIdFromPath) const { mstore } = this.props; mstore.initClient(); }; diff --git a/frontend/app/duck/site.js b/frontend/app/duck/site.js index ad451f1fb..e1a4b9ea6 100644 --- a/frontend/app/duck/site.js +++ b/frontend/app/duck/site.js @@ -65,7 +65,9 @@ const reducer = (state = initialState, action = {}) => { case FETCH_LIST_SUCCESS: let siteId = state.get("siteId"); const siteExists = action.data.map(s => s.projectId).includes(siteId); - if (!siteId || !siteExists) { + if (action.siteIdFromPath) { + siteId = action.siteIdFromPath; + } else if (!siteId || !siteExists) { siteId = !!action.data.find(s => s.projectId === parseInt(storedSiteId)) ? storedSiteId : action.data[0].projectId; @@ -83,7 +85,7 @@ const reducer = (state = initialState, action = {}) => { .set('active', list.find(s => s.id === parseInt(siteId))); case SET_SITE_ID: localStorage.setItem(SITE_ID_STORAGE_KEY, action.siteId) - const site = state.get('list').find(s => s.id === action.siteId); + const site = state.get('list').find(s => parseInt(s.id) == action.siteId); return state.set('siteId', action.siteId).set('active', site); } return state; @@ -110,10 +112,11 @@ export function saveGDPR(siteId, gdpr) { }; } -export function fetchList() { +export function fetchList(siteId) { return { types: array(FETCH_LIST), call: client => client.get('/projects'), + siteIdFromPath: siteId }; }