From 6875d928808625a89c1bc42f217ca53da5d64d41 Mon Sep 17 00:00:00 2001 From: Kristina Date: Mon, 19 Aug 2024 14:28:23 +0200 Subject: [PATCH] feature: Add ipfs link on Constitution versions --- frontend/public/icons/ExternalLink.svg | 4 ++ .../organisms/Constitution/Constitution.tsx | 17 +++++++-- .../organisms/Constitution/MDXComponents.tsx | 38 +++++++++++++++++-- frontend/src/components/organisms/types.ts | 1 + frontend/src/constants/icons.ts | 1 + 5 files changed, 54 insertions(+), 7 deletions(-) create mode 100644 frontend/public/icons/ExternalLink.svg diff --git a/frontend/public/icons/ExternalLink.svg b/frontend/public/icons/ExternalLink.svg new file mode 100644 index 00000000..a734f31b --- /dev/null +++ b/frontend/public/icons/ExternalLink.svg @@ -0,0 +1,4 @@ + + + + diff --git a/frontend/src/components/organisms/Constitution/Constitution.tsx b/frontend/src/components/organisms/Constitution/Constitution.tsx index 042d50dc..2020c895 100644 --- a/frontend/src/components/organisms/Constitution/Constitution.tsx +++ b/frontend/src/components/organisms/Constitution/Constitution.tsx @@ -16,20 +16,22 @@ import { } from "./MDXComponents"; import { ConstitutionMetadata, ConstitutionProps } from "../types"; import { useTranslations } from "next-intl"; -import { useModal } from "@/context"; +import { useAppContext, useModal } from "@/context"; import { Footer } from "../Footer"; import { CONSTITUTION_SIDEBAR_TABS, customPalette } from "@consts"; import { ContentWrapper } from "@/components/atoms"; import { NotFound } from "../NotFound"; import { PageTitleTabs } from "../PageTitleTabs"; +import { isAnyAdminRole } from "@utils"; export function Constitution({ constitution, metadata }: ConstitutionProps) { + const { userSession } = useAppContext(); const [isOpen, setIsOpen] = useState(true); const [tab, setTab] = useState("revisions"); const { openModal } = useModal(); const t = useTranslations("Constitution"); - const onCompare = (target: Omit) => { + const onCompare = (target: Omit) => { openModal({ type: "compareConstitutionModal", state: { @@ -90,7 +92,7 @@ export function Constitution({ constitution, metadata }: ConstitutionProps) { {tab === "revisions" ? ( {metadata ? ( - metadata.map(({ title, created_date, cid }) => { + metadata.map(({ title, created_date, cid, url }) => { return ( { @@ -106,6 +108,15 @@ export function Constitution({ constitution, metadata }: ConstitutionProps) { ? t("drawer.latest") : t("drawer.compare") } + url={ + userSession && + isAnyAdminRole(userSession?.role) && + userSession?.permissions.includes( + "add_constitution_version" + ) + ? url + : null + } key={cid} /> ); diff --git a/frontend/src/components/organisms/Constitution/MDXComponents.tsx b/frontend/src/components/organisms/Constitution/MDXComponents.tsx index 481308f8..26e500a3 100644 --- a/frontend/src/components/organisms/Constitution/MDXComponents.tsx +++ b/frontend/src/components/organisms/Constitution/MDXComponents.tsx @@ -4,6 +4,8 @@ import { getShortenedGovActionId } from "@utils"; import { Button, CopyButton, Typography } from "@atoms"; import { Box, Collapse, Grid } from "@mui/material"; import React, { ReactNode } from "react"; +import Image from "next/image"; +import Link from "next/link"; const Anchor = ({ id, offset = "-20vh " }) => { return ( @@ -203,7 +205,14 @@ export const NavDrawer = ({ ); }; -export const NavCard = ({ onClick, title, description, buttonLabel, hash }) => ( +export const NavCard = ({ + onClick, + title, + description, + buttonLabel, + hash, + url, +}) => ( ( justifyContent="space-between" alignItems={{ lg: "center" }} > - + {title} {description} - + ( - + {url && ( + + + ipfs link + + + )} + +