From 3e060b80428943c6562250a6ff77eff10a0259b7 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Mon, 24 Oct 2022 10:46:14 +0200 Subject: repo: integrate packages from former merchant-backoffice.git --- .../src/components/exception/AsyncButton.tsx | 49 +++ .../src/components/exception/QR.tsx | 49 +++ .../src/components/exception/loading.tsx | 32 ++ .../src/components/exception/login.tsx | 143 ++++++++ .../src/components/form/FormProvider.tsx | 81 +++++ .../src/components/form/Input.tsx | 71 ++++ .../src/components/form/InputArray.tsx | 97 +++++ .../src/components/form/InputBoolean.tsx | 72 ++++ .../src/components/form/InputCurrency.tsx | 47 +++ .../src/components/form/InputDate.tsx | 159 +++++++++ .../src/components/form/InputDuration.tsx | 172 +++++++++ .../src/components/form/InputGroup.tsx | 66 ++++ .../src/components/form/InputImage.tsx | 95 +++++ .../src/components/form/InputLocation.tsx | 43 +++ .../src/components/form/InputNumber.tsx | 42 +++ .../src/components/form/InputPayto.tsx | 39 ++ .../src/components/form/InputPaytoForm.tsx | 392 +++++++++++++++++++++ .../src/components/form/InputSearchProduct.tsx | 139 ++++++++ .../src/components/form/InputSecured.stories.tsx | 55 +++ .../src/components/form/InputSecured.tsx | 119 +++++++ .../src/components/form/InputSelector.tsx | 86 +++++ .../src/components/form/InputStock.stories.tsx | 162 +++++++++ .../src/components/form/InputStock.tsx | 171 +++++++++ .../src/components/form/InputTaxes.tsx | 97 +++++ .../src/components/form/InputWithAddon.tsx | 77 ++++ .../src/components/form/TextField.tsx | 53 +++ .../src/components/form/useField.tsx | 86 +++++ .../src/components/form/useGroupField.tsx | 40 +++ .../instance/DefaultInstanceFormFields.tsx | 135 +++++++ .../src/components/menu/LangSelector.tsx | 73 ++++ .../src/components/menu/NavigationBar.tsx | 58 +++ .../src/components/menu/SideBar.tsx | 227 ++++++++++++ .../src/components/menu/index.tsx | 210 +++++++++++ .../src/components/modal/index.tsx | 262 ++++++++++++++ .../notifications/CreatedSuccessfully.tsx | 49 +++ .../notifications/Notifications.stories.tsx | 57 +++ .../src/components/notifications/index.tsx | 52 +++ .../src/components/picker/DatePicker.tsx | 324 +++++++++++++++++ .../components/picker/DurationPicker.stories.tsx | 50 +++ .../src/components/picker/DurationPicker.tsx | 211 +++++++++++ .../product/InventoryProductForm.stories.tsx | 58 +++ .../components/product/InventoryProductForm.tsx | 95 +++++ .../components/product/NonInventoryProductForm.tsx | 146 ++++++++ .../src/components/product/ProductForm.tsx | 176 +++++++++ .../src/components/product/ProductList.tsx | 105 ++++++ 45 files changed, 5022 insertions(+) create mode 100644 packages/merchant-backoffice-ui/src/components/exception/AsyncButton.tsx create mode 100644 packages/merchant-backoffice-ui/src/components/exception/QR.tsx create mode 100644 packages/merchant-backoffice-ui/src/components/exception/loading.tsx create mode 100644 packages/merchant-backoffice-ui/src/components/exception/login.tsx create mode 100644 packages/merchant-backoffice-ui/src/components/form/FormProvider.tsx create mode 100644 packages/merchant-backoffice-ui/src/components/form/Input.tsx create mode 100644 packages/merchant-backoffice-ui/src/components/form/InputArray.tsx create mode 100644 packages/merchant-backoffice-ui/src/components/form/InputBoolean.tsx create mode 100644 packages/merchant-backoffice-ui/src/components/form/InputCurrency.tsx create mode 100644 packages/merchant-backoffice-ui/src/components/form/InputDate.tsx create mode 100644 packages/merchant-backoffice-ui/src/components/form/InputDuration.tsx create mode 100644 packages/merchant-backoffice-ui/src/components/form/InputGroup.tsx create mode 100644 packages/merchant-backoffice-ui/src/components/form/InputImage.tsx create mode 100644 packages/merchant-backoffice-ui/src/components/form/InputLocation.tsx create mode 100644 packages/merchant-backoffice-ui/src/components/form/InputNumber.tsx create mode 100644 packages/merchant-backoffice-ui/src/components/form/InputPayto.tsx create mode 100644 packages/merchant-backoffice-ui/src/components/form/InputPaytoForm.tsx create mode 100644 packages/merchant-backoffice-ui/src/components/form/InputSearchProduct.tsx create mode 100644 packages/merchant-backoffice-ui/src/components/form/InputSecured.stories.tsx create mode 100644 packages/merchant-backoffice-ui/src/components/form/InputSecured.tsx create mode 100644 packages/merchant-backoffice-ui/src/components/form/InputSelector.tsx create mode 100644 packages/merchant-backoffice-ui/src/components/form/InputStock.stories.tsx create mode 100644 packages/merchant-backoffice-ui/src/components/form/InputStock.tsx create mode 100644 packages/merchant-backoffice-ui/src/components/form/InputTaxes.tsx create mode 100644 packages/merchant-backoffice-ui/src/components/form/InputWithAddon.tsx create mode 100644 packages/merchant-backoffice-ui/src/components/form/TextField.tsx create mode 100644 packages/merchant-backoffice-ui/src/components/form/useField.tsx create mode 100644 packages/merchant-backoffice-ui/src/components/form/useGroupField.tsx create mode 100644 packages/merchant-backoffice-ui/src/components/instance/DefaultInstanceFormFields.tsx create mode 100644 packages/merchant-backoffice-ui/src/components/menu/LangSelector.tsx create mode 100644 packages/merchant-backoffice-ui/src/components/menu/NavigationBar.tsx create mode 100644 packages/merchant-backoffice-ui/src/components/menu/SideBar.tsx create mode 100644 packages/merchant-backoffice-ui/src/components/menu/index.tsx create mode 100644 packages/merchant-backoffice-ui/src/components/modal/index.tsx create mode 100644 packages/merchant-backoffice-ui/src/components/notifications/CreatedSuccessfully.tsx create mode 100644 packages/merchant-backoffice-ui/src/components/notifications/Notifications.stories.tsx create mode 100644 packages/merchant-backoffice-ui/src/components/notifications/index.tsx create mode 100644 packages/merchant-backoffice-ui/src/components/picker/DatePicker.tsx create mode 100644 packages/merchant-backoffice-ui/src/components/picker/DurationPicker.stories.tsx create mode 100644 packages/merchant-backoffice-ui/src/components/picker/DurationPicker.tsx create mode 100644 packages/merchant-backoffice-ui/src/components/product/InventoryProductForm.stories.tsx create mode 100644 packages/merchant-backoffice-ui/src/components/product/InventoryProductForm.tsx create mode 100644 packages/merchant-backoffice-ui/src/components/product/NonInventoryProductForm.tsx create mode 100644 packages/merchant-backoffice-ui/src/components/product/ProductForm.tsx create mode 100644 packages/merchant-backoffice-ui/src/components/product/ProductList.tsx (limited to 'packages/merchant-backoffice-ui/src/components') diff --git a/packages/merchant-backoffice-ui/src/components/exception/AsyncButton.tsx b/packages/merchant-backoffice-ui/src/components/exception/AsyncButton.tsx new file mode 100644 index 000000000..92bab4bfb --- /dev/null +++ b/packages/merchant-backoffice-ui/src/components/exception/AsyncButton.tsx @@ -0,0 +1,49 @@ +/* + This file is part of GNU Taler + (C) 2021 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 + Foundation; either version 3, or (at your option) any later version. + + GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + GNU Taler; see the file COPYING. If not, see + */ + +/** +* +* @author Sebastian Javier Marchano (sebasjm) +*/ + +import { ComponentChildren, h } from "preact"; +import { LoadingModal } from "../modal"; +import { useAsync } from "../../hooks/async"; +import { Translate } from "../../i18n"; + +type Props = { + children: ComponentChildren, + disabled: boolean; + onClick?: () => Promise; + [rest:string]: any, +}; + +export function AsyncButton({ onClick, disabled, children, ...rest }: Props) { + const { isSlow, isLoading, request, cancel } = useAsync(onClick); + + if (isSlow) { + return ; + } + if (isLoading) { + return ; + } + + return + + ; +} diff --git a/packages/merchant-backoffice-ui/src/components/exception/QR.tsx b/packages/merchant-backoffice-ui/src/components/exception/QR.tsx new file mode 100644 index 000000000..bcb9964a5 --- /dev/null +++ b/packages/merchant-backoffice-ui/src/components/exception/QR.tsx @@ -0,0 +1,49 @@ +/* + This file is part of GNU Taler + (C) 2021 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 + Foundation; either version 3, or (at your option) any later version. + + GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + GNU Taler; see the file COPYING. If not, see + */ + +import { h, VNode } from "preact"; +import { useEffect, useRef } from "preact/hooks"; +import qrcode from "qrcode-generator"; + +export function QR({ text }: { text: string }): VNode { + const divRef = useRef(null); + useEffect(() => { + const qr = qrcode(0, "L"); + qr.addData(text); + qr.make(); + if (divRef.current) { + divRef.current.innerHTML = qr.createSvgTag({ + scalable: true, + }); + } + }); + + return ( +
+
+
+ ); +} diff --git a/packages/merchant-backoffice-ui/src/components/exception/loading.tsx b/packages/merchant-backoffice-ui/src/components/exception/loading.tsx new file mode 100644 index 000000000..f2139a17e --- /dev/null +++ b/packages/merchant-backoffice-ui/src/components/exception/loading.tsx @@ -0,0 +1,32 @@ +/* + This file is part of GNU Taler + (C) 2021 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 + Foundation; either version 3, or (at your option) any later version. + + GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + GNU Taler; see the file COPYING. If not, see + */ + +/** +* +* @author Sebastian Javier Marchano (sebasjm) +*/ + +import { h, VNode } from "preact"; + +export function Loading(): VNode { + return
+ +
+} + +export function Spinner(): VNode { + return
+} \ No newline at end of file diff --git a/packages/merchant-backoffice-ui/src/components/exception/login.tsx b/packages/merchant-backoffice-ui/src/components/exception/login.tsx new file mode 100644 index 000000000..498d994ed --- /dev/null +++ b/packages/merchant-backoffice-ui/src/components/exception/login.tsx @@ -0,0 +1,143 @@ +/* + This file is part of GNU Taler + (C) 2021 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 + Foundation; either version 3, or (at your option) any later version. + + GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + GNU Taler; see the file COPYING. If not, see + */ + +/** + * + * @author Sebastian Javier Marchano (sebasjm) + */ + +import { h, VNode } from "preact"; +import { useState } from "preact/hooks"; +import { useBackendContext } from "../../context/backend"; +import { useInstanceContext } from "../../context/instance"; +import { Translate, useTranslator } from "../../i18n"; +import { Notification } from "../../utils/types"; + +interface Props { + withMessage?: Notification; + onConfirm: (backend: string, token?: string) => void; +} + +function getTokenValuePart(t?: string): string | undefined { + if (!t) return t; + const match = /secret-token:(.*)/.exec(t); + if (!match || !match[1]) return undefined; + return match[1]; +} + +function normalizeToken(r: string | undefined): string | undefined { + return r ? `secret-token:${encodeURIComponent(r)}` : undefined; +} + +export function LoginModal({ onConfirm, withMessage }: Props): VNode { + const { url: backendUrl, token: baseToken } = useBackendContext(); + const { admin, token: instanceToken } = useInstanceContext(); + const currentToken = getTokenValuePart( + !admin ? baseToken : instanceToken || "" + ); + const [token, setToken] = useState(currentToken); + + const [url, setURL] = useState(backendUrl); + const i18n = useTranslator(); + + return ( +
+
+ +
+
+ ); +} diff --git a/packages/merchant-backoffice-ui/src/components/form/FormProvider.tsx b/packages/merchant-backoffice-ui/src/components/form/FormProvider.tsx new file mode 100644 index 000000000..aef410ce7 --- /dev/null +++ b/packages/merchant-backoffice-ui/src/components/form/FormProvider.tsx @@ -0,0 +1,81 @@ +/* + This file is part of GNU Taler + (C) 2021 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 + Foundation; either version 3, or (at your option) any later version. + + GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + GNU Taler; see the file COPYING. If not, see + */ + +/** +* +* @author Sebastian Javier Marchano (sebasjm) +*/ + +import { ComponentChildren, createContext, h, VNode } from "preact"; +import { useContext, useMemo } from "preact/hooks"; + +type Updater = (value: ((prevState: S) => S) ) => void; + +export interface Props { + object?: Partial; + errors?: FormErrors; + name?: string; + valueHandler: Updater> | null; + children: ComponentChildren +} + +const noUpdater: Updater> = () => (s: unknown) => s + +export function FormProvider({ object = {}, errors = {}, name = '', valueHandler, children }: Props): VNode { + const initialObject = useMemo(() => object, []); + const value = useMemo>(() => ({ errors, object, initialObject, valueHandler: valueHandler ? valueHandler : noUpdater, name, toStr: {}, fromStr: {} }), [errors, object, valueHandler]); + + return +
{ + e.preventDefault(); + // if (valueHandler) valueHandler(object); + }}> + {children} +
+
; +} + +export interface FormType { + object: Partial; + initialObject: Partial; + errors: FormErrors; + toStr: FormtoStr; + name: string; + fromStr: FormfromStr; + valueHandler: Updater>; +} + +const FormContext = createContext>(null!) + +export function useFormContext() { + return useContext>(FormContext) +} + +export type FormErrors = { + [P in keyof T]?: string | FormErrors +} + +export type FormtoStr = { + [P in keyof T]?: ((f?: T[P]) => string) +} + +export type FormfromStr = { + [P in keyof T]?: ((f: string) => T[P]) +} + +export type FormUpdater = { + [P in keyof T]?: (f: keyof T) => (v: T[P]) => void +} diff --git a/packages/merchant-backoffice-ui/src/components/form/Input.tsx b/packages/merchant-backoffice-ui/src/components/form/Input.tsx new file mode 100644 index 000000000..9a9691e9b --- /dev/null +++ b/packages/merchant-backoffice-ui/src/components/form/Input.tsx @@ -0,0 +1,71 @@ +/* + This file is part of GNU Taler + (C) 2021 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 + Foundation; either version 3, or (at your option) any later version. + + GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + GNU Taler; see the file COPYING. If not, see + */ + +/** +* +* @author Sebastian Javier Marchano (sebasjm) +*/ +import { ComponentChildren, h, VNode } from "preact"; +import { useField, InputProps } from "./useField"; + +interface Props extends InputProps { + inputType?: 'text' | 'number' | 'multiline' | 'password'; + expand?: boolean; + toStr?: (v?: any) => string; + fromStr?: (s: string) => any; + inputExtra?: any, + side?: ComponentChildren; + children?: ComponentChildren; +} + +const defaultToString = (f?: any): string => f || '' +const defaultFromString = (v: string): any => v as any + +const TextInput = ({ inputType, error, ...rest }: any) => inputType === 'multiline' ? +