Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | 107x 1404x 688x 107x 677x 677x 677x 344x 344x 107x 510x 510x 510x 249x 249x 107x 19x 10x | import { useQuery, UseQueryOptions } from "@tanstack/react-query";
import { API } from "aws-amplify";
import { opensearch, ReactQueryApiError, SEATOOL_STATUS } from "shared-types";
import { sendGAEvent } from "@/utils/ReactGA/SendGAEvent";
export const getItem = async (id: string): Promise<opensearch.main.ItemResult> =>
await API.post("os", "/item", { body: { id } }).catch(() =>
sendGAEvent("api_error", { message: `failure /item ${id}` }),
);
export const idIsApproved = async (id: string) => {
try {
const record = await getItem(id);
return record._source.seatoolStatus == SEATOOL_STATUS.APPROVED;
} catch (e) {
console.error(e);
return false;
}
};
export const canBeRenewedOrAmended = async (id: string) => {
try {
const record = await getItem(id);
return ["New", "Renew"].includes(record._source.actionType);
} catch (e) {
console.error(e);
return false;
}
};
export const useGetItem = (
id: string,
options?: UseQueryOptions<opensearch.main.ItemResult, ReactQueryApiError>,
) => {
return useQuery<opensearch.main.ItemResult, ReactQueryApiError>(
["record", id],
() => getItem(id),
options,
);
};
|