Skip to content

Commit

Permalink
Merge pull request #2493 from Amsterdam/bugfix/debriefing-other-theme…
Browse files Browse the repository at this point in the history
…-dynamically

Updated debriefing form
  • Loading branch information
remyvdwereld authored Mar 28, 2024
2 parents ab4bee8 + f629c1d commit 0cccf84
Show file tree
Hide file tree
Showing 3 changed files with 125 additions and 37 deletions.
120 changes: 101 additions & 19 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions src/app/components/case/forms/DebriefForm/DebriefForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -19,7 +19,10 @@ const DebriefCreateForm: React.FC<Props> = ({ 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) => ({
Expand Down
35 changes: 19 additions & 16 deletions src/app/components/case/forms/DebriefForm/scaffold.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,35 @@ 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
}

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 = {
Expand All @@ -53,7 +56,7 @@ export default (
isRequired: true,
name: "violation_result.theme",
label: "Naar welk thema overdragen?",
options: getThemeOptions(themeName)
options: getThemeOptions(themes, themeName)
}
}
}
Expand Down

0 comments on commit 0cccf84

Please sign in to comment.