From 3dfeb73b4d5f2cdfc6e3f2a79ff51b3be7a18c75 Mon Sep 17 00:00:00 2001 From: casperiv0 <53900565+casperiv0@users.noreply.github.com> Date: Mon, 16 Oct 2023 17:34:17 +0200 Subject: [PATCH 1/2] chore: improved citizen logs --- .../manage/citizens/records-logs-controller.ts | 12 ++++++------ ...ts-tab.tsx => pending-citizen-logs-tab.tsx} | 18 +++++++++--------- .../officer/supervisor/citizen-logs/index.tsx | 10 +++++----- packages/types/src/api/admin.ts | 6 +++--- 4 files changed, 23 insertions(+), 23 deletions(-) rename apps/client/src/components/leo/citizen-logs/{arrest-reports-tab.tsx => pending-citizen-logs-tab.tsx} (92%) diff --git a/apps/api/src/controllers/admin/manage/citizens/records-logs-controller.ts b/apps/api/src/controllers/admin/manage/citizens/records-logs-controller.ts index eb369c837..621719d2f 100644 --- a/apps/api/src/controllers/admin/manage/citizens/records-logs-controller.ts +++ b/apps/api/src/controllers/admin/manage/citizens/records-logs-controller.ts @@ -75,7 +75,7 @@ export class AdminManageCitizensController { return { citizens, totalCount }; } - @Get("/pending-arrest-reports") + @Get("/pending-citizen-records") @Description("Get all the record logs within the CAD") @UsePermissions({ permissions: [ @@ -85,11 +85,11 @@ export class AdminManageCitizensController { Permissions.ViewCitizenLogs, ], }) - async getPendingArrestReports( + async getPendingCitizenRecords( @QueryParams("skip", Number) skip = 0, @QueryParams("includeAll", Boolean) includeAll = false, - ): Promise { - const [totalCount, arrestReports] = await prisma.$transaction([ + ): Promise { + const [totalCount, pendingCitizenRecords] = await prisma.$transaction([ prisma.recordLog.count({ where: { records: { status: WhitelistStatus.PENDING } }, }), @@ -109,7 +109,7 @@ export class AdminManageCitizensController { }), ]); - return { arrestReports, totalCount }; + return { pendingCitizenRecords, totalCount }; } @Get("/records-logs/:citizenId") @@ -146,7 +146,7 @@ export class AdminManageCitizensController { @UsePermissions({ permissions: [Permissions.ManageCitizens, Permissions.ViewCitizenLogs], }) - async acceptOrDeclineArrestReport( + async acceptOrDeclinePendingCitizenLog( @PathParams("id") id: string, @BodyParams("type") type: AcceptDeclineType | null, ): Promise { diff --git a/apps/client/src/components/leo/citizen-logs/arrest-reports-tab.tsx b/apps/client/src/components/leo/citizen-logs/pending-citizen-logs-tab.tsx similarity index 92% rename from apps/client/src/components/leo/citizen-logs/arrest-reports-tab.tsx rename to apps/client/src/components/leo/citizen-logs/pending-citizen-logs-tab.tsx index 06223fa80..3303ce3d8 100644 --- a/apps/client/src/components/leo/citizen-logs/arrest-reports-tab.tsx +++ b/apps/client/src/components/leo/citizen-logs/pending-citizen-logs-tab.tsx @@ -19,7 +19,7 @@ import { ManageRecordModal } from "../modals/manage-record/manage-record-modal"; import useFetch from "lib/useFetch"; import { ViolationsColumn } from "../ViolationsColumn"; import type { - GetManagePendingArrestReports, + GetManagePendingCitizenRecords, PostCitizenRecordLogsData, } from "@snailycad/types/api"; import { useQuery } from "@tanstack/react-query"; @@ -27,7 +27,7 @@ import { RecordsCaseNumberColumn } from "../records-case-number-column"; import { RecordsStatsColumn } from "../records-stats-column"; interface Props { - arrestReports: GetManagePendingArrestReports; + pendingCitizenRecords: GetManagePendingCitizenRecords; } const TYPE_LABELS = { @@ -36,7 +36,7 @@ const TYPE_LABELS = { [RecordType.WRITTEN_WARNING]: "Written Warning", }; -export function PendingCitizenRecordsTab({ arrestReports }: Props) { +export function PendingCitizenRecordsTab({ pendingCitizenRecords }: Props) { const [tempRecord, setTempRecord] = React.useState(null); const { data, isLoading, refetch } = useQuery({ @@ -54,14 +54,14 @@ export function PendingCitizenRecordsTab({ arrestReports }: Props) { const asyncTable = useAsyncTable({ getKey: (item) => item.recordId ?? item.warrantId ?? item.id, fetchOptions: { - onResponse: (data: GetManagePendingArrestReports) => ({ - data: data.arrestReports, + onResponse: (data: GetManagePendingCitizenRecords) => ({ + data: data.pendingCitizenRecords, totalCount: data.totalCount, }), - path: "/admin/manage/pending-arrest-reports", + path: "/admin/manage/pending-citizen-records", }, - totalCount: arrestReports.totalCount, - initialData: arrestReports.arrestReports, + totalCount: pendingCitizenRecords.totalCount, + initialData: pendingCitizenRecords.pendingCitizenRecords, }); const modalState = useModal(); @@ -71,7 +71,7 @@ export function PendingCitizenRecordsTab({ arrestReports }: Props) { const { state, execute } = useFetch(); const tableState = useTableState(); - function handleViewClick(item: GetManagePendingArrestReports["arrestReports"][number]) { + function handleViewClick(item: GetManagePendingCitizenRecords["pendingCitizenRecords"][number]) { setTempRecord(item.records!); modalState.openModal(ModalIds.ManageRecord, { diff --git a/apps/client/src/pages/officer/supervisor/citizen-logs/index.tsx b/apps/client/src/pages/officer/supervisor/citizen-logs/index.tsx index ca54db867..ef749d945 100644 --- a/apps/client/src/pages/officer/supervisor/citizen-logs/index.tsx +++ b/apps/client/src/pages/officer/supervisor/citizen-logs/index.tsx @@ -9,14 +9,14 @@ import { Title } from "components/shared/Title"; import { Permissions } from "@snailycad/permissions"; import { TabList } from "@snailycad/ui"; import { CitizenLogsTab } from "components/leo/citizen-logs/citizen-logs-tab"; -import { PendingCitizenRecordsTab } from "components/leo/citizen-logs/arrest-reports-tab"; +import { PendingCitizenRecordsTab } from "components/leo/citizen-logs/pending-citizen-logs-tab"; import { useFeatureEnabled } from "hooks/useFeatureEnabled"; -import type { GetManagePendingArrestReports, GetManageRecordLogsData } from "@snailycad/types/api"; +import type { GetManagePendingCitizenRecords, GetManageRecordLogsData } from "@snailycad/types/api"; export type CitizenLog = RecordLog & { citizen: Citizen }; interface Props { citizens: GetManageRecordLogsData; - pendingCitizenRecords: GetManagePendingArrestReports; + pendingCitizenRecords: GetManagePendingCitizenRecords; } export default function CitizenLogs(props: Props) { @@ -47,7 +47,7 @@ export default function CitizenLogs(props: Props) { {CITIZEN_RECORD_APPROVAL ? ( - + ) : null} @@ -58,7 +58,7 @@ export const getServerSideProps: GetServerSideProps = async ({ req, locale }) => const user = await getSessionUser(req); const [citizens, pendingCitizenRecords] = await requestAll(req, [ ["/admin/manage/records-logs", { citizens: [], totalCount: 0 }], - ["/admin/manage/pending-arrest-reports", { pendingCitizenRecords: [], totalCount: 0 }], + ["/admin/manage/pending-citizen-records", { pendingCitizenRecords: [], totalCount: 0 }], ]); return { diff --git a/packages/types/src/api/admin.ts b/packages/types/src/api/admin.ts index 4f7485929..6f25a308f 100644 --- a/packages/types/src/api/admin.ts +++ b/packages/types/src/api/admin.ts @@ -153,11 +153,11 @@ export interface GetManageRecordLogsData { /** * @method GET - * @route /admin/manage/citizens/pending-arrest-reports + * @route /admin/manage/citizens/pending-citizen-records */ -export interface GetManagePendingArrestReports { +export interface GetManagePendingCitizenRecords { totalCount: number; - arrestReports: GetManageRecordsLogsCitizenData["recordsLogs"]; + pendingCitizenRecords: GetManageRecordsLogsCitizenData["recordsLogs"]; } /** From 10cfe05bdcb0b0b258765282c9551afb504d9584 Mon Sep 17 00:00:00 2001 From: casperiv0 <53900565+casperiv0@users.noreply.github.com> Date: Mon, 16 Oct 2023 17:48:21 +0200 Subject: [PATCH 2/2] feat: able to edit a records before approval --- .../leo/citizen-logs/pending-citizen-logs-tab.tsx | 14 ++++++++++---- .../modals/manage-record/manage-record-modal.tsx | 1 + .../src/hooks/shared/table/use-async-table.ts | 3 ++- .../officer/supervisor/citizen-logs/index.tsx | 5 ++++- 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/apps/client/src/components/leo/citizen-logs/pending-citizen-logs-tab.tsx b/apps/client/src/components/leo/citizen-logs/pending-citizen-logs-tab.tsx index 3303ce3d8..3cc56dbb8 100644 --- a/apps/client/src/components/leo/citizen-logs/pending-citizen-logs-tab.tsx +++ b/apps/client/src/components/leo/citizen-logs/pending-citizen-logs-tab.tsx @@ -71,7 +71,7 @@ export function PendingCitizenRecordsTab({ pendingCitizenRecords }: Props) { const { state, execute } = useFetch(); const tableState = useTableState(); - function handleViewClick(item: GetManagePendingCitizenRecords["pendingCitizenRecords"][number]) { + function handleEditClick(item: GetManagePendingCitizenRecords["pendingCitizenRecords"][number]) { setTempRecord(item.records!); modalState.openModal(ModalIds.ManageRecord, { @@ -95,6 +95,12 @@ export function PendingCitizenRecordsTab({ pendingCitizenRecords }: Props) { } } + async function handleRecordUpdate() { + await refetch(); + asyncTable.refetch(); + setTempRecord(null); + } + return ( {record.status}, actions: ( <> -