Skip to content

Commit

Permalink
feat: show stats for record (closes #1835)
Browse files Browse the repository at this point in the history
  • Loading branch information
casperiv0 committed Oct 11, 2023
1 parent 05f4f60 commit 9652991
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 1 deletion.
3 changes: 2 additions & 1 deletion apps/client/locales/en/leo.json
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,8 @@
"arrestReportLogs": "Arrest report logs",
"all": "All",
"ungrouped": "Ungrouped",
"counts": "Counts"
"counts": "Counts",
"stats": "Stats"
},
"Bolos": {
"activeBolos": "Active Bolos",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import type {
} from "@snailycad/types/api";
import { useQuery } from "@tanstack/react-query";
import { RecordsCaseNumberColumn } from "../records-case-number-column";
import { RecordsStatsColumn } from "../records-stats-column";

interface Props {
arrestReports: GetManagePendingArrestReports;
Expand Down Expand Up @@ -134,6 +135,7 @@ export function PendingCitizenRecordsTab({ arrestReports }: Props) {
<HoverCardContent>{record.notes}</HoverCardContent>
</HoverCard>
),
stats: <RecordsStatsColumn record={record} />,
violations: <ViolationsColumn violations={record.violations} />,
createdAt: createdAt ? <FullDate>{createdAt}</FullDate> : "—",
status: <Status fallback="—">{record.status}</Status>,
Expand Down Expand Up @@ -172,6 +174,7 @@ export function PendingCitizenRecordsTab({ arrestReports }: Props) {
{ header: t("postal"), accessorKey: "postal" },
{ header: t("status"), accessorKey: "status" },
{ header: t("notes"), accessorKey: "notes" },
{ header: t("notes"), accessorKey: "stats" },
{ header: t("violations"), accessorKey: "violations" },
{ header: common("createdAt"), accessorKey: "createdAt" },
{ header: common("actions"), accessorKey: "actions" },
Expand Down
45 changes: 45 additions & 0 deletions apps/client/src/components/leo/records-stats-column.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { Record, Violation } from "@snailycad/types";
import { useTranslations } from "use-intl";

interface Props {
record: Record;
}

function sumOf(violations: Violation[], type: "fine" | "jailTime" | "bail"): number {
let sum = 0;

for (const violation of violations) {
const counts = violation.counts || 1;
const fine = violation[type];

if (fine) {
sum += fine * counts;
}
}

return sum;
}

function formatSum(sum: number) {
return Intl.NumberFormat().format(sum);
}

export function RecordsStatsColumn(props: Props) {
const totalBail = formatSum(sumOf(props.record.violations, "bail"));
const totalJail = formatSum(sumOf(props.record.violations, "jailTime"));
const totalFines = formatSum(sumOf(props.record.violations, "fine"));
const t = useTranslations("Leo");
const common = useTranslations("Common");

return (
<>
<b>{t("fines")}:</b> {common("currency")}
{totalFines}
<br />
<b>{t("jail")}:</b> {totalJail}
<br />
<b>{t("bail")}:</b> {common("currency")}
{totalBail}
</>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import Link from "next/link";
import { FullDate, Status, buttonVariants } from "@snailycad/ui";
import { ArrowLeft } from "react-bootstrap-icons";
import { RecordsCaseNumberColumn } from "components/leo/records-case-number-column";
import { RecordsStatsColumn } from "components/leo/records-stats-column";

export type CitizenLog = RecordLog & { citizen: Citizen };
interface Props {
Expand Down Expand Up @@ -79,6 +80,7 @@ export default function CitizenLogs(props: Props) {
status: <Status fallback="—">{item.records.status}</Status>,
postal: item.records.postal || common("none"),
notes: item.records.notes || common("none"),
stats: <RecordsStatsColumn record={item.records} />,
violations: <ViolationsColumn violations={item.records.violations} />,
paymentStatus: <Status fallback="—">{item.records.paymentStatus}</Status>,
}
Expand Down Expand Up @@ -107,6 +109,7 @@ export default function CitizenLogs(props: Props) {
{ header: t("postal"), accessorKey: "postal" },
{ header: t("status"), accessorKey: "status" },
{ header: t("paymentStatus"), accessorKey: "paymentStatus" },
{ header: t("stats"), accessorKey: "stats" },
{ header: t("notes"), accessorKey: "notes" },
{ header: t("violations"), accessorKey: "violations" },
{ header: common("createdAt"), accessorKey: "createdAt" },
Expand Down

0 comments on commit 9652991

Please sign in to comment.