-
-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: show stats for record (closes #1835)
- Loading branch information
Showing
4 changed files
with
53 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters