- Add utility functions for managing audit page state including parsing, serialization, and updates. - Introduce audit period resolution logic to handle various time frames. - Create API functions for finding and searching audit entries with appropriate DTOs and mappers. - Implement hooks for fetching audit entries and lists, integrating with the data source. - Add tests for utility functions, API calls, and mappers to ensure correctness. - Establish shared entities and DTOs for consistent data handling across the module. - Set up TypeScript configuration for the audit module.
24 lines
918 B
TypeScript
24 lines
918 B
TypeScript
import { useDataSource } from "@erp/core/hooks";
|
|
import { useIdentityAuthSession } from "@erp/identity/client";
|
|
import { type DefaultError, useQuery } from "@tanstack/react-query";
|
|
|
|
import { findAuditEntryById } from "../api/find-audit-entry-by-id.api";
|
|
import type { AuditEntryDetail } from "../entities/audit-entry-detail.entity";
|
|
|
|
import { auditQueryKeys } from "./audit-query-keys";
|
|
|
|
export const useAuditEntry = (id: string | null) => {
|
|
const dataSource = useDataSource();
|
|
const { activeCompany } = useIdentityAuthSession();
|
|
const companyId = activeCompany?.id ?? "none";
|
|
|
|
return useQuery<AuditEntryDetail, DefaultError>({
|
|
queryKey: auditQueryKeys.detail(companyId, id ?? "none"),
|
|
queryFn: ({ signal }) => {
|
|
if (!id) throw new Error("auditEntryId is required");
|
|
return findAuditEntryById(dataSource, { id, signal });
|
|
},
|
|
enabled: activeCompany !== null && id !== null,
|
|
});
|
|
};
|