diff --git a/app/src/controllers/user/actionCreators.js b/app/src/controllers/user/actionCreators.js index b94fe4daf5..c292ade0d3 100644 --- a/app/src/controllers/user/actionCreators.js +++ b/app/src/controllers/user/actionCreators.js @@ -35,6 +35,7 @@ import { DELETE_USER_ACCOUNT, SET_ACTIVE_PROJECT_KEY, SET_LOG_TIME_FORMAT, + SET_NOT_ASSIGNED_PROJECT_KEY, } from './constants'; export const fetchUserSuccessAction = (user) => ({ @@ -67,6 +68,11 @@ export const setActiveProjectKeyAction = (activeProjectKey) => ({ payload: activeProjectKey, }); +export const setNotAssignedProjectKeyAction = (notAssignedProjectKey) => ({ + type: SET_NOT_ASSIGNED_PROJECT_KEY, + payload: notAssignedProjectKey, +}); + export const addApiKeyAction = (name, successMessage, errorMessage, onSuccess) => ({ type: ADD_API_KEY, payload: { name, successMessage, errorMessage, onSuccess }, diff --git a/app/src/controllers/user/constants.js b/app/src/controllers/user/constants.js index 9a70817c0e..108aa6adf8 100644 --- a/app/src/controllers/user/constants.js +++ b/app/src/controllers/user/constants.js @@ -19,6 +19,7 @@ export const FETCH_USER_ERROR = 'fetchUserError'; export const FETCH_USER_SUCCESS = 'fetchUserSuccess'; export const SET_ACTIVE_PROJECT = 'setActiveProject'; export const SET_ACTIVE_PROJECT_KEY = 'setActiveProjectKey'; +export const SET_NOT_ASSIGNED_PROJECT_KEY = 'setNotAssignedProjectKey'; export const SET_START_TIME_FORMAT = 'setStartTimeFormat'; export const SET_LOG_TIME_FORMAT = 'setLogTimeFormat'; export const SET_PHOTO_TIME_STAMP = 'setPhotoTimeStamp'; diff --git a/app/src/controllers/user/index.js b/app/src/controllers/user/index.js index f0c1e9aff1..7cba148a11 100644 --- a/app/src/controllers/user/index.js +++ b/app/src/controllers/user/index.js @@ -42,6 +42,7 @@ export { assignToProjectErrorAction, assignToProjectSuccessAction, unassignFromProjectAction, + setNotAssignedProjectKeyAction, } from './actionCreators'; export { userReducer } from './reducer'; export { @@ -60,5 +61,6 @@ export { availableProjectsSelector, activeProjectKeySelector, assignedOrganizationsSelector, + notAssignedProjectKeySelector, } from './selectors'; export { userSagas } from './sagas'; diff --git a/app/src/controllers/user/reducer.js b/app/src/controllers/user/reducer.js index fb41354e7e..bce02ff3dd 100644 --- a/app/src/controllers/user/reducer.js +++ b/app/src/controllers/user/reducer.js @@ -28,6 +28,7 @@ import { DELETE_API_KEY_SUCCESS, SET_ACTIVE_PROJECT_KEY, SET_LOG_TIME_FORMAT, + SET_NOT_ASSIGNED_PROJECT_KEY, } from './constants'; export const settingsReducer = (state = SETTINGS_INITIAL_STATE, { type = '', payload = {} }) => { @@ -52,6 +53,15 @@ export const activeProjectKeyReducer = (state = '', { type, payload }) => { } }; +export const notAssignedProjectKeyReducer = (state = '', { type, payload }) => { + switch (type) { + case SET_NOT_ASSIGNED_PROJECT_KEY: + return payload; + default: + return state; + } +}; + export const activeProjectReducer = (state = '', { type = '', payload = {} }) => { switch (type) { case SET_ACTIVE_PROJECT: @@ -123,6 +133,7 @@ export const userReducer = combineReducers({ info: userInfoReducer, activeProject: activeProjectReducer, activeProjectKey: activeProjectKeyReducer, + notAssignedProjectKey: notAssignedProjectKeyReducer, settings: settingsReducer, apiKeys: apiKeysReducer, }); diff --git a/app/src/controllers/user/selectors.js b/app/src/controllers/user/selectors.js index 23138ae73e..98038274ec 100644 --- a/app/src/controllers/user/selectors.js +++ b/app/src/controllers/user/selectors.js @@ -77,3 +77,5 @@ export const availableProjectsSelector = createSelector( export const apiKeysSelector = (state) => userSelector(state).apiKeys || []; export const activeProjectKeySelector = (state) => userSelector(state).activeProjectKey; + +export const notAssignedProjectKeySelector = (state) => userSelector(state).notAssignedProjectKey; diff --git a/app/src/pages/organization/organizationProjectsPage/projectsListTable/projectName/projectName.jsx b/app/src/pages/organization/organizationProjectsPage/projectsListTable/projectName/projectName.jsx index 2242bb5853..0a935b3373 100644 --- a/app/src/pages/organization/organizationProjectsPage/projectsListTable/projectName/projectName.jsx +++ b/app/src/pages/organization/organizationProjectsPage/projectsListTable/projectName/projectName.jsx @@ -22,7 +22,7 @@ import { useDispatch, useSelector } from 'react-redux'; import { ADMIN_PROJECTS_PAGE_EVENTS } from 'components/main/analytics/events'; import { SCREEN_XS_MAX_MEDIA } from 'common/constants/screenSizeVariables'; import { navigateToProjectAction } from 'controllers/organizations/projects'; -import { setActiveProjectKeyAction } from 'controllers/user'; +import { setNotAssignedProjectKeyAction } from 'controllers/user'; import { userAssignedSelector, PROJECT_PAGE } from 'controllers/pages'; import styles from './projectName.scss'; @@ -40,7 +40,7 @@ export const ProjectName = ({ project, disableAnalytics = false }) => { return; } - dispatch(setActiveProjectKeyAction(projectKey)); + dispatch(setNotAssignedProjectKeyAction(projectKey)); dispatch(navigateToProjectAction({ project })); if (!disableAnalytics) { diff --git a/app/src/routes/routesMap.js b/app/src/routes/routesMap.js index 183d006d1f..62d6e53840 100644 --- a/app/src/routes/routesMap.js +++ b/app/src/routes/routesMap.js @@ -21,7 +21,8 @@ import { userInfoSelector, setActiveProjectAction, setActiveProjectKeyAction, - activeProjectKeySelector, + notAssignedProjectKeySelector, + setNotAssignedProjectKeyAction, } from 'controllers/user'; import { fetchProjectAction } from 'controllers/project'; import { @@ -326,7 +327,7 @@ export const onBeforeRouteChange = (dispatch, getState, { action }) => { } = action; let { organizationSlug, projectSlug } = activeProjectSelector(getState()); - const hashProjectKey = activeProjectKeySelector(getState()); + const notAssignedProjectKey = notAssignedProjectKeySelector(getState()); const currentPageType = pageSelector(getState()); const authorized = isAuthorizedSelector(getState()); const userId = userInfoSelector(getState())?.userId; @@ -341,13 +342,13 @@ export const onBeforeRouteChange = (dispatch, getState, { action }) => { const isAdminNewPageType = !!adminPageNames[nextPageType]; const isAdminCurrentPageType = !!adminPageNames[currentPageType]; - const projectKey = assignedProjectKey || (assignmentNotRequired && hashProjectKey); + const projectKey = assignedProjectKey || (assignmentNotRequired && notAssignedProjectKey); const isChangedProject = organizationSlug !== hashOrganizationSlug || projectSlug !== hashProjectSlug; if (hashOrganizationSlug && (isChangedProject || isAdminCurrentPageType) && !isAdminNewPageType) { - if (hashProjectSlug && hasPermission) { + if (projectKey && hashProjectSlug && hasPermission) { dispatch( setActiveProjectAction({ organizationSlug: hashOrganizationSlug, @@ -357,6 +358,7 @@ export const onBeforeRouteChange = (dispatch, getState, { action }) => { dispatch(setActiveProjectKeyAction(projectKey)); dispatch(fetchProjectAction(projectKey)); dispatch(fetchOrganizationBySlugAction(hashOrganizationSlug)); + dispatch(setNotAssignedProjectKeyAction(null)); organizationSlug = hashOrganizationSlug; projectSlug = hashProjectSlug; @@ -368,7 +370,7 @@ export const onBeforeRouteChange = (dispatch, getState, { action }) => { dispatch(fetchOrganizationBySlugAction(hashOrganizationSlug)); organizationSlug = hashOrganizationSlug; - } else if (isChangedProject) { + } else if (isChangedProject || !projectKey) { dispatch( redirect({ ...action,