diff --git a/package-lock.json b/package-lock.json index 86fa9e376..610f8ce96 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4884,6 +4884,62 @@ } } }, + "node_modules/@typescript-eslint/parser/node_modules/@typescript-eslint/typescript-estree": { + "version": "5.62.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-5.62.0.tgz", + "integrity": "sha512-CmcQ6uY7b9y694lKdRB8FEel7JbU/40iSAPomu++SjLMntB+2Leay2LO6i8VnJk58MtE9/nQSFIH6jpyRWyYzA==", + "dependencies": { + "@typescript-eslint/types": "5.62.0", + "@typescript-eslint/visitor-keys": "5.62.0", + "debug": "^4.3.4", + "globby": "^11.1.0", + "is-glob": "^4.0.3", + "semver": "^7.3.7", + "tsutils": "^3.21.0" + }, + "engines": { + "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + }, + "peerDependenciesMeta": { + "typescript": { + "optional": true + } + } + }, + "node_modules/@typescript-eslint/parser/node_modules/lru-cache": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", + "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", + "dependencies": { + "yallist": "^4.0.0" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/@typescript-eslint/parser/node_modules/semver": { + "version": "7.6.0", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.6.0.tgz", + "integrity": "sha512-EnwXhrlwXMk9gKu5/flx5sv/an57AkRplG3hTK68W7FRDN+k+OWBj65M7719OkA82XLBxrcX0KSHj+X5COhOVg==", + "dependencies": { + "lru-cache": "^6.0.0" + }, + "bin": { + "semver": "bin/semver.js" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/@typescript-eslint/parser/node_modules/yallist": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", + "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==" + }, "node_modules/@typescript-eslint/scope-manager": { "version": "5.62.0", "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-5.62.0.tgz", @@ -4926,19 +4982,7 @@ } } }, - "node_modules/@typescript-eslint/types": { - "version": "5.62.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-5.62.0.tgz", - "integrity": "sha512-87NVngcbVXUahrRTqIK27gD2t5Cu1yuCXxbLcFtCzZGlfyVWWh8mLHkoxzjsB6DDNnvdL+fW8MiwPEJyGJQDgQ==", - "engines": { - "node": "^12.22.0 || ^14.17.0 || >=16.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/typescript-eslint" - } - }, - "node_modules/@typescript-eslint/typescript-estree": { + "node_modules/@typescript-eslint/type-utils/node_modules/@typescript-eslint/typescript-estree": { "version": "5.62.0", "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-5.62.0.tgz", "integrity": "sha512-CmcQ6uY7b9y694lKdRB8FEel7JbU/40iSAPomu++SjLMntB+2Leay2LO6i8VnJk58MtE9/nQSFIH6jpyRWyYzA==", @@ -4964,7 +5008,7 @@ } } }, - "node_modules/@typescript-eslint/typescript-estree/node_modules/lru-cache": { + "node_modules/@typescript-eslint/type-utils/node_modules/lru-cache": { "version": "6.0.0", "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", @@ -4975,7 +5019,7 @@ "node": ">=10" } }, - "node_modules/@typescript-eslint/typescript-estree/node_modules/semver": { + "node_modules/@typescript-eslint/type-utils/node_modules/semver": { "version": "7.6.0", "resolved": "https://registry.npmjs.org/semver/-/semver-7.6.0.tgz", "integrity": "sha512-EnwXhrlwXMk9gKu5/flx5sv/an57AkRplG3hTK68W7FRDN+k+OWBj65M7719OkA82XLBxrcX0KSHj+X5COhOVg==", @@ -4989,11 +5033,23 @@ "node": ">=10" } }, - "node_modules/@typescript-eslint/typescript-estree/node_modules/yallist": { + "node_modules/@typescript-eslint/type-utils/node_modules/yallist": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==" }, + "node_modules/@typescript-eslint/types": { + "version": "5.62.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-5.62.0.tgz", + "integrity": "sha512-87NVngcbVXUahrRTqIK27gD2t5Cu1yuCXxbLcFtCzZGlfyVWWh8mLHkoxzjsB6DDNnvdL+fW8MiwPEJyGJQDgQ==", + "engines": { + "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + } + }, "node_modules/@typescript-eslint/utils": { "version": "5.62.0", "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-5.62.0.tgz", @@ -5019,6 +5075,32 @@ "eslint": "^6.0.0 || ^7.0.0 || ^8.0.0" } }, + "node_modules/@typescript-eslint/utils/node_modules/@typescript-eslint/typescript-estree": { + "version": "5.62.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-5.62.0.tgz", + "integrity": "sha512-CmcQ6uY7b9y694lKdRB8FEel7JbU/40iSAPomu++SjLMntB+2Leay2LO6i8VnJk58MtE9/nQSFIH6jpyRWyYzA==", + "dependencies": { + "@typescript-eslint/types": "5.62.0", + "@typescript-eslint/visitor-keys": "5.62.0", + "debug": "^4.3.4", + "globby": "^11.1.0", + "is-glob": "^4.0.3", + "semver": "^7.3.7", + "tsutils": "^3.21.0" + }, + "engines": { + "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + }, + "peerDependenciesMeta": { + "typescript": { + "optional": true + } + } + }, "node_modules/@typescript-eslint/utils/node_modules/eslint-scope": { "version": "5.1.1", "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-5.1.1.tgz", @@ -8205,9 +8287,9 @@ "peer": true }, "node_modules/follow-redirects": { - "version": "1.15.5", - "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.5.tgz", - "integrity": "sha512-vSFWUON1B+yAw1VN4xMfxgn5fTUiaOzAJCKBwIIgT/+7CuGy9+r+5gITvP62j3RmaD5Ph65UaERdOSRGUzZtgw==", + "version": "1.15.6", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.6.tgz", + "integrity": "sha512-wWN62YITEaOpSK584EZXJafH1AGpO8RVgElfkuXbTOrPX4fIfOyEpW/CsiNd8JdYrAoOvafRTOEnvsO++qCqFA==", "funding": [ { "type": "individual", diff --git a/src/app/components/case/forms/DebriefForm/DebriefForm.tsx b/src/app/components/case/forms/DebriefForm/DebriefForm.tsx index 53677ed23..c810dab6a 100644 --- a/src/app/components/case/forms/DebriefForm/DebriefForm.tsx +++ b/src/app/components/case/forms/DebriefForm/DebriefForm.tsx @@ -3,7 +3,7 @@ import { FormTitle } from "@amsterdam/asc-ui" import scaffold from "./scaffold" import useScaffoldedFields from "app/components/shared/ConfirmScaffoldForm/hooks/useScaffoldedFields" import WorkflowForm from "app/components/case/WorkflowForm/WorkflowForm" -import { useCase, useDebriefingCreate, useViolationTypes } from "app/state/rest" +import { useCase, useCaseThemes, useDebriefingCreate, useViolationTypes } from "app/state/rest" import useNavigation from "app/routing/useNavigation" type Props = { @@ -19,7 +19,10 @@ const DebriefCreateForm: React.FC = ({ id, caseUserTaskId }) => { const violationTypes = data?.results const [, { execPost }] = useDebriefingCreate() const { navigateTo } = useNavigation() - const fields = useScaffoldedFields(scaffold, id, navigateTo, violationTypes, themeName) + const [themesData] = useCaseThemes() + const fields = useScaffoldedFields( + scaffold, id, navigateTo, violationTypes, themesData?.results ?? [], themeName + ) // Nuisance is an array but a boolean is expected. const mapData = (data: any) => ({ diff --git a/src/app/components/case/forms/DebriefForm/scaffold.tsx b/src/app/components/case/forms/DebriefForm/scaffold.tsx index 04aabdf45..375169450 100644 --- a/src/app/components/case/forms/DebriefForm/scaffold.tsx +++ b/src/app/components/case/forms/DebriefForm/scaffold.tsx @@ -4,22 +4,25 @@ import InfoButton from "app/components/shared/InfoHeading/InfoButton" import InfoContent from "./components/InfoContent" import type { NavigateToFunction } from "app/routing/useNavigation" -const options = { - "-": "-", - "Kamerverhuur": "Kamerverhuur", - "Leegstand": "Leegstand", - "Onderhuur": "Onderhuur", - "Ondermijning": "Ondermijning", - "Vakantieverhuur": "Vakantieverhuur", - "Woningverbetering": "Woningverbetering" + +const createObjectFromArray = (arr: any) => { + const obj: any = {} + arr.forEach((item: any) => { + obj[item] = item + }) + return obj } -// Remove current theme from options -const getThemeOptions = (themeName?: string) => { - if (themeName !== undefined) { - const { [themeName]: remove, ...rest }: any = options - return rest - } +const getThemeOptions = (themes: Components.Schemas.CaseTheme[], themeName?: string) => { + const optionsArray: any = [ "-", "Woningverbetering" ] + themes.forEach((theme) => { + // Remove current theme from options + if (theme.name !== themeName) { + optionsArray.push([theme.name]) + } + }) + optionsArray.sort() + const options = createObjectFromArray(optionsArray) return options } @@ -27,9 +30,9 @@ export default ( caseId: Components.Schemas.CaseDetail["id"], navigateTo: NavigateToFunction, violationTypes: Components.Schemas.PaginatedViolationTypeList["results"], + themes: Components.Schemas.CaseTheme[], themeName?: string ) => { - const violationOptions = violationTypes?.reduce((acc, item) => ({ ...acc, [item.key]: [item.value] }), {}) const fields = { @@ -53,7 +56,7 @@ export default ( isRequired: true, name: "violation_result.theme", label: "Naar welk thema overdragen?", - options: getThemeOptions(themeName) + options: getThemeOptions(themes, themeName) } } }