Skip to content
Open
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
78 changes: 40 additions & 38 deletions src/routes/Boards/History/HistoryCard/HistoryCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {Button} from "components/Button";
import {UserRoleChip} from "routes/Boards/History/HistoryCard/AccessPolicyChip/UserRoleChip";
import {AccessPolicy, deleteHistoryBoard, setBoardFavourite} from "store/features";
import {ReactElement, useState} from "react";
import {MiniMenu} from "components/MiniMenu/MiniMenu";
import {MiniMenu, MiniMenuItem} from "components/MiniMenu/MiniMenu";
import {ConfirmationDialog} from "components/ConfirmationDialog/ConfirmationDialog";
import {Tooltip} from "components/Tooltip";
import {useTextOverflow} from "utils/hooks/useTextOverflow";
Expand Down Expand Up @@ -84,6 +84,10 @@ export const HistoryCard = (props: HistoryCardProps) => {
// owner: edit + delete; moderator: edit only; participant: neither.
const canEdit = isParticipantModerator(props.board.userRole);
const canDelete = props.board.userRole === "OWNER";
// creating templates from boards is only allowed if templates are available to the user
const isAnonymous = useAppSelector((state) => state.auth.user?.isAnonymous);
const allowAnonymousCustomTemplates = useAppSelector((state) => state.view.allowAnonymousCustomTemplates);
const canCreateTemplate = !isAnonymous || allowAnonymousCustomTemplates;

const joinedColumnsNames = props.board.columns.map((column) => column.name).join(", ");
const formattedCreatedAtDate = new Date(props.board.createdAt).toLocaleDateString(locale, {weekday: "long", year: "numeric", month: "2-digit", day: "2-digit"});
Expand All @@ -100,44 +104,42 @@ export const HistoryCard = (props: HistoryCardProps) => {
showMiniMenu ? (
<MiniMenu
className={classNames("history-card__menu", "history-card__menu--open")}
items={[
...(canDelete
? [
{
label: t("History.HistoryCard.Menu.delete"),
element: <TrashIcon />,
onClick: () => {
setShowMiniMenu(false);
setShowDeleteConfirmation(true);
},
},
]
: []),
{
label: t("History.HistoryCard.Menu.copyLink"),
element: <LinkIcon />,
onClick: () => {
navigator.clipboard.writeText(`${window.location.origin}/board/${props.board.id}`).then(() => {
Toast.success({title: t("History.HistoryCard.linkCopied")});
});
items={
[
canDelete && {
label: t("History.HistoryCard.Menu.delete"),
element: <TrashIcon />,
onClick: () => {
setShowMiniMenu(false);
setShowDeleteConfirmation(true);
},
},
},
{
label: t("History.HistoryCard.Menu.createTemplate"),
element: <Duplicate2Icon />,
onClick: () => navigate(`/boards/create-template/${props.board.id}`),
},
...(canEdit
? [
{
label: t("History.HistoryCard.Menu.edit"),
element: <EditIcon />,
onClick: () => navigate(`/boards/edit-board/${props.board.id}`),
},
]
: []),
{label: t("History.HistoryCard.Menu.close"), element: <CloseIcon />, onClick: () => setShowMiniMenu(false)},
]}
{
label: t("History.HistoryCard.Menu.copyLink"),
element: <LinkIcon />,
onClick: () => {
navigator.clipboard.writeText(`${window.location.origin}/board/${props.board.id}`).then(() => {
Toast.success({title: t("History.HistoryCard.linkCopied")});
});
},
},
canCreateTemplate && {
label: t("History.HistoryCard.Menu.createTemplate"),
element: <Duplicate2Icon />,
onClick: () => navigate(`/boards/create-template/${props.board.id}`),
},
canEdit && {
label: t("History.HistoryCard.Menu.edit"),
element: <EditIcon />,
onClick: () => navigate(`/boards/edit-board/${props.board.id}`),
},
{
label: t("History.HistoryCard.Menu.close"),
element: <CloseIcon />,
onClick: () => setShowMiniMenu(false),
},
].filter(Boolean) as MiniMenuItem[]
}
focusBehaviour="trap"
onBlur={() => setShowMiniMenu(false)}
dataCy="template-card__menu"
Expand Down
Loading