Skip to content

Commit

Permalink
refactor: get incident manager user group in configurations
Browse files Browse the repository at this point in the history
  • Loading branch information
deeonwuli committed Nov 13, 2024
1 parent 856f1df commit 8880da2
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 20 deletions.
3 changes: 2 additions & 1 deletion src/CompositionRoot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ function getCompositionRoot(repositories: Repositories) {
),
getConfigurations: new GetConfigurationsUseCase(
repositories.configurationsRepository,
repositories.teamMemberRepository
repositories.teamMemberRepository,
repositories.userGroupRepository
),
complete: new CompleteEventTrackerUseCase(repositories),
},
Expand Down
2 changes: 2 additions & 0 deletions src/domain/entities/AppConfigurations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
Capability1,
Capability2,
} from "./risk-assessment/RiskAssessmentGrading";
import { UserGroup } from "./UserGroup";

export type SelectableOptions = {
eventTrackerConfigurations: DiseaseOutbreakEventOptions;
Expand All @@ -43,6 +44,7 @@ export type SelectableOptions = {
incidentResponseActionConfigurations: IncidentResponseActionOptions;
};
export type Configurations = {
incidentManagerUserGroup: UserGroup;
selectableOptions: SelectableOptions;
teamMembers: {
all: TeamMember[];
Expand Down
16 changes: 14 additions & 2 deletions src/domain/usecases/GetConfigurationsUseCase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,40 @@ 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<Configurations> {
public execute({
incidentManagerUserGroupCode,
}: {
incidentManagerUserGroupCode: Code;
}): FutureData<Configurations> {
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,
incidentResponseOfficers,
managers,
riskAssessors,
selectableOptionsResponse,
incidentManagerUserGroup,
}) => {
const selectableOptions: SelectableOptions =
this.mapOptionsAndTeamMembersToSelectableOptions(
Expand All @@ -36,6 +47,7 @@ export class GetConfigurationsUseCase {

const configurations: Configurations = {
selectableOptions: selectableOptions,
incidentManagerUserGroup: incidentManagerUserGroup,
teamMembers: {
all: allTeamMembers,
riskAssessors: riskAssessors,
Expand Down
1 change: 1 addition & 0 deletions src/utils/tests.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export function getTestContext() {
orgUnits: [],
isDev: true,
configurations: {
incidentManagerUserGroup: { id: "incidentManagerUserGroup" },
selectableOptions: {
eventTrackerConfigurations: {
dataSources: [],
Expand Down
3 changes: 2 additions & 1 deletion src/webapp/pages/app/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ function getResponseActionSection(options: {
type: "select",
multiple: false,
options: verificationOptions,
required: true,
required: isIncidentManager ? true : false,
showIsRequired: true,
disabled: false,
},
Expand Down
20 changes: 5 additions & 15 deletions src/webapp/pages/incident-action-plan/useIncidentActionPlan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -45,7 +44,11 @@ export function useIncidentActionPlan(id: Id) {
const [incidentActionPlan, setIncidentActionPlan] = useState<IncidentActionPlan>();
const [incidentActionExists, setIncidentActionExists] = useState<boolean>(false);
const [incidentActionOptions, setIncidentActionOptions] = useState<UIIncidentActionOptions>();
const [isIncidentManager, setIsIncidentManager] = useState<boolean>(false);

const isIncidentManager = useMemo(
() => currentUser.belongToUserGroup(appConfiguration.incidentManagerUserGroup.id),
[currentUser, appConfiguration]
);

const saveTableOption = useCallback(
(value: Maybe<string>, rowIndex: number, column: TableColumn["value"]) => {
Expand Down Expand Up @@ -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 => {
Expand Down

0 comments on commit 8880da2

Please sign in to comment.