diff --git a/src/components/DynamicObject/ObjectArea/ObjectArea.tsx b/src/components/DynamicObject/ObjectArea/ObjectArea.tsx index 575b9871..cd3caf45 100644 --- a/src/components/DynamicObject/ObjectArea/ObjectArea.tsx +++ b/src/components/DynamicObject/ObjectArea/ObjectArea.tsx @@ -1,18 +1,54 @@ import { Heading, Notification, Text } from '@pzh-ui/components' import { LayerGroup, Lightbulb } from '@pzh-ui/icons' -import { Werkingsgebied } from '@/api/fetchers.schemas' +import { + useModulesModuleIdObjectWerkingsgebiedLatestLineageIdGet, + useWerkingsgebiedenLatestLineageIdGet, +} from '@/api/fetchers' +import { WerkingsgebiedStatics } from '@/api/fetchers.schemas' import { LeafletTinyViewer } from '@/components/Leaflet' import { Model } from '@/config/objects/types' -interface ObjectAreaProps extends Werkingsgebied { +interface ObjectAreaProps extends WerkingsgebiedStatics { objectTitle?: string + moduleId?: string model: Model } -const ObjectArea = ({ objectTitle, model, UUID, Title }: ObjectAreaProps) => { +const ObjectArea = ({ + objectTitle, + moduleId, + model, + Object_ID, +}: ObjectAreaProps) => { const { singular, prefixSingular } = model.defaults + const { data: moduleData, isSuccess } = + useModulesModuleIdObjectWerkingsgebiedLatestLineageIdGet( + parseInt(moduleId!), + Object_ID, + { + query: { + enabled: !!moduleId && !!Object_ID, + }, + } + ) + + const { data: validData } = useWerkingsgebiedenLatestLineageIdGet( + Object_ID, + { + query: { + enabled: + (!moduleId && !!Object_ID) || + (!!moduleId && !!Object_ID && !moduleData && isSuccess), + }, + } + ) + + const data = moduleId && isSuccess ? moduleData : validData + + if (!data) return null + return (