Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Ce 1161 #732

Merged
merged 10 commits into from
Nov 7, 2024
38 changes: 12 additions & 26 deletions frontend/cypress/e2e/complaint-filters-ceeb.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,6 @@ describe("Verify CEEB specific search filters work", () => {
cy.kcLogout().kcLogin(Roles.CEEB);
});

function needsDecision() {
let needsDecision = false;
cy.get("#ceeb-decision").then((decisionWrapper) => {
// If the action taken input is on the page, a decision needs to be made
if (decisionWrapper.find("#outcome-decision-action-taken").length > 0) {
needsDecision = true;
}
});
return needsDecision;
}

it.only("allows filtering of complaints by Action Taken", function () {
// Navigate to the complaint list
const complaintWithActionTakenID = "23-030990";
Expand All @@ -30,22 +19,19 @@ describe("Verify CEEB specific search filters work", () => {
cy.navigateToDetailsScreen(COMPLAINT_TYPES.ERS, complaintWithActionTakenID, true);
// If the action taken input is available then the complaint does not yet have a decision made on it.
// Set an action taken so that the filter will have results to return.
if (needsDecision()) {
cy.selectItemById("outcome-decision-schedule-sector", "Other");
cy.selectItemById("outcome-decision-sector-category", "None");
cy.selectItemById("outcome-decision-discharge", "Pesticides");
cy.selectItemById("outcome-decision-action-taken", actionTaken);
cy.selectItemById("outcome-decision-lead-agency", "Other");
cy.enterDateTimeInDatePicker("outcome-decision-outcome-date", "01");
// If the complaint is not assigned to anyone, assign it to self
if (cy.get("#comp-details-assigned-officer-name-text-id").contains("Not Assigned")) {
cy.get("#details-screen-assign-button").should("exist").click();
cy.get("#self_assign_button").should("exist").click();
cy.get("#ceeb-decision").then((decisionWrapper) => {
// If the edit button is on the page, a decision needs to be made
if (!decisionWrapper.find("#decision-edit-button").length) {
cy.selectItemById("outcome-decision-schedule-sector", "Other");
cy.selectItemById("outcome-decision-sector-category", "None");
cy.selectItemById("outcome-decision-discharge", "Pesticides");
cy.selectItemById("outcome-decision-action-taken", actionTaken);
cy.selectItemById("outcome-decision-lead-agency", "Other");
cy.enterDateTimeInDatePicker("outcome-decision-outcome-date", "01");
cy.get("#ceeb-decision > .card-body > .comp-details-form-buttons > #outcome-decision-save-button").click();
cy.contains("div", "Decision added").should("exist");
}
cy.get(".modal").should("not.exist"); // Ensure that the quick assign modal has closed
cy.get("#ceeb-decision > .card-body > .comp-details-form-buttons > #outcome-decision-save-button").click();
cy.contains("div", "Decision added").should("exist");
}
});

// Return to the complaints view
cy.get("#complaints-link").click();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,11 @@ import { CompInput } from "../../../../../common/comp-input";
import { openModal } from "../../../../../../store/reducers/app";
import { CANCEL_CONFIRM } from "../../../../../../types/modal/modal-types";
import { getCaseFile, upsertDecisionOutcome } from "../../../../../../store/reducers/case-thunks";
import {
assignComplaintToOfficer,
selectOfficersByAgency,
selectOfficerListByAgency,
} from "../../../../../../store/reducers/officer";
import { selectCaseId } from "../../../../../../store/reducers/case-selectors";
import { UUID } from "crypto";
import { getComplaintById, selectComplaintCallerInformation } from "../../../../../../store/reducers/complaints";
import { ToggleError } from "../../../../../../common/toast";

import COMPLAINT_TYPES from "../../../../../../types/app/complaint-types";
import { ValidationTextArea } from "../../../../../../common/validation-textarea";

type props = {
officerAssigned: string | null;
leadIdentifier: string;
toggleEdit: Function;
//-- properties
Expand All @@ -51,7 +41,6 @@ type props = {
};

export const DecisionForm: FC<props> = ({
officerAssigned,
leadIdentifier,
toggleEdit,
//--
Expand All @@ -71,6 +60,7 @@ export const DecisionForm: FC<props> = ({

//-- select data from redux
const caseId = useAppSelector(selectCaseId) as UUID;
const current_user = useAppSelector((state) => state.app.profile.idir);

//-- drop-downs
const dischargesOptions = useAppSelector(selectDischargeDropdown);
Expand All @@ -79,9 +69,6 @@ export const DecisionForm: FC<props> = ({
const schedulesOptions = useAppSelector(selectScheduleDropdown);
const decisionTypeOptions = useAppSelector(selectDecisionTypeDropdown);
const leadAgencyOptions = useAppSelector(selectLeadAgencyDropdown);
const { ownedByAgencyCode } = useAppSelector(selectComplaintCallerInformation);
const officerOptions = useAppSelector(selectOfficerListByAgency);
const officersInAgencyList = useAppSelector(selectOfficersByAgency(ownedByAgencyCode?.agency));
const scheduleSectorType = useAppSelector(selectScheduleSectorXref);

//-- error messgaes
Expand All @@ -92,7 +79,6 @@ export const DecisionForm: FC<props> = ({
const [dateActionTakenErrorMessage, setDateActionTakenErrorMessage] = useState("");
const [leadAgencyErrorMessage, setLeadAgencyErrorMessage] = useState("");
const [inspectionNumberErrorMessage, setInspectionNumberErrorMessage] = useState("");
const [assignedToErrorMessage, setAssignedToErrorMessage] = useState("");
const [actionTakenErrorMessage, setActionTakenErrorMessage] = useState("");

//-- component data
Expand All @@ -105,20 +91,13 @@ export const DecisionForm: FC<props> = ({
rationale,
inspectionNumber,
leadAgency,
assignedTo: officerAssigned ?? "",
assignedTo,
actionTaken,
actionTakenDate,
});

const [sectorList, setSectorList] = useState<Array<Option>>();

useEffect(() => {
if (officerAssigned) {
setData({ ...data, assignedTo: officerAssigned });
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [officerAssigned]);

useEffect(() => {
if (sector && schedule) {
let options = scheduleSectorType
Expand All @@ -129,11 +108,12 @@ export const DecisionForm: FC<props> = ({
});
setSectorList(options);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [officerAssigned]);
}, [sector, schedule, scheduleSectorType]);

//-- update the decision state by property
const updateModel = (property: string, value: string | Date | undefined) => {
const model = { ...data, [property]: value };

setData(model);
};

Expand Down Expand Up @@ -176,24 +156,11 @@ export const DecisionForm: FC<props> = ({
result = decisionTypeOptions.find((item) => item.value === actionTaken);
break;
}

case "assignedTo": {
const { assignedTo } = data;
result = officerOptions.find((item) => item.value === assignedTo);
break;
}
}

return !result ? null : result;
};

//-- when setting the assignment this should also update the assignment
//-- of the complaint to the officer being selected in the decision
const updateAssignment = (value?: string) => {
//-- need to get the officer_guid instead of the person
updateModel("assignedTo", value);
};

const handleRationaleChange = (value: string) => {
updateModel("rationale", value.trim());
};
Expand All @@ -217,7 +184,13 @@ export const DecisionForm: FC<props> = ({
const handleActionTakenChange = (value: string) => {
//-- if the action taken changes make sure to clear the
//-- lead agency and inspection number
const update = { ...data, actionTaken: value, leadAgency: undefined, inspectionNumber: undefined };
const update = {
...data,
actionTaken: value,
assignedTo: current_user,
leadAgency: undefined,
inspectionNumber: undefined,
};
setData(update);
};

Expand Down Expand Up @@ -260,7 +233,6 @@ export const DecisionForm: FC<props> = ({
setSectorErrorMessage("");
setDischargeErrorMessage("");
setActionTakenErrorMessage("");
setAssignedToErrorMessage("");
setDateActionTakenErrorMessage("");
setLeadAgencyErrorMessage("");
setInspectionNumberErrorMessage("");
Expand All @@ -273,25 +245,6 @@ export const DecisionForm: FC<props> = ({
if (isValid()) {
dispatch(upsertDecisionOutcome(identifier, data)).then(async (response) => {
if (response === "success") {
//-- update the assignment of the complaint to the selected officer
const { assignedTo } = data;
if (assignedTo && officersInAgencyList) {
const officerAssignedObj = officersInAgencyList.find((officer) => officer.auth_user_guid === assignedTo);

if (officerAssignedObj?.person_guid) {
const result = await dispatch(
assignComplaintToOfficer(leadIdentifier, officerAssignedObj.person_guid.person_guid),
);

if (result) {
//-- update the complaint
dispatch(getComplaintById(leadIdentifier, COMPLAINT_TYPES.ERS));
} else {
ToggleError("Error, unable to to assign officer to complaint");
}
}
}

dispatch(getCaseFile(leadIdentifier));

if (id !== undefined) {
Expand Down Expand Up @@ -325,32 +278,11 @@ export const DecisionForm: FC<props> = ({
};

const _isActionValid = (data: Decision, _isValid: boolean): boolean => {
if (data.actionTaken && (!data.actionTakenDate || !data.assignedTo)) {
if (data.actionTaken && !data.actionTakenDate) {
if (!data.actionTakenDate) {
mikevespi marked this conversation as resolved.
Show resolved Hide resolved
setDateActionTakenErrorMessage("Date required when action taken selected");
_isValid = false;
}

if (!data.assignedTo) {
setAssignedToErrorMessage("Assigned to required when action taken selected");
_isValid = false;
}
}

return _isValid;
};

const _isAssignedToValid = (data: Decision, _isValid: boolean): boolean => {
if (data.assignedTo && (!data.actionTaken || !data.actionTakenDate)) {
if (!data.actionTakenDate) {
setDateActionTakenErrorMessage("Date required when action taken selected");
_isValid = false;
}

if (!data.actionTaken) {
setActionTakenErrorMessage("Action taken required when assigned to is selected");
_isValid = false;
}
}

return _isValid;
Expand All @@ -373,7 +305,6 @@ export const DecisionForm: FC<props> = ({
}

_isValid = _isActionValid(data, _isValid);
_isValid = _isAssignedToValid(data, _isValid);

return _isValid;
};
Expand Down Expand Up @@ -556,27 +487,6 @@ export const DecisionForm: FC<props> = ({
/>
</div>
</div>
<div
className="comp-details-form-row"
id="decision-assigned-to"
>
<label htmlFor="outcome-decision-assigned-to">Assigned to</label>
<div className="comp-details-input full-width">
<CompSelect
id="outcome-decision-assigned-to"
className="comp-details-input"
classNamePrefix="comp-select"
options={officerOptions}
enableValidation={true}
errorMessage={assignedToErrorMessage}
placeholder="Select"
onChange={(evt) => {
updateAssignment(evt?.value);
}}
value={getValue("assignedTo")}
/>
</div>
</div>
<div
className="comp-details-form-row"
id="complaint-outcome-date-div"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
selectScheduleDropdown,
selectDecisionTypeDropdown,
} from "../../../../../../store/reducers/code-table-selectors";
import { selectOfficerListByAgency } from "../../../../../../store/reducers/officer";
import Option from "../../../../../../types/app/option";
import { CASE_ACTION_CODE } from "../../../../../../constants/case_actions";

Expand All @@ -28,15 +27,13 @@ type props = {
};

export const DecisionItem: FC<props> = ({
id,
schedule,
sector,
discharge,
nonCompliance,
rationale,
leadAgency,
inspectionNumber,
assignedTo,
actionTaken,
actionTakenDate,
}) => {
Expand All @@ -48,7 +45,6 @@ export const DecisionItem: FC<props> = ({
const scheduleSectorsOptions = useAppSelector(selectSectorDropdown);
const decisionTypeOptions = useAppSelector(selectDecisionTypeDropdown);
const agencyOptions = useAppSelector(selectLeadAgencyDropdown);
const officerOptions = useAppSelector(selectOfficerListByAgency);

const getValue = (property: string): Option | undefined | null => {
let result: Option | undefined;
Expand Down Expand Up @@ -90,11 +86,6 @@ export const DecisionItem: FC<props> = ({
result = decisionTypeOptions.find((item) => item.value === actionTaken);
break;
}

case "assignedTo": {
result = officerOptions.find((item) => item.value === assignedTo);
break;
}
}

return !result ? null : result;
Expand Down Expand Up @@ -139,11 +130,6 @@ export const DecisionItem: FC<props> = ({
<dt>Rationale</dt>
<dd>{rationale}</dd>
</div>
<div>
<dt>Assigned to</dt>
<dd>{getValue("assignedTo")?.label}</dd>
</div>

<div>
<dt>Date action taken</dt>
<dd>{actionTakenDate !== null && formatDate(new Date(actionTakenDate).toString())}</dd>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { setIsInEdit } from "../../../../../../store/reducers/cases";
import { DecisionForm } from "./decision-form";
import { DecisionItem } from "./decision-item";
import { BsExclamationCircleFill } from "react-icons/bs";
import { assignedOfficerAuthId } from "../../../../../../store/reducers/complaints";

export const CeebDecision: FC = () => {
const { id = "" } = useParams<ComplaintParams>();
Expand All @@ -17,9 +16,6 @@ export const CeebDecision: FC = () => {
//-- select the decision
const data = useAppSelector(selectCaseDecision);

//-- get the officer assigned to the complaint
const officerAssigned = useAppSelector(assignedOfficerAuthId);

const isInEdit = useAppSelector((state) => state.cases.isInEdit);
const [editable, setEditable] = useState(true);
const showSectionErrors = isInEdit.showSectionErrors;
Expand Down Expand Up @@ -52,6 +48,7 @@ export const CeebDecision: FC = () => {
{!editable && (
<div className="comp-details-section-header-actions">
<Button
id="decision-edit-button"
variant="outline-primary"
size="sm"
onClick={() => {
Expand Down Expand Up @@ -84,7 +81,6 @@ export const CeebDecision: FC = () => {
{editable ? (
<DecisionForm
{...data}
officerAssigned={officerAssigned}
leadIdentifier={id}
toggleEdit={setEditable}
/>
Expand Down
Loading
Loading