diff --git a/src/CompositionRoot.ts b/src/CompositionRoot.ts index d5c4b8c..54f09cb 100644 --- a/src/CompositionRoot.ts +++ b/src/CompositionRoot.ts @@ -110,7 +110,8 @@ function getCompositionRoot(repositories: Repositories) { ), getConfigurations: new GetConfigurationsUseCase( repositories.configurationsRepository, - repositories.teamMemberRepository + repositories.teamMemberRepository, + repositories.userGroupRepository ), complete: new CompleteEventTrackerUseCase(repositories), }, diff --git a/src/domain/entities/AppConfigurations.ts b/src/domain/entities/AppConfigurations.ts index 5e53135..f181a07 100644 --- a/src/domain/entities/AppConfigurations.ts +++ b/src/domain/entities/AppConfigurations.ts @@ -23,6 +23,7 @@ import { Capability1, Capability2, } from "./risk-assessment/RiskAssessmentGrading"; +import { UserGroup } from "./UserGroup"; export type SelectableOptions = { eventTrackerConfigurations: DiseaseOutbreakEventOptions; @@ -43,6 +44,7 @@ export type SelectableOptions = { incidentResponseActionConfigurations: IncidentResponseActionOptions; }; export type Configurations = { + incidentManagerUserGroup: UserGroup; selectableOptions: SelectableOptions; teamMembers: { all: TeamMember[]; diff --git a/src/domain/usecases/GetConfigurationsUseCase.ts b/src/domain/usecases/GetConfigurationsUseCase.ts index 7b6fd86..c0e8f1a 100644 --- a/src/domain/usecases/GetConfigurationsUseCase.ts +++ b/src/domain/usecases/GetConfigurationsUseCase.ts @@ -2,22 +2,32 @@ import { FutureData } from "../../data/api-futures"; import { Configurations, SelectableOptions } from "../entities/AppConfigurations"; import { Future } from "../entities/generic/Future"; import { TeamMember } from "../entities/incident-management-team/TeamMember"; +import { Code } from "../entities/Ref"; import { ConfigurationsRepository } from "../repositories/ConfigurationsRepository"; import { TeamMemberRepository } from "../repositories/TeamMemberRepository"; +import { UserGroupRepository } from "../repositories/UserGroupRepository"; export class GetConfigurationsUseCase { constructor( private configurationsRepository: ConfigurationsRepository, - private teamMemberRepository: TeamMemberRepository + private teamMemberRepository: TeamMemberRepository, + private userGroupRepository: UserGroupRepository ) {} - public execute(): FutureData { + public execute({ + incidentManagerUserGroupCode, + }: { + incidentManagerUserGroupCode: Code; + }): FutureData { return Future.joinObj({ allTeamMembers: this.teamMemberRepository.getAll(), incidentResponseOfficers: this.teamMemberRepository.getIncidentResponseOfficers(), managers: this.teamMemberRepository.getIncidentManagers(), riskAssessors: this.teamMemberRepository.getRiskAssessors(), selectableOptionsResponse: this.configurationsRepository.getSelectableOptions(), + incidentManagerUserGroup: this.userGroupRepository.getUserGroupByCode( + incidentManagerUserGroupCode + ), }).flatMap( ({ allTeamMembers, @@ -25,6 +35,7 @@ export class GetConfigurationsUseCase { managers, riskAssessors, selectableOptionsResponse, + incidentManagerUserGroup, }) => { const selectableOptions: SelectableOptions = this.mapOptionsAndTeamMembersToSelectableOptions( @@ -36,6 +47,7 @@ export class GetConfigurationsUseCase { const configurations: Configurations = { selectableOptions: selectableOptions, + incidentManagerUserGroup: incidentManagerUserGroup, teamMembers: { all: allTeamMembers, riskAssessors: riskAssessors, diff --git a/src/utils/tests.tsx b/src/utils/tests.tsx index e94989b..1ad68ef 100644 --- a/src/utils/tests.tsx +++ b/src/utils/tests.tsx @@ -20,6 +20,7 @@ export function getTestContext() { orgUnits: [], isDev: true, configurations: { + incidentManagerUserGroup: { id: "incidentManagerUserGroup" }, selectableOptions: { eventTrackerConfigurations: { dataSources: [], diff --git a/src/webapp/pages/app/App.tsx b/src/webapp/pages/app/App.tsx index 4d39c89..b7da6f9 100644 --- a/src/webapp/pages/app/App.tsx +++ b/src/webapp/pages/app/App.tsx @@ -18,6 +18,7 @@ import { D2Api } from "../../../types/d2-api"; import "./App.css"; import { CurrentEventTrackerContextProvider } from "../../contexts/CurrentEventTrackerProvider"; import { ExistingEventTrackerTypesProvider } from "../../contexts/ExistingEventTrackerTypes"; +import { RTSL_ZEBRA_INCIDENTMANAGER } from "../../../data/repositories/TeamMemberD2Repository"; export interface AppProps { compositionRoot: CompositionRoot; @@ -38,7 +39,7 @@ function App(props: AppProps) { const orgUnits = await compositionRoot.orgUnits.getAll.execute().toPromise(); const configurations = await compositionRoot.diseaseOutbreakEvent.getConfigurations - .execute() + .execute({ incidentManagerUserGroupCode: RTSL_ZEBRA_INCIDENTMANAGER }) .toPromise(); const isDev = process.env.NODE_ENV === "development"; diff --git a/src/webapp/pages/form-page/incident-action/mapIncidentActionToInitialFormState.ts b/src/webapp/pages/form-page/incident-action/mapIncidentActionToInitialFormState.ts index a6d61d2..492040e 100644 --- a/src/webapp/pages/form-page/incident-action/mapIncidentActionToInitialFormState.ts +++ b/src/webapp/pages/form-page/incident-action/mapIncidentActionToInitialFormState.ts @@ -377,7 +377,7 @@ function getResponseActionSection(options: { type: "select", multiple: false, options: verificationOptions, - required: true, + required: isIncidentManager ? true : false, showIsRequired: true, disabled: false, }, diff --git a/src/webapp/pages/incident-action-plan/useIncidentActionPlan.ts b/src/webapp/pages/incident-action-plan/useIncidentActionPlan.ts index dadd4a5..71b7bcd 100644 --- a/src/webapp/pages/incident-action-plan/useIncidentActionPlan.ts +++ b/src/webapp/pages/incident-action-plan/useIncidentActionPlan.ts @@ -21,7 +21,6 @@ import { Option } from "../../components/utils/option"; import { useCurrentEventTracker } from "../../contexts/current-event-tracker-context"; import { DiseaseOutbreakEvent } from "../../../domain/entities/disease-outbreak-event/DiseaseOutbreakEvent"; import _c from "../../../domain/entities/generic/Collection"; -import { RTSL_ZEBRA_INCIDENTMANAGER } from "../../../data/repositories/TeamMemberD2Repository"; export type IncidentActionFormSummaryData = { subTitle: string; @@ -45,7 +44,11 @@ export function useIncidentActionPlan(id: Id) { const [incidentActionPlan, setIncidentActionPlan] = useState(); const [incidentActionExists, setIncidentActionExists] = useState(false); const [incidentActionOptions, setIncidentActionOptions] = useState(); - const [isIncidentManager, setIsIncidentManager] = useState(false); + + const isIncidentManager = useMemo( + () => currentUser.belongToUserGroup(appConfiguration.incidentManagerUserGroup.id), + [currentUser, appConfiguration] + ); const saveTableOption = useCallback( (value: Maybe, rowIndex: number, column: TableColumn["value"]) => { @@ -131,19 +134,6 @@ export function useIncidentActionPlan(id: Id) { } }, [changeCurrentEventTracker, currentEventTracker, incidentActionExists, incidentActionPlan]); - useEffect(() => { - compositionRoot.userGroup.getByCode.execute(RTSL_ZEBRA_INCIDENTMANAGER).run( - userGroup => { - const isIncidentManager = currentUser.belongToUserGroup(userGroup.id); - setIsIncidentManager(isIncidentManager); - }, - err => { - console.error(err); - setIsIncidentManager(false); - } - ); - }, [compositionRoot.userGroup.getByCode, currentUser]); - const orderByDueDate = useCallback( (direction: "asc" | "desc") => { setResponseActionRows(prevRows => {