aboutsummaryrefslogtreecommitdiff
path: root/packages/merchant-backoffice-ui/src/paths/instance/orders/create
diff options
context:
space:
mode:
authorSebastian <sebasjm@gmail.com>2022-12-19 12:23:39 -0300
committerSebastian <sebasjm@gmail.com>2022-12-19 12:23:39 -0300
commit72b429321553841ac1ff48cf974bfc65da01bb06 (patch)
tree7db9a4462f02de6cb86de695a1e64772b00ead5f /packages/merchant-backoffice-ui/src/paths/instance/orders/create
parent770ab6f01dc81a16f384f314982bd761540f8e65 (diff)
downloadwallet-core-72b429321553841ac1ff48cf974bfc65da01bb06.tar.xz
pretty
Diffstat (limited to 'packages/merchant-backoffice-ui/src/paths/instance/orders/create')
-rw-r--r--packages/merchant-backoffice-ui/src/paths/instance/orders/create/Create.stories.tsx2
-rw-r--r--packages/merchant-backoffice-ui/src/paths/instance/orders/create/CreatePage.tsx20
-rw-r--r--packages/merchant-backoffice-ui/src/paths/instance/orders/create/OrderCreatedSuccessfully.tsx123
-rw-r--r--packages/merchant-backoffice-ui/src/paths/instance/orders/create/index.tsx89
4 files changed, 136 insertions, 98 deletions
diff --git a/packages/merchant-backoffice-ui/src/paths/instance/orders/create/Create.stories.tsx b/packages/merchant-backoffice-ui/src/paths/instance/orders/create/Create.stories.tsx
index 4ce2eb43d..5f8dbbdd9 100644
--- a/packages/merchant-backoffice-ui/src/paths/instance/orders/create/Create.stories.tsx
+++ b/packages/merchant-backoffice-ui/src/paths/instance/orders/create/Create.stories.tsx
@@ -33,7 +33,7 @@ export default {
function createExample<Props>(
Component: FunctionalComponent<Props>,
- props: Partial<Props>
+ props: Partial<Props>,
) {
const r = (args: any) => <Component {...args} />;
r.args = props;
diff --git a/packages/merchant-backoffice-ui/src/paths/instance/orders/create/CreatePage.tsx b/packages/merchant-backoffice-ui/src/paths/instance/orders/create/CreatePage.tsx
index 379c5eab5..145df717d 100644
--- a/packages/merchant-backoffice-ui/src/paths/instance/orders/create/CreatePage.tsx
+++ b/packages/merchant-backoffice-ui/src/paths/instance/orders/create/CreatePage.tsx
@@ -166,7 +166,7 @@ export function CreatePage({
: value.payments.wire_transfer_deadline &&
isBefore(
value.payments.wire_transfer_deadline,
- value.payments.refund_deadline
+ value.payments.refund_deadline,
)
? i18n`wire transfer deadline cannot be before refund deadline`
: undefined,
@@ -177,7 +177,7 @@ export function CreatePage({
: value.payments.wire_transfer_deadline &&
isBefore(
value.payments.wire_transfer_deadline,
- value.payments.pay_deadline
+ value.payments.pay_deadline,
)
? i18n`wire transfer deadline cannot be before pay deadline`
: undefined,
@@ -189,7 +189,7 @@ export function CreatePage({
? i18n`should have a refund deadline`
: !isAfter(
value.payments.refund_deadline,
- value.payments.auto_refund_deadline
+ value.payments.auto_refund_deadline,
)
? i18n`auto refund cannot be after refund deadline`
: undefined,
@@ -203,7 +203,7 @@ export function CreatePage({
}),
};
const hasErrors = Object.keys(errors).some(
- (k) => (errors as any)[k] !== undefined
+ (k) => (errors as any)[k] !== undefined,
);
const submit = (): void => {
@@ -225,7 +225,7 @@ export function CreatePage({
wire_transfer_deadline: value.payments.wire_transfer_deadline
? {
t_s: Math.floor(
- value.payments.wire_transfer_deadline.getTime() / 1000
+ value.payments.wire_transfer_deadline.getTime() / 1000,
),
}
: undefined,
@@ -237,7 +237,7 @@ export function CreatePage({
auto_refund: value.payments.auto_refund_deadline
? {
d_us: Math.floor(
- value.payments.auto_refund_deadline.getTime() * 1000
+ value.payments.auto_refund_deadline.getTime() * 1000,
),
}
: undefined,
@@ -264,7 +264,7 @@ export function CreatePage({
const addProductToTheInventoryList = (
product: MerchantBackend.Products.ProductDetail & WithId,
- quantity: number
+ quantity: number,
) => {
valueHandler((v) => {
const inventoryProducts = { ...v.inventoryProducts };
@@ -332,13 +332,13 @@ export function CreatePage({
const discountOrRise = rate(
value.pricing?.order_price || `${config.currency}:0`,
- totalAsString
+ totalAsString,
);
const minAgeByProducts = allProducts.reduce(
(cur, prev) =>
!prev.minimum_age || cur > prev.minimum_age ? cur : prev.minimum_age,
- 0
+ 0,
);
return (
<div>
@@ -415,7 +415,7 @@ export function CreatePage({
discountOrRise > 0 &&
(discountOrRise < 1
? `discount of %${Math.round(
- (1 - discountOrRise) * 100
+ (1 - discountOrRise) * 100,
)}`
: `rise of %${Math.round((discountOrRise - 1) * 100)}`)
}
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 bd63ca371..6d3ac311a 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
@@ -26,64 +26,89 @@ interface Props {
onCreateAnother?: () => void;
}
-export function OrderCreatedSuccessfully({ entity, onConfirm, onCreateAnother }: Props): VNode {
- const { getPaymentURL } = useOrderAPI()
- const [url, setURL] = useState<string | undefined>(undefined)
+export function OrderCreatedSuccessfully({
+ entity,
+ onConfirm,
+ onCreateAnother,
+}: Props): VNode {
+ const { getPaymentURL } = useOrderAPI();
+ const [url, setURL] = useState<string | undefined>(undefined);
useEffect(() => {
- getPaymentURL(entity.response.order_id).then(response => {
- setURL(response.data)
- })
- }, [getPaymentURL, entity.response.order_id])
+ getPaymentURL(entity.response.order_id).then((response) => {
+ setURL(response.data);
+ });
+ }, [getPaymentURL, entity.response.order_id]);
- return <CreatedSuccessfully onConfirm={onConfirm} onCreateAnother={onCreateAnother}>
- <div class="field is-horizontal">
- <div class="field-label is-normal">
- <label class="label"><Translate>Amount</Translate></label>
- </div>
- <div class="field-body is-flex-grow-3">
- <div class="field">
- <p class="control">
- <input class="input" readonly value={entity.request.order.amount} />
- </p>
+ return (
+ <CreatedSuccessfully
+ onConfirm={onConfirm}
+ onCreateAnother={onCreateAnother}
+ >
+ <div class="field is-horizontal">
+ <div class="field-label is-normal">
+ <label class="label">
+ <Translate>Amount</Translate>
+ </label>
</div>
- </div>
- </div>
- <div class="field is-horizontal">
- <div class="field-label is-normal">
- <label class="label"><Translate>Summary</Translate></label>
- </div>
- <div class="field-body is-flex-grow-3">
- <div class="field">
- <p class="control">
- <input class="input" readonly value={entity.request.order.summary} />
- </p>
+ <div class="field-body is-flex-grow-3">
+ <div class="field">
+ <p class="control">
+ <input
+ class="input"
+ readonly
+ value={entity.request.order.amount}
+ />
+ </p>
+ </div>
</div>
</div>
- </div>
- <div class="field is-horizontal">
- <div class="field-label is-normal">
- <label class="label"><Translate>Order ID</Translate></label>
- </div>
- <div class="field-body is-flex-grow-3">
- <div class="field">
- <p class="control">
- <input class="input" readonly value={entity.response.order_id} />
- </p>
+ <div class="field is-horizontal">
+ <div class="field-label is-normal">
+ <label class="label">
+ <Translate>Summary</Translate>
+ </label>
+ </div>
+ <div class="field-body is-flex-grow-3">
+ <div class="field">
+ <p class="control">
+ <input
+ class="input"
+ readonly
+ value={entity.request.order.summary}
+ />
+ </p>
+ </div>
</div>
</div>
- </div>
- <div class="field is-horizontal">
- <div class="field-label is-normal">
- <label class="label"><Translate>Payment URL</Translate></label>
+ <div class="field is-horizontal">
+ <div class="field-label is-normal">
+ <label class="label">
+ <Translate>Order ID</Translate>
+ </label>
+ </div>
+ <div class="field-body is-flex-grow-3">
+ <div class="field">
+ <p class="control">
+ <input class="input" readonly value={entity.response.order_id} />
+ </p>
+ </div>
+ </div>
</div>
- <div class="field-body is-flex-grow-3">
- <div class="field">
- <p class="control">
- <input class="input" readonly value={url} />
- </p>
+ <div class="field is-horizontal">
+ <div class="field-label is-normal">
+ <label class="label">
+ <Translate>Payment URL</Translate>
+ </label>
+ </div>
+ <div class="field-body is-flex-grow-3">
+ <div class="field">
+ <p class="control">
+ <input class="input" readonly value={url} />
+ </p>
+ </div>
</div>
</div>
- </div>
- </CreatedSuccessfully>;
+ </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 feb75aa25..95232da92 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
@@ -15,12 +15,12 @@
*/
/**
-*
-* @author Sebastian Javier Marchano (sebasjm)
-*/
+ *
+ * @author Sebastian Javier Marchano (sebasjm)
+ */
-import { Fragment, h, VNode } from 'preact';
-import { useState } from 'preact/hooks';
+import { Fragment, h, VNode } from "preact";
+import { useState } from "preact/hooks";
import { Loading } from "../../../../components/exception/loading.js";
import { NotificationCard } from "../../../../components/menu/index.js";
import { MerchantBackend } from "../../../../declaration.js";
@@ -33,9 +33,9 @@ import { CreatePage } from "./CreatePage.js";
import { OrderCreatedSuccessfully } from "./OrderCreatedSuccessfully.js";
export type Entity = {
- request: MerchantBackend.Orders.PostOrderRequest,
- response: MerchantBackend.Orders.PostOrderResponse
-}
+ request: MerchantBackend.Orders.PostOrderRequest;
+ response: MerchantBackend.Orders.PostOrderResponse;
+};
interface Props {
onBack?: () => void;
onConfirm: () => void;
@@ -43,40 +43,53 @@ interface Props {
onNotFound: () => VNode;
onLoadError: (error: HttpError) => VNode;
}
-export default function OrderCreate({ onConfirm, onBack, onLoadError, onNotFound, onUnauthorized }: Props): VNode {
- const { createOrder } = useOrderAPI()
- const [notif, setNotif] = useState<Notification | undefined>(undefined)
+export default function OrderCreate({
+ onConfirm,
+ onBack,
+ onLoadError,
+ onNotFound,
+ onUnauthorized,
+}: Props): VNode {
+ const { createOrder } = useOrderAPI();
+ const [notif, setNotif] = useState<Notification | undefined>(undefined);
- const detailsResult = useInstanceDetails()
- const inventoryResult = useInstanceProducts()
+ const detailsResult = useInstanceDetails();
+ const inventoryResult = useInstanceProducts();
- if (detailsResult.clientError && detailsResult.isUnauthorized) return onUnauthorized()
- if (detailsResult.clientError && detailsResult.isNotfound) return onNotFound()
- if (detailsResult.loading) return <Loading />
- if (!detailsResult.ok) return onLoadError(detailsResult)
+ if (detailsResult.clientError && detailsResult.isUnauthorized)
+ return onUnauthorized();
+ if (detailsResult.clientError && detailsResult.isNotfound)
+ return onNotFound();
+ if (detailsResult.loading) return <Loading />;
+ if (!detailsResult.ok) return onLoadError(detailsResult);
- if (inventoryResult.clientError && inventoryResult.isUnauthorized) return onUnauthorized()
- if (inventoryResult.clientError && inventoryResult.isNotfound) return onNotFound()
- if (inventoryResult.loading) return <Loading />
- if (!inventoryResult.ok) return onLoadError(inventoryResult)
+ if (inventoryResult.clientError && inventoryResult.isUnauthorized)
+ return onUnauthorized();
+ if (inventoryResult.clientError && inventoryResult.isNotfound)
+ return onNotFound();
+ if (inventoryResult.loading) return <Loading />;
+ if (!inventoryResult.ok) return onLoadError(inventoryResult);
- return <Fragment>
-
- <NotificationCard notification={notif} />
+ return (
+ <Fragment>
+ <NotificationCard notification={notif} />
- <CreatePage
- onBack={onBack}
- onCreate={(request: MerchantBackend.Orders.PostOrderRequest) => {
- createOrder(request).then(onConfirm).catch((error) => {
- setNotif({
- message: 'could not create order',
- type: "ERROR",
- description: error.message
- })
- })
- }}
- instanceConfig={detailsResult.data}
- instanceInventory={inventoryResult.data}
+ <CreatePage
+ onBack={onBack}
+ onCreate={(request: MerchantBackend.Orders.PostOrderRequest) => {
+ createOrder(request)
+ .then(onConfirm)
+ .catch((error) => {
+ setNotif({
+ message: "could not create order",
+ type: "ERROR",
+ description: error.message,
+ });
+ });
+ }}
+ instanceConfig={detailsResult.data}
+ instanceInventory={inventoryResult.data}
/>
- </Fragment>
+ </Fragment>
+ );
}