aboutsummaryrefslogtreecommitdiff
path: root/packages/merchant-backoffice-ui/src/hooks/product.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/merchant-backoffice-ui/src/hooks/product.ts')
-rw-r--r--packages/merchant-backoffice-ui/src/hooks/product.ts22
1 files changed, 15 insertions, 7 deletions
diff --git a/packages/merchant-backoffice-ui/src/hooks/product.ts b/packages/merchant-backoffice-ui/src/hooks/product.ts
index af8ad74f3..5d95a2f8f 100644
--- a/packages/merchant-backoffice-ui/src/hooks/product.ts
+++ b/packages/merchant-backoffice-ui/src/hooks/product.ts
@@ -15,7 +15,11 @@
*/
import useSWR, { useSWRConfig } from "swr";
import { MerchantBackend, WithId } from "../declaration.js";
-import { HttpError, HttpResponse, HttpResponseOk } from "../utils/request.js";
+import {
+ HttpError,
+ HttpResponse,
+ HttpResponseOk,
+} from "@gnu-taler/web-util/lib/index.browser";
import { useBackendInstanceRequest, useMatchMutate } from "./backend.js";
export interface ProductAPI {
@@ -85,13 +89,14 @@ export function useProductAPI(): ProductAPI {
}
export function useInstanceProducts(): HttpResponse<
- (MerchantBackend.Products.ProductDetail & WithId)[]
+ (MerchantBackend.Products.ProductDetail & WithId)[],
+ MerchantBackend.ErrorDetail
> {
const { fetcher, multiFetcher } = useBackendInstanceRequest();
const { data: list, error: listError } = useSWR<
HttpResponseOk<MerchantBackend.Products.InventorySummaryResponse>,
- HttpError
+ HttpError<MerchantBackend.ErrorDetail>
>([`/private/products`], fetcher, {
refreshInterval: 0,
refreshWhenHidden: false,
@@ -105,7 +110,7 @@ export function useInstanceProducts(): HttpResponse<
);
const { data: products, error: productError } = useSWR<
HttpResponseOk<MerchantBackend.Products.ProductDetail>[],
- HttpError
+ HttpError<MerchantBackend.ErrorDetail>
>([paths], multiFetcher, {
refreshInterval: 0,
refreshWhenHidden: false,
@@ -122,7 +127,7 @@ export function useInstanceProducts(): HttpResponse<
//take the id from the queried url
return {
...d.data,
- id: d.info?.url.href.replace(/.*\/private\/products\//, "") || "",
+ id: d.info?.url.replace(/.*\/private\/products\//, "") || "",
};
});
return { ok: true, data: dataWithId };
@@ -132,12 +137,15 @@ export function useInstanceProducts(): HttpResponse<
export function useProductDetails(
productId: string,
-): HttpResponse<MerchantBackend.Products.ProductDetail> {
+): HttpResponse<
+ MerchantBackend.Products.ProductDetail,
+ MerchantBackend.ErrorDetail
+> {
const { fetcher } = useBackendInstanceRequest();
const { data, error, isValidating } = useSWR<
HttpResponseOk<MerchantBackend.Products.ProductDetail>,
- HttpError
+ HttpError<MerchantBackend.ErrorDetail>
>([`/private/products/${productId}`], fetcher, {
refreshInterval: 0,
refreshWhenHidden: false,