Skip to content

Commit

Permalink
feat: open law book
Browse files Browse the repository at this point in the history
  • Loading branch information
casperiv0 committed Sep 25, 2023
1 parent c8286cc commit cf46762
Show file tree
Hide file tree
Showing 9 changed files with 139 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterEnum
ALTER TYPE "Feature" ADD VALUE 'OPEN_LAW_BOOK';
1 change: 1 addition & 0 deletions apps/api/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -1957,6 +1957,7 @@ enum Feature {
REQUIRED_CITIZEN_IMAGE // see #1681
LEO_EDITABLE_CITIZEN_PROFILE // see #1698
ALLOW_MULTIPLE_UNITS_DEPARTMENTS_PER_USER // see #1722
OPEN_LAW_BOOK
}

enum DashboardLayoutCardType {
Expand Down
6 changes: 0 additions & 6 deletions apps/api/src/controllers/admin/admin-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,19 +126,13 @@ export class AdminController {
{ headers: { "user-agent": "SnailyCAD", accept: "application/vnd.github+json" } },
);

console.log({ response });

res.setHeader(
"Cache-Control",
`private, max-age=${ONE_DAY} stale-while-revalidate=${ONE_DAY / 2}`,
);

const body = (await response.body.json()) as { body: string };

console.log({
body,
});

this.changelogBody = body.body;
const json = body.body;
return json;
Expand Down
4 changes: 3 additions & 1 deletion apps/client/locales/en/cad-settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,9 @@
"LEO_EDITABLE_CITIZEN_PROFILE": "LEO Editable Citizen Profile",
"LEO_EDITABLE_CITIZEN_PROFILE-description": "When enabled, this will allow LEO/EMS/FD/Dispatch to edit citizen profiles if the user has the 'Manage Citizen Profile (non-admin)' permission.",
"ALLOW_MULTIPLE_UNITS_DEPARTMENTS_PER_USER": "Allow multiple units with the same callsign and department per user",
"ALLOW_MULTIPLE_UNITS_DEPARTMENTS_PER_USER-description": "When enabled, officers and deputies can create multiple units with the same callsign and department."
"ALLOW_MULTIPLE_UNITS_DEPARTMENTS_PER_USER-description": "When enabled, officers and deputies can create multiple units with the same callsign and department.",
"OPEN_LAW_BOOK": "Open Law Book",
"OPEN_LAW_BOOK-description": "When enabled, this will allow every user to view the CAD's penal codes (Law Book)"
},
"Permissions": {
"defaultPermissions": "Default Permissions",
Expand Down
9 changes: 9 additions & 0 deletions apps/client/locales/en/citizen.json
Original file line number Diff line number Diff line change
Expand Up @@ -146,5 +146,14 @@
"deletePet": "Delete Pet",
"alert_deletePet": "Are you sure you want to delete this pet? This action cannot be undone.",
"alert_deleteNote": "Are you sure you want to delete this note? This action cannot be undone."
},
"LawBook": {
"lawBook": "Law Book",
"warningApplicable": "Warning Applicable",
"warningNotApplicable": "Warning Not Applicable",
"fines": "Fines",
"bail": "Bail",
"jailTime": "Jail Time",
"isPrimary": "Is Primary"
}
}
3 changes: 2 additions & 1 deletion apps/client/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@
"bureauOfFirearms": "Bureau of Firearms",
"emsFdIncidents": "EMS/FD Incidents",
"hospitalServices": "Hospital Services",
"pets": "Pets"
"pets": "Pets",
"lawBook": "Law Book"
},
"Errors": {
"unknown": "An unexpected error occurred",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { useRouter } from "next/router";
import { ChevronDown } from "react-bootstrap-icons";
import { useFeatureEnabled } from "hooks/useFeatureEnabled";
import type { Feature } from "@snailycad/types";
import { useTranslations } from "next-intl";
import {
Button,
Expand Down Expand Up @@ -29,14 +28,19 @@ export function CitizenDropdown() {
href: "/taxi",
show: hasPermissions([Permissions.ViewTaxiCalls, Permissions.ManageTaxiCalls]),
},
{ name: t("bleeter"), href: "/bleeter" },
{ name: t("truckLogs"), href: "/truck-logs" },
{ name: t("business"), href: "/business" },
{ name: t("bleeter"), href: "/bleeter", show: enabled.BLEETER },
{ name: t("truckLogs"), href: "/truck-logs", show: enabled.TRUCK_LOGS },
{ name: t("business"), href: "/business", show: enabled.BUSINESS },
{
name: t("pets"),
href: "/pets",
show: enabled.PETS,
},
{
name: t("lawBook"),
href: "/law-book",
show: enabled.OPEN_LAW_BOOK,
},
];

if (!user) {
Expand Down Expand Up @@ -65,9 +69,7 @@ export function CitizenDropdown() {
<DropdownMenuLinkItem href="/citizen">{t("citizens")}</DropdownMenuLinkItem>

{items.map((item) => {
const upperCase = item.href.replace(/-/g, "_").replace("/", "").toUpperCase() as Feature;

if (!enabled[upperCase]) {
if (!item.show) {
return null;
}

Expand Down
112 changes: 112 additions & 0 deletions apps/client/src/pages/law-book.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
import * as React from "react";
import { Layout } from "components/Layout";
import { getSessionUser } from "lib/auth";
import { getTranslations } from "lib/getTranslation";
import type { GetServerSideProps } from "next";
import { Infofield, TextField } from "@snailycad/ui";
import { useTranslations } from "use-intl";
import { requestAll, yesOrNoText } from "lib/utils";
import { Title } from "components/shared/Title";
import { useValues } from "context/ValuesContext";
import {
getPenalCodeMaxFines,
getPenalCodeMinFines,
} from "components/leo/modals/manage-record/table-item-form";
import { Editor, dataToSlate } from "components/editor/editor";

export default function Taxi() {
const t = useTranslations("LawBook");
const common = useTranslations("Common");
const { penalCode } = useValues();
const [search, setSearch] = React.useState("");

const filteredPenalCodes = React.useMemo(() => {
if (!search) {
return penalCode.values;
}

return penalCode.values.filter((v) => v.title.toLowerCase().includes(search.toLowerCase()));
}, [search, penalCode.values]);

return (
<Layout className="dark:text-white">
<header className="flex items-center justify-between mb-5">
<Title>{t("lawBook")}</Title>
</header>

{penalCode.values.length <= 0 ? (
<p className="mt-5">{t("noPenalCodes")}</p>
) : (
<>
<TextField
label={common("search")}
className="my-2"
name="search"
value={search}
onChange={(value) => setSearch(value)}
/>

<ul className="flex flex-col mt-3 gap-y-2">
{filteredPenalCodes.map((penalCode) => {
const description = dataToSlate(penalCode);
const maxFine = getPenalCodeMaxFines(penalCode);
const minFine = getPenalCodeMinFines(penalCode);
const [minJailTime, maxJailTime] = penalCode.warningNotApplicable?.prisonTerm ?? [];
const [minBail, maxBail] = penalCode.warningNotApplicable?.bail ?? [];

return (
<li className="card p-4" key={penalCode.id}>
<header>
<h3 className="text-2xl font-semibold">{penalCode.title}</h3>

<div className="mt-2">
<Infofield label={common("type")}>
{penalCode.type?.toLowerCase() ?? common("none")}
</Infofield>
<Infofield label={t("isPrimary")}>
{yesOrNoText(penalCode.isPrimary)}
</Infofield>
<Infofield label={t("warningApplicable")}>
{String(Boolean(penalCode.warningApplicable))}
</Infofield>
<Infofield label={t("fines")}>
{minFine}-{maxFine}
</Infofield>
{typeof minJailTime !== "undefined" ? (
<Infofield label={t("jailTime")}>
{minJailTime}-{maxJailTime}
</Infofield>
) : null}
{typeof minBail !== "undefined" ? (
<Infofield label={t("bail")}>
{minBail}-{maxBail}
</Infofield>
) : null}
</div>
</header>

<Editor hideBorder isReadonly value={description} />
</li>
);
})}
</ul>
</>
)}
</Layout>
);
}

export const getServerSideProps: GetServerSideProps = async ({ locale, req }) => {
const user = await getSessionUser(req);
const [values] = await requestAll(req, [["/admin/values/penal_code", []]]);

return {
props: {
values,
session: user,
messages: {
...(await getTranslations(["citizen"], user?.locale ?? locale)),
},
},
};
};
1 change: 1 addition & 0 deletions packages/types/src/enums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export const Feature = {
REQUIRED_CITIZEN_IMAGE: "REQUIRED_CITIZEN_IMAGE",
LEO_EDITABLE_CITIZEN_PROFILE: "LEO_EDITABLE_CITIZEN_PROFILE",
ALLOW_MULTIPLE_UNITS_DEPARTMENTS_PER_USER: "ALLOW_MULTIPLE_UNITS_DEPARTMENTS_PER_USER",
OPEN_LAW_BOOK: "OPEN_LAW_BOOK",
} as const;

export type Feature = (typeof Feature)[keyof typeof Feature];
Expand Down

0 comments on commit cf46762

Please sign in to comment.