import * as React from 'react' import { Item, ItemsApi } from '../../../../types' import { useHasUserPermission } from '../../hooks/usePermissions' import { getValue } from '../../../../Utils/GetValue' import { useAppState } from '../../../AppShell/hooks/useAppState' import DialogModal from '../../../Templates/DialogModal' import { useNavigate } from 'react-router-dom' export function HeaderView({ item, api, editCallback, deleteCallback, setPositionCallback, itemNameField, itemSubnameField, itemAvatarField, loading, hideMenu = false, big = false, truncateSubname = true, hideSubname = false, showAddress = false, }: { item: Item api?: ItemsApi editCallback?: any deleteCallback?: any setPositionCallback?: any itemNameField?: string itemAvatarField?: string itemSubnameField?: string loading?: boolean hideMenu?: boolean big?: boolean hideSubname?: boolean truncateSubname?: boolean showAddress?: boolean }) { const [modalOpen, setModalOpen] = React.useState(false) const hasUserPermission = useHasUserPermission() const navigate = useNavigate() const appState = useAppState() const avatar = itemAvatarField && getValue(item, itemAvatarField) ? appState.assetsApi.url + getValue(item, itemAvatarField) + `${big ? '?width=160&heigth=160' : '?width=80&heigth=80'}` : item.layer?.itemAvatarField && item && getValue(item, item.layer?.itemAvatarField) && appState.assetsApi.url + getValue(item, item.layer?.itemAvatarField) + `${big ? '?width=160&heigth=160' : '?width=80&heigth=80'}` const title = itemNameField ? getValue(item, itemNameField) : item.layer?.itemNameField && item && getValue(item, item.layer?.itemNameField) const subtitle = itemSubnameField ? getValue(item, itemSubnameField) : item.layer?.itemSubnameField && item && getValue(item, item.layer?.itemSubnameField) const [address] = React.useState('') const params = new URLSearchParams(window.location.search) const openDeleteModal = async (event: React.MouseEvent) => { setModalOpen(true) event.stopPropagation() } return ( <>
{avatar && (
{item.name
)}
{title}
{showAddress && address && !hideSubname && (
{address}
)} {subtitle && !hideSubname && (
{subtitle}
)}
e.stopPropagation()} className={`${big ? 'tw-mt-5' : 'tw-mt-1'}`}> {(api?.deleteItem || item.layer?.api?.updateItem) && (hasUserPermission(api?.collectionName!, 'delete', item) || hasUserPermission(api?.collectionName!, 'update', item)) && !hideMenu && (
)}
setModalOpen(false)} >
e.stopPropagation()}> Do you want to delete {item.name}?
) }