Skip to content

Commit

Permalink
refactor: improve useInvoiceVersions hook
Browse files Browse the repository at this point in the history
  • Loading branch information
alisher-epam committed Nov 13, 2024
1 parent cf1d71b commit 71674fa
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/common/hooks/useInvoiceVersions/useInvoiceVersions.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,20 @@ import {

import { AUDIT_INVOICE_API } from '../../constants';

const DEFAULT_VALUE = [];

export const useInvoiceVersions = (invoiceId, options = {}) => {
const ky = useOkapiKy();
const [namespace] = useNamespace({ key: 'invoice-versions' });

const searchParams = {
sortBy: 'event_date',
sortOrder: 'desc',
};

const { isLoading, data } = useQuery(
[namespace, invoiceId],
() => ky.get(`${AUDIT_INVOICE_API}/${invoiceId}`).json(),
({ signal }) => ky.get(`${AUDIT_INVOICE_API}/${invoiceId}`, { signal, searchParams }).json(),
{
enabled: Boolean(invoiceId),
...options,
Expand All @@ -22,6 +29,6 @@ export const useInvoiceVersions = (invoiceId, options = {}) => {

return {
isLoading,
versions: data?.invoiceAuditEvents || [],
versions: data?.invoiceAuditEvents || DEFAULT_VALUE,
};
};

0 comments on commit 71674fa

Please sign in to comment.