fix(ui) - activeSite id from path
This commit is contained in:
parent
3980a29869
commit
bf3916353c
2 changed files with 8 additions and 4 deletions
|
|
@ -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();
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue