diff options
Diffstat (limited to 'packages/merchant-backoffice-ui/src/hooks')
8 files changed, 71 insertions, 72 deletions
diff --git a/packages/merchant-backoffice-ui/src/hooks/backend.ts b/packages/merchant-backoffice-ui/src/hooks/backend.ts index 952b33f7e..6c4e5c176 100644 --- a/packages/merchant-backoffice-ui/src/hooks/backend.ts +++ b/packages/merchant-backoffice-ui/src/hooks/backend.ts @@ -47,8 +47,7 @@ export function useMatchMutate(): (      const allKeys = Array.from(cache.keys());      const keys = allKeys.filter((key) => re.test(key));      const mutations = keys.map((key) => { -      // console.log(key) -      mutate(key, value, true); +      return mutate(key, value, true);      });      return Promise.all(mutations);    }; diff --git a/packages/merchant-backoffice-ui/src/hooks/instance.ts b/packages/merchant-backoffice-ui/src/hooks/instance.ts index f118e1e6e..0b00936cd 100644 --- a/packages/merchant-backoffice-ui/src/hooks/instance.ts +++ b/packages/merchant-backoffice-ui/src/hooks/instance.ts @@ -13,14 +13,14 @@   You should have received a copy of the GNU General Public License along with   GNU Taler; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>   */ -import useSWR, { useSWRConfig } from "swr"; -import { useBackendContext } from "../context/backend.js"; -import { MerchantBackend } from "../declaration.js";  import { -  HttpError,    HttpResponse,    HttpResponseOk, +  RequestError,  } from "@gnu-taler/web-util/lib/index.browser"; +import useSWR, { useSWRConfig } from "swr"; +import { useBackendContext } from "../context/backend.js"; +import { MerchantBackend } from "../declaration.js";  import {    useBackendBaseRequest,    useBackendInstanceRequest, @@ -188,7 +188,7 @@ export function useInstanceDetails(): HttpResponse<    const { data, error, isValidating } = useSWR<      HttpResponseOk<MerchantBackend.Instances.QueryInstancesResponse>, -    HttpError<MerchantBackend.ErrorDetail> +    RequestError<MerchantBackend.ErrorDetail>    >([`/private/`], fetcher, {      refreshInterval: 0,      refreshWhenHidden: false, @@ -202,7 +202,7 @@ export function useInstanceDetails(): HttpResponse<    if (isValidating) return { loading: true, data: data?.data };    if (data) return data; -  if (error) return error; +  if (error) return error.info;    return { loading: true };  } @@ -218,7 +218,7 @@ export function useInstanceKYCDetails(): HttpResponse<    const { data, error } = useSWR<      HttpResponseOk<MerchantBackend.Instances.AccountKycRedirects>, -    HttpError<MerchantBackend.ErrorDetail> +    RequestError<MerchantBackend.ErrorDetail>    >([`/private/kyc`], fetcher, {      refreshInterval: 5000,      refreshWhenHidden: false, @@ -235,7 +235,7 @@ export function useInstanceKYCDetails(): HttpResponse<        return { ok: true, data: { type: "redirect", status: data.data } };      return { ok: true, data: { type: "ok" } };    } -  if (error) return error; +  if (error) return error.info;    return { loading: true };  } @@ -249,7 +249,7 @@ export function useManagedInstanceDetails(    const { data, error, isValidating } = useSWR<      HttpResponseOk<MerchantBackend.Instances.QueryInstancesResponse>, -    HttpError<MerchantBackend.ErrorDetail> +    RequestError<MerchantBackend.ErrorDetail>    >([`/management/instances/${instanceId}`], request, {      refreshInterval: 0,      refreshWhenHidden: false, @@ -263,7 +263,7 @@ export function useManagedInstanceDetails(    if (isValidating) return { loading: true, data: data?.data };    if (data) return data; -  if (error) return error; +  if (error) return error.info;    return { loading: true };  } @@ -275,11 +275,11 @@ export function useBackendInstances(): HttpResponse<    const { data, error, isValidating } = useSWR<      HttpResponseOk<MerchantBackend.Instances.InstancesResponse>, -    HttpError<MerchantBackend.ErrorDetail> +    RequestError<MerchantBackend.ErrorDetail>    >(["/management/instances"], request);    if (isValidating) return { loading: true, data: data?.data };    if (data) return data; -  if (error) return error; +  if (error) return error.info;    return { loading: true };  } diff --git a/packages/merchant-backoffice-ui/src/hooks/order.ts b/packages/merchant-backoffice-ui/src/hooks/order.ts index c01f8dd83..3bcf7aaab 100644 --- a/packages/merchant-backoffice-ui/src/hooks/order.ts +++ b/packages/merchant-backoffice-ui/src/hooks/order.ts @@ -13,16 +13,16 @@   You should have received a copy of the GNU General Public License along with   GNU Taler; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>   */ -import { useEffect, useState } from "preact/hooks"; -import useSWR from "swr"; -import { MerchantBackend } from "../declaration.js"; -import { MAX_RESULT_SIZE, PAGE_SIZE } from "../utils/constants.js";  import { -  HttpError,    HttpResponse,    HttpResponseOk,    HttpResponsePaginated, +  RequestError,  } from "@gnu-taler/web-util/lib/index.browser"; +import { useEffect, useState } from "preact/hooks"; +import useSWR from "swr"; +import { MerchantBackend } from "../declaration.js"; +import { MAX_RESULT_SIZE, PAGE_SIZE } from "../utils/constants.js";  import { useBackendInstanceRequest, useMatchMutate } from "./backend.js";  export interface OrderAPI { @@ -136,7 +136,7 @@ export function useOrderDetails(    const { data, error, isValidating } = useSWR<      HttpResponseOk<MerchantBackend.Orders.MerchantOrderStatusResponse>, -    HttpError<MerchantBackend.ErrorDetail> +    RequestError<MerchantBackend.ErrorDetail>    >([`/private/orders/${oderId}`], fetcher, {      refreshInterval: 0,      refreshWhenHidden: false, @@ -147,7 +147,7 @@ export function useOrderDetails(    if (isValidating) return { loading: true, data: data?.data };    if (data) return data; -  if (error) return error; +  if (error) return error.info;    return { loading: true };  } @@ -185,7 +185,7 @@ export function useInstanceOrders(      isValidating: loadingBefore,    } = useSWR<      HttpResponseOk<MerchantBackend.Orders.OrderHistory>, -    HttpError<MerchantBackend.ErrorDetail> +    RequestError<MerchantBackend.ErrorDetail>    >(      [        `/private/orders`, @@ -203,7 +203,7 @@ export function useInstanceOrders(      isValidating: loadingAfter,    } = useSWR<      HttpResponseOk<MerchantBackend.Orders.OrderHistory>, -    HttpError<MerchantBackend.ErrorDetail> +    RequestError<MerchantBackend.ErrorDetail>    >(      [        `/private/orders`, @@ -234,8 +234,8 @@ export function useInstanceOrders(      if (beforeData) setLastBefore(beforeData);    }, [afterData, beforeData]); -  if (beforeError) return beforeError; -  if (afterError) return afterError; +  if (beforeError) return beforeError.info; +  if (afterError) return afterError.info;    // if the query returns less that we ask, then we have reach the end or beginning    const isReachingEnd = afterData && afterData.data.orders.length < totalAfter; diff --git a/packages/merchant-backoffice-ui/src/hooks/product.ts b/packages/merchant-backoffice-ui/src/hooks/product.ts index 5d95a2f8f..df86f68f5 100644 --- a/packages/merchant-backoffice-ui/src/hooks/product.ts +++ b/packages/merchant-backoffice-ui/src/hooks/product.ts @@ -13,13 +13,13 @@   You should have received a copy of the GNU General Public License along with   GNU Taler; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>   */ -import useSWR, { useSWRConfig } from "swr"; -import { MerchantBackend, WithId } from "../declaration.js";  import { -  HttpError,    HttpResponse,    HttpResponseOk, +  RequestError,  } from "@gnu-taler/web-util/lib/index.browser"; +import useSWR, { useSWRConfig } from "swr"; +import { MerchantBackend, WithId } from "../declaration.js";  import { useBackendInstanceRequest, useMatchMutate } from "./backend.js";  export interface ProductAPI { @@ -96,7 +96,7 @@ export function useInstanceProducts(): HttpResponse<    const { data: list, error: listError } = useSWR<      HttpResponseOk<MerchantBackend.Products.InventorySummaryResponse>, -    HttpError<MerchantBackend.ErrorDetail> +    RequestError<MerchantBackend.ErrorDetail>    >([`/private/products`], fetcher, {      refreshInterval: 0,      refreshWhenHidden: false, @@ -110,7 +110,7 @@ export function useInstanceProducts(): HttpResponse<    );    const { data: products, error: productError } = useSWR<      HttpResponseOk<MerchantBackend.Products.ProductDetail>[], -    HttpError<MerchantBackend.ErrorDetail> +    RequestError<MerchantBackend.ErrorDetail>    >([paths], multiFetcher, {      refreshInterval: 0,      refreshWhenHidden: false, @@ -119,8 +119,8 @@ export function useInstanceProducts(): HttpResponse<      refreshWhenOffline: false,    }); -  if (listError) return listError; -  if (productError) return productError; +  if (listError) return listError.info; +  if (productError) return productError.info;    if (products) {      const dataWithId = products.map((d) => { @@ -145,7 +145,7 @@ export function useProductDetails(    const { data, error, isValidating } = useSWR<      HttpResponseOk<MerchantBackend.Products.ProductDetail>, -    HttpError<MerchantBackend.ErrorDetail> +    RequestError<MerchantBackend.ErrorDetail>    >([`/private/products/${productId}`], fetcher, {      refreshInterval: 0,      refreshWhenHidden: false, @@ -156,6 +156,6 @@ export function useProductDetails(    if (isValidating) return { loading: true, data: data?.data };    if (data) return data; -  if (error) return error; +  if (error) return error.info;    return { loading: true };  } diff --git a/packages/merchant-backoffice-ui/src/hooks/reserves.ts b/packages/merchant-backoffice-ui/src/hooks/reserves.ts index 0215f32c5..a4c0a7e55 100644 --- a/packages/merchant-backoffice-ui/src/hooks/reserves.ts +++ b/packages/merchant-backoffice-ui/src/hooks/reserves.ts @@ -13,13 +13,13 @@   You should have received a copy of the GNU General Public License along with   GNU Taler; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>   */ -import useSWR, { useSWRConfig } from "swr"; -import { MerchantBackend } from "../declaration.js";  import { -  HttpError,    HttpResponse,    HttpResponseOk, +  RequestError,  } from "@gnu-taler/web-util/lib/index.browser"; +import useSWR, { useSWRConfig } from "swr"; +import { MerchantBackend } from "../declaration.js";  import { useBackendInstanceRequest, useMatchMutate } from "./backend.js";  export function useReservesAPI(): ReserveMutateAPI { @@ -121,12 +121,12 @@ export function useInstanceReserves(): HttpResponse<    const { data, error, isValidating } = useSWR<      HttpResponseOk<MerchantBackend.Tips.TippingReserveStatus>, -    HttpError<MerchantBackend.ErrorDetail> +    RequestError<MerchantBackend.ErrorDetail>    >([`/private/reserves`], fetcher);    if (isValidating) return { loading: true, data: data?.data };    if (data) return data; -  if (error) return error; +  if (error) return error.info;    return { loading: true };  } @@ -140,7 +140,7 @@ export function useReserveDetails(    const { data, error, isValidating } = useSWR<      HttpResponseOk<MerchantBackend.Tips.ReserveDetail>, -    HttpError<MerchantBackend.ErrorDetail> +    RequestError<MerchantBackend.ErrorDetail>    >([`/private/reserves/${reserveId}`], reserveDetailFetcher, {      refreshInterval: 0,      refreshWhenHidden: false, @@ -151,7 +151,7 @@ export function useReserveDetails(    if (isValidating) return { loading: true, data: data?.data };    if (data) return data; -  if (error) return error; +  if (error) return error.info;    return { loading: true };  } @@ -162,7 +162,7 @@ export function useTipDetails(    const { data, error, isValidating } = useSWR<      HttpResponseOk<MerchantBackend.Tips.TipDetails>, -    HttpError<MerchantBackend.ErrorDetail> +    RequestError<MerchantBackend.ErrorDetail>    >([`/private/tips/${tipId}`], tipsDetailFetcher, {      refreshInterval: 0,      refreshWhenHidden: false, @@ -173,6 +173,6 @@ export function useTipDetails(    if (isValidating) return { loading: true, data: data?.data };    if (data) return data; -  if (error) return error; +  if (error) return error.info;    return { loading: true };  } diff --git a/packages/merchant-backoffice-ui/src/hooks/templates.ts b/packages/merchant-backoffice-ui/src/hooks/templates.ts index 124786887..579478537 100644 --- a/packages/merchant-backoffice-ui/src/hooks/templates.ts +++ b/packages/merchant-backoffice-ui/src/hooks/templates.ts @@ -13,17 +13,17 @@   You should have received a copy of the GNU General Public License along with   GNU Taler; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>   */ -import { MerchantBackend } from "../declaration.js"; -import { useMatchMutate, useBackendInstanceRequest } from "./backend.js"; -import useSWR from "swr"; -import { MAX_RESULT_SIZE, PAGE_SIZE } from "../utils/constants.js"; -import { useEffect, useState } from "preact/hooks";  import { -  HttpError,    HttpResponse,    HttpResponseOk,    HttpResponsePaginated, +  RequestError,  } from "@gnu-taler/web-util/lib/index.browser"; +import { useEffect, useState } from "preact/hooks"; +import useSWR from "swr"; +import { MerchantBackend } from "../declaration.js"; +import { MAX_RESULT_SIZE, PAGE_SIZE } from "../utils/constants.js"; +import { useBackendInstanceRequest, useMatchMutate } from "./backend.js";  export function useTemplateAPI(): TemplateAPI {    const mutateAll = useMatchMutate(); @@ -148,7 +148,7 @@ export function useInstanceTemplates(      isValidating: loadingAfter,    } = useSWR<      HttpResponseOk<MerchantBackend.Template.TemplateSummaryResponse>, -    HttpError<MerchantBackend.ErrorDetail> +    RequestError<MerchantBackend.ErrorDetail>    >([`/private/templates`, args?.position, -totalAfter], templateFetcher);    //this will save last result @@ -167,7 +167,7 @@ export function useInstanceTemplates(    }, [afterData /*, beforeData*/]);    // if (beforeError) return beforeError; -  if (afterError) return afterError; +  if (afterError) return afterError.info;    // if the query returns less that we ask, then we have reach the end or beginning    const isReachingEnd = @@ -231,7 +231,7 @@ export function useTemplateDetails(    const { data, error, isValidating } = useSWR<      HttpResponseOk<MerchantBackend.Template.TemplateDetails>, -    HttpError<MerchantBackend.ErrorDetail> +    RequestError<MerchantBackend.ErrorDetail>    >([`/private/templates/${templateId}`], templateFetcher, {      refreshInterval: 0,      refreshWhenHidden: false, @@ -242,6 +242,6 @@ export function useTemplateDetails(    if (isValidating) return { loading: true, data: data?.data };    if (data) return data; -  if (error) return error; +  if (error) return error.info;    return { loading: true };  } diff --git a/packages/merchant-backoffice-ui/src/hooks/transfer.ts b/packages/merchant-backoffice-ui/src/hooks/transfer.ts index 6b30047e9..0f9d79f24 100644 --- a/packages/merchant-backoffice-ui/src/hooks/transfer.ts +++ b/packages/merchant-backoffice-ui/src/hooks/transfer.ts @@ -13,16 +13,16 @@   You should have received a copy of the GNU General Public License along with   GNU Taler; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>   */ -import { useEffect, useState } from "preact/hooks"; -import useSWR from "swr"; -import { MerchantBackend } from "../declaration.js"; -import { MAX_RESULT_SIZE, PAGE_SIZE } from "../utils/constants.js";  import { -  HttpError,    HttpResponse,    HttpResponseOk,    HttpResponsePaginated, +  RequestError,  } from "@gnu-taler/web-util/lib/index.browser"; +import { useEffect, useState } from "preact/hooks"; +import useSWR from "swr"; +import { MerchantBackend } from "../declaration.js"; +import { MAX_RESULT_SIZE, PAGE_SIZE } from "../utils/constants.js";  import { useBackendInstanceRequest, useMatchMutate } from "./backend.js";  export function useTransferAPI(): TransferAPI { @@ -91,7 +91,7 @@ export function useInstanceTransfers(      isValidating: loadingBefore,    } = useSWR<      HttpResponseOk<MerchantBackend.Transfers.TransferList>, -    HttpError<MerchantBackend.ErrorDetail> +    RequestError<MerchantBackend.ErrorDetail>    >(      [        `/private/transfers`, @@ -108,7 +108,7 @@ export function useInstanceTransfers(      isValidating: loadingAfter,    } = useSWR<      HttpResponseOk<MerchantBackend.Transfers.TransferList>, -    HttpError<MerchantBackend.ErrorDetail> +    RequestError<MerchantBackend.ErrorDetail>    >(      [        `/private/transfers`, @@ -138,8 +138,8 @@ export function useInstanceTransfers(      if (beforeData) setLastBefore(beforeData);    }, [afterData, beforeData]); -  if (beforeError) return beforeError; -  if (afterError) return afterError; +  if (beforeError) return beforeError.info; +  if (afterError) return afterError.info;    // if the query returns less that we ask, then we have reach the end or beginning    const isReachingEnd = diff --git a/packages/merchant-backoffice-ui/src/hooks/webhooks.ts b/packages/merchant-backoffice-ui/src/hooks/webhooks.ts index e1cd3daf2..9cf6fae03 100644 --- a/packages/merchant-backoffice-ui/src/hooks/webhooks.ts +++ b/packages/merchant-backoffice-ui/src/hooks/webhooks.ts @@ -13,17 +13,17 @@   You should have received a copy of the GNU General Public License along with   GNU Taler; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>   */ -import { MerchantBackend } from "../declaration.js"; -import { useMatchMutate, useBackendInstanceRequest } from "./backend.js"; -import useSWR from "swr"; -import { MAX_RESULT_SIZE, PAGE_SIZE } from "../utils/constants.js"; -import { useEffect, useState } from "preact/hooks";  import { -  HttpError,    HttpResponse,    HttpResponseOk,    HttpResponsePaginated, +  RequestError,  } from "@gnu-taler/web-util/lib/index.browser"; +import { useEffect, useState } from "preact/hooks"; +import useSWR from "swr"; +import { MerchantBackend } from "../declaration.js"; +import { MAX_RESULT_SIZE, PAGE_SIZE } from "../utils/constants.js"; +import { useBackendInstanceRequest, useMatchMutate } from "./backend.js";  export function useWebhookAPI(): WebhookAPI {    const mutateAll = useMatchMutate(); @@ -100,7 +100,7 @@ export function useInstanceWebhooks(      isValidating: loadingAfter,    } = useSWR<      HttpResponseOk<MerchantBackend.Webhooks.WebhookSummaryResponse>, -    HttpError<MerchantBackend.ErrorDetail> +    RequestError<MerchantBackend.ErrorDetail>    >([`/private/webhooks`, args?.position, -totalAfter], webhookFetcher);    const [lastAfter, setLastAfter] = useState< @@ -113,7 +113,7 @@ export function useInstanceWebhooks(      if (afterData) setLastAfter(afterData);    }, [afterData]); -  if (afterError) return afterError; +  if (afterError) return afterError.info;    const isReachingEnd =      afterData && afterData.data.webhooks.length < totalAfter; @@ -157,7 +157,7 @@ export function useWebhookDetails(    const { data, error, isValidating } = useSWR<      HttpResponseOk<MerchantBackend.Webhooks.WebhookDetails>, -    HttpError<MerchantBackend.ErrorDetail> +    RequestError<MerchantBackend.ErrorDetail>    >([`/private/webhooks/${webhookId}`], webhookFetcher, {      refreshInterval: 0,      refreshWhenHidden: false, @@ -168,6 +168,6 @@ export function useWebhookDetails(    if (isValidating) return { loading: true, data: data?.data };    if (data) return data; -  if (error) return error; +  if (error) return error.info;    return { loading: true };  }  | 
