Skip to content

Commit

Permalink
🎉 feat: able to update more unit data (#369)
Browse files Browse the repository at this point in the history
  • Loading branch information
casperiv0 authored Feb 5, 2022
1 parent c714aab commit 71f5d24
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
4 changes: 3 additions & 1 deletion packages/api/src/controllers/admin/manage/Units.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,9 @@ export class ManageUnitsController {
departmentId: data.department,
divisionId: data.division,
rankId: data.rank || null,
suspended: data.suspended,
suspended: data.suspended ?? false,
callsign2: data.callsign2,
callsign: data.callsign,
},
});

Expand Down
34 changes: 33 additions & 1 deletion packages/client/src/pages/admin/manage/units/[id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import type { OfficerLog } from "@snailycad/types";
import { Toggle } from "components/form/Toggle";
import { Title } from "components/shared/Title";
import { OfficerLogsTable } from "components/leo/logs/OfficerLogsTable";
import { FormRow } from "components/form/FormRow";
import { Input } from "components/form/inputs/Input";

type Unit = (FullOfficer & { logs: OfficerLog[] }) | FullDeputy;

Expand Down Expand Up @@ -63,8 +65,10 @@ export default function SupervisorPanelPage({ unit }: Props) {
division: "divisionId" in unit ? unit.divisionId : "",
divisions: divisions.map((v) => ({ value: v.id, label: v.value.value })) ?? [],
callsign: unit.callsign,
callsign2: unit.callsign2,
rank: unit.rankId,
suspended: unit.suspended,
badgeNumber: unit.badgeNumber ?? "",
};

return (
Expand All @@ -76,7 +80,7 @@ export default function SupervisorPanelPage({ unit }: Props) {
<h1 className="mb-3 text-2xl font-semibold capitalize">{makeUnitName(unit)}</h1>

<Formik onSubmit={onSubmit} initialValues={INITIAL_VALUES}>
{({ handleChange, values }) => (
{({ handleChange, values, errors }) => (
<Form>
<FormField label={t("status")}>
<Select
Expand Down Expand Up @@ -149,6 +153,34 @@ export default function SupervisorPanelPage({ unit }: Props) {
/>
</FormField>

<FormField errorMessage={errors.badgeNumber} label={t("badgeNumber")}>
<Input
type="number"
value={values.badgeNumber}
name="badgeNumber"
onChange={(e) =>
handleChange({
...e,
target: {
...e.target,
id: "badgeNumber",
value: e.target.valueAsNumber,
},
})
}
/>
</FormField>

<FormRow>
<FormField errorMessage={errors.callsign} label={"Callsign Symbol 1"}>
<Input value={values.callsign} name="callsign" onChange={handleChange} />
</FormField>

<FormField errorMessage={errors.callsign2} label={"Callsign Symbol 2"}>
<Input value={values.callsign2} name="callsign2" onChange={handleChange} />
</FormField>
</FormRow>

<FormField label={t("suspended")}>
<Toggle onClick={handleChange} name="suspended" toggled={values.suspended} />
</FormField>
Expand Down
1 change: 1 addition & 0 deletions packages/schemas/src/leo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const CREATE_OFFICER_SCHEMA = z.object({

export const UPDATE_UNIT_SCHEMA = z.object({
callsign: z.string().min(1).max(255),
callsign2: z.string().min(1).max(255),
department: z.string().min(2).max(255),
division: z.string().min(2).max(255).nullable(),
rank: z.string().max(255).nullable(),
Expand Down

0 comments on commit 71f5d24

Please sign in to comment.