summaryrefslogtreecommitdiff
path: root/packages/merchant-backoffice-ui/src/paths/instance/orders/list/index.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'packages/merchant-backoffice-ui/src/paths/instance/orders/list/index.tsx')
-rw-r--r--packages/merchant-backoffice-ui/src/paths/instance/orders/list/index.tsx42
1 files changed, 32 insertions, 10 deletions
diff --git a/packages/merchant-backoffice-ui/src/paths/instance/orders/list/index.tsx b/packages/merchant-backoffice-ui/src/paths/instance/orders/list/index.tsx
index cd62685ca..a50f02a2d 100644
--- a/packages/merchant-backoffice-ui/src/paths/instance/orders/list/index.tsx
+++ b/packages/merchant-backoffice-ui/src/paths/instance/orders/list/index.tsx
@@ -19,10 +19,11 @@
* @author Sebastian Javier Marchano (sebasjm)
*/
-import { HttpStatusCode, TalerErrorDetail, TalerMerchantApi } from "@gnu-taler/taler-util";
+import { HttpStatusCode, TalerErrorDetail, TalerMerchantApi, stringifyPayUri } from "@gnu-taler/taler-util";
import {
ErrorType,
HttpError,
+ useMerchantApiContext,
useTranslationContext,
} from "@gnu-taler/web-util/browser";
import { Fragment, VNode, h } from "preact";
@@ -33,12 +34,12 @@ import { NotificationCard } from "../../../../components/menu/index.js";
import {
InstanceOrderFilter,
useInstanceOrders,
- useOrderAPI,
useOrderDetails,
} from "../../../../hooks/order.js";
import { Notification } from "../../../../utils/types.js";
import { ListPage } from "./ListPage.js";
import { RefundModal } from "./Table.js";
+import { useSessionContext } from "../../../../context/session.js";
interface Props {
onUnauthorized: () => VNode;
@@ -64,11 +65,12 @@ export default function OrderList({
setFilter((prev) => ({ ...prev, date }));
const result = useInstanceOrders(filter, setNewDate);
- const { refundOrder, getPaymentURL } = useOrderAPI();
+ const { lib } = useMerchantApiContext();
const [notif, setNotif] = useState<Notification | undefined>(undefined);
const { i18n } = useTranslationContext();
+ const { state } = useSessionContext()
if (result.loading) return <Loading />;
if (!result.ok) {
@@ -102,7 +104,13 @@ export default function OrderList({
<NotificationCard notification={notif} />
<JumpToElementById
- testIfExist={getPaymentURL}
+ testIfExist={async (order) => {
+ if (state.status !== "loggedIn") {
+ return false;
+ }
+ const resp = await lib.management.getOrder(state.token, order)
+ return resp.type === "ok"
+ }}
onSelect={onSelect}
description={i18n.str`jump to order with the given product ID`}
placeholder={i18n.str`order id`}
@@ -123,9 +131,22 @@ export default function OrderList({
isNotPaidActive={isNotPaidActive}
isRefundedActive={isRefundedActive}
jumpToDate={filter.date}
- onCopyURL={(id) =>
- getPaymentURL(id).then((resp) => copyToClipboard(resp.data))
- }
+ onCopyURL={async (id) => {
+ if (state.status !== "loggedIn") {
+ return false;
+ }
+ const resp = await lib.management.getOrder(state.token, id)
+ if (resp.type === "ok") {
+ if (resp.body.order_status === "unpaid") {
+ copyToClipboard(resp.body.taler_pay_uri)
+ } else {
+ if (resp.body.contract_terms.fulfillment_url) {
+ copyToClipboard(resp.body.contract_terms.fulfillment_url)
+ }
+ }
+ copyToClipboard(resp.body.order_status)
+ }
+ }}
onCreate={onCreate}
onSelectDate={setNewDate}
onShowAll={() => setFilter({})}
@@ -140,8 +161,8 @@ export default function OrderList({
<RefundModalForTable
id={orderToBeRefunded.order_id}
onCancel={() => setOrderToBeRefunded(undefined)}
- onConfirm={(value) =>
- refundOrder(orderToBeRefunded.order_id, value)
+ onConfirm={(value) => {
+ lib.management.addRefund(state.token, orderToBeRefunded.order_id, value)
.then(() =>
setNotif({
message: i18n.str`refund created successfully`,
@@ -156,7 +177,8 @@ export default function OrderList({
}),
)
.then(() => setOrderToBeRefunded(undefined))
- }
+
+ }}
onLoadError={(error) => {
setNotif({
message: i18n.str`could not create the refund`,