From 72b429321553841ac1ff48cf974bfc65da01bb06 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Mon, 19 Dec 2022 12:23:39 -0300 Subject: pretty --- .../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 +- 36 files changed, 2285 insertions(+), 1340 deletions(-) (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 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' ? -