fix: can't match project when last visit page is dashboard (#7762)

* fix: can't match project when last visit page is dashboard

* fix: typo
This commit is contained in:
Curry Yang 2024-07-26 16:48:43 +08:00 committed by GitHub
parent 1cf0901895
commit ec48392081
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,4 +1,4 @@
import { matchPath } from 'react-router-dom'; import { matchPath, type PathMatch } from 'react-router-dom';
import { database } from '../common/database'; import { database } from '../common/database';
import * as models from '../models'; import * as models from '../models';
@ -11,6 +11,27 @@ export const enum AsyncTask {
MigrateProjects, MigrateProjects,
SyncProjects, SyncProjects,
} }
const getMatchParams = (location: string) => {
const workspaceMatch = matchPath(
{
path: '/organization/:organizationId/project/:projectId/workspace/:workspaceId',
end: false,
},
location
);
const projectMatch = matchPath(
{
path: '/organization/:organizationId/project/:projectId',
end: false,
},
location
);
return (workspaceMatch || projectMatch) as PathMatch<'organizationId' | 'projectId' | 'workspaceId'> | null;
};
export const getInitialRouteForOrganization = async ({ export const getInitialRouteForOrganization = async ({
organizationId, organizationId,
navigateToWorkspace = false, navigateToWorkspace = false,
@ -21,13 +42,8 @@ export const getInitialRouteForOrganization = async ({
); );
// Check if the last visited project exists and redirect to it // Check if the last visited project exists and redirect to it
if (prevOrganizationLocation) { if (prevOrganizationLocation) {
const match = matchPath(
{ const match = getMatchParams(prevOrganizationLocation);
path: '/organization/:organizationId/project/:projectId/workspace/:workspaceId',
end: false,
},
prevOrganizationLocation
);
if (match && match.params.organizationId && match.params.projectId) { if (match && match.params.organizationId && match.params.projectId) {
const existingProject = await models.project.getById(match.params.projectId); const existingProject = await models.project.getById(match.params.projectId);