@zauru-sdk/components 1.0.13 → 1.0.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (94) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/Chat/ChatLayout.d.ts +17 -0
  3. package/dist/Chat/ChatLayout.js +28 -0
  4. package/dist/Chat/ChatMessageHistory.d.ts +12 -0
  5. package/dist/Chat/ChatMessageHistory.js +53 -0
  6. package/dist/Chat/index.d.ts +2 -0
  7. package/dist/Chat/index.js +2 -0
  8. package/dist/ConnectionState/ConnectionState.d.ts +2 -0
  9. package/dist/ConnectionState/ConnectionState.js +22 -0
  10. package/dist/ConnectionState/index.d.ts +1 -0
  11. package/dist/ConnectionState/index.js +1 -0
  12. package/dist/DynamicTable/BasicPrintDynamicTable.d.ts +10 -0
  13. package/dist/DynamicTable/BasicPrintDynamicTable.js +27 -0
  14. package/dist/DynamicTable/DynamicPrintTable.d.ts +23 -0
  15. package/dist/DynamicTable/DynamicPrintTable.js +132 -0
  16. package/dist/DynamicTable/GenericDynamicTable.d.ts +21 -0
  17. package/dist/DynamicTable/GenericDynamicTable.js +195 -0
  18. package/dist/DynamicTable/index.d.ts +24 -0
  19. package/dist/DynamicTable/index.js +193 -0
  20. package/dist/Footer/Footer.js +2 -2
  21. package/dist/Form/Checkbox/index.d.ts +17 -0
  22. package/dist/Form/Checkbox/index.js +34 -0
  23. package/dist/Form/Checklist/index.d.ts +14 -0
  24. package/dist/Form/Checklist/index.js +10 -0
  25. package/dist/Form/DatePicker/index.d.ts +18 -0
  26. package/dist/Form/DatePicker/index.js +31 -0
  27. package/dist/Form/DynamicBaculoForm/index.d.ts +18 -0
  28. package/dist/Form/DynamicBaculoForm/index.js +138 -0
  29. package/dist/Form/FieldContainer/DoubleFieldContainer.d.ts +8 -0
  30. package/dist/Form/FieldContainer/DoubleFieldContainer.js +14 -0
  31. package/dist/Form/FieldContainer/QuadrupleFieldContainer.d.ts +7 -0
  32. package/dist/Form/FieldContainer/QuadrupleFieldContainer.js +14 -0
  33. package/dist/Form/FieldContainer/TripleFieldContainer.d.ts +7 -0
  34. package/dist/Form/FieldContainer/TripleFieldContainer.js +14 -0
  35. package/dist/Form/FieldContainer/index.d.ts +3 -0
  36. package/dist/Form/FieldContainer/index.js +3 -0
  37. package/dist/Form/FileUpload/index.d.ts +21 -0
  38. package/dist/Form/FileUpload/index.js +54 -0
  39. package/dist/Form/FormButtons/index.d.ts +16 -0
  40. package/dist/Form/FormButtons/index.js +5 -0
  41. package/dist/Form/FormLayout/index.d.ts +11 -0
  42. package/dist/Form/FormLayout/index.js +7 -0
  43. package/dist/Form/SelectField/index.d.ts +27 -0
  44. package/dist/Form/SelectField/index.js +74 -0
  45. package/dist/Form/TextArea/index.d.ts +23 -0
  46. package/dist/Form/TextArea/index.js +36 -0
  47. package/dist/Form/TextField/index.d.ts +25 -0
  48. package/dist/Form/TextField/index.js +70 -0
  49. package/dist/Form/TimePicker/index.d.ts +16 -0
  50. package/dist/Form/TimePicker/index.js +31 -0
  51. package/dist/Form/YesNo/index.d.ts +12 -0
  52. package/dist/Form/YesNo/index.js +19 -0
  53. package/dist/Form/index.d.ts +13 -0
  54. package/dist/Form/index.js +13 -0
  55. package/dist/Zendesk/Chat.d.ts +14 -0
  56. package/dist/Zendesk/Chat.js +64 -0
  57. package/dist/Zendesk/index.d.ts +2 -0
  58. package/dist/Zendesk/index.js +2 -0
  59. package/dist/Zendesk/zendesk.config.d.ts +9 -0
  60. package/dist/Zendesk/zendesk.config.js +24 -0
  61. package/dist/index.d.ts +4 -0
  62. package/dist/index.js +4 -2
  63. package/package.json +5 -5
  64. package/src/Chat/ChatLayout.tsx +133 -0
  65. package/src/Chat/ChatMessageHistory.tsx +142 -0
  66. package/src/Chat/index.ts +2 -0
  67. package/src/ConnectionState/ConnectionState.tsx +29 -0
  68. package/src/ConnectionState/index.tsx +1 -0
  69. package/src/DynamicTable/BasicPrintDynamicTable.tsx +73 -0
  70. package/src/DynamicTable/DynamicPrintTable.tsx +290 -0
  71. package/src/DynamicTable/GenericDynamicTable.tsx +455 -0
  72. package/src/DynamicTable/index.tsx +407 -0
  73. package/src/Footer/Footer.tsx +3 -3
  74. package/src/Form/Checkbox/index.tsx +96 -0
  75. package/src/Form/Checklist/index.tsx +35 -0
  76. package/src/Form/DatePicker/index.tsx +132 -0
  77. package/src/Form/DynamicBaculoForm/index.tsx +359 -0
  78. package/src/Form/FieldContainer/DoubleFieldContainer.tsx +35 -0
  79. package/src/Form/FieldContainer/QuadrupleFieldContainer.tsx +36 -0
  80. package/src/Form/FieldContainer/TripleFieldContainer.tsx +35 -0
  81. package/src/Form/FieldContainer/index.ts +3 -0
  82. package/src/Form/FileUpload/index.tsx +184 -0
  83. package/src/Form/FormButtons/index.tsx +78 -0
  84. package/src/Form/FormLayout/index.tsx +37 -0
  85. package/src/Form/SelectField/index.tsx +237 -0
  86. package/src/Form/TextArea/index.tsx +125 -0
  87. package/src/Form/TextField/index.tsx +194 -0
  88. package/src/Form/TimePicker/index.tsx +127 -0
  89. package/src/Form/YesNo/index.tsx +79 -0
  90. package/src/Form/index.ts +13 -0
  91. package/src/Zendesk/Chat.tsx +85 -0
  92. package/src/Zendesk/index.ts +2 -0
  93. package/src/Zendesk/zendesk.config.ts +40 -0
  94. package/src/index.ts +4 -2
