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 (
@@ -20,7 +56,7 @@ const ObjectArea = ({ objectTitle, model, UUID, Title }: ObjectAreaProps) => { {prefixSingular} {singular} ‘{objectTitle}’ heeft als - werkingsgebied ‘{Title}’. + werkingsgebied ‘{data.Title}’. @@ -35,7 +71,7 @@ const ObjectArea = ({ objectTitle, model, UUID, Title }: ObjectAreaProps) => {
- +
) diff --git a/src/pages/protected/DynamicObject/ObjectEdit/ObjectEdit.tsx b/src/pages/protected/DynamicObject/ObjectEdit/ObjectEdit.tsx index f2d5c52f..3240db55 100644 --- a/src/pages/protected/DynamicObject/ObjectEdit/ObjectEdit.tsx +++ b/src/pages/protected/DynamicObject/ObjectEdit/ObjectEdit.tsx @@ -142,14 +142,21 @@ const ObjectEdit = ({ model }: ObjectEditProps) => { onCancel={() => navigate(`/muteer/modules/${moduleId}`)} isLocked={isLocked} isLoading={isLoading || moduleIsLoading} - defaultValues={ - object?.Hierarchy_Statics && { + defaultValues={{ + ...(object?.Hierarchy_Statics && { Hierarchy_Code: { label: object?.Hierarchy_Statics?.Cached_Title, value: object?.Hierarchy_Statics?.Code, }, - } - } + }), + ...(object?.Werkingsgebied_Statics && { + Werkingsgebied_Code: { + label: object?.Werkingsgebied_Statics + ?.Cached_Title, + value: object?.Werkingsgebied_Statics?.Code, + }, + }), + }} /> diff --git a/src/pages/public/DynamicObject/DynamicObject.tsx b/src/pages/public/DynamicObject/DynamicObject.tsx index ef364f1e..2c8e0f2e 100644 --- a/src/pages/public/DynamicObject/DynamicObject.tsx +++ b/src/pages/public/DynamicObject/DynamicObject.tsx @@ -221,12 +221,13 @@ const DynamicObject = ({ model, isRevision }: DynamicObjectProps) => { /> - {data?.Gebied && ( + {data?.Werkingsgebied_Statics && (
)}