aboutsummaryrefslogtreecommitdiff
path: root/packages/merchant-backoffice-ui/src/paths/instance/products/list/Table.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'packages/merchant-backoffice-ui/src/paths/instance/products/list/Table.tsx')
-rw-r--r--packages/merchant-backoffice-ui/src/paths/instance/products/list/Table.tsx67
1 files changed, 41 insertions, 26 deletions
diff --git a/packages/merchant-backoffice-ui/src/paths/instance/products/list/Table.tsx b/packages/merchant-backoffice-ui/src/paths/instance/products/list/Table.tsx
index 275f855cb..9d5701fa7 100644
--- a/packages/merchant-backoffice-ui/src/paths/instance/products/list/Table.tsx
+++ b/packages/merchant-backoffice-ui/src/paths/instance/products/list/Table.tsx
@@ -1,6 +1,6 @@
/*
This file is part of GNU Taler
- (C) 2021-2023 Taler Systems S.A.
+ (C) 2021-2024 Taler Systems S.A.
GNU Taler is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
@@ -19,10 +19,10 @@
* @author Sebastian Javier Marchano (sebasjm)
*/
-import { Amounts } from "@gnu-taler/taler-util";
+import { AmountString, Amounts, TalerMerchantApi } from "@gnu-taler/taler-util";
import { useTranslationContext } from "@gnu-taler/web-util/browser";
import { format } from "date-fns";
-import { ComponentChildren, Fragment, h, VNode } from "preact";
+import { ComponentChildren, Fragment, VNode, h } from "preact";
import { StateUpdater, useState } from "preact/hooks";
import emptyImage from "../../../../assets/empty.png";
import {
@@ -31,10 +31,9 @@ import {
} from "../../../../components/form/FormProvider.js";
import { InputCurrency } from "../../../../components/form/InputCurrency.js";
import { InputNumber } from "../../../../components/form/InputNumber.js";
-import { MerchantBackend, WithId } from "../../../../declaration.js";
-import { dateFormatForSettings, useSettings } from "../../../../hooks/useSettings.js";
+import { dateFormatForSettings, usePreference } from "../../../../hooks/preference.js";
-type Entity = MerchantBackend.Products.ProductDetail & WithId;
+type Entity = TalerMerchantApi.ProductDetail & WithId;
interface Props {
instances: Entity[];
@@ -42,10 +41,12 @@ interface Props {
onSelect: (product: Entity) => void;
onUpdate: (
id: string,
- data: MerchantBackend.Products.ProductPatchDetail,
+ data: TalerMerchantApi.ProductPatchDetail,
) => Promise<void>;
onCreate: () => void;
selected?: boolean;
+ onLoadMoreBefore?: () => void;
+ onLoadMoreAfter?: () => void;
}
export function CardTable({
@@ -54,6 +55,8 @@ export function CardTable({
onSelect,
onUpdate,
onDelete,
+ onLoadMoreAfter,
+ onLoadMoreBefore
}: Props): VNode {
const [rowSelection, rowSelectionHandler] = useState<string | undefined>(
undefined,
@@ -90,6 +93,8 @@ export function CardTable({
onSelect={onSelect}
onDelete={onDelete}
onUpdate={onUpdate}
+ onLoadMoreAfter={onLoadMoreAfter}
+ onLoadMoreBefore={onLoadMoreBefore}
rowSelection={rowSelection}
rowSelectionHandler={rowSelectionHandler}
/>
@@ -108,10 +113,12 @@ interface TableProps {
onSelect: (id: Entity) => void;
onUpdate: (
id: string,
- data: MerchantBackend.Products.ProductPatchDetail,
+ data: TalerMerchantApi.ProductPatchDetail,
) => Promise<void>;
onDelete: (id: Entity) => void;
rowSelectionHandler: StateUpdater<string | undefined>;
+ onLoadMoreBefore?: () => void;
+ onLoadMoreAfter?: () => void;
}
function Table({
@@ -121,11 +128,18 @@ function Table({
onSelect,
onUpdate,
onDelete,
+ onLoadMoreAfter,
+ onLoadMoreBefore
}: TableProps): VNode {
const { i18n } = useTranslationContext();
- const [settings] = useSettings();
+ const [settings] = usePreference();
return (
<div class="table-container">
+ {onLoadMoreBefore && (
+ <button class="button is-fullwidth" onClick={onLoadMoreBefore}>
+ <i18n.Translate>load first page</i18n.Translate>
+ </button>
+ )}
<table class="table is-fullwidth is-striped is-hoverable is-fullwidth">
<thead>
<tr>
@@ -197,14 +211,14 @@ function Table({
/>
</td>
<td
- class="has-tooltip-right"
+ class="has-tooltip-right"
data-tooltip={i.description}
onClick={() =>
rowSelection !== i.id && rowSelectionHandler(i.id)
}
style={{ cursor: "pointer" }}
>
- {i.description.length > 30 ? i.description.substring(0, 30) + "..." : i.description}
+ {i.description.length > 30 ? i.description.substring(0, 30) + "..." : i.description}
</td>
<td
onClick={() =>
@@ -244,9 +258,9 @@ function Table({
}
style={{ cursor: "pointer" }}
>
- <span style={{"whiteSpace":"nowrap"}}>
+ <span style={{ "whiteSpace": "nowrap" }}>
- {i.total_sold} {i.unit}
+ {i.total_sold} {i.unit}
</span>
</td>
<td class="is-actions-cell right-sticky">
@@ -284,7 +298,7 @@ function Table({
<FastProductUpdateForm
product={i}
onUpdate={(prod) =>
- onUpdate(i.id, prod).then((r) =>
+ onUpdate(i.id, prod).then(() =>
rowSelectionHandler(undefined),
)
}
@@ -298,6 +312,13 @@ function Table({
})}
</tbody>
</table>
+ {onLoadMoreAfter && (
+ <button class="button is-fullwidth"
+ data-tooltip={i18n.str`load more products after the last one`}
+ onClick={onLoadMoreAfter}>
+ <i18n.Translate>load next page</i18n.Translate>
+ </button>
+ )}
</div>
);
}
@@ -305,7 +326,7 @@ function Table({
interface FastProductUpdateFormProps {
product: Entity;
onUpdate: (
- data: MerchantBackend.Products.ProductPatchDetail,
+ data: TalerMerchantApi.ProductPatchDetail,
) => Promise<void>;
onCancel: () => void;
}
@@ -342,12 +363,6 @@ function FastProductWithInfiniteStockUpdateForm({
<div class="buttons is-expanded">
- <div class="buttons mt-5">
-
- <button class="button mt-5" onClick={onCancel}>
- <i18n.Translate>Clone</i18n.Translate>
- </button>
- </div>
<div class="buttons is-right mt-5">
<button class="button" onClick={onCancel}>
<i18n.Translate>Cancel</i18n.Translate>
@@ -361,7 +376,7 @@ function FastProductWithInfiniteStockUpdateForm({
onClick={() =>
onUpdate({
...product,
- price: value.price,
+ price: value.price as AmountString,
})
}
>
@@ -397,7 +412,7 @@ function FastProductWithManagedStockUpdateForm({
};
const hasErrors = Object.keys(errors).some(
- (k) => (errors as any)[k] !== undefined,
+ (k) => (errors as Record<string,unknown>)[k] !== undefined,
);
const { i18n } = useTranslationContext();
@@ -446,7 +461,7 @@ function FastProductWithManagedStockUpdateForm({
...product,
total_stock: product.total_stock + value.incoming,
total_lost: product.total_lost + value.lost,
- price: value.price,
+ price: value.price as AmountString,
})
}
>
@@ -472,7 +487,7 @@ function EmptyTable(): VNode {
<div class="content has-text-grey has-text-centered">
<p>
<span class="icon is-large">
- <i class="mdi mdi-emoticon-sad mdi-48px" />
+ <i class="mdi mdi-magnify mdi-48px" />
</span>
</p>
<p>
@@ -491,6 +506,6 @@ function difference(price: string, tax: number) {
ps[1] = `${p - tax}`;
return ps.join(":");
}
-function sum(taxes: MerchantBackend.Tax[]) {
+function sum(taxes: TalerMerchantApi.Tax[]) {
return taxes.reduce((p, c) => p + parseInt(c.tax.split(":")[1], 10), 0);
}