diff --git a/src/Components/Profile/ProfileView.tsx b/src/Components/Profile/ProfileView.tsx index dff33da6..46a6863d 100644 --- a/src/Components/Profile/ProfileView.tsx +++ b/src/Components/Profile/ProfileView.tsx @@ -19,7 +19,7 @@ import { useTags } from '../Map/hooks/useTags'; export function ProfileView({ userType }: { userType: string }) { - const [item, setItem] = useState({} as Item) + const [item, setItem] = useState() const [updatePermission, setUpdatePermission] = useState(false); const [relations, setRelations] = useState>([]); const [offers, setOffers] = useState>([]); @@ -51,15 +51,15 @@ export function ProfileView({ userType }: { userType: string }) { setNeeds([]); setRelations([]); - item.layer?.itemOffersField && getValue(item, item.layer.itemOffersField)?.map(o => { + item?.layer?.itemOffersField && getValue(item, item.layer.itemOffersField)?.map(o => { const tag = tags.find(t => t.id === o.tags_id); tag && setOffers(current => [...current, tag]) }) - item.layer?.itemNeedsField && getValue(item, item.layer.itemNeedsField)?.map(n => { + item?.layer?.itemNeedsField && getValue(item, item.layer.itemNeedsField)?.map(n => { const tag = tags.find(t => t.id === n.tags_id); tag && setNeeds(current => [...current, tag]) }) - item.relations?.map(r => { + item?.relations?.map(r => { const item = items.find(i => i.id == r.related_items_id) item && setRelations(current => [...current, item]) }) @@ -116,7 +116,7 @@ export function ProfileView({ userType }: { userType: string }) { }, [selectPosition]) useEffect(() => { - setTemplate(item.layer?.itemType.template || userType); + setTemplate(item?.layer?.itemType.template || userType); }, [userType, item]) const [urlParams, setUrlParams] = useState(new URLSearchParams(location.search)); @@ -124,7 +124,7 @@ export function ProfileView({ userType }: { userType: string }) { return ( <> - {item && + {item && <>