Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dashboard refonte: fix user permissions qui n'affiche plus les dossier dans la side bar quand on refresh #2693

Merged
merged 1 commit into from
Sep 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion front/src/Apps/Dashboard/DashboardRoutes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { BsdasriSignatureType, Query } from "generated/graphql/types";
import { filter } from "graphql-anywhere";
import { Location } from "history";
import DashboardPage from "Pages/Dashboard";
import React, { useCallback } from "react";
import React, { useCallback, useEffect } from "react";
import {
generatePath,
Redirect,
Expand All @@ -35,6 +35,7 @@ import {
} from "../../dashboard/detail";
import Exports from "../../dashboard/exports/Exports";
import DashboardTabs from "./Components/DashboardTabs/DashboardTabs";
import { usePermissions } from "common/contexts/PermissionsContext";

import "./dashboard.scss";

Expand All @@ -58,6 +59,7 @@ export const GET_ME = gql`
function DashboardRoutes() {
const { siret } = useParams<{ siret: string }>();
const { data } = useQuery<Pick<Query, "me">>(GET_ME);
const { updatePermissions } = usePermissions();

const history = useHistory();

Expand All @@ -84,6 +86,16 @@ function DashboardRoutes() {
});
}, [history, siret]);

useEffect(() => {
if (data) {
const companies = data.me.companies;
const currentCompany = companies.find(company => company.orgId === siret);
if (currentCompany) {
updatePermissions(currentCompany.userPermissions);
}
}
}, [updatePermissions, data, siret]);

if (data?.me == null) {
return <Loader />;
}
Expand Down
14 changes: 1 addition & 13 deletions front/src/dashboard/Dashboard.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useQuery, gql } from "@apollo/client";
import { filter } from "graphql-anywhere";
import React, { useEffect } from "react";
import React from "react";
import {
generatePath,
Redirect,
Expand Down Expand Up @@ -44,7 +44,6 @@ import { RouteBsddRequestRevision } from "./components/RevisionRequestList/bsdd/
import { DashboardTabs } from "./DashboardTabs";
import SideMenu from "common/components/SideMenu";
import { RouteBsdaRequestRevision } from "./components/RevisionRequestList/bsda/request";
import { usePermissions } from "common/contexts/PermissionsContext";

export const GET_ME = gql`
{
Expand All @@ -64,7 +63,6 @@ export const GET_ME = gql`
`;

export default function Dashboard() {
const { updatePermissions } = usePermissions();
const { siret } = useParams<{ siret: string }>();
const { data } = useQuery<Pick<Query, "me">>(GET_ME);

Expand All @@ -82,16 +80,6 @@ export default function Dashboard() {
}),
};

useEffect(() => {
if (data) {
const companies = data.me.companies;
const currentCompany = companies.find(company => company.orgId === siret);
if (currentCompany) {
updatePermissions(currentCompany.userPermissions);
}
}
}, [updatePermissions, data, siret]);

if (data?.me == null) {
return <Loader />;
}
Expand Down