diff --git a/src/openforms/js/components/admin/form_design/registrations/zgw/OptionalOptionsFieldset.js b/src/openforms/js/components/admin/form_design/registrations/zgw/OptionalOptionsFieldset.js index 156cd40ecd..28fb460d73 100644 --- a/src/openforms/js/components/admin/form_design/registrations/zgw/OptionalOptionsFieldset.js +++ b/src/openforms/js/components/admin/form_design/registrations/zgw/OptionalOptionsFieldset.js @@ -31,7 +31,7 @@ const OptionalOptionsFieldset = ({confidentialityLevelChoices, catalogueUrl}) => - + { + const response = await get(ROLE_TYPES_ENDPOINT, { + zgw_api_group: apiGroupID, + catalogue_url: catalogueUrl, + case_type_identification: caseTypeIdentification, + }); + if (!response.ok) { + throw new Error('Loading available object types failed'); + } + const roleTypes = response.data.sort((a, b) => a.description.localeCompare(b.description)); + return roleTypes.map(({description, descriptionGeneric}) => ({ + value: description, + label: description, + descriptionGeneric: descriptionGeneric, // omschrijvingGeneriek, which is an enum + })); +}; + +// Components + +const MedewerkerRoltype = ({catalogueUrl = ''}) => { + const { + values: {zgwApiGroup = null, caseTypeIdentification = ''}, + } = useFormikContext(); + const [, , fieldHelpers] = useField('medewerkerRoltype'); + const {setValue} = fieldHelpers; + + const { + loading, + value: roleTypes = [], + error, + } = useAsync(async () => { + if (!zgwApiGroup || !catalogueUrl || !caseTypeIdentification) return []; + return await getAvailableRoleTypes(zgwApiGroup, catalogueUrl, caseTypeIdentification); + }, [zgwApiGroup, catalogueUrl, caseTypeIdentification]); + if (error) throw error; -const MedewerkerRoltype = () => { - const [fieldProps] = useField('medewerkerRoltype'); return ( { employees filling in a form for a citizen/company.`} /> } + noManageChildProps > - + { + setValue(selectedOption ? selectedOption.value : ''); + }} + /> ); }; -MedewerkerRoltype.propTypes = {}; +MedewerkerRoltype.propTypes = { + catalogueUrl: PropTypes.string, +}; export default MedewerkerRoltype; diff --git a/src/openforms/js/components/admin/form_design/registrations/zgw/mocks.js b/src/openforms/js/components/admin/form_design/registrations/zgw/mocks.js index 72b5d26331..b4273dfa37 100644 --- a/src/openforms/js/components/admin/form_design/registrations/zgw/mocks.js +++ b/src/openforms/js/components/admin/form_design/registrations/zgw/mocks.js @@ -146,6 +146,23 @@ export const mockDocumenTypesGet = () => return HttpResponse.json(match); }); +// The backend must filter out the 'initiator' as there can only be one. +const ROLE_TYPES = [ + { + description: 'Baliemedewerker', + descriptionGeneric: 'klantcontacter', + }, + { + description: 'Belanghebbende', + descriptionGeneric: 'belanghebbende', + }, +]; + +export const mockRoleTypesGet = () => + http.get(`${API_BASE_URL}/api/v2/registration/plugins/zgw-api/role-types`, () => + HttpResponse.json(ROLE_TYPES) + ); + const PRODUCTS = [ { url: 'https://example.com/product/1234',