diff --git a/src/Components/AppShell/NavBar.tsx b/src/Components/AppShell/NavBar.tsx index 36ecee76..2b1d1b36 100644 --- a/src/Components/AppShell/NavBar.tsx +++ b/src/Components/AppShell/NavBar.tsx @@ -16,12 +16,10 @@ export default function NavBar({ appName, userType }: { appName: string; userTyp useEffect(() => { const profile = - user && - items.find((i) => i.user_created?.id === user.id && i.layer?.itemType.name === userType) + user && items.find((i) => i.user_created?.id === user.id && i.layer?.userProfileLayer) profile ? setUserProfile(profile) : setUserProfile({ id: crypto.randomUUID(), name: user?.first_name ?? '', text: '' }) - // eslint-disable-next-line react-hooks/exhaustive-deps }, [user, items]) // useEffect(() => {}, [userProfile]) diff --git a/src/Components/Gaming/Quests.tsx b/src/Components/Gaming/Quests.tsx index 2d14488d..597f597b 100644 --- a/src/Components/Gaming/Quests.tsx +++ b/src/Components/Gaming/Quests.tsx @@ -29,7 +29,7 @@ export function Quests() { items.find( (i) => i.user_created?.id === user?.id && - i.layer?.itemType.name === 'user' && + i.layer?.userProfileLayer && i.user_created?.id != null, ), ) diff --git a/src/Components/Map/Subcomponents/ItemFormPopup.tsx b/src/Components/Map/Subcomponents/ItemFormPopup.tsx index fa574e24..ef191276 100644 --- a/src/Components/Map/Subcomponents/ItemFormPopup.tsx +++ b/src/Components/Map/Subcomponents/ItemFormPopup.tsx @@ -86,8 +86,7 @@ export function ItemFormPopup(props: ItemFormPopupProps) { map.closePopup() } else { const item = items.find( - (i) => - i.user_created?.id === user?.id && i.layer?.itemType.name === props.layer.itemType.name, + (i) => i.user_created?.id === user?.id && i.layer?.id === props.layer.id, ) const uuid = crypto.randomUUID() @@ -114,7 +113,6 @@ export function ItemFormPopup(props: ItemFormPopupProps) { ...formItem, name: (formItem.name ? formItem.name : user?.first_name) ?? '', user_created: user ?? undefined, - type: props.layer.itemType, id: uuid, layer: props.layer, public_edit: !user, diff --git a/src/Components/Profile/ProfileForm.tsx b/src/Components/Profile/ProfileForm.tsx index d7af5b70..0b109010 100644 --- a/src/Components/Profile/ProfileForm.tsx +++ b/src/Components/Profile/ProfileForm.tsx @@ -3,6 +3,7 @@ /* eslint-disable @typescript-eslint/no-unsafe-argument */ import { useEffect, useState } from 'react' import { useLocation, useNavigate } from 'react-router-dom' +import { toast } from 'react-toastify' import { useAppState } from '#components/AppShell/hooks/useAppState' import { useAuth } from '#components/Auth/useAuth' @@ -76,14 +77,19 @@ export function ProfileForm() { item && setItem(item) if (!item) { - const layer = layers.find((l) => l.itemType.name === appState.userType) - setItem({ - id: crypto.randomUUID(), - name: user?.first_name ?? '', - text: '', - layer, - new: true, - }) + if (items.some((i) => i.user_created?.id === user?.id && i.layer?.userProfileLayer)) { + navigate('/') + toast.error('Item does not exist') + } else { + const layer = layers.find((l) => l.userProfileLayer) + setItem({ + id: crypto.randomUUID(), + name: user?.first_name ?? '', + text: '', + layer, + new: true, + }) + } } // eslint-disable-next-line react-hooks/exhaustive-deps diff --git a/src/Components/Profile/Subcomponents/ContactInfoView.tsx b/src/Components/Profile/Subcomponents/ContactInfoView.tsx index 34e6b8fa..3c11e641 100644 --- a/src/Components/Profile/Subcomponents/ContactInfoView.tsx +++ b/src/Components/Profile/Subcomponents/ContactInfoView.tsx @@ -16,24 +16,9 @@ export const ContactInfoView = ({ item, heading }: { item: Item; heading: string const items = useItems() useEffect(() => { - // eslint-disable-next-line no-console - console.log( - 'user:', - items.find( - (i) => - i.user_created?.id === item.user_created?.id && - i.layer?.itemType.name === appState.userType, - ), - ) - setProfileOwner( - items.find( - (i) => - i.user_created?.id === item.user_created?.id && - i.layer?.itemType.name === appState.userType, - ), + items.find((i) => i.user_created?.id === item.user_created?.id && i.layer?.userProfileLayer), ) - // eslint-disable-next-line react-hooks/exhaustive-deps }, [item, items]) return ( diff --git a/src/Components/Profile/itemFunctions.ts b/src/Components/Profile/itemFunctions.ts index ad11c536..7c7443d0 100644 --- a/src/Components/Profile/itemFunctions.ts +++ b/src/Components/Profile/itemFunctions.ts @@ -273,7 +273,6 @@ export const onUpdateItem = async ( ...changedItem, layer: item.layer, user_created: user, - type: item.layer?.itemType, }), ) .then(() => { diff --git a/src/Components/Templates/AttestationForm.tsx b/src/Components/Templates/AttestationForm.tsx index a127b1d0..edee6d4c 100644 --- a/src/Components/Templates/AttestationForm.tsx +++ b/src/Components/Templates/AttestationForm.tsx @@ -76,7 +76,7 @@ export const AttestationForm = ({ api }: { api?: ItemsApi }) => { (i) => // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access i.user_created?.id === to[0].directus_users_id && - i.layer?.itemType.name === 'player', + i.layer?.userProfileLayer === true, )?.id + '?tab=2', ), diff --git a/src/Components/Templates/SelectUser.tsx b/src/Components/Templates/SelectUser.tsx index 1cd48a9a..770bd1ed 100644 --- a/src/Components/Templates/SelectUser.tsx +++ b/src/Components/Templates/SelectUser.tsx @@ -13,7 +13,7 @@ import { MapOverlayPage } from './MapOverlayPage' export const SelectUser = () => { const appState = useAppState() const items = useItems() - const users = items.filter((i) => i.layer?.itemType.name === appState.userType) + const users = items.filter((i) => i.layer?.userProfileLayer) const [selectedUsers, setSelectedUsers] = useState([]) diff --git a/src/types/Item.d.ts b/src/types/Item.d.ts index 4e84e992..1dd7bde4 100644 --- a/src/types/Item.d.ts +++ b/src/types/Item.d.ts @@ -1,5 +1,4 @@ import type { ItemsApi } from './ItemsApi' -import type { ItemType } from './ItemType' import type { LayerProps } from './LayerProps' import type { Relation } from './Relation' import type { UserItem } from './UserItem' @@ -50,7 +49,6 @@ export interface Item { contact?: string telephone?: string next_appointment?: string - type?: ItemType gallery?: GalleryItem[] // {