Skip to content

Commit

Permalink
🚸 [#4606] Present available role types in a dropdown
Browse files Browse the repository at this point in the history
Instead of having to enter the values in a text box, you can now
select them in a dropdown.
  • Loading branch information
sergei-maertens committed Nov 29, 2024
1 parent baa59ec commit 0c5bdc6
Show file tree
Hide file tree
Showing 9 changed files with 124 additions and 9 deletions.
6 changes: 6 additions & 0 deletions src/openforms/js/compiled-lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1237,6 +1237,12 @@
"value": "Confidentiality"
}
],
"AdyBdF": [
{
"type": 0,
"value": "Something went wrong while retrieving the available role types defined in the selected case. Please check that the services in the selected API group are configured correctly."
}
],
"AtBVAV": [
{
"type": 0,
Expand Down
6 changes: 6 additions & 0 deletions src/openforms/js/compiled-lang/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -1241,6 +1241,12 @@
"value": "Vertrouwelijkheidaanduiding"
}
],
"AdyBdF": [
{
"type": 0,
"value": "Something went wrong while retrieving the available role types defined in the selected case. Please check that the services in the selected API group are configured correctly."
}
],
"AtBVAV": [
{
"type": 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ import {
} from 'components/admin/form_design/registrations/objectsapi/mocks';
import {
mockCaseTypesGet,
mockProductsGet,
mockCataloguesGet as mockZGWApisCataloguesGet,
mockDocumenTypesGet as mockZGWApisDocumenTypesGet,
mockProductsGet as mockZGWApisProductsGet,
mockRoleTypesGet as mockZGWApisRoleTypesGet,
} from 'components/admin/form_design/registrations/zgw/mocks';
import {
FormDecorator,
Expand Down Expand Up @@ -511,7 +513,13 @@ export default {
mockObjectsApiCataloguesGet(),
mockDocumentTypesGet(),
],
zgwMocks: [mockZGWApisCataloguesGet(), mockCaseTypesGet(), mockProductsGet()],
zgwMocks: [
mockZGWApisCataloguesGet(),
mockCaseTypesGet(),
mockZGWApisDocumenTypesGet(),
mockZGWApisRoleTypesGet(),
mockZGWApisProductsGet(),
],
camundaMocks: [mockProcessDefinitionsGet()],
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,19 @@ const OptionalOptionsFieldset = ({confidentialityLevelChoices, catalogueUrl}) =>
</div>
<OrganisationRSIN />
<ConfidentialityLevel options={confidentialityLevelChoices} />
<MedewerkerRoltype />

<ErrorBoundary
errorMessage={
<FormattedMessage
description="ZGW APIs registrations options: role type error"
defaultMessage={`Something went wrong while retrieving the available
role types defined in the selected case. Please check that the services in
the selected API group are configured correctly.`}
/>
}
>
<MedewerkerRoltype catalogueUrl={catalogueUrl} />
</ErrorBoundary>

<ErrorBoundary
errorMessage={
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
mockCataloguesGetError,
mockDocumenTypesGet,
mockProductsGet,
mockRoleTypesGet,
} from './mocks';

const NAME = 'form.registrationBackends.0.options';
Expand Down Expand Up @@ -83,6 +84,7 @@ export default {
catalogues: [mockCataloguesGet()],
caseTypes: [mockCaseTypesGet()],
documentTypes: [mockDocumenTypesGet()],
roleTypes: [mockRoleTypesGet()],
products: [mockProductsGet()],
},
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,53 @@
import {useField} from 'formik';
import {useField, useFormikContext} from 'formik';
import PropTypes from 'prop-types';
import {FormattedMessage} from 'react-intl';
import useAsync from 'react-use/esm/useAsync';

import Field from 'components/admin/forms/Field';
import FormRow from 'components/admin/forms/FormRow';
import {TextInput} from 'components/admin/forms/Inputs';
import ReactSelect from 'components/admin/forms/ReactSelect';
import {get} from 'utils/fetch';

// Data fetching

const ROLE_TYPES_ENDPOINT = '/api/v2/registration/plugins/zgw-api/role-types';

const getAvailableRoleTypes = async (apiGroupID, catalogueUrl, caseTypeIdentification) => {
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 (
<FormRow>
<Field
Expand All @@ -24,13 +65,26 @@ const MedewerkerRoltype = () => {
employees filling in a form for a citizen/company.`}
/>
}
noManageChildProps
>
<TextInput id="id_medewerkerRoltype" {...fieldProps} />
<ReactSelect
name="medewerkerRoltype"
options={roleTypes}
isLoading={loading}
isDisabled={!zgwApiGroup || !caseTypeIdentification}
required={false}
isClearable
onChange={selectedOption => {
setValue(selectedOption ? selectedOption.value : '');
}}
/>
</Field>
</FormRow>
);
};

MedewerkerRoltype.propTypes = {};
MedewerkerRoltype.propTypes = {
catalogueUrl: PropTypes.string,
};

export default MedewerkerRoltype;
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
5 changes: 5 additions & 0 deletions src/openforms/js/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,11 @@
"description": "ZGW APIs registration options 'zaakVertrouwelijkheidaanduiding' label",
"originalDefault": "Confidentiality"
},
"AdyBdF": {
"defaultMessage": "Something went wrong while retrieving the available role types defined in the selected case. Please check that the services in the selected API group are configured correctly.",
"description": "ZGW APIs registrations options: role type error",
"originalDefault": "Something went wrong while retrieving the available role types defined in the selected case. Please check that the services in the selected API group are configured correctly."
},
"AtBVAV": {
"defaultMessage": "Confirm",
"description": "Form definition select confirm button",
Expand Down
5 changes: 5 additions & 0 deletions src/openforms/js/lang/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,11 @@
"description": "ZGW APIs registration options 'zaakVertrouwelijkheidaanduiding' label",
"originalDefault": "Confidentiality"
},
"AdyBdF": {
"defaultMessage": "Something went wrong while retrieving the available role types defined in the selected case. Please check that the services in the selected API group are configured correctly.",
"description": "ZGW APIs registrations options: role type error",
"originalDefault": "Something went wrong while retrieving the available role types defined in the selected case. Please check that the services in the selected API group are configured correctly."
},
"AtBVAV": {
"defaultMessage": "Bevestigen",
"description": "Form definition select confirm button",
Expand Down

0 comments on commit 0c5bdc6

Please sign in to comment.