From 72b429321553841ac1ff48cf974bfc65da01bb06 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Mon, 19 Dec 2022 12:23:39 -0300 Subject: pretty --- .../merchant-backoffice-ui/src/AdminRoutes.tsx | 65 +- .../merchant-backoffice-ui/src/Application.tsx | 168 +- .../src/ApplicationReadyRoutes.tsx | 7 +- .../merchant-backoffice-ui/src/InstanceRoutes.tsx | 4 +- .../src/components/exception/AsyncButton.tsx | 28 +- .../src/components/exception/loading.tsx | 32 +- .../src/components/exception/login.tsx | 2 +- .../src/components/form/FormProvider.tsx | 76 +- .../src/components/form/Input.tsx | 118 +- .../src/components/form/InputArray.tsx | 156 +- .../src/components/form/InputBoolean.tsx | 89 +- .../src/components/form/InputCurrency.tsx | 51 +- .../src/components/form/InputDuration.tsx | 2 +- .../src/components/form/InputGroup.tsx | 82 +- .../src/components/form/InputImage.tsx | 144 +- .../src/components/form/InputLocation.tsx | 51 +- .../src/components/form/InputNumber.tsx | 44 +- .../src/components/form/InputPayto.tsx | 41 +- .../src/components/form/InputSearchProduct.tsx | 199 +- .../src/components/form/InputSecured.stories.tsx | 56 +- .../src/components/form/InputSecured.tsx | 222 +- .../src/components/form/InputStock.tsx | 232 +- .../src/components/form/InputTaxes.tsx | 119 +- .../src/components/form/InputWithAddon.tsx | 118 +- .../src/components/form/TextField.tsx | 64 +- .../src/components/form/useField.tsx | 65 +- .../src/components/form/useGroupField.tsx | 17 +- .../src/components/menu/LangSelector.tsx | 99 +- .../src/components/menu/NavigationBar.tsx | 74 +- .../src/components/modal/index.tsx | 561 +- .../notifications/CreatedSuccessfully.tsx | 48 +- .../notifications/Notifications.stories.tsx | 55 +- .../src/components/notifications/index.tsx | 55 +- .../src/components/picker/DatePicker.tsx | 315 +- .../components/picker/DurationPicker.stories.tsx | 43 +- .../product/InventoryProductForm.stories.tsx | 46 +- .../components/product/InventoryProductForm.tsx | 98 +- .../components/product/NonInventoryProductForm.tsx | 215 +- .../src/components/product/ProductForm.tsx | 4 +- .../src/components/product/ProductList.tsx | 4 +- .../merchant-backoffice-ui/src/context/backend.ts | 81 +- .../merchant-backoffice-ui/src/context/config.ts | 14 +- .../merchant-backoffice-ui/src/context/instance.ts | 16 +- .../merchant-backoffice-ui/src/context/listener.ts | 16 +- .../src/context/translation.ts | 47 +- packages/merchant-backoffice-ui/src/custom.d.ts | 8 +- .../merchant-backoffice-ui/src/declaration.d.ts | 2338 ++- packages/merchant-backoffice-ui/src/hooks/async.ts | 41 +- .../merchant-backoffice-ui/src/hooks/backend.ts | 21 +- packages/merchant-backoffice-ui/src/hooks/index.ts | 114 +- .../merchant-backoffice-ui/src/hooks/instance.ts | 22 +- .../merchant-backoffice-ui/src/hooks/listener.ts | 42 +- .../src/hooks/notifications.ts | 38 +- packages/merchant-backoffice-ui/src/hooks/order.ts | 76 +- .../merchant-backoffice-ui/src/hooks/product.ts | 39 +- .../merchant-backoffice-ui/src/hooks/reserves.ts | 34 +- .../merchant-backoffice-ui/src/hooks/transfer.ts | 69 +- packages/merchant-backoffice-ui/src/i18n/index.tsx | 4 +- .../merchant-backoffice-ui/src/i18n/strings.ts | 4633 ++---- packages/merchant-backoffice-ui/src/index.html | 12 +- packages/merchant-backoffice-ui/src/index.tsx | 2 +- packages/merchant-backoffice-ui/src/manifest.json | 2 +- .../src/paths/admin/create/Create.stories.tsx | 31 +- .../src/paths/admin/create/CreatePage.tsx | 4 +- .../admin/create/InstanceCreatedSuccessfully.tsx | 85 +- .../src/paths/admin/create/index.tsx | 2 +- .../src/paths/admin/list/TableActive.tsx | 278 +- .../src/paths/admin/list/View.stories.tsx | 104 +- .../src/paths/admin/list/View.tsx | 114 +- .../src/paths/index.stories.ts | 2 +- .../src/paths/instance/details/DetailPage.tsx | 84 +- .../src/paths/instance/details/Details.stories.tsx | 2 +- .../src/paths/instance/details/index.tsx | 68 +- .../instance/orders/create/Create.stories.tsx | 2 +- .../paths/instance/orders/create/CreatePage.tsx | 20 +- .../orders/create/OrderCreatedSuccessfully.tsx | 123 +- .../src/paths/instance/orders/create/index.tsx | 89 +- .../instance/orders/details/Detail.stories.tsx | 2 +- .../paths/instance/orders/details/DetailPage.tsx | 6 +- .../src/paths/instance/orders/details/index.tsx | 69 +- .../paths/instance/orders/list/List.stories.tsx | 2 +- .../src/paths/instance/orders/list/ListPage.tsx | 256 +- .../src/paths/instance/orders/list/Table.tsx | 10 +- .../src/paths/instance/orders/list/index.tsx | 258 +- .../instance/products/create/Create.stories.tsx | 29 +- .../paths/instance/products/create/CreatePage.tsx | 71 +- .../products/create/CreatedSuccessfully.tsx | 73 +- .../src/paths/instance/products/create/index.tsx | 57 +- .../paths/instance/products/list/List.stories.tsx | 59 +- .../src/paths/instance/products/list/Table.tsx | 14 +- .../src/paths/instance/products/list/index.tsx | 112 +- .../instance/products/update/Update.stories.tsx | 54 +- .../paths/instance/products/update/UpdatePage.tsx | 92 +- .../src/paths/instance/products/update/index.tsx | 78 +- .../instance/reserves/create/Create.stories.tsx | 29 +- .../paths/instance/reserves/create/CreatePage.tsx | 296 +- .../create/CreatedSuccessfully.stories.tsx | 40 +- .../reserves/create/CreatedSuccessfully.tsx | 112 +- .../paths/instance/reserves/details/DetailPage.tsx | 7 +- .../instance/reserves/details/Details.stories.tsx | 2 +- .../paths/instance/reserves/details/TipInfo.tsx | 2 +- .../instance/reserves/list/AutorizeTipModal.tsx | 107 +- .../instance/reserves/list/CreatedSuccessfully.tsx | 2 +- .../paths/instance/reserves/list/List.stories.tsx | 2 +- .../src/paths/instance/reserves/list/Table.tsx | 4 +- .../src/paths/instance/reserves/list/index.tsx | 4 +- .../instance/transfers/create/Create.stories.tsx | 28 +- .../paths/instance/transfers/create/CreatePage.tsx | 148 +- .../src/paths/instance/transfers/create/index.tsx | 67 +- .../paths/instance/transfers/list/List.stories.tsx | 2 +- .../src/paths/instance/transfers/list/ListPage.tsx | 135 +- .../src/paths/instance/transfers/list/Table.tsx | 2 +- .../src/paths/instance/transfers/list/index.tsx | 100 +- .../src/paths/instance/transfers/update/index.tsx | 14 +- .../src/paths/instance/update/Update.stories.tsx | 2 +- .../src/paths/instance/update/UpdatePage.tsx | 8 +- .../src/paths/instance/update/index.tsx | 10 +- .../src/paths/login/index.tsx | 12 +- .../src/paths/notfound/index.tsx | 25 +- .../merchant-backoffice-ui/src/schemas/index.ts | 258 +- .../src/scss/DurationPicker.scss | 1 - .../merchant-backoffice-ui/src/scss/_aside.scss | 30 +- .../merchant-backoffice-ui/src/scss/_card.scss | 4 +- .../src/scss/_custom-calendar.scss | 83 +- .../merchant-backoffice-ui/src/scss/_footer.scss | 2 +- .../merchant-backoffice-ui/src/scss/_form.scss | 33 +- .../merchant-backoffice-ui/src/scss/_hero-bar.scss | 8 +- .../src/scss/_main-section.scss | 2 +- .../merchant-backoffice-ui/src/scss/_mixins.scss | 6 +- .../merchant-backoffice-ui/src/scss/_modal.scss | 2 +- .../merchant-backoffice-ui/src/scss/_nav-bar.scss | 16 +- .../merchant-backoffice-ui/src/scss/_table.scss | 28 +- .../merchant-backoffice-ui/src/scss/_tiles.scss | 3 +- .../src/scss/_title-bar.scss | 8 +- .../src/scss/fonts/nunito.css | 4 +- .../scss/icons/materialdesignicons-4.9.95.min.css | 15108 ++++++++++++++++++- .../merchant-backoffice-ui/src/scss/libs/_all.scss | 2 +- packages/merchant-backoffice-ui/src/sw.js | 2 +- .../merchant-backoffice-ui/src/utils/amount.ts | 56 +- .../merchant-backoffice-ui/src/utils/constants.ts | 33 +- .../src/utils/switchableAxios.ts | 47 +- packages/merchant-backoffice-ui/src/utils/table.ts | 36 +- 142 files changed, 22735 insertions(+), 7985 deletions(-) (limited to 'packages/merchant-backoffice-ui/src') diff --git a/packages/merchant-backoffice-ui/src/AdminRoutes.tsx b/packages/merchant-backoffice-ui/src/AdminRoutes.tsx index d3eb8a5b9..7f86d92ab 100644 --- a/packages/merchant-backoffice-ui/src/AdminRoutes.tsx +++ b/packages/merchant-backoffice-ui/src/AdminRoutes.tsx @@ -16,43 +16,38 @@ import { h, VNode } from "preact"; import Router, { route, Route } from "preact-router"; import InstanceCreatePage from "./paths/admin/create/index.js"; -import InstanceListPage from './paths/admin/list/index.js'; - +import InstanceListPage from "./paths/admin/list/index.js"; export enum AdminPaths { - list_instances = '/instances', - new_instance = '/instance/new', + list_instances = "/instances", + new_instance = "/instance/new", } export function AdminRoutes(): VNode { - - return - - { - route(AdminPaths.new_instance); - }} - - onUpdate={(id: string): void => { - route(`/instance/${id}/update`); - }} - - /> - - route(AdminPaths.list_instances)} - - onConfirm={() => { - // route(AdminPaths.list_instances); - }} - - // onError={(error: any) => { - // }} - - /> - - - -} \ No newline at end of file + return ( + + { + route(AdminPaths.new_instance); + }} + onUpdate={(id: string): void => { + route(`/instance/${id}/update`); + }} + /> + + route(AdminPaths.list_instances)} + onConfirm={() => { + // route(AdminPaths.list_instances); + }} + + // onError={(error: any) => { + // }} + /> + + ); +} diff --git a/packages/merchant-backoffice-ui/src/Application.tsx b/packages/merchant-backoffice-ui/src/Application.tsx index 4aa0f7891..0b92375c1 100644 --- a/packages/merchant-backoffice-ui/src/Application.tsx +++ b/packages/merchant-backoffice-ui/src/Application.tsx @@ -15,95 +15,125 @@ */ /** -* -* @author Sebastian Javier Marchano (sebasjm) -*/ + * + * @author Sebastian Javier Marchano (sebasjm) + */ -import { h, VNode } from 'preact'; -import { route } from 'preact-router'; +import { h, VNode } from "preact"; +import { route } from "preact-router"; import { useMemo } from "preact/hooks"; import { ApplicationReadyRoutes } from "./ApplicationReadyRoutes.js"; import { Loading } from "./components/exception/loading.js"; -import { NotificationCard, NotYetReadyAppMenu } from "./components/menu/index.js"; -import { BackendContextProvider, useBackendContext } from './context/backend.js'; -import { ConfigContextProvider } from './context/config.js'; -import { TranslationProvider } from './context/translation.js'; +import { + NotificationCard, + NotYetReadyAppMenu, +} from "./components/menu/index.js"; +import { + BackendContextProvider, + useBackendContext, +} from "./context/backend.js"; +import { ConfigContextProvider } from "./context/config.js"; +import { TranslationProvider } from "./context/translation.js"; import { useBackendConfig } from "./hooks/backend.js"; -import { useTranslator } from './i18n/index.js'; -import LoginPage from './paths/login/index.js'; +import { useTranslator } from "./i18n/index.js"; +import LoginPage from "./paths/login/index.js"; export function Application(): VNode { return ( // - - - - - + + + + + // ); } function ApplicationStatusRoutes(): VNode { - const { updateLoginStatus, triedToLog } = useBackendContext() + const { updateLoginStatus, triedToLog } = useBackendContext(); const result = useBackendConfig(); - const i18n = useTranslator() + const i18n = useTranslator(); const updateLoginInfoAndGoToRoot = (url: string, token?: string) => { - updateLoginStatus(url, token) - route('/') - } + updateLoginStatus(url, token); + route("/"); + }; - const { currency, version } = result.ok ? result.data : { currency: 'unknown', version: 'unknown' } - const ctx = useMemo(() => ({ currency, version }), [currency, version]) + const { currency, version } = result.ok + ? result.data + : { currency: "unknown", version: "unknown" }; + const ctx = useMemo(() => ({ currency, version }), [currency, version]); if (!triedToLog) { - return
- - -
+ return ( +
+ + +
+ ); } - if (result.clientError && result.isUnauthorized) return
- - -
- - if (result.clientError && result.isNotfound) return
- - - -
- - if (result.serverError) return
- - - -
- - if (result.loading) return - - if (!result.ok) return
- - - -
- - return
- - - -
+ if (result.clientError && result.isUnauthorized) + return ( +
+ + +
+ ); + + if (result.clientError && result.isNotfound) + return ( +
+ + + +
+ ); + + if (result.serverError) + return ( +
+ + + +
+ ); + + if (result.loading) return ; + + if (!result.ok) + return ( +
+ + + +
+ ); + + return ( +
+ + + +
+ ); } diff --git a/packages/merchant-backoffice-ui/src/ApplicationReadyRoutes.tsx b/packages/merchant-backoffice-ui/src/ApplicationReadyRoutes.tsx index 78cbd505b..fe4493bff 100644 --- a/packages/merchant-backoffice-ui/src/ApplicationReadyRoutes.tsx +++ b/packages/merchant-backoffice-ui/src/ApplicationReadyRoutes.tsx @@ -25,7 +25,10 @@ import { useBackendInstancesTestForAdmin } from "./hooks/backend.js"; import { InstanceRoutes } from "./InstanceRoutes.js"; import LoginPage from "./paths/login/index.js"; import { INSTANCE_ID_LOOKUP } from "./utils/constants.js"; -import { NotYetReadyAppMenu, NotificationCard } from "./components/menu/index.js"; +import { + NotYetReadyAppMenu, + NotificationCard, +} from "./components/menu/index.js"; import { useTranslator } from "./i18n/index.js"; import { createHashHistory } from "history"; import { useState } from "preact/hooks"; @@ -107,7 +110,7 @@ export function ApplicationReadyRoutes(): VNode { function DefaultMainRoute({ instance, admin, instanceNameByBackendURL }: any) { const [instanceName, setInstanceName] = useState( - instanceNameByBackendURL || instance || "default" + instanceNameByBackendURL || instance || "default", ); return ( diff --git a/packages/merchant-backoffice-ui/src/InstanceRoutes.tsx b/packages/merchant-backoffice-ui/src/InstanceRoutes.tsx index eef8e68ac..adfc73e20 100644 --- a/packages/merchant-backoffice-ui/src/InstanceRoutes.tsx +++ b/packages/merchant-backoffice-ui/src/InstanceRoutes.tsx @@ -131,7 +131,7 @@ export function InstanceRoutes({ id, admin, setInstanceName }: Props): VNode { const value = useMemo( () => ({ id, token, admin, changeToken }), - [id, token, admin] + [id, token, admin], ); function ServerErrorRedirectTo(to: InstancePaths | AdminPaths) { @@ -451,7 +451,7 @@ function AdminInstanceUpdatePage({ }; const value = useMemo( () => ({ id, token, admin: true, changeToken }), - [id, token] + [id, token], ); const i18n = useTranslator(); diff --git a/packages/merchant-backoffice-ui/src/components/exception/AsyncButton.tsx b/packages/merchant-backoffice-ui/src/components/exception/AsyncButton.tsx index b234ce847..510bc29b8 100644 --- a/packages/merchant-backoffice-ui/src/components/exception/AsyncButton.tsx +++ b/packages/merchant-backoffice-ui/src/components/exception/AsyncButton.tsx @@ -15,9 +15,9 @@ */ /** -* -* @author Sebastian Javier Marchano (sebasjm) -*/ + * + * @author Sebastian Javier Marchano (sebasjm) + */ import { ComponentChildren, h } from "preact"; import { LoadingModal } from "../modal/index.js"; @@ -25,10 +25,10 @@ import { useAsync } from "../../hooks/async.js"; import { Translate } from "../../i18n/index.js"; type Props = { - children: ComponentChildren, + children: ComponentChildren; disabled: boolean; onClick?: () => Promise; - [rest:string]: any, + [rest: string]: any; }; export function AsyncButton({ onClick, disabled, children, ...rest }: Props) { @@ -38,12 +38,18 @@ export function AsyncButton({ onClick, disabled, children, ...rest }: Props) { return ; } if (isLoading) { - return ; + return ( + + ); } - return - - ; + return ( + + + + ); } diff --git a/packages/merchant-backoffice-ui/src/components/exception/loading.tsx b/packages/merchant-backoffice-ui/src/components/exception/loading.tsx index 9c9b4daae..a043b81eb 100644 --- a/packages/merchant-backoffice-ui/src/components/exception/loading.tsx +++ b/packages/merchant-backoffice-ui/src/components/exception/loading.tsx @@ -15,18 +15,34 @@ */ /** -* -* @author Sebastian Javier Marchano (sebasjm) -*/ + * + * @author Sebastian Javier Marchano (sebasjm) + */ import { h, VNode } from "preact"; export function Loading(): VNode { - return
- -
+ return ( +
+ +
+ ); } export function Spinner(): VNode { - return
-} \ No newline at end of file + return ( +
+
+
+
+
+
+ ); +} diff --git a/packages/merchant-backoffice-ui/src/components/exception/login.tsx b/packages/merchant-backoffice-ui/src/components/exception/login.tsx index c2af2a83a..d1898915d 100644 --- a/packages/merchant-backoffice-ui/src/components/exception/login.tsx +++ b/packages/merchant-backoffice-ui/src/components/exception/login.tsx @@ -46,7 +46,7 @@ export function LoginModal({ onConfirm, withMessage }: Props): VNode { const { url: backendUrl, token: baseToken } = useBackendContext(); const { admin, token: instanceToken } = useInstanceContext(); const currentToken = getTokenValuePart( - !admin ? baseToken : instanceToken || "" + !admin ? baseToken : instanceToken || "", ); const [token, setToken] = useState(currentToken); diff --git a/packages/merchant-backoffice-ui/src/components/form/FormProvider.tsx b/packages/merchant-backoffice-ui/src/components/form/FormProvider.tsx index ab32b6bed..7bcebd706 100644 --- a/packages/merchant-backoffice-ui/src/components/form/FormProvider.tsx +++ b/packages/merchant-backoffice-ui/src/components/form/FormProvider.tsx @@ -15,37 +15,59 @@ */ /** -* -* @author Sebastian Javier Marchano (sebasjm) -*/ + * + * @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; +type Updater = (value: (prevState: S) => S) => void; export interface Props { object?: Partial; errors?: FormErrors; name?: string; valueHandler: Updater> | null; - children: ComponentChildren + children: ComponentChildren; } -const noUpdater: Updater> = () => (s: unknown) => s +const noUpdater: Updater> = () => (s: unknown) => s; -export function FormProvider({ object = {}, errors = {}, name = '', valueHandler, children }: Props): VNode { +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} -
-
; + 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 { @@ -58,24 +80,24 @@ export interface FormType { valueHandler: Updater>; } -const FormContext = createContext>(null!) +const FormContext = createContext>(null!); export function useFormContext() { - return useContext>(FormContext) + return useContext>(FormContext); } export type FormErrors = { - [P in keyof T]?: string | FormErrors -} + [P in keyof T]?: string | FormErrors; +}; export type FormtoStr = { - [P in keyof T]?: ((f?: T[P]) => string) -} + [P in keyof T]?: (f?: T[P]) => string; +}; export type FormfromStr = { - [P in keyof T]?: ((f: string) => T[P]) -} + [P in keyof T]?: (f: string) => T[P]; +}; export type FormUpdater = { - [P in keyof T]?: (f: keyof T) => (v: T[P]) => void -} + [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 index 793477f3d..54140ba4d 100644 --- a/packages/merchant-backoffice-ui/src/components/form/Input.tsx +++ b/packages/merchant-backoffice-ui/src/components/form/Input.tsx @@ -15,57 +15,101 @@ */ /** -* -* @author Sebastian Javier Marchano (sebasjm) -*/ + * + * @author Sebastian Javier Marchano (sebasjm) + */ import { ComponentChildren, h, VNode } from "preact"; import { useField, InputProps } from "./useField.js"; interface Props extends InputProps { - inputType?: 'text' | 'number' | 'multiline' | 'password'; + inputType?: "text" | "number" | "multiline" | "password"; expand?: boolean; toStr?: (v?: any) => string; fromStr?: (s: string) => any; - inputExtra?: any, + inputExtra?: any; side?: ComponentChildren; children?: ComponentChildren; } -const defaultToString = (f?: any): string => f || '' -const defaultFromString = (v: string): any => v as any +const defaultToString = (f?: any): string => f || ""; +const defaultFromString = (v: string): any => v as any; -const TextInput = ({ inputType, error, ...rest }: any) => inputType === 'multiline' ? -