Skip to content

Commit a00f888

Browse files
authored
CUP-1342-switch-management-system (#256)
* feat(navigation): navigate to localized home after a ws switch * chore(api): update api models * refactor(projects): update components in order to support prj wsId
1 parent 1ad4604 commit a00f888

File tree

4 files changed

+27
-8
lines changed

4 files changed

+27
-8
lines changed

src/features/api/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ export type Workspace = {
416416
};
417417
coins?: number;
418418
};
419-
export type Output = 'bugs' | 'reports' | 'media';
419+
export type Output = 'bugs' | 'media';
420420
export type Campaign = {
421421
id: number;
422422
start_date: string;
@@ -450,6 +450,7 @@ export type Project = {
450450
id: number;
451451
name: string;
452452
campaigns_count: number;
453+
workspaceId: number;
453454
};
454455
export type Campaign2 = {
455456
id: number;

src/features/navigation/Navigation.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,9 @@ export const Navigation = ({
219219
company: workspaceName,
220220
},
221221
});
222+
223+
// Navigate to home
224+
navigateTo('home');
222225
};
223226

224227
if (!activeWorkspace) return null;

src/pages/Dashboard/Project.tsx

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
1+
import { useEffect } from 'react';
12
import { useTranslation } from 'react-i18next';
23
import { Page } from 'src/features/templates/Page';
34
import { Grid } from '@appquality/unguess-design-system';
45
import { useAppDispatch } from 'src/app/hooks';
56
import { useNavigate, useParams } from 'react-router-dom';
67
import { useLocalizeRoute } from 'src/hooks/useLocalizedRoute';
8+
import { useGetProjectsByPidQuery } from 'src/features/api';
79
import {
810
projectFilterChanged,
911
resetFilters,
1012
} from 'src/features/campaignsFilter/campaignsFilterSlice';
1113
import { ProjectItems } from './project-items';
1214
import { ProjectPageHeader } from './projectPageHeader';
1315

16+
import { CardRowLoading } from './CardRowLoading';
17+
1418
const Project = () => {
1519
const { t } = useTranslation();
1620
const navigate = useNavigate();
@@ -19,10 +23,22 @@ const Project = () => {
1923
const { projectId } = useParams();
2024

2125
if (!projectId || Number.isNaN(Number(projectId))) {
22-
navigate(notFoundRoute, { replace: true });
23-
} else {
24-
dispatch(resetFilters());
25-
dispatch(projectFilterChanged(Number(projectId)));
26+
navigate(notFoundRoute);
27+
}
28+
29+
const project = useGetProjectsByPidQuery({
30+
pid: Number(projectId),
31+
});
32+
33+
useEffect(() => {
34+
if (project.isSuccess) {
35+
dispatch(resetFilters());
36+
dispatch(projectFilterChanged(Number(projectId)));
37+
}
38+
}, [project]);
39+
40+
if (project.isError) {
41+
navigate(notFoundRoute);
2642
}
2743

2844
return (
@@ -31,9 +47,7 @@ const Project = () => {
3147
route="projects"
3248
pageHeader={<ProjectPageHeader projectId={Number(projectId) || 0} />}
3349
>
34-
<Grid>
35-
<ProjectItems />
36-
</Grid>
50+
<Grid>{project.isSuccess ? <ProjectItems /> : <CardRowLoading />}</Grid>
3751
</Page>
3852
);
3953
};

src/pages/ExpressWizard/projectDropdown.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export const ProjectDropdown = () => {
4141
id: 0,
4242
name: t('__WIZARD_EXPRESS_DEFAULT_ITEM'),
4343
campaigns_count: 0,
44+
workspaceId: 0,
4445
};
4546

4647
const [selectedItem, setSelectedItem] = useState<Project>();

0 commit comments

Comments
 (0)