diff options
author | Nic Eigel <nic@eigel.ch> | 2024-01-14 17:44:02 +0100 |
---|---|---|
committer | Nic Eigel <nic@eigel.ch> | 2024-01-14 17:44:02 +0100 |
commit | a29db7a4a5311ab5b5d489a1eedfd1f4555773ae (patch) | |
tree | b6f0a43daf7b7eaf1ad95fe09171212c59b48546 /packages/auditor-backoffice-ui | |
parent | e162a8cb655adc95c8cd8d87319a76c8e9792994 (diff) | |
download | wallet-core-a29db7a4a5311ab5b5d489a1eedfd1f4555773ae.tar.xz |
updating makefile, fixing auditor-backoffice
Diffstat (limited to 'packages/auditor-backoffice-ui')
10 files changed, 16 insertions, 720 deletions
diff --git a/packages/auditor-backoffice-ui/src/InstanceRoutes.tsx b/packages/auditor-backoffice-ui/src/InstanceRoutes.tsx index 14ccf773a..163438654 100644 --- a/packages/auditor-backoffice-ui/src/InstanceRoutes.tsx +++ b/packages/auditor-backoffice-ui/src/InstanceRoutes.tsx @@ -203,12 +203,6 @@ export function InstanceRoutes({ type: "INFO", }} /> - <InstanceCreatePage - forceId="default" - onConfirm={() => { - route(InstancePaths.order_list); - }} - /> </Fragment> ); } @@ -251,7 +245,6 @@ export function InstanceRoutes({ } }} > - <Route path="/" component={Redirect} to={InstancePaths.order_list} /> {/** * Admin pages */} @@ -272,16 +265,6 @@ export function InstanceRoutes({ )} {admin && ( <Route - path={AdminPaths.new_instance} - component={InstanceCreatePage} - onBack={() => route(AdminPaths.list_instances)} - onConfirm={() => { - route(InstancePaths.order_list); - }} - /> - )} - {admin && ( - <Route path={AdminPaths.update_instance} component={AdminInstanceUpdatePage} onBack={() => route(AdminPaths.list_instances)} @@ -311,22 +294,6 @@ export function InstanceRoutes({ onLoadError={ServerErrorRedirectTo(InstancePaths.error)} /> {/** - * Update instance page - */} - <Route - path={InstancePaths.token} - component={TokenPage} - onChange={() => { - route(`/`); - }} - onCancel={() => { - route(InstancePaths.order_list) - }} - onNotFound={IfAdminCreateDefaultOr(NotFoundPage)} - onUnauthorized={LoginPageAccessDenied} - onLoadError={ServerErrorRedirectTo(InstancePaths.error)} - /> - {/** * Inventory pages */} <Route @@ -404,288 +371,6 @@ export function InstanceRoutes({ route(InstancePaths.deposit_confirmation_list); }} /> - {/** - * Bank pages - */} - <Route - path={InstancePaths.bank_list} - component={BankAccountListPage} - onUnauthorized={LoginPageAccessDenied} - onLoadError={ServerErrorRedirectTo(InstancePaths.settings)} - onCreate={() => { - route(InstancePaths.bank_new); - }} - onSelect={(id: string) => { - route(InstancePaths.bank_update.replace(":bid", id)); - }} - onNotFound={IfAdminCreateDefaultOr(NotFoundPage)} - /> - <Route - path={InstancePaths.bank_update} - component={BankAccountUpdatePage} - onUnauthorized={LoginPageAccessDenied} - onLoadError={ServerErrorRedirectTo(InstancePaths.inventory_list)} - onConfirm={() => { - route(InstancePaths.bank_list); - }} - onBack={() => { - route(InstancePaths.bank_list); - }} - onNotFound={IfAdminCreateDefaultOr(NotFoundPage)} - /> - <Route - path={InstancePaths.bank_new} - component={BankAccountCreatePage} - onConfirm={() => { - route(InstancePaths.bank_list); - }} - onBack={() => { - route(InstancePaths.bank_list); - }} - /> - {/** - * Order pages - */} - <Route - path={InstancePaths.order_list} - component={OrderListPage} - onCreate={() => { - route(InstancePaths.order_new); - }} - onSelect={(id: string) => { - route(InstancePaths.order_details.replace(":oid", id)); - }} - onUnauthorized={LoginPageAccessDenied} - onLoadError={ServerErrorRedirectTo(InstancePaths.settings)} - onNotFound={IfAdminCreateDefaultOr(NotFoundPage)} - /> - <Route - path={InstancePaths.order_details} - component={OrderDetailsPage} - onUnauthorized={LoginPageAccessDenied} - onLoadError={ServerErrorRedirectTo(InstancePaths.order_list)} - onNotFound={IfAdminCreateDefaultOr(NotFoundPage)} - onBack={() => { - route(InstancePaths.order_list); - }} - /> - <Route - path={InstancePaths.order_new} - component={OrderCreatePage} - onConfirm={(orderId: string) => { - route(InstancePaths.order_details.replace(":oid", orderId)); - }} - onBack={() => { - route(InstancePaths.order_list); - }} - /> - {/** - * Transfer pages - */} - <Route - path={InstancePaths.transfers_list} - component={TransferListPage} - onUnauthorized={LoginPageAccessDenied} - onNotFound={IfAdminCreateDefaultOr(NotFoundPage)} - onLoadError={ServerErrorRedirectTo(InstancePaths.settings)} - onCreate={() => { - route(InstancePaths.transfers_new); - }} - /> - <Route - path={InstancePaths.transfers_new} - component={TransferCreatePage} - onConfirm={() => { - route(InstancePaths.transfers_list); - }} - onBack={() => { - route(InstancePaths.transfers_list); - }} - /> - {/** - * Webhooks pages - */} - <Route - path={InstancePaths.webhooks_list} - component={WebhookListPage} - onUnauthorized={LoginPageAccessDenied} - onNotFound={IfAdminCreateDefaultOr(NotFoundPage)} - onLoadError={ServerErrorRedirectTo(InstancePaths.settings)} - onCreate={() => { - route(InstancePaths.webhooks_new); - }} - onSelect={(id: string) => { - route(InstancePaths.webhooks_update.replace(":tid", id)); - }} - /> - <Route - path={InstancePaths.webhooks_update} - component={WebhookUpdatePage} - onConfirm={() => { - route(InstancePaths.webhooks_list); - }} - onUnauthorized={LoginPageAccessDenied} - onLoadError={ServerErrorRedirectTo(InstancePaths.webhooks_list)} - onNotFound={IfAdminCreateDefaultOr(NotFoundPage)} - onBack={() => { - route(InstancePaths.webhooks_list); - }} - /> - <Route - path={InstancePaths.webhooks_new} - component={WebhookCreatePage} - onConfirm={() => { - route(InstancePaths.webhooks_list); - }} - onBack={() => { - route(InstancePaths.webhooks_list); - }} - /> - {/** - * Validator pages - */} - <Route - path={InstancePaths.otp_devices_list} - component={ValidatorListPage} - onUnauthorized={LoginPageAccessDenied} - onNotFound={IfAdminCreateDefaultOr(NotFoundPage)} - onLoadError={ServerErrorRedirectTo(InstancePaths.settings)} - onCreate={() => { - route(InstancePaths.otp_devices_new); - }} - onSelect={(id: string) => { - route(InstancePaths.otp_devices_update.replace(":vid", id)); - }} - /> - <Route - path={InstancePaths.otp_devices_update} - component={ValidatorUpdatePage} - onConfirm={() => { - route(InstancePaths.otp_devices_list); - }} - onUnauthorized={LoginPageAccessDenied} - onLoadError={ServerErrorRedirectTo(InstancePaths.otp_devices_list)} - onNotFound={IfAdminCreateDefaultOr(NotFoundPage)} - onBack={() => { - route(InstancePaths.otp_devices_list); - }} - /> - <Route - path={InstancePaths.otp_devices_new} - component={ValidatorCreatePage} - onConfirm={() => { - route(InstancePaths.otp_devices_list); - }} - onBack={() => { - route(InstancePaths.otp_devices_list); - }} - /> - {/** - * Templates pages - */} - <Route - path={InstancePaths.templates_list} - component={TemplateListPage} - onUnauthorized={LoginPageAccessDenied} - onNotFound={IfAdminCreateDefaultOr(NotFoundPage)} - onLoadError={ServerErrorRedirectTo(InstancePaths.settings)} - onCreate={() => { - route(InstancePaths.templates_new); - }} - onNewOrder={(id: string) => { - route(InstancePaths.templates_use.replace(":tid", id)); - }} - onQR={(id: string) => { - route(InstancePaths.templates_qr.replace(":tid", id)); - }} - onSelect={(id: string) => { - route(InstancePaths.templates_update.replace(":tid", id)); - }} - /> - <Route - path={InstancePaths.templates_update} - component={TemplateUpdatePage} - onConfirm={() => { - route(InstancePaths.templates_list); - }} - onUnauthorized={LoginPageAccessDenied} - onLoadError={ServerErrorRedirectTo(InstancePaths.templates_list)} - onNotFound={IfAdminCreateDefaultOr(NotFoundPage)} - onBack={() => { - route(InstancePaths.templates_list); - }} - /> - <Route - path={InstancePaths.templates_new} - component={TemplateCreatePage} - onConfirm={() => { - route(InstancePaths.templates_list); - }} - onBack={() => { - route(InstancePaths.templates_list); - }} - /> - <Route - path={InstancePaths.templates_use} - component={TemplateUsePage} - onOrderCreated={(id: string) => { - route(InstancePaths.order_details.replace(":oid", id)); - }} - onUnauthorized={LoginPageAccessDenied} - onLoadError={ServerErrorRedirectTo(InstancePaths.templates_list)} - onNotFound={IfAdminCreateDefaultOr(NotFoundPage)} - onBack={() => { - route(InstancePaths.templates_list); - }} - /> - <Route - path={InstancePaths.templates_qr} - component={TemplateQrPage} - onUnauthorized={LoginPageAccessDenied} - onLoadError={ServerErrorRedirectTo(InstancePaths.templates_list)} - onNotFound={IfAdminCreateDefaultOr(NotFoundPage)} - onBack={() => { - route(InstancePaths.templates_list); - }} - /> - - {/** - * reserves pages - */} - <Route - path={InstancePaths.reserves_list} - component={ReservesListPage} - onUnauthorized={LoginPageAccessDenied} - onNotFound={IfAdminCreateDefaultOr(NotFoundPage)} - onLoadError={ServerErrorRedirectTo(InstancePaths.settings)} - onSelect={(id: string) => { - route(InstancePaths.reserves_details.replace(":rid", id)); - }} - onCreate={() => { - route(InstancePaths.reserves_new); - }} - /> - <Route - path={InstancePaths.reserves_details} - component={ReservesDetailsPage} - onUnauthorized={LoginPageAccessDenied} - onLoadError={ServerErrorRedirectTo(InstancePaths.reserves_list)} - onNotFound={IfAdminCreateDefaultOr(NotFoundPage)} - onBack={() => { - route(InstancePaths.reserves_list); - }} - /> - <Route - path={InstancePaths.reserves_new} - component={ReservesCreatePage} - onConfirm={() => { - route(InstancePaths.reserves_list); - }} - onBack={() => { - route(InstancePaths.reserves_list); - }} - /> - <Route path={InstancePaths.kyc} component={ListKYCPage} /> <Route path={InstancePaths.interface} component={Settings} /> {/** * Example pages diff --git a/packages/auditor-backoffice-ui/src/components/menu/index.tsx b/packages/auditor-backoffice-ui/src/components/menu/index.tsx index 03ae3b005..015d3bd05 100644 --- a/packages/auditor-backoffice-ui/src/components/menu/index.tsx +++ b/packages/auditor-backoffice-ui/src/components/menu/index.tsx @@ -26,10 +26,6 @@ function getInstanceTitle(path: string, id: string): string { switch (path) { case InstancePaths.settings: return `${id}: Settings`; - case InstancePaths.order_list: - return `${id}: Orders`; - case InstancePaths.order_new: - return `${id}: New order`; case InstancePaths.inventory_list: return `${id}: Inventory`; case InstancePaths.deposit_confirmation_list: @@ -38,34 +34,6 @@ function getInstanceTitle(path: string, id: string): string { return `${id}: New product`; case InstancePaths.inventory_update: return `${id}: Update product`; - case InstancePaths.reserves_new: - return `${id}: New reserve`; - case InstancePaths.reserves_list: - return `${id}: Reserves`; - case InstancePaths.transfers_list: - return `${id}: Transfers`; - case InstancePaths.transfers_new: - return `${id}: New transfer`; - case InstancePaths.webhooks_list: - return `${id}: Webhooks`; - case InstancePaths.webhooks_new: - return `${id}: New webhook`; - case InstancePaths.webhooks_update: - return `${id}: Update webhook`; - case InstancePaths.otp_devices_list: - return `${id}: otp devices`; - case InstancePaths.otp_devices_new: - return `${id}: New otp devices`; - case InstancePaths.otp_devices_update: - return `${id}: Update otp devices`; - case InstancePaths.templates_new: - return `${id}: New template`; - case InstancePaths.templates_update: - return `${id}: Update template`; - case InstancePaths.templates_list: - return `${id}: Templates`; - case InstancePaths.templates_use: - return `${id}: Use template`; case InstancePaths.interface: return `${id}: Interface`; default: diff --git a/packages/auditor-backoffice-ui/src/declaration.d.ts b/packages/auditor-backoffice-ui/src/declaration.d.ts index f0c79268c..0c6f599f7 100644 --- a/packages/auditor-backoffice-ui/src/declaration.d.ts +++ b/packages/auditor-backoffice-ui/src/declaration.d.ts @@ -298,50 +298,13 @@ export namespace AuditorBackend { amount_without_fee: string; } - // GET /private/products/$PRODUCT_ID + // GET /deposit-confirmation/$SERIAL_ID interface DepositConfirmationDetail { - // Human-readable product description. - description: string; - - // Map from IETF BCP 47 language tags to localized descriptions - description_i18n: { [lang_tag: string]: string }; - - // unit in which the product is measured (liters, kilograms, packages, etc.) - unit: string; - - // The price for one unit of the product. Zero is used - // to imply that this product is not sold separately, or - // that the price is not fixed, and must be supplied by the - // front-end. If non-zero, this price MUST include applicable - // taxes. - price: Amount; - - // An optional base64-encoded product image - image: ImageDataUrl; - - // a list of taxes paid by the merchant for one unit of this product - taxes: Tax[]; - - // Number of units of the product in stock in sum in total, - // including all existing sales ever. Given in product-specific - // units. - // A value of -1 indicates "infinite" (i.e. for "electronic" books). - total_stock: Integer; - - // Number of units of the product that have already been sold. - total_sold: Integer; - - // Number of units of the product that were lost (spoiled, stolen, etc.) - total_lost: Integer; - - // Identifies where the product is in stock. - address: Location; - - // Identifies when we expect the next restocking to happen. - next_restock?: Timestamp; - - // Minimum age buyer must have (in years). Default is 0. - minimum_age?: Integer; + serial_id: string; + timestamp: string; + refund_deadline: string; + wire_deadline: string; + amount_without_fee: string; } } diff --git a/packages/auditor-backoffice-ui/src/hooks/product.ts b/packages/auditor-backoffice-ui/src/hooks/product.ts index b8f55cb77..8ca8d2724 100644 --- a/packages/auditor-backoffice-ui/src/hooks/product.ts +++ b/packages/auditor-backoffice-ui/src/hooks/product.ts @@ -18,7 +18,7 @@ import { HttpResponseOk, RequestError, } from "@gnu-taler/web-util/browser"; -import { AuditorBackend, MerchantBackend, WithId } from "../declaration.js"; +import { MerchantBackend, WithId } from "../declaration.js"; import { useBackendInstanceRequest, useMatchMutate } from "./backend.js"; // FIX default import https://github.com/microsoft/TypeScript/issues/49189 @@ -27,7 +27,7 @@ const useSWR = _useSWR as unknown as SWRHook; export interface ProductAPI { getProduct: ( - id: string, + id: string, ) => Promise<void>; createProduct: ( data: MerchantBackend.Products.ProductAddDetail, @@ -122,11 +122,11 @@ export function useInstanceProducts(): HttpResponse< }); const paths = (list?.data.products || []).map( - (p) => `/deposit-confirmation/${p.serial_id}`, + (p) => `/private/products/${p.product_id}`, ); const { data: products, error: productError } = useSWR< - HttpResponseOk<AuditorBackend.DepositConfirmation.DepositConfirmationDetail>[], - RequestError<AuditorBackend.ErrorDetail> + HttpResponseOk<MerchantBackend.Products.ProductDetail>[], + RequestError<MerchantBackend.ErrorDetail> >([paths], multiFetcher, { refreshInterval: 0, refreshWhenHidden: false, 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> ); } |