aboutsummaryrefslogtreecommitdiff
path: root/packages/merchant-backoffice-ui/src/paths/instance/orders/create
diff options
context:
space:
mode:
authorSebastian <sebasjm@gmail.com>2024-04-03 13:37:27 -0300
committerSebastian <sebasjm@gmail.com>2024-04-03 14:56:30 -0300
commit4bf1ab8ba924b2a0fc4813814bdeeb66a2928382 (patch)
tree8052cd83d9935db2c054a58f7d231c528b8dfc0d /packages/merchant-backoffice-ui/src/paths/instance/orders/create
parent56da180423029a1b53d2be343eed4f073e96dc89 (diff)
downloadwallet-core-4bf1ab8ba924b2a0fc4813814bdeeb66a2928382.tar.xz
wip #8655: fixing broken build
Diffstat (limited to 'packages/merchant-backoffice-ui/src/paths/instance/orders/create')
-rw-r--r--packages/merchant-backoffice-ui/src/paths/instance/orders/create/OrderCreatedSuccessfully.tsx57
-rw-r--r--packages/merchant-backoffice-ui/src/paths/instance/orders/create/index.tsx60
2 files changed, 49 insertions, 68 deletions
diff --git a/packages/merchant-backoffice-ui/src/paths/instance/orders/create/OrderCreatedSuccessfully.tsx b/packages/merchant-backoffice-ui/src/paths/instance/orders/create/OrderCreatedSuccessfully.tsx
index be631c1e0..d7abc4fbe 100644
--- a/packages/merchant-backoffice-ui/src/paths/instance/orders/create/OrderCreatedSuccessfully.tsx
+++ b/packages/merchant-backoffice-ui/src/paths/instance/orders/create/OrderCreatedSuccessfully.tsx
@@ -13,52 +13,55 @@
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 { ErrorType, HttpError, Loading, useTranslationContext } from "@gnu-taler/web-util/browser";
-import { h, VNode } from "preact";
-import { useEffect, useState } from "preact/hooks";
+import { HttpStatusCode, TalerError, assertUnreachable } from "@gnu-taler/taler-util";
+import { Loading, useTranslationContext } from "@gnu-taler/web-util/browser";
+import { VNode, h } from "preact";
+import { ErrorLoadingMerchant } from "../../../../components/ErrorLoadingMerchant.js";
import { CreatedSuccessfully } from "../../../../components/notifications/CreatedSuccessfully.js";
-import { Entity } from "./index.js";
import { useOrderDetails } from "../../../../hooks/order.js";
-import { HttpStatusCode, TalerErrorDetail } from "@gnu-taler/taler-util";
+import { NotFoundPageOrAdminCreate } from "../../../notfound/index.js";
+import { Entity } from "./index.js";
interface Props {
entity: Entity;
onConfirm: () => void;
onCreateAnother?: () => void;
- onUnauthorized: () => VNode;
- onNotFound: () => VNode;
- onLoadError: (error: HttpError<TalerErrorDetail>) => VNode;
}
export function OrderCreatedSuccessfully({
entity,
onConfirm,
onCreateAnother,
- onLoadError,
- onNotFound,
- onUnauthorized,
}: Props): VNode {
const result = useOrderDetails(entity.response.order_id)
const { i18n } = useTranslationContext();
- if (result.loading) return <Loading />;
- if (!result.ok) {
- if (
- result.type === ErrorType.CLIENT &&
- result.status === HttpStatusCode.Unauthorized
- )
- return onUnauthorized();
- if (
- result.type === ErrorType.CLIENT &&
- result.status === HttpStatusCode.NotFound
- )
- return onNotFound();
- return onLoadError(result);
+ if (!result) return <Loading />
+ if (result instanceof TalerError) {
+ return <ErrorLoadingMerchant error={result} />
+ }
+ if (result.type === "fail") {
+ switch(result.case) {
+ case HttpStatusCode.NotFound: {
+ return <NotFoundPageOrAdminCreate />
+ }
+ case HttpStatusCode.BadGateway: {
+ return <div>Failed to obtain a response from the exchange</div>;
+ }
+ case HttpStatusCode.GatewayTimeout: {
+ return (
+ <div>The merchant's interaction with the exchange took too long</div>
+ );
+ }
+ default: {
+ assertUnreachable(result)
+ }
+ }
}
- const url = result.data.order_status === "unpaid" ?
- result.data.taler_pay_uri :
- result.data.contract_terms.fulfillment_url
+ const url = result.body.order_status === "unpaid" ?
+ result.body.taler_pay_uri :
+ result.body.contract_terms.fulfillment_url
return (
<CreatedSuccessfully
diff --git a/packages/merchant-backoffice-ui/src/paths/instance/orders/create/index.tsx b/packages/merchant-backoffice-ui/src/paths/instance/orders/create/index.tsx
index 54d8c7b47..e40e766dd 100644
--- a/packages/merchant-backoffice-ui/src/paths/instance/orders/create/index.tsx
+++ b/packages/merchant-backoffice-ui/src/paths/instance/orders/create/index.tsx
@@ -19,18 +19,19 @@
* @author Sebastian Javier Marchano (sebasjm)
*/
-import { HttpStatusCode, TalerError, TalerErrorDetail, TalerMerchantApi } from "@gnu-taler/taler-util";
-import { ErrorType, HttpError, useMerchantApiContext } from "@gnu-taler/web-util/browser";
+import { HttpStatusCode, TalerError, TalerMerchantApi, assertUnreachable } from "@gnu-taler/taler-util";
+import { useMerchantApiContext } from "@gnu-taler/web-util/browser";
import { Fragment, VNode, h } from "preact";
import { useState } from "preact/hooks";
+import { ErrorLoadingMerchant } from "../../../../components/ErrorLoadingMerchant.js";
import { Loading } from "../../../../components/exception/loading.js";
import { NotificationCard } from "../../../../components/menu/index.js";
+import { useSessionContext } from "../../../../context/session.js";
import { useInstanceDetails } from "../../../../hooks/instance.js";
import { useInstanceProducts } from "../../../../hooks/product.js";
import { Notification } from "../../../../utils/types.js";
import { CreatePage } from "./CreatePage.js";
-import { useSessionContext } from "../../../../context/session.js";
-import { ErrorLoadingMerchant } from "../../../../components/ErrorLoadingMerchant.js";
+import { NotFoundPageOrAdminCreate } from "../../../notfound/index.js";
export type Entity = {
request: TalerMerchantApi.PostOrderRequest;
@@ -39,16 +40,10 @@ export type Entity = {
interface Props {
onBack?: () => void;
onConfirm: (id: string) => void;
- onUnauthorized: () => VNode;
- onNotFound: () => VNode;
- onLoadError: (error: HttpError<TalerErrorDetail>) => VNode;
}
export default function OrderCreate({
onConfirm,
onBack,
- onLoadError,
- onNotFound,
- onUnauthorized,
}: Props): VNode {
const { lib } = useMerchantApiContext();
const [notif, setNotif] = useState<Notification | undefined>(undefined);
@@ -60,36 +55,19 @@ export default function OrderCreate({
if (detailsResult instanceof TalerError) {
return <ErrorLoadingMerchant error={detailsResult} />
}
-
- // if (detailsResult.loading) return <Loading />;
- if (inventoryResult.loading) return <Loading />;
-
- // if (!detailsResult.ok) {
- // if (
- // detailsResult.type === ErrorType.CLIENT &&
- // detailsResult.status === HttpStatusCode.Unauthorized
- // )
- // return onUnauthorized();
- // if (
- // detailsResult.type === ErrorType.CLIENT &&
- // detailsResult.status === HttpStatusCode.NotFound
- // )
- // return onNotFound();
- // return onLoadError(detailsResult);
- // }
-
- if (!inventoryResult.ok) {
- if (
- inventoryResult.type === ErrorType.CLIENT &&
- inventoryResult.status === HttpStatusCode.Unauthorized
- )
- return onUnauthorized();
- if (
- inventoryResult.type === ErrorType.CLIENT &&
- inventoryResult.status === HttpStatusCode.NotFound
- )
- return onNotFound();
- return onLoadError(inventoryResult);
+ if (!inventoryResult) return <Loading />
+ if (inventoryResult instanceof TalerError) {
+ return <ErrorLoadingMerchant error={inventoryResult} />
+ }
+ if (inventoryResult.type === "fail") {
+ switch (inventoryResult.case) {
+ case HttpStatusCode.NotFound: {
+ return <NotFoundPageOrAdminCreate />;
+ }
+ default: {
+ assertUnreachable(inventoryResult.case);
+ }
+ }
}
return (
@@ -119,7 +97,7 @@ export default function OrderCreate({
});
}}
instanceConfig={detailsResult.body}
- instanceInventory={inventoryResult.data}
+ instanceInventory={inventoryResult.body}
/>
</Fragment>
);