diff --git a/src/Components/Profile/Subcomponents/ProfileTextView.tsx b/src/Components/Profile/Subcomponents/ProfileTextView.tsx
index a9604a69..5dfa9cf2 100644
--- a/src/Components/Profile/Subcomponents/ProfileTextView.tsx
+++ b/src/Components/Profile/Subcomponents/ProfileTextView.tsx
@@ -4,24 +4,22 @@ import type { Item } from '#types/Item'
export const ProfileTextView = ({
item,
- dataField,
+ text,
heading,
hideWhenEmpty,
}: {
item: Item
- dataField: string
+ text: string
heading: string
hideWhenEmpty: boolean
}) => {
return (
- {/* eslint-disable-next-line security/detect-object-injection */}
- {!(item[dataField] === '' && hideWhenEmpty) && (
+ {!(text === '' && hideWhenEmpty) && (
{heading}
)}
- {/* eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, security/detect-object-injection */}
-
+
)
diff --git a/src/Components/Profile/Templates/FlexView.tsx b/src/Components/Profile/Templates/FlexView.tsx
index c25b85f3..eeb95888 100644
--- a/src/Components/Profile/Templates/FlexView.tsx
+++ b/src/Components/Profile/Templates/FlexView.tsx
@@ -1,18 +1,51 @@
-/* eslint-disable @typescript-eslint/no-unsafe-assignment */
-
import { ContactInfoView } from '#components/Profile/Subcomponents/ContactInfoView'
import { GroupSubHeaderView } from '#components/Profile/Subcomponents/GroupSubHeaderView'
import { ProfileStartEndView } from '#components/Profile/Subcomponents/ProfileStartEndView'
import { ProfileTextView } from '#components/Profile/Subcomponents/ProfileTextView'
import type { Item } from '#types/Item'
-import type { Key } from 'react'
+import type {
+ ContactInfoParameters,
+ GroupSubHeaderParameters,
+ Parameters,
+ TextParameters,
+} from '#types/ItemType'
-const componentMap = {
- groupSubheaders: GroupSubHeaderView,
- texts: ProfileTextView,
- contactInfos: ContactInfoView,
- startEnd: ProfileStartEndView,
+const componentMap: Record<
+ string,
+ ((item: Item, parameters: Parameters) => JSX.Element) | undefined
+> = {
+ groupSubheaders: (item: Item, parameters: GroupSubHeaderParameters) => (
+
+ ),
+ texts: (item: Item, parameters: TextParameters) => {
+ if (!(parameters.dataField in item)) {
+ throw new Error(`Item does not have property ${parameters.dataField}`)
+ }
+
+ const text = item[parameters.dataField]
+
+ if (typeof text !== 'string') {
+ throw new Error(`Property ${parameters.dataField} is not a string`)
+ }
+
+ return (
+
+ )
+ },
+ contactInfos: (item: Item, parameters: ContactInfoParameters) => (
+
+ ),
+ startEnd: (item: Item) => ,
// weitere Komponenten hier
}
@@ -21,17 +54,14 @@ export const FlexView = ({ item }: { item: Item }) => {
console.log(item)
return (
- {item.layer?.itemType.profileTemplate.map(
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
- (templateItem: { collection: string | number; id: Key | null | undefined; item: any }) => {
- const TemplateComponent = componentMap[templateItem.collection]
- return TemplateComponent ? (
-
- ) : (
-
Component not found
- )
- },
- )}
+ {item.layer?.itemType.profileTemplate.map((templateItem) => {
+ const TemplateComponent = componentMap[templateItem.collection]
+ return TemplateComponent ? (
+ TemplateComponent(item, templateItem.item)
+ ) : (
+
Component not found
+ )
+ })}
)
}
diff --git a/types/Item.d.ts b/types/Item.d.ts
index 880cc9fc..2c01e713 100644
--- a/types/Item.d.ts
+++ b/types/Item.d.ts
@@ -7,7 +7,7 @@ import type { Point } from 'geojson'
type TagIds = { tags_id: string }[]
-export interface Item {
+interface BaseItem {
id: string
name: string
text: string
@@ -40,22 +40,6 @@ export interface Item {
telephone?: string
next_appointment?: string
type?: ItemType
-
- // {
- // coordinates: [number, number]
- /* constructor(
- id: string,
- name: string,
- text: string,
- position: Geometry,
- layer?: LayerProps,
- api?: ItemsApi,
- ) {
- this.id = id
- this.name = name
- this.text = text
- this.position = position
- this.layer = layer
- this.api = api
- } */
}
+
+export type Item = BaseItem & Record
diff --git a/types/ItemType.d.ts b/types/ItemType.d.ts
index 9a4f621c..05b1b7f8 100644
--- a/types/ItemType.d.ts
+++ b/types/ItemType.d.ts
@@ -1,11 +1,35 @@
import type { Key } from 'react'
+interface TextParameters {
+ dataField: string
+ heading: string
+ hideWhenEmpty: boolean
+}
+
+interface GroupSubHeaderParameters {
+ shareBaseUrl: string
+ platforms: string[]
+}
+
+interface ContactInfoParameters {
+ heading: string
+}
+
+interface StartEndParemeters {
+ heading: string
+}
+
+export type Parameters =
+ | TextParameters
+ | GroupSubHeaderParameters
+ | ContactInfoParameters
+ | StartEndParemeters
+
export interface ItemType {
name: string
show_start_end: boolean
show_text: boolean
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
- profileTemplate: { collection: string | number; id: Key | null | undefined; item: any }[]
+ profileTemplate: { collection: string | number; id: Key | null | undefined; item: Parameters }[]
offers_and_needs: boolean
icon_as_labels: unknown
relations: boolean