Skip to content

Commit

Permalink
🐛 fix: not able to select involved officers with incidents (closes #273)
Browse files Browse the repository at this point in the history
  • Loading branch information
casperiv0 committed Jan 11, 2022
1 parent 934bbf3 commit ccc2772
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 9 deletions.
6 changes: 5 additions & 1 deletion packages/api/src/controllers/leo/IncidentController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ export class IncidentController {
},
});

return incidents;
const officers = await prisma.officer.findMany({
include: leoProperties,
});

return { incidents, officers };
}

@UseBefore(ActiveOfficer)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { LEO_INCIDENT_SCHEMA } from "@snailycad/schemas";
import { Button } from "components/Button";
import { FormField } from "components/form/FormField";
import { Select } from "components/form/Select";
import { Select, SelectValue } from "components/form/Select";
import { Loader } from "components/Loader";
import { Modal } from "components/modal/Modal";
import { useModal } from "context/ModalContext";
Expand Down Expand Up @@ -31,9 +31,14 @@ export function CreateIncidentModal() {
const { allOfficers } = useDispatchState();

async function onSubmit(values: typeof INITIAL_VALUES) {
const data = {
...values,
involvedOfficers: values.involvedOfficers.map((v) => v.value),
};

const { json } = await execute("/incidents", {
method: "POST",
data: values,
data,
});

if (json.id) {
Expand All @@ -48,7 +53,7 @@ export function CreateIncidentModal() {
const validate = handleValidate(LEO_INCIDENT_SCHEMA);
const INITIAL_VALUES = {
description: "",
involvedOfficers: [],
involvedOfficers: [] as SelectValue[],
firearmsInvolved: false,
injuriesOrFatalities: false,
arrestsMade: false,
Expand All @@ -69,6 +74,7 @@ export function CreateIncidentModal() {
label={t("involvedOfficers")}
>
<Select
isMulti
value={values.involvedOfficers}
name="involvedOfficers"
onChange={handleChange}
Expand Down
4 changes: 2 additions & 2 deletions packages/client/src/pages/officer/call-history.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,9 @@ export default function CallHistory({ data: calls, incidents }: Props) {
}

export const getServerSideProps: GetServerSideProps = async ({ req, locale }) => {
const [calls, incidents] = await requestAll(req, [
const [calls, { incidents }] = await requestAll(req, [
["/911-calls?includeEnded=true", []],
["/incidents", []],
["/incidents", [{ incidents: [] }]],
]);

return {
Expand Down
9 changes: 6 additions & 3 deletions packages/client/src/pages/officer/incidents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ export default function LeoIncidents({ officers, activeOfficer, incidents }: Pro
<p className="mt-5">{t("noIncidents")}</p>
) : (
<Table
defaultSort={{
columnId: "caseNumber",
descending: true,
}}
data={incidents.map((incident) => ({
caseNumber: `#${incident.caseNumber}`,
officer: (
Expand Down Expand Up @@ -174,10 +178,9 @@ export default function LeoIncidents({ officers, activeOfficer, incidents }: Pro
}

export const getServerSideProps: GetServerSideProps = async ({ req, locale }) => {
const [incidents, activeOfficer, { officers }] = await requestAll(req, [
["/incidents", []],
const [{ incidents, officers }, activeOfficer] = await requestAll(req, [
["/incidents", [{ officers: [], incidents: [] }]],
["/leo/active-officer", null],
["/leo", { officers: [] }],
]);

return {
Expand Down

0 comments on commit ccc2772

Please sign in to comment.