Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: pending citizen logs #1844

Merged
merged 2 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand All @@ -85,11 +85,11 @@ export class AdminManageCitizensController {
Permissions.ViewCitizenLogs,
],
})
async getPendingArrestReports(
async getPendingCitizenRecords(
@QueryParams("skip", Number) skip = 0,
@QueryParams("includeAll", Boolean) includeAll = false,
): Promise<APITypes.GetManagePendingArrestReports> {
const [totalCount, arrestReports] = await prisma.$transaction([
): Promise<APITypes.GetManagePendingCitizenRecords> {
const [totalCount, pendingCitizenRecords] = await prisma.$transaction([
prisma.recordLog.count({
where: { records: { status: WhitelistStatus.PENDING } },
}),
Expand All @@ -109,7 +109,7 @@ export class AdminManageCitizensController {
}),
]);

return { arrestReports, totalCount };
return { pendingCitizenRecords, totalCount };
}

@Get("/records-logs/:citizenId")
Expand Down Expand Up @@ -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<APITypes.PostCitizenRecordLogsData> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ 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";
import { RecordsCaseNumberColumn } from "../records-case-number-column";
import { RecordsStatsColumn } from "../records-stats-column";

interface Props {
arrestReports: GetManagePendingArrestReports;
pendingCitizenRecords: GetManagePendingCitizenRecords;
}

const TYPE_LABELS = {
Expand All @@ -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<Record | null>(null);

const { data, isLoading, refetch } = useQuery({
Expand All @@ -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();
Expand All @@ -71,7 +71,7 @@ export function PendingCitizenRecordsTab({ arrestReports }: Props) {
const { state, execute } = useFetch();
const tableState = useTableState();

function handleViewClick(item: GetManagePendingArrestReports["arrestReports"][number]) {
function handleEditClick(item: GetManagePendingCitizenRecords["pendingCitizenRecords"][number]) {
setTempRecord(item.records!);

modalState.openModal(ModalIds.ManageRecord, {
Expand All @@ -95,6 +95,12 @@ export function PendingCitizenRecordsTab({ arrestReports }: Props) {
}
}

async function handleRecordUpdate() {
await refetch();
asyncTable.refetch();
setTempRecord(null);
}

return (
<TabsContent
tabName={`${t("pendingCitizenRecords")} ${
Expand Down Expand Up @@ -141,8 +147,8 @@ export function PendingCitizenRecordsTab({ arrestReports }: Props) {
status: <Status fallback="—">{record.status}</Status>,
actions: (
<>
<Button size="xs" className="mr-2" onPress={() => handleViewClick(item)}>
{common("view")}
<Button size="xs" className="mr-2" onPress={() => handleEditClick(item)}>
{common("edit")}
</Button>
<Button
variant="success"
Expand Down Expand Up @@ -187,8 +193,8 @@ export function PendingCitizenRecordsTab({ arrestReports }: Props) {
id={ModalIds.ManageRecord}
type={tempRecord.type}
isEdit
onUpdate={handleRecordUpdate}
record={tempRecord}
isReadOnly
/>
) : null}
</TabsContent>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ export function ManageRecordModal(props: Props) {
{({ setFieldValue, setValues, errors, values, isValid }) => (
<Form autoComplete="off">
<TabList
defaultValue="general-information-tab"
queryState={false}
tabs={[
{ name: t("generalInformation"), value: "general-information-tab" },
Expand Down
3 changes: 2 additions & 1 deletion apps/client/src/hooks/shared/table/use-async-table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export function useAsyncTable<T>(options: Options<T>) {
pageIndex: options.fetchOptions.pageIndex ?? 0,
});

const { isInitialLoading, error } = useQuery({
const { isInitialLoading, error, refetch } = useQuery({
retry: false,
enabled: !options.disabled,
initialData: options.initialData ?? undefined,
Expand Down Expand Up @@ -131,5 +131,6 @@ export function useAsyncTable<T>(options: Options<T>) {
setFilters,
isLoading: loadingState === "loading",
pagination,
refetch,
};
}
15 changes: 9 additions & 6 deletions apps/client/src/pages/officer/supervisor/citizen-logs/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -47,7 +47,7 @@ export default function CitizenLogs(props: Props) {
<TabList tabs={TABS}>
<CitizenLogsTab citizens={props.citizens} />
{CITIZEN_RECORD_APPROVAL ? (
<PendingCitizenRecordsTab arrestReports={props.pendingCitizenRecords} />
<PendingCitizenRecordsTab pendingCitizenRecords={props.pendingCitizenRecords} />
) : null}
</TabList>
</Layout>
Expand All @@ -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 {
Expand All @@ -67,7 +67,10 @@ export const getServerSideProps: GetServerSideProps = async ({ req, locale }) =>
pendingCitizenRecords,
citizens,
messages: {
...(await getTranslations(["leo", "common"], user?.locale ?? locale)),
...(await getTranslations(
["leo", "common", "courthouse", "citizen"],
user?.locale ?? locale,
)),
},
},
};
Expand Down
6 changes: 3 additions & 3 deletions packages/types/src/api/admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"];
}

/**
Expand Down
Loading