diff --git a/apps/api/prisma/migrations/20230925141841_open_law_book/migration.sql b/apps/api/prisma/migrations/20230925141841_open_law_book/migration.sql new file mode 100644 index 000000000..bf61934e6 --- /dev/null +++ b/apps/api/prisma/migrations/20230925141841_open_law_book/migration.sql @@ -0,0 +1,2 @@ +-- AlterEnum +ALTER TYPE "Feature" ADD VALUE 'OPEN_LAW_BOOK'; diff --git a/apps/api/prisma/schema.prisma b/apps/api/prisma/schema.prisma index 89415b9b7..7469980ef 100644 --- a/apps/api/prisma/schema.prisma +++ b/apps/api/prisma/schema.prisma @@ -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 { diff --git a/apps/api/src/controllers/admin/admin-controller.ts b/apps/api/src/controllers/admin/admin-controller.ts index d889462b1..5449e6673 100644 --- a/apps/api/src/controllers/admin/admin-controller.ts +++ b/apps/api/src/controllers/admin/admin-controller.ts @@ -126,8 +126,6 @@ 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}`, @@ -135,10 +133,6 @@ export class AdminController { const body = (await response.body.json()) as { body: string }; - console.log({ - body, - }); - this.changelogBody = body.body; const json = body.body; return json; diff --git a/apps/client/locales/en/cad-settings.json b/apps/client/locales/en/cad-settings.json index ac227fce3..760fb64ae 100644 --- a/apps/client/locales/en/cad-settings.json +++ b/apps/client/locales/en/cad-settings.json @@ -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", diff --git a/apps/client/locales/en/citizen.json b/apps/client/locales/en/citizen.json index fd056bcd0..96c73e2cd 100644 --- a/apps/client/locales/en/citizen.json +++ b/apps/client/locales/en/citizen.json @@ -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" } } diff --git a/apps/client/locales/en/common.json b/apps/client/locales/en/common.json index 7ccfd3bf6..2b6beb7fa 100644 --- a/apps/client/locales/en/common.json +++ b/apps/client/locales/en/common.json @@ -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", diff --git a/apps/client/src/components/shared/nav/dropdowns/citizen-dropdown.tsx b/apps/client/src/components/shared/nav/dropdowns/citizen-dropdown.tsx index 27b170a6d..b32ebb35e 100644 --- a/apps/client/src/components/shared/nav/dropdowns/citizen-dropdown.tsx +++ b/apps/client/src/components/shared/nav/dropdowns/citizen-dropdown.tsx @@ -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, @@ -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) { @@ -65,9 +69,7 @@ export function CitizenDropdown() { {t("citizens")} {items.map((item) => { - const upperCase = item.href.replace(/-/g, "_").replace("/", "").toUpperCase() as Feature; - - if (!enabled[upperCase]) { + if (!item.show) { return null; } diff --git a/apps/client/src/pages/law-book.tsx b/apps/client/src/pages/law-book.tsx new file mode 100644 index 000000000..c77e80d2f --- /dev/null +++ b/apps/client/src/pages/law-book.tsx @@ -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 ( + +
+ {t("lawBook")} +
+ + {penalCode.values.length <= 0 ? ( +

{t("noPenalCodes")}

+ ) : ( + <> + setSearch(value)} + /> + + + + )} +
+ ); +} + +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)), + }, + }, + }; +}; diff --git a/packages/types/src/enums.ts b/packages/types/src/enums.ts index fc22676f7..2da6c1eeb 100644 --- a/packages/types/src/enums.ts +++ b/packages/types/src/enums.ts @@ -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];