diff --git a/packages/app/src/modules/ScorecardList/components/Cards/ScorecardListCard.tsx b/packages/app/src/modules/ScorecardList/components/Cards/ScorecardListCard.tsx index 68822ca2..015aa4a6 100644 --- a/packages/app/src/modules/ScorecardList/components/Cards/ScorecardListCard.tsx +++ b/packages/app/src/modules/ScorecardList/components/Cards/ScorecardListCard.tsx @@ -1,33 +1,41 @@ import { colors } from "@dhis2/ui"; -import { getOrgUnitIdsFromOrgUnitSelection, ScorecardCardImage as holderImage, truncateDescription } from "@scorecard/shared"; +import { getOrgUnitIdsFromOrgUnitSelection, getUserAuthority, ScorecardCardImage as holderImage, truncateDescription, UserState } from "@scorecard/shared"; import React, { useState } from "react"; import { useNavigate } from "react-router-dom"; import { ScorecardListItem } from "../../types"; import { ScorecardListCardActions } from "./ScorecardListCardActions"; import { OrgUnitSelection } from "@hisptz/dhis2-utils"; +import { getSharingSettingsFromOldConfiguration } from "../../../../utils/sharing"; +import { useRecoilValue } from "recoil"; export default function ScorecardListCard({ scorecard, grid }: { scorecard: ScorecardListItem; - grid: boolean; + grid?: boolean; }) { + const user = useRecoilValue(UserState); const { title, description, id, orgUnitSelection, periodSelection } = scorecard ?? {}; const [showFullDescription, setShowFullDescription] = useState(false); const navigate = useNavigate(); + const accessConfig = getUserAuthority(user, scorecard.sharing ?? getSharingSettingsFromOldConfiguration(scorecard as any)); + const { read } = accessConfig; + const onView = () => { - const orgUnitIds = getOrgUnitIdsFromOrgUnitSelection(orgUnitSelection as OrgUnitSelection).join(";"); - const periodIds = periodSelection.periods.map(({ id }) => id).join(";"); - navigate(`/view/${id}?ou=${orgUnitIds}&pe=${periodIds}`); + if (read) { + const orgUnitIds = getOrgUnitIdsFromOrgUnitSelection(orgUnitSelection as OrgUnitSelection).join(";"); + const periodIds = periodSelection.periods.map(({ id }) => id).join(";"); + navigate(`/view/${id}?ou=${orgUnitIds}&pe=${periodIds}`); + } }; return grid ? (