diff --git a/packages/resource-detail/src/resource-detail.tsx b/packages/resource-detail/src/resource-detail.tsx index 957e5b9af..fe5b3e0d6 100644 --- a/packages/resource-detail/src/resource-detail.tsx +++ b/packages/resource-detail/src/resource-detail.tsx @@ -26,6 +26,9 @@ import { ResourceDetailMapWidgetProps } from '@openstad-headless/leaflet-map/src import { ResourceDetailMap } from '@openstad-headless/leaflet-map/src/resource-detail-map'; import { ShareLinks } from '../../apostrophe-widgets/share-links/src/share-links'; +import { Button } from '@utrecht/component-library-react'; +import {hasRole} from '../../lib'; + type booleanProps = { [K in | 'displayImage' @@ -232,6 +235,23 @@ function ResourceDetail({ ); }; + const { data: currentUser } = datastore.useCurrentUser({ ...props }); + const resourceUserId = resource?.userId || null; + const canDelete = hasRole(currentUser, ['moderator', 'owner'], resourceUserId); + + const onRemoveClick = async (resource: any) => { + try { + if (typeof resource.delete === 'function') { + await resource.delete(resource.id); + window.history.back(); + } else { + console.error('Delete method not found on resource'); + } + } catch (e) { + console.error(e); + } + } + return (
+ {canDelete && ( + <> + + + + )} + {Array.isArray(useSentiments) && diff --git a/packages/resource-overview/src/gridder-resource-detail.tsx b/packages/resource-overview/src/gridder-resource-detail.tsx index 522771945..99898e871 100644 --- a/packages/resource-overview/src/gridder-resource-detail.tsx +++ b/packages/resource-overview/src/gridder-resource-detail.tsx @@ -23,6 +23,7 @@ import { Icon } from "../../ui/src/icon" import {Likes, LikeWidgetProps} from '@openstad-headless/likes/src/likes'; import { BaseProps } from '@openstad-headless/types/base-props'; import { ProjectSettingProps } from '@openstad-headless/types/project-setting-props'; +import {hasRole} from "../../lib"; export type GridderResourceDetailProps = BaseProps & @@ -30,8 +31,7 @@ export type GridderResourceDetailProps = { resource: any; onRemoveClick?: (resource: any) => void; - isModerator?: boolean; - loginUrl?: string; + currentUser?: any; displayDocuments?: boolean; displayLikeButton?: boolean; clickableImage?: boolean; @@ -46,19 +46,21 @@ export type GridderResourceDetailProps = export const GridderResourceDetail = ({ resource, onRemoveClick, - isModerator = false, - loginUrl = '', displayDocuments = false, displayLikeButton = false, documentsTitle = '', documentsDesc = '', clickableImage = false, + currentUser, ...props }: GridderResourceDetailProps) => { // When resource is correctly typed the we will not need :any const theme = resource.tags?.filter((t: any) => t.type === 'theme')?.at(0); const area = resource.tags?.filter((t: any) => t.type === 'area')?.at(0); + const resourceUserId = resource?.userId || null; + const canDelete = hasRole(currentUser, ['moderator', 'owner'], resourceUserId); + type DocumentType = { name?: string; url?: string; @@ -173,19 +175,17 @@ export const GridderResourceDetail = ({ /> )} - + }} + > + Verwijder + + )}
diff --git a/packages/resource-overview/src/resource-overview.tsx b/packages/resource-overview/src/resource-overview.tsx index a4b196aa0..2c8934c1f 100644 --- a/packages/resource-overview/src/resource-overview.tsx +++ b/packages/resource-overview/src/resource-overview.tsx @@ -479,7 +479,6 @@ function ResourceOverview({ }, [filteredResources]); const { data: currentUser } = datastore.useCurrentUser({ ...props }); - const isModerator = hasRole(currentUser, 'moderator'); const onResourceClick = useCallback( (resource: any, index: number) => { @@ -532,8 +531,7 @@ function ResourceOverview({ itemRenderer={(item) => (