aboutsummaryrefslogtreecommitdiff
path: root/packages/auditor-backoffice-ui/src/paths
diff options
context:
space:
mode:
authorNic Eigel <nic@eigel.ch>2024-01-14 17:44:02 +0100
committerNic Eigel <nic@eigel.ch>2024-01-14 17:44:02 +0100
commita29db7a4a5311ab5b5d489a1eedfd1f4555773ae (patch)
treeb6f0a43daf7b7eaf1ad95fe09171212c59b48546 /packages/auditor-backoffice-ui/src/paths
parente162a8cb655adc95c8cd8d87319a76c8e9792994 (diff)
downloadwallet-core-a29db7a4a5311ab5b5d489a1eedfd1f4555773ae.tar.xz
updating makefile, fixing auditor-backoffice
Diffstat (limited to 'packages/auditor-backoffice-ui/src/paths')
-rw-r--r--packages/auditor-backoffice-ui/src/paths/instance/deposit_confirmations/create/CreatedSuccessfully.tsx3
-rw-r--r--packages/auditor-backoffice-ui/src/paths/instance/deposit_confirmations/create/index.tsx16
-rw-r--r--packages/auditor-backoffice-ui/src/paths/instance/deposit_confirmations/list/List.stories.tsx18
-rw-r--r--packages/auditor-backoffice-ui/src/paths/instance/deposit_confirmations/list/Table.tsx249
-rw-r--r--packages/auditor-backoffice-ui/src/paths/instance/deposit_confirmations/list/index.tsx25
-rw-r--r--packages/auditor-backoffice-ui/src/paths/instance/products/create/index.tsx19
6 files changed, 5 insertions, 325 deletions
diff --git a/packages/auditor-backoffice-ui/src/paths/instance/deposit_confirmations/create/CreatedSuccessfully.tsx b/packages/auditor-backoffice-ui/src/paths/instance/deposit_confirmations/create/CreatedSuccessfully.tsx
index 6b02430cc..573064aea 100644
--- a/packages/auditor-backoffice-ui/src/paths/instance/deposit_confirmations/create/CreatedSuccessfully.tsx
+++ b/packages/auditor-backoffice-ui/src/paths/instance/deposit_confirmations/create/CreatedSuccessfully.tsx
@@ -38,7 +38,6 @@ export function CreatedSuccessfully({
<div class="field-body is-flex-grow-3">
<div class="field">
<p class="control">
- <img src={entity.image} style={{ width: 200, height: 200 }} />
</p>
</div>
</div>
@@ -50,7 +49,6 @@ export function CreatedSuccessfully({
<div class="field-body is-flex-grow-3">
<div class="field">
<p class="control">
- <textarea class="input" readonly value={entity.description} />
</p>
</div>
</div>
@@ -62,7 +60,6 @@ export function CreatedSuccessfully({
<div class="field-body is-flex-grow-3">
<div class="field">
<p class="control">
- <input class="input" readonly value={entity.price} />
</p>
</div>
</div>
diff --git a/packages/auditor-backoffice-ui/src/paths/instance/deposit_confirmations/create/index.tsx b/packages/auditor-backoffice-ui/src/paths/instance/deposit_confirmations/create/index.tsx
index 4b59e9807..99599cfab 100644
--- a/packages/auditor-backoffice-ui/src/paths/instance/deposit_confirmations/create/index.tsx
+++ b/packages/auditor-backoffice-ui/src/paths/instance/deposit_confirmations/create/index.tsx
@@ -34,27 +34,13 @@ interface Props {
onConfirm: () => void;
}
export default function CreateProduct({ onConfirm, onBack }: Props): VNode {
- const { createProduct } = useProductAPI();
+ const { createDepositConfirmation } = useDepositConfirmationAPI();
const [notif, setNotif] = useState<Notification | undefined>(undefined);
const { i18n } = useTranslationContext();
return (
<Fragment>
<NotificationCard notification={notif} />
- <CreatePage
- onBack={onBack}
- onCreate={(request: MerchantBackend.Products.ProductAddDetail) => {
- return createProduct(request)
- .then(() => onConfirm())
- .catch((error) => {
- setNotif({
- message: i18n.str`could not create product`,
- type: "ERROR",
- description: error.message,
- });
- });
- }}
- />
</Fragment>
);
}
diff --git a/packages/auditor-backoffice-ui/src/paths/instance/deposit_confirmations/list/List.stories.tsx b/packages/auditor-backoffice-ui/src/paths/instance/deposit_confirmations/list/List.stories.tsx
index c2c4d548c..41c297d5b 100644
--- a/packages/auditor-backoffice-ui/src/paths/instance/deposit_confirmations/list/List.stories.tsx
+++ b/packages/auditor-backoffice-ui/src/paths/instance/deposit_confirmations/list/List.stories.tsx
@@ -41,21 +41,3 @@ function createExample<Props>(
r.args = props;
return r;
}
-
-export const Example = createExample(TestedComponent, {
- instances: [
- {
- id: "orderid",
- description: "description1",
- description_i18n: {} as any,
- image: "",
- price: "TESTKUDOS:10",
- taxes: [],
- total_lost: 10,
- total_sold: 5,
- total_stock: 15,
- unit: "bar",
- address: {},
- },
- ],
-});
diff --git a/packages/auditor-backoffice-ui/src/paths/instance/deposit_confirmations/list/Table.tsx b/packages/auditor-backoffice-ui/src/paths/instance/deposit_confirmations/list/Table.tsx
index ffd1f12e5..2c97b59e8 100644
--- a/packages/auditor-backoffice-ui/src/paths/instance/deposit_confirmations/list/Table.tsx
+++ b/packages/auditor-backoffice-ui/src/paths/instance/deposit_confirmations/list/Table.tsx
@@ -155,27 +155,6 @@ function Table({
</thead>
<tbody>
{instances.map((i) => {
- const restStockInfo = !i.next_restock
- ? ""
- : i.next_restock.t_s === "never"
- ? "never"
- : `restock at ${format(
- new Date(i.next_restock.t_s * 1000),
- dateFormatForSettings(settings),
- )}`;
- let stockInfo: ComponentChildren = "";
- if (i.total_stock < 0) {
- stockInfo = "infinite";
- } else {
- const totalStock = i.total_stock - i.total_lost - i.total_sold;
- stockInfo = (
- <label title={restStockInfo}>
- {totalStock} {i.unit}
- </label>
- );
- }
-
- const isFree = Amounts.isZero(Amounts.parseOrThrow(i.price));
return (
<Fragment key={i.id}>
@@ -186,69 +165,8 @@ function Table({
}
style={{ cursor: "pointer" }}
>
- <img
- src={i.image ? i.image : emptyImage}
- style={{
- border: "solid black 1px",
- maxHeight: "2em",
- width: "auto",
- height: "auto",
- }}
- />
</td>
- <td
- 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}
- </td>
- <td
- onClick={() =>
- rowSelection !== i.id && rowSelectionHandler(i.id)
- }
- style={{ cursor: "pointer" }}
- >
- {isFree ? i18n.str`free` : `${i.price} / ${i.unit}`}
- </td>
- <td
- onClick={() =>
- rowSelection !== i.id && rowSelectionHandler(i.id)
- }
- style={{ cursor: "pointer" }}
- >
- {sum(i.taxes)}
- </td>
- <td
- onClick={() =>
- rowSelection !== i.id && rowSelectionHandler(i.id)
- }
- style={{ cursor: "pointer" }}
- >
- {difference(i.price, sum(i.taxes))}
- </td>
- <td
- onClick={() =>
- rowSelection !== i.id && rowSelectionHandler(i.id)
- }
- style={{ cursor: "pointer" }}
- >
- {stockInfo}
- </td>
- <td
- onClick={() =>
- rowSelection !== i.id && rowSelectionHandler(i.id)
- }
- style={{ cursor: "pointer" }}
- >
- <span style={{"whiteSpace":"nowrap"}}>
- {i.total_sold} {i.unit}
- </span>
- </td>
<td class="is-actions-cell right-sticky">
<div class="buttons is-right">
<span
@@ -281,15 +199,6 @@ function Table({
{rowSelection === i.id && (
<tr key="form">
<td colSpan={10}>
- <FastProductUpdateForm
- product={i}
- onUpdate={(prod) =>
- onUpdate(i.id, prod).then((r) =>
- rowSelectionHandler(undefined),
- )
- }
- onCancel={() => rowSelectionHandler(undefined)}
- />
</td>
</tr>
)}
@@ -302,13 +211,6 @@ function Table({
);
}
-interface FastProductUpdateFormProps {
- product: Entity;
- onUpdate: (
- data: MerchantBackend.Products.ProductPatchDetail,
- ) => Promise<void>;
- onCancel: () => void;
-}
interface FastProductUpdate {
incoming: number;
lost: number;
@@ -318,153 +220,7 @@ interface UpdatePrice {
price: string;
}
-function FastProductWithInfiniteStockUpdateForm({
- product,
- onUpdate,
- onCancel,
-}: FastProductUpdateFormProps) {
- const [value, valueHandler] = useState<UpdatePrice>({ price: product.price });
- const { i18n } = useTranslationContext();
-
- return (
- <Fragment>
- <FormProvider<FastProductUpdate>
- name="added"
- object={value}
- valueHandler={valueHandler as any}
- >
- <InputCurrency<FastProductUpdate>
- name="price"
- label={i18n.str`Price`}
- tooltip={i18n.str`update the product with new price`}
- />
- </FormProvider>
-
- <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>
- </button>
- <span
- class="has-tooltip-left"
- data-tooltip={i18n.str`update product with new price`}
- >
- <button
- class="button is-info"
- onClick={() =>
- onUpdate({
- ...product,
- price: value.price,
- })
- }
- >
- <i18n.Translate>Confirm update</i18n.Translate>
- </button>
- </span>
- </div>
- </div>
- </Fragment>
- );
-}
-
-function FastProductWithManagedStockUpdateForm({
- product,
- onUpdate,
- onCancel,
-}: FastProductUpdateFormProps) {
- const [value, valueHandler] = useState<FastProductUpdate>({
- incoming: 0,
- lost: 0,
- price: product.price,
- });
-
- const currentStock =
- product.total_stock - product.total_sold - product.total_lost;
-
- const errors: FormErrors<FastProductUpdate> = {
- lost:
- currentStock + value.incoming < value.lost
- ? `lost cannot be greater that current + incoming (max ${currentStock + value.incoming
- })`
- : undefined,
- };
-
- const hasErrors = Object.keys(errors).some(
- (k) => (errors as any)[k] !== undefined,
- );
- const { i18n } = useTranslationContext();
-
- return (
- <Fragment>
- <FormProvider<FastProductUpdate>
- name="added"
- errors={errors}
- object={value}
- valueHandler={valueHandler as any}
- >
- <InputNumber<FastProductUpdate>
- name="incoming"
- label={i18n.str`Incoming`}
- tooltip={i18n.str`add more elements to the inventory`}
- />
- <InputNumber<FastProductUpdate>
- name="lost"
- label={i18n.str`Lost`}
- tooltip={i18n.str`report elements lost in the inventory`}
- />
- <InputCurrency<FastProductUpdate>
- name="price"
- label={i18n.str`Price`}
- tooltip={i18n.str`new price for the product`}
- />
- </FormProvider>
-
- <div class="buttons is-right mt-5">
- <button class="button" onClick={onCancel}>
- <i18n.Translate>Cancel</i18n.Translate>
- </button>
- <span
- class="has-tooltip-left"
- data-tooltip={
- hasErrors
- ? i18n.str`the are value with errors`
- : i18n.str`update product with new stock and price`
- }
- >
- <button
- class="button is-info"
- disabled={hasErrors}
- onClick={() =>
- onUpdate({
- ...product,
- total_stock: product.total_stock + value.incoming,
- total_lost: product.total_lost + value.lost,
- price: value.price,
- })
- }
- >
- <i18n.Translate>Confirm</i18n.Translate>
- </button>
- </span>
- </div>
- </Fragment>
- );
-}
-
-function FastProductUpdateForm(props: FastProductUpdateFormProps) {
- return props.product.total_stock === -1 ? (
- <FastProductWithInfiniteStockUpdateForm {...props} />
- ) : (
- <FastProductWithManagedStockUpdateForm {...props} />
- );
-}
function EmptyTable(): VNode {
const { i18n } = useTranslationContext();
@@ -490,7 +246,4 @@ function difference(price: string, tax: number) {
const p = parseInt(ps[1], 10);
ps[1] = `${p - tax}`;
return ps.join(":");
-}
-function sum(taxes: MerchantBackend.Tax[]) {
- return taxes.reduce((p, c) => p + parseInt(c.tax.split(":")[1], 10), 0);
-}
+} \ No newline at end of file
diff --git a/packages/auditor-backoffice-ui/src/paths/instance/deposit_confirmations/list/index.tsx b/packages/auditor-backoffice-ui/src/paths/instance/deposit_confirmations/list/index.tsx
index dccb3ef25..e3eda37f6 100644
--- a/packages/auditor-backoffice-ui/src/paths/instance/deposit_confirmations/list/index.tsx
+++ b/packages/auditor-backoffice-ui/src/paths/instance/deposit_confirmations/list/index.tsx
@@ -88,31 +88,6 @@ export default function DepositConfirmationList({
palceholder={i18n.str`serial id`}
/>
- <CardTable
- instances={result.data}
- onCreate={onCreate}
- onUpdate={(id, prod) =>
- updateDepositConfirmation(id, prod)
- .then(() =>
- setNotif({
- message: i18n.str`deposit_confirmation updated successfully`,
- type: "SUCCESS",
- }),
- )
- .catch((error) =>
- setNotif({
- message: i18n.str`could not update the deposit_confirmation`,
- type: "ERROR",
- description: error.message,
- }),
- )
- }
- onSelect={(depositConfirmation) => onSelect(depositConfirmation.id)}
- onDelete={(depositConfirmation : AuditorBackend.DepositConfirmation.DepositConfirmationDetail & WithId) =>
- setDeleting(depositConfirmation)
- }
- />
-
{deleting && (
<ConfirmModal
label={`Delete deposit-confirmation`}
diff --git a/packages/auditor-backoffice-ui/src/paths/instance/products/create/index.tsx b/packages/auditor-backoffice-ui/src/paths/instance/products/create/index.tsx
index 775690bd1..0c30ff14c 100644
--- a/packages/auditor-backoffice-ui/src/paths/instance/products/create/index.tsx
+++ b/packages/auditor-backoffice-ui/src/paths/instance/products/create/index.tsx
@@ -23,12 +23,12 @@ import { useTranslationContext } from "@gnu-taler/web-util/browser";
import { Fragment, h, VNode } from "preact";
import { useState } from "preact/hooks";
import { NotificationCard } from "../../../../components/menu/index.js";
-import { MerchantBackend } from "../../../../declaration.js";
+import { AuditorBackend, MerchantBackend } from "../../../../declaration.js";
import { useProductAPI } from "../../../../hooks/product.js";
import { Notification } from "../../../../utils/types.js";
import { CreatePage } from "./CreatePage.js";
-export type Entity = MerchantBackend.Products.ProductAddDetail;
+export type Entity = MerchantBackend.Products.ProductDetail;
interface Props {
onBack?: () => void;
onConfirm: () => void;
@@ -41,20 +41,7 @@ export default function CreateProduct({ onConfirm, onBack }: Props): VNode {
return (
<Fragment>
<NotificationCard notification={notif} />
- <CreatePage
- onBack={onBack}
- onCreate={(request: MerchantBackend.Products.ProductAddDetail) => {
- return createProduct(request)
- .then(() => onConfirm())
- .catch((error) => {
- setNotif({
- message: i18n.str`could not create product`,
- type: "ERROR",
- description: error.message,
- });
- });
- }}
- />
+
</Fragment>
);
}