@@ -0,0 +1,54 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { DownloadIconSVG, IdeaIconSVG } from "@zauru-sdk/icons";
3
+ import { useAppSelector } from "@zauru-sdk/redux";
4
+ import { useState } from "react";
5
+ export const FileUploadFieldWithoutValidation = (props) => {
6
+ const { id, name, title, helpText, hint, onChange, disabled = false, readOnly = false, error, fileTypes = [], showAvailableTypes = false, className, defaultValue = undefined, download = false, } = props;
7
+ const [showTooltip, setShowTooltip] = useState(false);
8
+ if (typeof defaultValue == "string") {
9
+ if (download) {
10
+ return (_jsxs("div", { role: "button", tabIndex: 0, onClick: () => {
11
+ window.open(defaultValue, "_blank");
12
+ }, onKeyDown: (event) => {
13
+ // Permite que el evento se active con la tecla Enter
14
+ if (event.key === "Enter") {
15
+ window.open(defaultValue, "_blank");
16
+ }
17
+ }, children: [title && (_jsx("label", { htmlFor: name, className: "block mb-1 text-sm font-medium text-gray-700", children: title })), " ", _jsx(DownloadIconSVG, {})] }));
18
+ }
19
+ return (_jsxs("div", { className: `col-span-6 sm:col-span-3 ${className}`, children: [title && (_jsx("label", { htmlFor: name, className: `block mb-1 text-sm font-medium text-gray-700`, children: title })), " ", _jsx("div", { role: "button", tabIndex: 0, onClick: () => {
20
+ window.open(defaultValue, "_blank");
21
+ }, onKeyDown: (event) => {
22
+ // Permite que el evento se active con la tecla Enter
23
+ if (event.key === "Enter") {
24
+ window.open(defaultValue, "_blank");
25
+ }
26
+ }, children: _jsx("img", { src: defaultValue, alt: name, className: `h-48 w-48 inline mr-1 pb-1`, style: {
27
+ stroke: "currentColor",
28
+ strokeWidth: 2,
29
+ strokeLinecap: "round",
30
+ strokeLinejoin: "round",
31
+ fill: "none",
32
+ backgroundColor: "transparent",
33
+ } }) })] }));
34
+ }
35
+ const handleInputChange = (event) => {
36
+ onChange && onChange(event);
37
+ };
38
+ let hintMessage = hint;
39
+ if (showAvailableTypes && fileTypes.length > 0) {
40
+ hintMessage = `${hint} Archivos permitidos: ${fileTypes.join(", ")}`;
41
+ }
42
+ const color = error ? "red" : "gray";
43
+ const isReadOnly = disabled || readOnly;
44
+ const bgColor = isReadOnly ? "bg-gray-200" : `bg-${color}-50`;
45
+ const textColor = isReadOnly ? "text-gray-500" : `text-${color}-900`;
46
+ const borderColor = isReadOnly ? "border-gray-300" : `border-${color}-500`;
47
+ return (_jsxs("div", { className: `col-span-6 sm:col-span-3 ${className}`, children: [title && (_jsx("label", { htmlFor: name, className: `block mb-1 text-sm font-medium text-${color}-700`, children: title })), _jsxs("div", { className: "flex relative items-center", children: [_jsx("input", { type: "file", name: name, id: id ?? name, disabled: disabled, readOnly: readOnly, accept: fileTypes.map((ft) => `.${ft}`).join(", "), onChange: handleInputChange, className: `block w-full rounded-md ${bgColor} ${borderColor} ${textColor} shadow-sm focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm` }), helpText && (_jsx("div", { className: "flex items-center relative ml-3", children: _jsxs("div", { className: "relative cursor-pointer", onMouseEnter: () => setShowTooltip(true), onMouseLeave: () => setShowTooltip(false), children: [_jsx(IdeaIconSVG, {}), showTooltip && (_jsx("div", { className: "absolute -left-48 top-0 mt-8 p-2 bg-white border rounded shadow text-black z-50", children: helpText }))] }) }))] }), error && (_jsxs("p", { className: `mt-2 text-sm text-${color}-600`, children: [_jsx("span", { className: "font-medium", children: "Oops!" }), " ", error] })), !error && hintMessage && (_jsx("p", { className: `mt-2 italic text-sm text-${color}-500`, children: hintMessage }))] }));
48
+ };
49
+ export const FileUploadField = (props) => {
50
+ const { formValidations } = useAppSelector((state) => state.formValidation);
51
+ const error = formValidations[props.formName ?? "-1"]?.[props.name ?? "-1"];
52
+ props = { ...props, error };
53
+ return _jsx(FileUploadFieldWithoutValidation, { ...props });
54
+ };
@@ -0,0 +1,16 @@
1
+ import React from "react";
2
+ type Props = {
3
+ saveTitle?: string;
4
+ saveName?: string;
5
+ onClickSave?: (e: React.MouseEvent<HTMLButtonElement, MouseEvent>) => void;
6
+ showCancel?: boolean;
7
+ cancelTitle?: string;
8
+ cancelName?: string;
9
+ showClear?: boolean;
10
+ clearTitle?: string;
11
+ clearName?: string;
12
+ loading?: boolean;
13
+ loadingSaveText?: string;
14
+ };
15
+ export declare const FormButtons: (props: Props) => import("react/jsx-runtime").JSX.Element;
16
+ export {};
@@ -0,0 +1,5 @@
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
+ export const FormButtons = (props) => {
3
+ const { saveTitle = "Guardar", saveName = "save", cancelTitle = "Cancelar", cancelName = "cancel", showCancel = true, showClear = false, clearName = "clear", clearTitle = "Limpiar", loading = false, onClickSave, loadingSaveText = "Guardando...", } = props;
4
+ return (_jsxs(_Fragment, { children: [showClear && (_jsx("button", { type: "reset", name: "action", disabled: loading, value: clearName, className: `ml-5 ${loading ? " bg-opacity-25 cursor-progress" : ""} rounded-md border border-gray-300 bg-white py-2 px-3 text-sm font-medium leading-4 text-gray-700 shadow-sm hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2`, children: clearTitle })), showCancel && (_jsx("button", { type: "button", name: "action", disabled: loading, value: cancelName, className: `${showClear ? "ml-2" : "ml-5"} ${loading ? " bg-opacity-25 cursor-progress" : ""} rounded-md border border-gray-300 bg-white py-2 px-3 text-sm font-medium leading-4 text-gray-700 shadow-sm hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2`, children: cancelTitle })), _jsx("button", { type: "submit", name: "action", disabled: loading, value: saveName, onClick: onClickSave, className: `ml-2 ${loading ? " bg-opacity-25 cursor-progress" : "hover:bg-indigo-700"} inline-flex justify-center rounded-md border border-transparent bg-indigo-600 py-2 px-4 text-sm font-medium text-white shadow-sm focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2`, children: loading ? loadingSaveText : saveTitle })] }));
5
+ };
@@ -0,0 +1,11 @@
1
+ import { type FormMethod } from "@remix-run/react";
2
+ import { type ReactNode } from "react";
3
+ type Props = {
4
+ formId: string;
5
+ title?: string;
6
+ children: ReactNode;
7
+ buttons?: ReactNode;
8
+ method?: FormMethod;
9
+ };
10
+ export declare const FormLayout: (props: Props) => import("react/jsx-runtime").JSX.Element;
11
+ export {};
@@ -0,0 +1,7 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Form } from "@remix-run/react";
3
+ import { ButtonSectionContainer } from "src";
4
+ export const FormLayout = (props) => {
5
+ const { title, children, buttons, method, formId } = props;
6
+ return (_jsxs(Form, { id: formId, name: formId, method: method ?? "post", children: [title && (_jsx("label", { className: "block text-sm font-medium text-gray-700 mb-3", children: title })), _jsxs("div", { className: "shadow sm:overflow-hidden sm:rounded-md", children: [_jsx("div", { className: "space-y-6 bg-white px-4 py-5 sm:p-6", children: children }), buttons && (_jsx(ButtonSectionContainer, { children: buttons }))] })] }, formId));
7
+ };
@@ -0,0 +1,27 @@
1
+ import { SelectFieldOption } from "@zauru-sdk/types";
2
+ import type { SingleValue, InputActionMeta } from "react-select";
3
+ type Props = {
4
+ id?: string;
5
+ formName?: string;
6
+ name?: string;
7
+ title?: string;
8
+ defaultValue?: SingleValue<SelectFieldOption>;
9
+ defaultValueMulti?: SingleValue<SelectFieldOption>[];
10
+ helpText?: string;
11
+ options: Array<SelectFieldOption>;
12
+ onChange?: (value: SingleValue<SelectFieldOption>) => void;
13
+ onChangeMulti?: (value: Array<SingleValue<SelectFieldOption>>) => void;
14
+ onInputChange?: (newValue: string, actionMeta: InputActionMeta) => void;
15
+ isClearable?: boolean;
16
+ error?: string | undefined;
17
+ disabled?: boolean;
18
+ menuIsOpen?: boolean;
19
+ readOnly?: boolean;
20
+ isMulti?: boolean;
21
+ loading?: boolean;
22
+ hint?: string;
23
+ className?: string;
24
+ };
25
+ export declare const SelectFieldWithoutValidation: (props: Props) => import("react/jsx-runtime").JSX.Element;
26
+ export declare const SelectField: (props: Props) => import("react/jsx-runtime").JSX.Element;
27
+ export {};
@@ -0,0 +1,74 @@
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { IdeaIconSVG } from "@zauru-sdk/icons";
3
+ import { useAppSelector } from "@zauru-sdk/redux";
4
+ import { useEffect, useState } from "react";
5
+ import Select, { components } from "react-select";
6
+ import { LoadingInputSkeleton } from "src";
7
+ const Input = (props) => (_jsx(components.Input, { ...props, readOnly: props.selectProps.isReadOnly }));
8
+ export const SelectFieldWithoutValidation = (props) => {
9
+ const { id, name, title, defaultValue, defaultValueMulti = [], helpText, hint, options, onChange, onChangeMulti, isClearable = false, error = false, disabled = false, readOnly = false, isMulti = false, loading = false, className = "", onInputChange, } = props;
10
+ const [value, setValue] = useState(defaultValue || null);
11
+ const [valueMulti, setValueMulti] = useState(defaultValueMulti);
12
+ const [inputValue, setInputValue] = useState("");
13
+ const [showTooltip, setShowTooltip] = useState(false);
14
+ const [isClient, setIsClient] = useState(typeof window !== "undefined");
15
+ const menuIsOpen = readOnly ? false : props?.menuIsOpen;
16
+ const color = error ? "red" : "gray";
17
+ let documentRef = null;
18
+ const isReadOnly = disabled || readOnly;
19
+ const bgColor = isReadOnly ? "bg-gray-200" : `bg-${color}-50`;
20
+ const textColor = isReadOnly ? "text-gray-500" : `text-${color}-900`;
21
+ const borderColor = isReadOnly ? "border-gray-300" : `border-${color}-500`;
22
+ if (typeof window !== "undefined") {
23
+ documentRef = document;
24
+ }
25
+ useEffect(() => {
26
+ setValue(defaultValue || null);
27
+ }, [defaultValue]);
28
+ useEffect(() => {
29
+ setIsClient(true);
30
+ }, []);
31
+ if (!isClient || loading || !documentRef) {
32
+ return (_jsxs(_Fragment, { children: [title && (_jsx("label", { htmlFor: error ? `${name}-error` : `${name}-success`, className: `block text-sm font-medium text-${color}-700 dark:text-${color}-500`, children: title })), _jsx(LoadingInputSkeleton, {}), helpText && (_jsx("p", { className: `mt-2 italic text-sm text-${color}-500 dark:text-${color}-400`, children: helpText }))] }));
33
+ }
34
+ const handleOnChange = (selection) => {
35
+ // Verificar si el valor de selección es un objeto con propiedades 'value' y 'label'
36
+ if (typeof selection === "object" &&
37
+ selection !== null &&
38
+ "value" in selection &&
39
+ "label" in selection) {
40
+ setValue(selection);
41
+ onChange && onChange(selection);
42
+ }
43
+ else {
44
+ setValue(null);
45
+ onChange && onChange(null);
46
+ }
47
+ };
48
+ const handleOnChangeMulti = (selection) => {
49
+ if (Array.isArray(selection)) {
50
+ setValueMulti(selection);
51
+ onChangeMulti &&
52
+ onChangeMulti(selection);
53
+ }
54
+ else {
55
+ setValueMulti([]);
56
+ onChangeMulti && onChangeMulti([]);
57
+ }
58
+ };
59
+ const selectComponent = (_jsxs(_Fragment, { children: [_jsx(Select, { className: `block w-full rounded-md ${bgColor} ${borderColor} ${textColor} shadow-sm focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm`, id: isMulti ? undefined : id, instanceId: isMulti ? undefined : id, isDisabled: disabled, name: isMulti ? undefined : name, options: options, onChange: isMulti ? handleOnChangeMulti : handleOnChange, defaultValue: isMulti ? valueMulti : value, onInputChange: (newValue, actionMeta) => {
60
+ setInputValue(newValue);
61
+ onInputChange && onInputChange(newValue, actionMeta);
62
+ }, inputValue: inputValue, onMenuOpen: () => { }, onMenuClose: () => { }, menuPortalTarget: documentRef?.body, styles: { menuPortal: (base) => ({ ...base, zIndex: 9999 }) }, isClearable: isClearable, isSearchable: true, components: { Input }, menuIsOpen: menuIsOpen,
63
+ //windowThreshold={50}
64
+ isMulti: isMulti }), isMulti && (_jsx("input", { hidden: true, readOnly: true, name: name, value: valueMulti.map((x) => x?.value).join(","), id: id }))] }));
65
+ return (_jsxs("div", { className: `col-span-6 sm:col-span-3 ${className}`, children: [title && (_jsx("label", { htmlFor: error ? `${name}-error` : `${name}-success`, className: `block text-sm font-medium ${color === "red"
66
+ ? "text-red-700 dark:text-red-500"
67
+ : "text-gray-700 dark:text-gray-500"}`, children: title })), _jsxs("div", { className: "flex relative items-center", children: [selectComponent, helpText && (_jsx("div", { className: "flex items-center relative ml-3", children: _jsxs("div", { className: "relative cursor-pointer", onMouseEnter: () => setShowTooltip(true), onMouseLeave: () => setShowTooltip(false), children: [_jsx(IdeaIconSVG, {}), showTooltip && (_jsx("div", { className: "absolute -left-48 top-0 mt-8 p-2 bg-white border rounded shadow text-black z-50", children: helpText }))] }) }))] }), error && (_jsxs("p", { className: `mt-2 text-sm text-${color}-600 dark:text-${color}-500`, children: [_jsx("span", { className: "font-medium", children: "Oops!" }), " ", error] })), !error && hint && (_jsx("p", { className: `mt-2 italic text-sm text-${color}-500 dark:text-${color}-400`, children: hint }))] }));
68
+ };
69
+ export const SelectField = (props) => {
70
+ const { formValidations } = useAppSelector((state) => state.formValidation);
71
+ const error = formValidations[props.formName ?? "-1"]?.[props.name ?? "-1"];
72
+ props = { ...props, error };
73
+ return _jsx(SelectFieldWithoutValidation, { ...props });
74
+ };
@@ -0,0 +1,23 @@
1
+ import React from "react";
2
+ type Props = {
3
+ id?: string;
4
+ name: string;
5
+ formName?: string;
6
+ title?: string;
7
+ defaultValue?: string | number;
8
+ hidden?: boolean;
9
+ hint?: string;
10
+ helpText?: string;
11
+ onChange?: (value: string) => void;
12
+ onKeyDown?: (event: React.KeyboardEvent) => void;
13
+ disabled?: boolean;
14
+ readOnly?: boolean;
15
+ error?: string | undefined;
16
+ rows?: number;
17
+ cols?: number;
18
+ stopChangeEvents?: boolean;
19
+ className?: string;
20
+ };
21
+ export declare const TextAreaWithoutValidation: (props: Props) => import("react/jsx-runtime").JSX.Element;
22
+ export declare const TextArea: (props: Props) => import("react/jsx-runtime").JSX.Element;
23
+ export {};
@@ -0,0 +1,36 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useAppSelector } from "@zauru-sdk/redux";
3
+ import { useEffect, useState } from "react";
4
+ export const TextAreaWithoutValidation = (props) => {
5
+ const { id, name, title, defaultValue = "", hidden, hint, onChange, onKeyDown, disabled = false, error = false, readOnly = false, rows, cols, stopChangeEvents, className = "", } = props;
6
+ const [value, setValue] = useState(defaultValue);
7
+ const color = error ? "red" : "gray";
8
+ const isReadOnly = disabled || readOnly;
9
+ const bgColor = isReadOnly ? "bg-gray-200" : `bg-${color}-50`;
10
+ const textColor = isReadOnly ? "text-gray-500" : `text-${color}-900`;
11
+ const borderColor = isReadOnly ? "border-gray-300" : `border-${color}-500`;
12
+ useEffect(() => {
13
+ setValue(defaultValue);
14
+ }, [defaultValue]);
15
+ if (hidden) {
16
+ return (_jsx("textarea", { id: id ?? name, name: name, value: defaultValue, readOnly: true, hidden: true }));
17
+ }
18
+ const handleInputChange = (event) => {
19
+ if (stopChangeEvents) {
20
+ event.stopPropagation();
21
+ event.preventDefault();
22
+ }
23
+ setValue(event.target.value);
24
+ onChange && onChange(event.target.value);
25
+ };
26
+ return (_jsxs("div", { className: `col-span-6 sm:col-span-3 ${className}`, children: [title && (_jsx("label", { htmlFor: error ? `${name}-error` : `${name}-success`, className: `block text-sm font-medium text-${color}-700 dark:text-${color}-500`, children: title })), _jsx("textarea", { name: name, readOnly: readOnly, disabled: disabled, id: id ?? name, autoComplete: "given-name", value: value, rows: rows, cols: cols, onChange: handleInputChange, onKeyDown: (event) => {
27
+ onKeyDown && onKeyDown(event);
28
+ }, className: `mt-1 block w-full rounded-md ${bgColor} ${borderColor} ${textColor} shadow-sm focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm` }), error && (_jsxs("p", { className: `mt-2 text-sm text-${color}-600 dark:text-${color}-500`, children: [_jsx("span", { className: "font-medium", children: "Oops!" }), " ", error] })), !error && hint && (_jsx("p", { className: `mt-2 italic text-sm text-${color}-500 dark:text-${color}-400`, children: hint }))] }));
29
+ };
30
+ //<reference> https://tailwindui.com/components/application-ui/forms/form-layouts
31
+ export const TextArea = (props) => {
32
+ const { formValidations } = useAppSelector((state) => state.formValidation);
33
+ const error = formValidations[props.formName ?? "-1"]?.[props.name ?? "-1"];
34
+ props = { ...props, error };
35
+ return _jsx(TextAreaWithoutValidation, { ...props });
36
+ };
@@ -0,0 +1,25 @@
1
+ import React from "react";
2
+ type Props = {
3
+ id?: string;
4
+ name?: string;
5
+ formName?: string;
6
+ title?: string;
7
+ defaultValue?: string | number;
8
+ hidden?: boolean;
9
+ type?: React.HTMLInputTypeAttribute;
10
+ helpText?: string;
11
+ hint?: string;
12
+ onChange?: (value: string, event: React.ChangeEvent<HTMLInputElement>) => void;
13
+ onKeyDown?: (event: React.KeyboardEvent) => void;
14
+ disabled?: boolean;
15
+ readOnly?: boolean;
16
+ error?: string;
17
+ min?: string | number;
18
+ integer?: boolean;
19
+ stopChangeEvents?: boolean;
20
+ style?: React.CSSProperties;
21
+ className?: string;
22
+ };
23
+ export declare const TextFieldWithoutValidation: (props: Props) => import("react/jsx-runtime").JSX.Element;
24
+ export declare const TextField: (props: Props) => import("react/jsx-runtime").JSX.Element;
25
+ export {};
@@ -0,0 +1,70 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { IdeaIconSVG } from "@zauru-sdk/icons";
3
+ import { useAppSelector } from "@zauru-sdk/redux";
4
+ import { useEffect, useState } from "react";
5
+ export const TextFieldWithoutValidation = (props) => {
6
+ const { id, name, defaultValue = "", hidden, type = "text", onChange, onKeyDown, disabled = false, readOnly = false, min, integer = false, stopChangeEvents, style, error, title, helpText, className, hint, } = props;
7
+ const [showTooltip, setShowTooltip] = useState(false);
8
+ const [value, setValue] = useState(defaultValue);
9
+ const color = error ? "red" : "gray";
10
+ const isReadOnly = disabled || readOnly;
11
+ const bgColor = isReadOnly ? "bg-gray-200" : `bg-${color}-50`;
12
+ const textColor = isReadOnly ? "text-gray-500" : `text-${color}-900`;
13
+ const borderColor = isReadOnly ? "border-gray-300" : `border-${color}-500`;
14
+ useEffect(() => {
15
+ setValue(defaultValue);
16
+ }, [defaultValue]);
17
+ if (hidden) {
18
+ return (_jsx("input", { type: type, id: id ?? name, name: name, value: defaultValue, readOnly: true, hidden: true }));
19
+ }
20
+ const handleInputChange = (event) => {
21
+ if (stopChangeEvents) {
22
+ event.stopPropagation();
23
+ event.preventDefault();
24
+ }
25
+ if (integer && type === "number") {
26
+ const value = event.target.value;
27
+ const isInteger = /^[0-9]*$/.test(value);
28
+ if (isInteger || value === "") {
29
+ setValue(value);
30
+ onChange && onChange(value, event);
31
+ }
32
+ }
33
+ else {
34
+ setValue(event.target.value);
35
+ onChange && onChange(event.target.value, event);
36
+ }
37
+ };
38
+ const handleKeyDown = (event) => {
39
+ if (integer && type === "number") {
40
+ // Permitir solo números y teclas de control
41
+ const allowedKeys = [
42
+ "Backspace",
43
+ "ArrowLeft",
44
+ "ArrowRight",
45
+ "Delete",
46
+ "Enter",
47
+ "Tab",
48
+ ];
49
+ if (!allowedKeys.includes(event.key) && !/^[0-9]$/.test(event.key)) {
50
+ event.preventDefault();
51
+ }
52
+ }
53
+ };
54
+ const inputComponent = (_jsx("input", { type: type, name: name, readOnly: readOnly, disabled: disabled, id: id ?? name, autoComplete: "given-name", value: value, onWheel: (e) => {
55
+ e.currentTarget.blur();
56
+ }, step: type === "number" ? 0.01 : undefined, onChange: handleInputChange, onKeyDown: (event) => {
57
+ handleKeyDown(event);
58
+ onKeyDown && onKeyDown(event);
59
+ }, min: min, style: style, className: `block w-full rounded-md ${bgColor} ${borderColor} ${textColor} shadow-sm focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm` }));
60
+ if (!error && !title) {
61
+ return _jsx("div", { className: `${className}`, children: inputComponent });
62
+ }
63
+ return (_jsxs("div", { className: `col-span-6 sm:col-span-3 ${className}`, children: [title && (_jsx("label", { htmlFor: error ? `${name}-error` : `${name}-success`, className: `block mb-1 text-sm font-medium text-${color}-700 dark:text-${color}-500`, children: title })), _jsxs("div", { className: "flex relative items-center", children: [inputComponent, helpText && (_jsx("div", { className: "flex items-center relative ml-3", children: _jsxs("div", { className: "relative cursor-pointer", onMouseEnter: () => setShowTooltip(true), onMouseLeave: () => setShowTooltip(false), children: [_jsx(IdeaIconSVG, {}), showTooltip && (_jsx("div", { className: "absolute -left-48 top-0 mt-8 p-2 bg-white border rounded shadow text-black z-50", children: helpText }))] }) }))] }), error && (_jsxs("p", { className: `mt-2 text-sm text-${color}-600 dark:text-${color}-500`, children: [_jsx("span", { className: "font-medium", children: "Oops!" }), " ", error] })), !error && hint && (_jsx("p", { className: `mt-2 italic text-sm text-${color}-500 dark:text-${color}-400`, children: hint }))] }));
64
+ };
65
+ export const TextField = (props) => {
66
+ const { formValidations } = useAppSelector((state) => state.formValidation);
67
+ const error = formValidations[props.formName ?? "-1"]?.[props.name ?? "-1"];
68
+ props = { ...props, error };
69
+ return _jsx(TextFieldWithoutValidation, { ...props });
70
+ };
@@ -0,0 +1,16 @@
1
+ type Props = {
2
+ id?: string;
3
+ name: string;
4
+ formName?: string;
5
+ title?: string;
6
+ hint?: string;
7
+ helpText?: string;
8
+ defaultValue?: string;
9
+ onChange?: (value: string) => void;
10
+ tabIndex?: number;
11
+ error?: string;
12
+ disabled?: boolean;
13
+ };
14
+ export declare const FormTimePickerWithoutValidation: (props: Props) => import("react/jsx-runtime").JSX.Element;
15
+ export declare const FormTimePicker: (props: Props) => import("react/jsx-runtime").JSX.Element;
16
+ export {};
@@ -0,0 +1,31 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { ClockIconSVG, CloseSvgIcon, IdeaIconSVG } from "@zauru-sdk/icons";
3
+ import { useAppSelector } from "@zauru-sdk/redux";
4
+ import { useEffect, useState } from "react";
5
+ export const FormTimePickerWithoutValidation = (props) => {
6
+ const { id, name, title, defaultValue = "", hint, helpText, onChange, tabIndex, error, disabled = false, } = props;
7
+ const [value, setValue] = useState(defaultValue);
8
+ const [showTooltip, setShowTooltip] = useState(false);
9
+ const color = error ? "red" : "gray";
10
+ const isReadOnly = disabled;
11
+ const bgColor = isReadOnly ? "bg-gray-200" : `bg-${color}-50`;
12
+ const textColor = isReadOnly ? "text-gray-500" : `text-${color}-500`;
13
+ const borderColor = isReadOnly ? "border-gray-300" : `border-${color}-200`;
14
+ useEffect(() => {
15
+ setValue(defaultValue);
16
+ }, [defaultValue]);
17
+ const clearValue = () => {
18
+ setValue("");
19
+ onChange && onChange("");
20
+ };
21
+ return (_jsxs(_Fragment, { children: [title && (_jsx("label", { htmlFor: error ? `${name}-error` : `${name}-success`, className: `block text-sm font-medium ${textColor}`, children: title })), _jsxs("div", { className: "flex relative items-center", children: [_jsx("div", { className: "absolute left-0 flex items-center pl-3 pointer-events-none", children: _jsx(ClockIconSVG, {}) }), _jsx("input", { id: id, name: name, tabIndex: tabIndex, type: "time", onChange: (e) => {
22
+ setValue(e.target.value);
23
+ onChange && onChange(e.target.value);
24
+ }, value: value, pattern: "\\d{2}:\\d{2}", className: `${bgColor} ${borderColor} ${textColor} text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full pl-10 p-2.5` }), value && (_jsx("button", { type: "button", onClick: clearValue, className: "absolute right-0 mr-10", children: _jsx(CloseSvgIcon, {}) })), helpText && (_jsx("div", { className: "flex items-center relative ml-3", children: _jsxs("div", { className: "relative cursor-pointer", onMouseEnter: () => setShowTooltip(true), onMouseLeave: () => setShowTooltip(false), children: [_jsx(IdeaIconSVG, {}), showTooltip && (_jsx("div", { className: "absolute -left-48 top-0 mt-8 p-2 bg-white border rounded shadow text-black", children: helpText }))] }) }))] }), error && (_jsxs("p", { className: `mt-2 text-sm text-${color}-600 dark:text-${color}-500`, children: [_jsx("span", { className: "font-medium", children: "Oops!" }), " ", error] })), !error && hint && (_jsx("p", { className: `mt-2 italic text-sm text-${color}-500 dark:text-${color}-400`, children: hint }))] }));
25
+ };
26
+ export const FormTimePicker = (props) => {
27
+ const { formValidations } = useAppSelector((state) => state.formValidation);
28
+ const error = formValidations[props.formName ?? "-1"]?.[props.name ?? "-1"];
29
+ props = { ...props, error };
30
+ return _jsx(FormTimePickerWithoutValidation, { ...props });
31
+ };
@@ -0,0 +1,12 @@
1
+ type Props = {
2
+ id?: string;
3
+ name: string;
4
+ formName?: string;
5
+ title?: string;
6
+ defaultValue?: boolean;
7
+ helpText?: string;
8
+ onChange?: (value: boolean) => void;
9
+ disabled?: boolean;
10
+ };
11
+ declare const YesNo: (props: Props) => import("react/jsx-runtime").JSX.Element;
12
+ export default YesNo;
@@ -0,0 +1,19 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { useAppSelector } from "@zauru-sdk/redux";
3
+ import { useState } from "react";
4
+ const YesNo = (props) => {
5
+ const { id, name, title, defaultValue = false, helpText, onChange, disabled, } = props;
6
+ const { formValidations } = useAppSelector((state) => state.formValidation);
7
+ const error = formValidations[props.formName ?? "-1"]?.[props.name ?? "-1"];
8
+ const [value, setValue] = useState(defaultValue);
9
+ const color = error ? "red" : "gray";
10
+ const handleOnChange = () => {
11
+ if (disabled)
12
+ return; // No hacer nada si está deshabilitado
13
+ const newValue = !value;
14
+ setValue(newValue);
15
+ onChange && onChange(newValue);
16
+ };
17
+ return (_jsxs(_Fragment, { children: [_jsxs("label", { className: `relative inline-flex items-center cursor-pointer ${disabled ? "opacity-50" : ""}`, children: [_jsx("input", { type: "checkbox", id: id ?? name, name: name, checked: value, value: value.toString(), className: "sr-only peer", onChange: handleOnChange, disabled: disabled }), value.toString() === "false" && (_jsx("input", { type: "hidden", name: name, value: "false" })), _jsx("div", { className: "w-11 h-6 bg-gray-200 peer-focus:outline-none peer-focus:ring-4 peer-focus:ring-blue-300 rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-blue-600" }), _jsx("span", { className: "ml-3 text-sm font-medium text-gray-900", children: title })] }), error && (_jsxs("p", { className: `mt-2 text-sm text-${color}-600 dark:text-${color}-500`, children: [_jsx("span", { className: "font-medium", children: "Oops!" }), " ", error] })), !error && helpText && (_jsx("p", { className: `mt-2 italic text-sm text-${color}-500 dark:text-${color}-400`, children: helpText }))] }));
18
+ };
19
+ export default YesNo;
@@ -0,0 +1,13 @@
1
+ export * from "./Checkbox";
2
+ export * from "./Checklist";
3
+ export * from "./DatePicker";
4
+ export * from "./DynamicBaculoForm";
5
+ export * from "./FieldContainer";
6
+ export * from "./FileUpload";
7
+ export * from "./FormButtons";
8
+ export * from "./FormLayout";
9
+ export * from "./SelectField";
10
+ export * from "./TextArea";
11
+ export * from "./TextField";
12
+ export * from "./TimePicker";
13
+ export * from "./YesNo";
@@ -0,0 +1,13 @@
1
+ export * from "./Checkbox";
2
+ export * from "./Checklist";
3
+ export * from "./DatePicker";
4
+ export * from "./DynamicBaculoForm";
5
+ export * from "./FieldContainer";
6
+ export * from "./FileUpload";
7
+ export * from "./FormButtons";
8
+ export * from "./FormLayout";
9
+ export * from "./SelectField";
10
+ export * from "./TextArea";
11
+ export * from "./TextField";
12
+ export * from "./TimePicker";
13
+ export * from "./YesNo";
@@ -0,0 +1,14 @@
1
+ /// <reference types="react" />
2
+ export declare const logoutFromZendesk: () => void;
3
+ export declare const ZendeskAPI: (...args: any[]) => void;
4
+ interface ZendeskProps {
5
+ defer?: boolean;
6
+ onLoaded?: () => void;
7
+ token: string;
8
+ configuration: {
9
+ zendeskChatKey: string;
10
+ };
11
+ [key: string]: any;
12
+ }
13
+ declare const Zendesk: React.FC<ZendeskProps>;
14
+ export default Zendesk;
@@ -0,0 +1,64 @@
1
+ import { useEffect } from "react";
2
+ const canUseDOM = () => {
3
+ if (typeof window === "undefined" ||
4
+ !window.document ||
5
+ !window.document.createElement) {
6
+ return false;
7
+ }
8
+ return true;
9
+ };
10
+ export const logoutFromZendesk = () => {
11
+ if (canUseDOM() && window.zE) {
12
+ window.zE("messenger", "logoutUser");
13
+ }
14
+ else {
15
+ console.warn("Zendesk is not initialized yet");
16
+ }
17
+ };
18
+ export const ZendeskAPI = (...args) => {
19
+ if (canUseDOM() && window.zE) {
20
+ window.zE.apply(null, args);
21
+ }
22
+ else {
23
+ console.warn("Zendesk is not initialized yet");
24
+ }
25
+ };
26
+ const Zendesk = (props) => {
27
+ const { defer, configuration, token, ...other } = props;
28
+ useEffect(() => {
29
+ const insertScript = () => {
30
+ const zendeskScript = document.createElement("script");
31
+ if (defer) {
32
+ zendeskScript.defer = true;
33
+ }
34
+ else {
35
+ zendeskScript.async = true;
36
+ }
37
+ zendeskScript.id = "ze-snippet";
38
+ zendeskScript.src = `https://static.zdassets.com/ekr/snippet.js?key=${configuration.zendeskChatKey}`;
39
+ zendeskScript.addEventListener("load", () => {
40
+ if (props.onLoaded) {
41
+ props.onLoaded();
42
+ }
43
+ window.zE("messenger", "loginUser", function (callback) {
44
+ callback(token);
45
+ });
46
+ });
47
+ document.body.appendChild(zendeskScript);
48
+ return zendeskScript; // Devolvemos la referencia del script
49
+ };
50
+ let script; // Guardamos la referencia del script aquí
51
+ if (canUseDOM() && !window.zE) {
52
+ script = insertScript();
53
+ window.zESettings = other;
54
+ }
55
+ return () => {
56
+ if (script) {
57
+ // Si el script existe, lo eliminamos del DOM
58
+ script.remove();
59
+ }
60
+ };
61
+ }, [props, defer, other, configuration, token]);
62
+ return null;
63
+ };
64
+ export default Zendesk;
@@ -0,0 +1,2 @@
1
+ export * from "./Chat";
2
+ export * from "./zendesk.config";
@@ -0,0 +1,2 @@
1
+ export * from "./Chat";
2
+ export * from "./zendesk.config";
@@ -0,0 +1,9 @@
1
+ export declare function zendeskJwt(current_user: {
2
+ selected_entity_id: number;
3
+ id: number;
4
+ email: string;
5
+ name: string;
6
+ }, configuration: {
7
+ zendeskJWTSecret: string;
8
+ zendeskJWTKey: string;
9
+ }): string;
@@ -0,0 +1,24 @@
1
+ import jwt from "jsonwebtoken";
2
+ export function zendeskJwt(current_user, configuration) {
3
+ // get the INFO
4
+ const jwtSecret = configuration.zendeskJWTSecret;
5
+ const jwtKey = configuration.zendeskJWTKey;
6
+ const expiresIn = Math.floor(Date.now() / 1000) + 60 * 60 * 24; // Expires in 1 day
7
+ // create the payload
8
+ const payload = {
9
+ external_id: "z" +
10
+ current_user.selected_entity_id.toString() +
11
+ "-" +
12
+ current_user.id.toString(),
13
+ email: current_user.email,
14
+ name: current_user.name,
15
+ organization_id: current_user.selected_entity_id.toString(),
16
+ scope: "user",
17
+ exp: expiresIn,
18
+ };
19
+ const jwtHeader = { kid: jwtKey, typ: "JWT", alg: "HS256" };
20
+ return jwt.sign(payload, jwtSecret, {
21
+ algorithm: "HS256",
22
+ header: jwtHeader,
23
+ });
24
+ }
package/dist/index.d.ts CHANGED
@@ -2,8 +2,11 @@ export * from "./Alerts";
2
2
  export * from "./BlockUI";
3
3
  export * from "./Buttons";
4
4
  export * from "./Card";
5
+ export * from "./ConnectionState";
6
+ export * from "./Chat";
5
7
  export * from "./Containers";
6
8
  export * from "./Footer";
9
+ export * from "./Form";
7
10
  export * from "./Labels";
8
11
  export * from "./Layouts";
9
12
  export * from "./LineSeparator";
@@ -17,3 +20,4 @@ export * from "./Titles";
17
20
  export * from "./Tooltip";
18
21
  export * from "./WithTooltip";
19
22
  export * from "./Wizards";
23
+ export * from "./Zendesk";