@zauru-sdk/components 1.0.99 → 1.0.100
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.
- package/CHANGELOG.md +8 -0
- package/dist/Form/Checkbox/index.d.ts +1 -3
- package/dist/Form/DatePicker/index.d.ts +1 -3
- package/dist/Form/FileUpload/index.d.ts +1 -2
- package/dist/Form/ReactZodForm/index.d.ts +12 -0
- package/dist/Form/SelectField/index.d.ts +6 -9
- package/dist/Form/TextArea/index.d.ts +1 -3
- package/dist/Form/TextField/index.d.ts +1 -3
- package/dist/Form/TimePicker/index.d.ts +1 -2
- package/dist/Form/YesNo/index.d.ts +1 -0
- package/dist/Form/index.d.ts +1 -2
- package/dist/Layouts/homeLayout/index.d.ts +3 -1
- package/dist/Modal/Modal.d.ts +1 -1
- package/dist/Zendesk/zendesk.config.d.ts +1 -1
- package/dist/cjs/Alerts/StaticAlert.js +0 -6
- package/dist/cjs/Buttons/Button.js +13 -2
- package/dist/cjs/DynamicTable/DynamicPrintTable.js +2 -2
- package/dist/cjs/DynamicTable/DynamicTable.js +3 -3
- package/dist/cjs/DynamicTable/GenericDynamicTable.js +4 -5
- package/dist/cjs/Footer/Footer.js +1 -1
- package/dist/cjs/Form/Checkbox/index.js +14 -14
- package/dist/cjs/Form/Checklist/index.js +1 -1
- package/dist/cjs/Form/DatePicker/index.js +14 -13
- package/dist/cjs/Form/DynamicBaculoForm/index.js +1 -1
- package/dist/cjs/Form/FileUpload/index.js +25 -13
- package/dist/cjs/Form/ReactZodForm/index.js +31 -0
- package/dist/cjs/Form/SelectField/index.js +118 -73
- package/dist/cjs/Form/TextArea/index.js +15 -15
- package/dist/cjs/Form/TextField/index.js +20 -16
- package/dist/cjs/Form/TimePicker/index.js +17 -15
- package/dist/cjs/Form/YesNo/index.js +12 -6
- package/dist/cjs/Form/index.js +1 -2
- package/dist/cjs/Layouts/homeLayout/index.js +45 -8
- package/dist/cjs/Modal/Modal.js +1 -2
- package/dist/cjs/NavBar/NavBar.js +12 -17
- package/dist/cjs/Table/ZauruTable.js +11 -4
- package/dist/cjs/WithTooltip/WithTooltip.js +1 -1
- package/dist/cjs/Zendesk/zendesk.config.js +7 -9
- package/dist/esm/Alerts/StaticAlert.js +0 -6
- package/dist/esm/Buttons/Button.js +13 -2
- package/dist/esm/DynamicTable/DynamicPrintTable.js +4 -4
- package/dist/esm/DynamicTable/DynamicTable.js +6 -6
- package/dist/esm/DynamicTable/GenericDynamicTable.js +7 -8
- package/dist/esm/Footer/Footer.js +1 -1
- package/dist/esm/Form/Checkbox/index.js +13 -12
- package/dist/esm/Form/Checklist/index.js +2 -2
- package/dist/esm/Form/DatePicker/index.js +13 -11
- package/dist/esm/Form/DynamicBaculoForm/index.js +2 -2
- package/dist/esm/Form/FileUpload/index.js +24 -11
- package/dist/esm/Form/ReactZodForm/index.js +27 -0
- package/dist/esm/Form/SelectField/index.js +118 -49
- package/dist/esm/Form/TextArea/index.js +14 -13
- package/dist/esm/Form/TextField/index.js +19 -14
- package/dist/esm/Form/TimePicker/index.js +16 -13
- package/dist/esm/Form/YesNo/index.js +12 -6
- package/dist/esm/Form/index.js +1 -2
- package/dist/esm/Layouts/homeLayout/index.js +46 -9
- package/dist/esm/Modal/Modal.js +1 -2
- package/dist/esm/NavBar/NavBar.js +12 -17
- package/dist/esm/Table/ZauruTable.js +11 -4
- package/dist/esm/WithTooltip/WithTooltip.js +2 -2
- package/dist/esm/Zendesk/zendesk.config.js +7 -6
- package/package.json +6 -3
- package/src/Alerts/StaticAlert.tsx +0 -10
- package/src/Buttons/Button.tsx +24 -4
- package/src/DynamicTable/DynamicPrintTable.tsx +5 -6
- package/src/DynamicTable/DynamicTable.tsx +7 -7
- package/src/DynamicTable/GenericDynamicTable.tsx +7 -8
- package/src/Footer/Footer.tsx +1 -1
- package/src/Form/Checkbox/index.tsx +21 -18
- package/src/Form/Checklist/index.tsx +2 -2
- package/src/Form/DatePicker/index.tsx +22 -19
- package/src/Form/DynamicBaculoForm/index.tsx +2 -2
- package/src/Form/FileUpload/index.tsx +29 -14
- package/src/Form/ReactZodForm/index.tsx +60 -0
- package/src/Form/SelectField/index.tsx +246 -130
- package/src/Form/TextArea/index.tsx +22 -19
- package/src/Form/TextField/index.tsx +25 -18
- package/src/Form/TimePicker/index.tsx +25 -18
- package/src/Form/YesNo/index.tsx +20 -7
- package/src/Form/index.ts +1 -2
- package/src/Layouts/homeLayout/index.tsx +114 -21
- package/src/Modal/Modal.tsx +2 -5
- package/src/NavBar/NavBar.tsx +35 -46
- package/src/Table/ZauruTable.tsx +11 -4
- package/src/WithTooltip/WithTooltip.tsx +8 -7
- package/src/Zendesk/zendesk.config.ts +8 -6
- package/dist/Form/FormLayout/index.d.ts +0 -11
- package/dist/Form/RadioButtonGroup/index.d.ts +0 -20
- package/dist/cjs/Form/FormLayout/index.js +0 -11
- package/dist/cjs/Form/RadioButtonGroup/index.js +0 -26
- package/dist/esm/Form/FormLayout/index.js +0 -7
- package/dist/esm/Form/RadioButtonGroup/index.js +0 -21
- package/src/Form/FormLayout/index.tsx +0 -37
- package/src/Form/RadioButtonGroup/index.tsx +0 -108
|
@@ -11,26 +11,21 @@ const OptionsDropDownButton = ({ color, options, name }) => {
|
|
|
11
11
|
const [showOptionsMenu, setShowOptionsMenu] = (0, react_1.useState)(true);
|
|
12
12
|
return ((0, jsx_runtime_1.jsx)("div", { className: "nav-item ml-auto", children: (0, jsx_runtime_1.jsx)("div", { className: "flex justify-center", children: (0, jsx_runtime_1.jsxs)("div", { className: "relative inline-block", children: [(0, jsx_runtime_1.jsxs)("button", { onClick: () => setShowOptionsMenu(!showOptionsMenu), className: `relative flex items-center p-2 text-xs text-white ${color.bg700} active:${color.bg900} border border-transparent rounded-full uppercase focus:ring-opacity-40 focus:outline-none`, children: [name ?? (0, jsx_runtime_1.jsx)(icons_1.OpcionButtonSvgIcon, {}), (0, jsx_runtime_1.jsx)(icons_1.DropDownArrowSvgIcon, {})] }), (0, jsx_runtime_1.jsx)("div", { className: "absolute right-0 z-20 w-56 py-2 mt-2 overflow-hidden bg-white rounded-md shadow-xl dark:bg-gray-800", hidden: showOptionsMenu, onMouseLeave: () => setShowOptionsMenu(true), children: options.map((option) => option) })] }) }) }));
|
|
13
13
|
};
|
|
14
|
-
const NavItem = ({ name, link, icon, color, specialColor, childrens = [], }) => ((0, jsx_runtime_1.jsx)("li", { className: "nav-item", children: childrens.length > 0 ? ((0, jsx_runtime_1.jsx)(OptionsDropDownButton, { name: name, color: color, options: childrens.map((x, index) => ((0, jsx_runtime_1.jsx)(DropDownLinkButton, { text: x.name, path: x.link, buttonHover: "hover:bg-red-100" }, index))) })) : ((0, jsx_runtime_1.jsx)("div", { className: `${specialColor ? specialColor.bg700 : color.bg700} container text-white w-
|
|
14
|
+
const NavItem = ({ name, link, icon, color, specialColor, childrens = [], }) => ((0, jsx_runtime_1.jsx)("li", { className: "nav-item", children: childrens.length > 0 ? ((0, jsx_runtime_1.jsx)(OptionsDropDownButton, { name: name, color: color, options: childrens.map((x, index) => ((0, jsx_runtime_1.jsx)(DropDownLinkButton, { text: x.name, path: x.link, buttonHover: "hover:bg-red-100" }, index))) })) : ((0, jsx_runtime_1.jsx)("div", { className: `${specialColor ? specialColor.bg700 : color.bg700} container text-white w-full sm:w-auto h-10 text-sm py-1 uppercase shadow hover:shadow-lg outline-none rounded-full focus:outline-none my-auto sm:my-0 sm:mr-1 mb-1 ease-linear transition-all duration-150 `, children: (0, jsx_runtime_1.jsx)(react_2.Link, { className: "px-3 flex items-center text-xs leading-snug text-white uppercase hover:opacity-75", to: link, prefetch: "none", children: (0, jsx_runtime_1.jsxs)("div", { className: "mx-auto pt-2", children: [icon, (0, jsx_runtime_1.jsx)("span", { children: name })] }) }) })) }));
|
|
15
15
|
const NavBar = ({ title, loggedIn, items, selectedColor, }) => {
|
|
16
16
|
const color = NavBar_utils_js_1.COLORS[selectedColor];
|
|
17
17
|
const [NavBarOpen, setNavBarOpen] = (0, react_1.useState)(false);
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}) })) }), (0, jsx_runtime_1.jsx)("ul", { className: "sm:flex sm:flex-col ml-auto lg:flex-row", children: loggedIn ? ((0, jsx_runtime_1.jsx)(OptionsDropDownButton, { color: color, options: [
|
|
18
|
+
const renderNavItems = (items) => ((0, jsx_runtime_1.jsx)("div", { className: "flex flex-col lg:flex-row w-full", children: items.map((item, index) => {
|
|
19
|
+
const specialColor = item.color
|
|
20
|
+
? NavBar_utils_js_1.COLORS[item.color]
|
|
21
|
+
: undefined;
|
|
22
|
+
return ((0, jsx_runtime_1.jsx)(NavItem, { name: item.name, link: item.link, icon: item.icon, specialColor: specialColor, color: color, childrens: item.childrens?.map((x) => {
|
|
23
|
+
return { ...x };
|
|
24
|
+
}) }, index));
|
|
25
|
+
}) }));
|
|
26
|
+
const options = ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("ul", { className: "w-full lg:flex lg:items-center", children: renderNavItems(items.filter((item) => item.loggedIn === loggedIn)) }), (0, jsx_runtime_1.jsx)("ul", { className: "sm:flex sm:flex-col lg:flex-row ml-auto", children: loggedIn && ((0, jsx_runtime_1.jsx)(OptionsDropDownButton, { color: color, options: [
|
|
28
27
|
(0, jsx_runtime_1.jsx)(DropDownLinkButton, { text: "Cerrar Sesi\u00F3n", path: "/logout", icon: (0, jsx_runtime_1.jsx)(icons_1.LogoutDropDownSvgIcon, {}), buttonHover: "hover:bg-red-100" }, 0),
|
|
29
|
-
] }))
|
|
30
|
-
|
|
31
|
-
.map((item, index) => {
|
|
32
|
-
return ((0, jsx_runtime_1.jsx)(NavItem, { name: item.name, link: item.link, icon: item.icon, color: color }, index));
|
|
33
|
-
})) })] }));
|
|
34
|
-
return ((0, jsx_runtime_1.jsx)("nav", { className: `py-3 ${color.bg600}`, children: (0, jsx_runtime_1.jsxs)("div", { className: "flex items-center justify-between ml-5 mr-5", children: [(0, jsx_runtime_1.jsxs)("div", { className: "flex justify-between w-full lg:w-auto", children: [(0, jsx_runtime_1.jsx)(react_2.Link, { className: "text-sm font-bold leading-relaxed inline-block mr-4 py-2 whitespace-nowrap uppercase text-white", to: "/home", prefetch: "none", children: (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("div", { className: "inline-block mr-2 mb-2 align-middle", children: (0, jsx_runtime_1.jsx)("img", { className: "w-auto h-7", src: "/logo.png", alt: "logo-zauru" }) }), title] }) }), (0, jsx_runtime_1.jsx)("button", { className: `rounded lg:hidden focus:outline-none focus:ring focus:${color.ring600} focus:ring-opacity-50`, "aria-label": "Toggle mobile menu", type: "button", onClick: () => setNavBarOpen(!NavBarOpen), children: (0, jsx_runtime_1.jsx)(icons_1.MenuAlt4Svg, { open: NavBarOpen }) })] }), (0, jsx_runtime_1.jsx)("div", { className: `lg:hidden absolute top-0 left-0 z-50 w-64 h-full ${color.bg700} shadow-lg transform ${NavBarOpen ? "translate-x-0" : "-translate-x-full"} transition-transform duration-300 ease-in-out`, children: options }), (0, jsx_runtime_1.jsx)("div", { className: "hidden lg:flex w-full lg:w-auto", children: options })] }) }));
|
|
28
|
+
] })) })] }));
|
|
29
|
+
return ((0, jsx_runtime_1.jsx)("nav", { className: `py-3 ${color.bg600}`, children: (0, jsx_runtime_1.jsxs)("div", { className: "flex items-center justify-between ml-5 mr-5", children: [(0, jsx_runtime_1.jsxs)("div", { className: "flex justify-between w-full lg:w-auto", children: [(0, jsx_runtime_1.jsx)(react_2.Link, { className: "text-sm font-bold leading-relaxed inline-block mr-4 py-2 whitespace-nowrap uppercase text-white", to: "/home", prefetch: "none", children: (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("div", { className: "inline-block mr-2 mb-2 align-middle", children: (0, jsx_runtime_1.jsx)("img", { className: "w-auto h-7", src: "/logo.png", alt: "logo-zauru" }) }), title] }) }), (0, jsx_runtime_1.jsx)("button", { className: `rounded lg:hidden focus:outline-none focus:ring focus:${color.ring600} focus:ring-opacity-50`, "aria-label": "Toggle mobile menu", type: "button", onClick: () => setNavBarOpen(!NavBarOpen), children: (0, jsx_runtime_1.jsx)(icons_1.MenuAlt4Svg, { open: NavBarOpen }) })] }), (0, jsx_runtime_1.jsx)("div", { className: `lg:hidden fixed top-0 left-0 z-50 w-64 h-full ${color.bg700} shadow-lg transform ${NavBarOpen ? "translate-x-0" : "-translate-x-full"} transition-transform duration-300 ease-in-out overflow-y-auto`, children: (0, jsx_runtime_1.jsx)("div", { className: "p-4", children: options }) }), (0, jsx_runtime_1.jsx)("div", { className: "hidden lg:flex lg:items-center w-full lg:w-auto", children: options })] }) }));
|
|
35
30
|
};
|
|
36
31
|
exports.NavBar = NavBar;
|
|
@@ -36,10 +36,17 @@ const customStyles = {
|
|
|
36
36
|
style: {
|
|
37
37
|
color: "#202124",
|
|
38
38
|
fontSize: "14px",
|
|
39
|
-
justifyContent: "left",
|
|
40
|
-
whiteSpace: "normal",
|
|
41
|
-
wordBreak: "break-word",
|
|
42
|
-
maxWidth: "
|
|
39
|
+
justifyContent: "left",
|
|
40
|
+
whiteSpace: "normal",
|
|
41
|
+
wordBreak: "break-word",
|
|
42
|
+
maxWidth: "250px",
|
|
43
|
+
padding: "4px", // Add some padding
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
cells: {
|
|
47
|
+
style: {
|
|
48
|
+
whiteSpace: "normal", // Allow wrapping for cell content
|
|
49
|
+
wordBreak: "break-word",
|
|
43
50
|
},
|
|
44
51
|
},
|
|
45
52
|
rows: {
|
|
@@ -4,6 +4,6 @@ exports.WithTooltip = void 0;
|
|
|
4
4
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
5
|
const WithTooltip = (props) => {
|
|
6
6
|
const { children, text } = props;
|
|
7
|
-
return ((0, jsx_runtime_1.
|
|
7
|
+
return ((0, jsx_runtime_1.jsxs)("div", { className: "group relative inline-block", children: [children, (0, jsx_runtime_1.jsx)("div", { className: "pointer-events-none absolute left-1/2 -translate-x-1/2 bottom-full mb-2 opacity-0 transition-opacity duration-300 group-hover:opacity-100", children: (0, jsx_runtime_1.jsxs)("div", { className: "relative bg-black text-white text-sm rounded py-1 px-2 text-wrap w-40", children: [text, (0, jsx_runtime_1.jsx)("div", { className: "absolute top-full left-1/2 -translate-x-1/2 border-4 border-transparent border-t-black" })] }) })] }));
|
|
8
8
|
};
|
|
9
9
|
exports.WithTooltip = WithTooltip;
|
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
2
|
+
//import jwt from "jsonwebtoken";
|
|
5
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
4
|
exports.zendeskJwt = void 0;
|
|
7
|
-
const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
|
|
8
5
|
function zendeskJwt(current_user, configuration) {
|
|
9
6
|
// get the INFO
|
|
10
7
|
const jwtSecret = configuration.zendeskJWTSecret;
|
|
@@ -22,10 +19,11 @@ function zendeskJwt(current_user, configuration) {
|
|
|
22
19
|
scope: "user",
|
|
23
20
|
exp: expiresIn,
|
|
24
21
|
};
|
|
25
|
-
const jwtHeader = { kid: jwtKey, typ: "JWT", alg: "HS256" };
|
|
26
|
-
return
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
});
|
|
22
|
+
// const jwtHeader: jwt.JwtHeader = { kid: jwtKey, typ: "JWT", alg: "HS256" };
|
|
23
|
+
// return jwt.sign(payload, jwtSecret, {
|
|
24
|
+
// algorithm: "HS256",
|
|
25
|
+
// header: jwtHeader,
|
|
26
|
+
// });
|
|
27
|
+
return {};
|
|
30
28
|
}
|
|
31
29
|
exports.zendeskJwt = zendeskJwt;
|
|
@@ -13,12 +13,6 @@ const getConfig = (type) => {
|
|
|
13
13
|
buttonClassName: "rounded-md focus:outline-none focus:ring-2 focus:ring-green-500",
|
|
14
14
|
path: (_jsx("path", { d: "M8.445 12.6675A.9.9 0 0 0 7.1424 13.91l2.5726 2.7448c.3679.3856.9884.3689 1.335-.036l5.591-7.0366a.9.9 0 0 0-1.3674-1.1705l-4.6548 5.9132a.4.4 0 0 1-.607.0252l-1.567-1.6826zM1.9995 12c0-5.5 4.5-10 10-10s10 4.5 10 10-4.5 10-10 10-10-4.5-10-10z" })),
|
|
15
15
|
};
|
|
16
|
-
case "warning":
|
|
17
|
-
return {
|
|
18
|
-
containerClassName: "text-yellow-900 bg-yellow-100 border border-yellow-200 rounded-md",
|
|
19
|
-
buttonClassName: "rounded-md focus:outline-none focus:ring-2 focus:ring-yellow-500",
|
|
20
|
-
path: (_jsx("path", { d: "M12 2C6.5 2 2 6.5 2 12s4.5 10 10 10 10-4.5 10-10S17.5 2 12 2M12 18a1.5 1.5 0 1 1 0-3 1.5 1.5 0 0 1 0 3zm0-9a1 1 0 0 1 1 1v4a1 1 0 0 1-2 0v-4a1 1 0 0 1 1-1z" })),
|
|
21
|
-
};
|
|
22
16
|
default:
|
|
23
17
|
return {
|
|
24
18
|
containerClassName: "text-blue-900 bg-blue-100 border border-blue-200 rounded-md",
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useFormContext } from "react-hook-form";
|
|
3
|
+
import { WithTooltip } from "../index.js";
|
|
2
4
|
export const Button = (props) => {
|
|
3
5
|
const { type = "submit", loading = false, loadingText = "Guardando...", title = "Guardar", name = "save", onClickSave, selectedColor = "indigo", children, className = "", disabled = false, } = props;
|
|
6
|
+
const formContext = useFormContext();
|
|
7
|
+
const formHasErrors = formContext ? !formContext.formState.isValid : false;
|
|
8
|
+
const formErrors = formContext ? formContext.formState.errors : {};
|
|
4
9
|
const COLORS = {
|
|
5
10
|
green: {
|
|
6
11
|
bg900: "bg-green-900",
|
|
@@ -37,7 +42,13 @@ export const Button = (props) => {
|
|
|
37
42
|
};
|
|
38
43
|
const color = COLORS[selectedColor];
|
|
39
44
|
const inside = children ?? title;
|
|
40
|
-
|
|
45
|
+
const errorMessage = formHasErrors
|
|
46
|
+
? Object.values(formErrors)
|
|
47
|
+
.map((error) => error?.message?.toString())
|
|
48
|
+
.join(", ")
|
|
49
|
+
: "";
|
|
50
|
+
const buttonContent = (_jsx("button", { type: type, name: "action", disabled: loading || disabled || formHasErrors, value: name, onClick: onClickSave, className: `ml-2 ${loading || disabled || formHasErrors ? " bg-opacity-25 " : ""} ${loading
|
|
41
51
|
? " cursor-progress"
|
|
42
|
-
: `${disabled ? "" : `hover:${color.bg700}`}`} inline-flex justify-center rounded-md border border-transparent ${color.bg600} py-2 px-4 text-sm font-medium text-white shadow-sm focus:outline-none focus:ring-2 focus:${color.ring500} focus:ring-offset-2 ${className}`, children: loading ? loadingText : inside }));
|
|
52
|
+
: `${disabled || formHasErrors ? "" : `hover:${color.bg700}`}`} inline-flex justify-center rounded-md border border-transparent ${color.bg600} py-2 px-4 text-sm font-medium text-white shadow-sm focus:outline-none focus:ring-2 focus:${color.ring500} focus:ring-offset-2 ${className}`, children: loading ? loadingText : inside }));
|
|
53
|
+
return formHasErrors ? (_jsx(WithTooltip, { text: errorMessage, children: buttonContent })) : (buttonContent);
|
|
43
54
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import React, { useEffect, useCallback, useState } from "react";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { TextField } from "../Form/TextField/index.js";
|
|
4
|
+
import { SelectField } from "../Form/SelectField/index.js";
|
|
5
5
|
import { useAppSelector } from "@zauru-sdk/redux";
|
|
6
6
|
const errorAnimation = {
|
|
7
7
|
hidden: { opacity: 0, y: -10 },
|
|
@@ -10,11 +10,11 @@ const errorAnimation = {
|
|
|
10
10
|
export const DynamicPrintTable = ({ forwardedRef, ...props }) => {
|
|
11
11
|
const { items, onChange, className } = props;
|
|
12
12
|
const { formValidations } = useAppSelector((state) => state.formValidation);
|
|
13
|
-
const createItemSelect = (rowIndex, defaultValue) => (_jsx(
|
|
13
|
+
const createItemSelect = (rowIndex, defaultValue) => (_jsx(SelectField, { name: "item_select", isClearable: true, onChange: (value) => {
|
|
14
14
|
const selectedItem = items?.find((x) => x.value === value?.value);
|
|
15
15
|
updateRow(rowIndex, selectedItem);
|
|
16
16
|
}, options: items, defaultValue: defaultValue }, rowIndex));
|
|
17
|
-
const createItemQuantity = (rowIndex, defaultValue) => (_jsx(
|
|
17
|
+
const createItemQuantity = (rowIndex, defaultValue) => (_jsx(TextField, { name: "item_quantity", type: "number", integer: true, defaultValue: defaultValue ?? 1, min: 1, onChange: (value) => {
|
|
18
18
|
updateRow(rowIndex, undefined, Number(value));
|
|
19
19
|
} }, rowIndex));
|
|
20
20
|
const createTemplateName = (rowIndex, defaultValue) => (_jsx("div", { children: defaultValue != "" ? defaultValue : "No hay etiqueta" }, rowIndex));
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { jsxs as _jsxs, Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import React, { useEffect, useState } from "react";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
3
|
+
import { TextArea } from "../Form/TextArea/index.js";
|
|
4
|
+
import { TextField } from "../Form/TextField/index.js";
|
|
5
|
+
import { CheckBox } from "../Form/Checkbox/index.js";
|
|
6
6
|
export const DynamicTable = ({ forwardedRef, ...props }, ref) => {
|
|
7
7
|
const [tableData, setTableData] = useState({});
|
|
8
8
|
const { cellInputs, intersectionTitle, className, onChange, defaultValue, margins, } = props;
|
|
@@ -147,7 +147,7 @@ export const DynamicTable = ({ forwardedRef, ...props }, ref) => {
|
|
|
147
147
|
return (_jsxs("tr", { children: [_jsx("th", { className: "align-middle py-2 text-center", style: {
|
|
148
148
|
...cellBordered,
|
|
149
149
|
...pastelGrayBackground,
|
|
150
|
-
}, children: intersectionTitle ?? "" }), cols.map((col) => (_jsx("th", { className: "align-middle py-2 text-center", style: { ...cellBordered, ...pastelGrayBackground }, children: _jsxs("div", { className: "inline-flex", children: [_jsx(
|
|
150
|
+
}, children: intersectionTitle ?? "" }), cols.map((col) => (_jsx("th", { className: "align-middle py-2 text-center", style: { ...cellBordered, ...pastelGrayBackground }, children: _jsxs("div", { className: "inline-flex", children: [_jsx(TextField, { style: { maxWidth: "45%", minWidth: "45%" }, name: `column${col.id}`, defaultValue: tableData[`column${col.id}`] || 1, type: "number", onChange: (value) => handleInputChange(`column${col.id}`, value) }), col.id > 0 && (_jsx("button", { className: "bg-red-500 hover:bg-red-600 font-bold py-1 px-2 rounded ml-2", onClick: () => removeCol(col.id), children: "x" }))] }) }, col.id))), _jsx("th", { children: _jsx("button", { className: "bg-blue-500 hover:bg-blue-600 font-bold py-2 px-4 rounded", onClick: addCol, children: "+" }) })] }));
|
|
151
151
|
};
|
|
152
152
|
const renderRow = (rowId) => {
|
|
153
153
|
const cols = getCols();
|
|
@@ -157,14 +157,14 @@ export const DynamicTable = ({ forwardedRef, ...props }, ref) => {
|
|
|
157
157
|
textOverflow: "ellipsis",
|
|
158
158
|
msTextOverflow: "ellipsis",
|
|
159
159
|
maxWidth: "200px",
|
|
160
|
-
}, children: _jsxs("div", { className: "inline-flex", children: [_jsx(
|
|
160
|
+
}, children: _jsxs("div", { className: "inline-flex", children: [_jsx(TextField, { style: { maxWidth: "45%", minWidth: "45%" }, name: `row${rowId}`, defaultValue: tableData[`row${rowId}`] || 1, type: "number", onChange: (value) => handleInputChange(`row${rowId}`, value) }), rowId > 0 && (_jsx("button", { className: "bg-red-500 hover:bg-red-600 font-bold py-1 px-2 rounded ml-2", onClick: () => {
|
|
161
161
|
removeRow(rowId);
|
|
162
162
|
}, children: "x" }))] }) }), cols.map((col) => {
|
|
163
163
|
const cellId = `cell-${rowId}-${col.id}`;
|
|
164
164
|
const cellValidation = tableData[cellId] === true;
|
|
165
165
|
if (!cellInputs)
|
|
166
166
|
tableData[cellId] = cellValidation;
|
|
167
|
-
return (_jsx("td", { id: cellId, style: { ...cellBordered, ...cellCenteredContent }, children: cellInputs ? (_jsx(
|
|
167
|
+
return (_jsx("td", { id: cellId, style: { ...cellBordered, ...cellCenteredContent }, children: cellInputs ? (_jsx(TextArea, { name: cellId, defaultValue: tableData[cellId] || "", onChange: (value) => handleInputChange(cellId, value) })) : (_jsx(CheckBox, { name: cellId, defaultValue: cellValidation, onChange: (value) => {
|
|
168
168
|
if (value) {
|
|
169
169
|
return handleValidation(cellId, col.id, rowId);
|
|
170
170
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
2
|
import { useEffect, useState } from "react";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
3
|
+
import { SelectField } from "../Form/SelectField/index.js";
|
|
4
|
+
import { TextField } from "../Form/TextField/index.js";
|
|
5
|
+
import { CheckBox } from "../Form/Checkbox/index.js";
|
|
6
6
|
import { createModal } from "../Modal/index.js";
|
|
7
7
|
import { Button } from "../Buttons/index.js";
|
|
8
8
|
import { useAppSelector } from "@zauru-sdk/redux";
|
|
@@ -61,7 +61,6 @@ export const GenericDynamicTable = (props) => {
|
|
|
61
61
|
newDeletedData.push(deletedItem);
|
|
62
62
|
}
|
|
63
63
|
setDeletedData(newDeletedData);
|
|
64
|
-
onChange && onChange(tableData?.filter((x) => x.id !== rowId));
|
|
65
64
|
setTableData((prevData) => prevData?.filter((x) => x.id !== rowId));
|
|
66
65
|
};
|
|
67
66
|
const handleChange = (name, value, rowId) => {
|
|
@@ -94,10 +93,10 @@ export const GenericDynamicTable = (props) => {
|
|
|
94
93
|
return (_jsx("td", { className: "align-middle p-1", children: _jsx("div", { children: defaultVal }) }, `${rowData.id}-${column.name}`));
|
|
95
94
|
}
|
|
96
95
|
const FieldComponent = column.type === "textField"
|
|
97
|
-
?
|
|
96
|
+
? TextField
|
|
98
97
|
: column.type === "checkbox"
|
|
99
|
-
?
|
|
100
|
-
:
|
|
98
|
+
? CheckBox
|
|
99
|
+
: SelectField;
|
|
101
100
|
const setTableValue = (columnName, newValue) => {
|
|
102
101
|
setTableData((prevState) => {
|
|
103
102
|
// Encontrar el índice de la fila que está cambiando
|
|
@@ -182,7 +181,7 @@ export const GenericDynamicTable = (props) => {
|
|
|
182
181
|
setFilteredTableData(tableData);
|
|
183
182
|
}
|
|
184
183
|
};
|
|
185
|
-
return (_jsxs(_Fragment, { children: [name && (_jsxs(_Fragment, { children: [_jsx(GenericDynamicTableErrorComponent, { name: name }), _jsx("input", { name: name, type: "hidden", value: JSON.stringify(tableData), hidden: true }), _jsx("input", { name: `deleted_${name}`, type: "hidden", value: JSON.stringify(deletedData), hidden: true })] })), _jsxs("div", { className: `${className}`, children: [searcheables.length > 0 && (_jsx("div", { children: _jsx(
|
|
184
|
+
return (_jsxs(_Fragment, { children: [name && (_jsxs(_Fragment, { children: [_jsx(GenericDynamicTableErrorComponent, { name: name }), _jsx("input", { name: name, type: "hidden", value: JSON.stringify(tableData), hidden: true }), _jsx("input", { name: `deleted_${name}`, type: "hidden", value: JSON.stringify(deletedData), hidden: true })] })), _jsxs("div", { className: `${className}`, children: [searcheables.length > 0 && (_jsx("div", { children: _jsx(TextField, { className: "mb-2", name: "search", title: `Buscar por: ${searcheables
|
|
186
185
|
.map((x) => x.label)
|
|
187
186
|
.join(", ")}`, onChange: handleChangeSearch, disabled: loading }) })), _jsxs("table", { className: "w-full", children: [_jsx("thead", { children: renderHeader() }), _jsx("tbody", { children: renderRows() }), footerRow && !editable ? (_jsx("tfoot", { className: "border-t-2 border-black", children: _jsx("tr", { children: Object.keys(footerRow ?? {})?.map((x, indx) => {
|
|
188
187
|
return (_jsx("td", { className: "align-middle", children: footerRow[x] }, indx));
|
|
@@ -12,5 +12,5 @@ const COLORS = {
|
|
|
12
12
|
};
|
|
13
13
|
export const Footer = ({ href, selectedColor, showConnection = false, }) => {
|
|
14
14
|
const color = COLORS[selectedColor];
|
|
15
|
-
return (_jsx("footer", { className: `inset-x-0 bottom-0 px-2 py-[20px] ${color}`, children: _jsxs("div", { className: "px-4 mx-auto flex flex-wrap items-center justify-center", children: [_jsxs("p", { className: "text-white text-[1.2rem]", children: [`Creado en `, " ", _jsx("a", { href: href, children: "Zauru" }), " ", `con ❤️ ${new Date().getFullYear()} v.
|
|
15
|
+
return (_jsx("footer", { className: `inset-x-0 bottom-0 px-2 py-[20px] ${color}`, children: _jsxs("div", { className: "px-4 mx-auto flex flex-wrap items-center justify-center", children: [_jsxs("p", { className: "text-white text-[1.2rem]", children: [`Creado en `, " ", _jsx("a", { href: href, children: "Zauru" }), " ", `con ❤️ ${new Date().getFullYear()} v.2.0.0`] }), showConnection && (_jsx("div", { className: "ml-5", children: _jsx(ConnectionState, {}) }))] }) }));
|
|
16
16
|
};
|
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { useAppSelector } from "@zauru-sdk/redux";
|
|
3
2
|
import { useEffect, useState } from "react";
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
import { useFormContext } from "react-hook-form";
|
|
4
|
+
export const CheckBox = (props) => {
|
|
5
|
+
const { id, name, defaultValue = false, onChange, disabled = false, label, required = false, } = props;
|
|
6
6
|
const [checked, setChecked] = useState(defaultValue);
|
|
7
7
|
useEffect(() => {
|
|
8
8
|
setChecked(defaultValue);
|
|
9
9
|
}, [defaultValue]);
|
|
10
10
|
const handleInputChange = (event) => {
|
|
11
11
|
const isChecked = event.target.checked;
|
|
12
|
+
if (register) {
|
|
13
|
+
register.onChange(event);
|
|
14
|
+
}
|
|
12
15
|
if (onChange) {
|
|
13
16
|
const result = onChange(isChecked, event);
|
|
14
17
|
if (result?.stopUIChange) {
|
|
@@ -17,18 +20,16 @@ export const CheckboxWithoutValidation = (props) => {
|
|
|
17
20
|
}
|
|
18
21
|
setChecked(isChecked);
|
|
19
22
|
};
|
|
23
|
+
const { register: tempRegister, formState: { errors }, } = useFormContext() || { formState: {} }; // Obtener el contexto solo si existe
|
|
24
|
+
const error = errors ? errors[props.name ?? "-1"] : undefined;
|
|
25
|
+
const register = tempRegister
|
|
26
|
+
? tempRegister(props.name ?? "-1", { required })
|
|
27
|
+
: undefined; // Solo usar register si está disponible
|
|
20
28
|
const color = error ? "red" : "gray";
|
|
21
29
|
const borderColor = disabled ? "border-gray-300" : `border-${color}-500`;
|
|
22
|
-
const inputComponent = (_jsx("input", { type: "checkbox", id: id ?? name,
|
|
30
|
+
const inputComponent = (_jsx("input", { type: "checkbox", id: id ?? name, checked: checked, className: `form-checkbox h-4 w-4 text-indigo-600 ${borderColor} focus:border-indigo-500 focus:ring-indigo-500`, disabled: disabled, ...(register ?? {}), name: name, onChange: handleInputChange }));
|
|
23
31
|
if (!error && !label) {
|
|
24
32
|
return inputComponent;
|
|
25
33
|
}
|
|
26
|
-
return (_jsxs("div", { className: "col-span-6 sm:col-span-3", children: [_jsxs("div", { className: `flex items-center ${borderColor}`, children: [inputComponent, label && (
|
|
27
|
-
};
|
|
28
|
-
//<reference> https://tailwindui.com/components/application-ui/forms/form-layouts
|
|
29
|
-
export const CheckBox = (props) => {
|
|
30
|
-
const { formValidations } = useAppSelector((state) => state.formValidation);
|
|
31
|
-
const error = formValidations[props.formName ?? "-1"]?.[props.name ?? "-1"];
|
|
32
|
-
props = { ...props, error };
|
|
33
|
-
return _jsx(CheckboxWithoutValidation, { ...props });
|
|
34
|
+
return (_jsxs("div", { className: "col-span-6 sm:col-span-3", children: [_jsxs("div", { className: `flex items-center ${borderColor}`, children: [inputComponent, label && (_jsxs("label", { htmlFor: id ?? name, className: `ml-2 block text-sm font-medium text-${color}-700 dark:text-${color}-500`, children: [label, required && _jsx("span", { className: "text-red-500", children: "*" })] }))] }), error && (_jsxs("p", { className: `mt-2 text-sm text-${color}-600 dark:text-${color}-500`, children: [_jsx("span", { className: "font-medium", children: "Oops!" }), " ", error.message?.toString()] }))] }));
|
|
34
35
|
};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import {
|
|
2
|
+
import { CheckBox } from "../Checkbox/index.js";
|
|
3
3
|
export const Checklist = ({ items, onChange }) => {
|
|
4
4
|
const handleCheckboxChange = (name, value) => {
|
|
5
5
|
if (onChange) {
|
|
6
6
|
onChange(name, value);
|
|
7
7
|
}
|
|
8
8
|
};
|
|
9
|
-
return (_jsx("div", { children: items.map((item) => (_jsx(
|
|
9
|
+
return (_jsx("div", { children: items.map((item) => (_jsx(CheckBox, { ...item, onChange: (value) => handleCheckboxChange(item.name, value) }, item.id))) }));
|
|
10
10
|
};
|
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
2
|
import { useEffect, useState } from "react";
|
|
3
3
|
import { CalendarIconSVG, CloseSvgIcon, IdeaIconSVG } from "@zauru-sdk/icons";
|
|
4
|
-
import {
|
|
5
|
-
export const
|
|
6
|
-
const { id, name, title, defaultValue = "", hint, helpText, onChange, tabIndex,
|
|
4
|
+
import { useFormContext } from "react-hook-form";
|
|
5
|
+
export const FormDatePicker = (props) => {
|
|
6
|
+
const { id, name, title, defaultValue = "", hint, helpText, onChange, tabIndex, disabled = false, className = "", isClearable = false, required = false, } = props;
|
|
7
7
|
const [value, setValue] = useState(defaultValue);
|
|
8
8
|
const [showTooltip, setShowTooltip] = useState(false);
|
|
9
|
+
const { register: tempRegister, formState: { errors }, } = useFormContext() || { formState: {} }; // Obtener el contexto solo si existe
|
|
10
|
+
const error = errors ? errors[props.name ?? "-1"] : undefined;
|
|
11
|
+
const register = tempRegister
|
|
12
|
+
? tempRegister(props.name ?? "-1", { required })
|
|
13
|
+
: undefined; // Solo usar register si está disponible
|
|
9
14
|
const color = error ? "red" : "gray";
|
|
10
15
|
const isReadOnly = disabled;
|
|
11
16
|
const bgColor = isReadOnly ? "bg-gray-200" : `bg-${color}-50`;
|
|
@@ -18,14 +23,11 @@ export const FormDatePickerWithoutValidation = (props) => {
|
|
|
18
23
|
setValue("");
|
|
19
24
|
onChange && onChange("");
|
|
20
25
|
};
|
|
21
|
-
return (_jsxs(_Fragment, { children: [title && (
|
|
26
|
+
return (_jsxs(_Fragment, { children: [title && (_jsxs("label", { htmlFor: error ? `${name}-error` : `${name}-success`, className: `block text-sm font-medium ${textColor} ${className}`, children: [title, required && _jsx("span", { className: "text-red-500", children: "*" })] })), _jsxs("div", { className: "flex relative items-center", children: [_jsx("div", { className: "absolute left-0 flex items-center pl-3 pointer-events-none", children: _jsx(CalendarIconSVG, {}) }), _jsx("input", { id: id, tabIndex: tabIndex, type: "date", value: value ?? "", pattern: "\\d{4}-\\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`, ...(register ?? {}), name: name, onChange: (e) => {
|
|
22
27
|
setValue(e.target.value);
|
|
23
28
|
onChange && onChange(e.target.value);
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
const error = formValidations[props.formName ?? "-1"]?.[props.name ?? "-1"];
|
|
29
|
-
props = { ...props, error };
|
|
30
|
-
return _jsx(FormDatePickerWithoutValidation, { ...props });
|
|
29
|
+
if (register) {
|
|
30
|
+
register.onChange(e);
|
|
31
|
+
}
|
|
32
|
+
} }), value && isClearable && (_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.message?.toString()] })), !error && hint && (_jsx("p", { className: `mt-2 italic text-sm text-${color}-500 dark:text-${color}-400`, children: hint }))] }));
|
|
31
33
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { TextField
|
|
2
|
+
import { TextField } from "../TextField/index.js";
|
|
3
3
|
import { TripleFieldContainer } from "../FieldContainer/index.js";
|
|
4
4
|
import { DoubleFieldContainer } from "../FieldContainer/index.js";
|
|
5
5
|
import { YesNo } from "../YesNo/index.js";
|
|
@@ -33,7 +33,7 @@ export function DynamicBaculoForm(props) {
|
|
|
33
33
|
return (_jsx(SubContainer, { title: field.name, children: _jsx(GenericDynamicTable, { name: "fixed_columns_table", columns: columns }) }, field.id));
|
|
34
34
|
}
|
|
35
35
|
case "zauru_data":
|
|
36
|
-
return (_jsx(
|
|
36
|
+
return (_jsx(TextField, { title: `${field.required ? "*" : ""}${field.name}`, hint: field.hint, defaultValue: defaultValue?.value ?? field.default_value, disabled: true }, field.id));
|
|
37
37
|
case "hour":
|
|
38
38
|
return (_jsx(FormTimePicker, { title: `${field.required ? "*" : ""}${field.name}`, name: `${namesStr}${field.form_id}_${field.id}`, hint: field.hint, disabled: readOnly, defaultValue: defaultValue?.value }, field.id));
|
|
39
39
|
case "date":
|
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { DownloadIconSVG, IdeaIconSVG } from "@zauru-sdk/icons";
|
|
3
|
-
import { useAppSelector } from "@zauru-sdk/redux";
|
|
4
3
|
import { useState } from "react";
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
import { useFormContext } from "react-hook-form";
|
|
5
|
+
export const FileUploadField = (props) => {
|
|
6
|
+
const { id, name, title, helpText, hint, onChange, disabled = false, readOnly = false, fileTypes = [], showAvailableTypes = false, className, defaultValue = undefined, download = false, required = false, } = props;
|
|
7
|
+
const { register: tempRegister, formState: { errors }, } = useFormContext() || { formState: {} }; // Obtener el contexto solo si existe
|
|
8
|
+
const error = errors ? errors[props.name ?? "-1"] : undefined;
|
|
9
|
+
const register = tempRegister
|
|
10
|
+
? tempRegister(props.name ?? "-1", { required })
|
|
11
|
+
: undefined; // Solo usar register si está disponible
|
|
7
12
|
const [showTooltip, setShowTooltip] = useState(false);
|
|
8
13
|
if (typeof defaultValue == "string") {
|
|
9
14
|
if (download) {
|
|
@@ -16,11 +21,25 @@ export const FileUploadFieldWithoutValidation = (props) => {
|
|
|
16
21
|
}
|
|
17
22
|
}, children: [title && (_jsx("label", { htmlFor: name, className: "block mb-1 text-sm font-medium text-gray-700", children: title })), " ", _jsx(DownloadIconSVG, {})] }));
|
|
18
23
|
}
|
|
19
|
-
return (_jsxs("div", { className: `col-span-6 sm:col-span-3 ${className}`, children: [title && (
|
|
24
|
+
return (_jsxs("div", { className: `col-span-6 sm:col-span-3 ${className}`, children: [title && (_jsxs("label", { htmlFor: name, className: `block mb-1 text-sm font-medium text-gray-700`, children: [title, required && _jsx("span", { className: "text-red-500", children: "*" })] })), " ", _jsx("div", { role: "button", tabIndex: 0, onClick: () => {
|
|
25
|
+
if (register) {
|
|
26
|
+
register.onChange({
|
|
27
|
+
target: {
|
|
28
|
+
value: defaultValue,
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
}
|
|
20
32
|
window.open(defaultValue, "_blank");
|
|
21
33
|
}, onKeyDown: (event) => {
|
|
22
34
|
// Permite que el evento se active con la tecla Enter
|
|
23
35
|
if (event.key === "Enter") {
|
|
36
|
+
if (register) {
|
|
37
|
+
register.onChange({
|
|
38
|
+
target: {
|
|
39
|
+
value: defaultValue,
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
}
|
|
24
43
|
window.open(defaultValue, "_blank");
|
|
25
44
|
}
|
|
26
45
|
}, children: _jsx("img", { src: defaultValue, alt: name, className: `h-48 w-48 inline mr-1 pb-1`, style: {
|
|
@@ -44,11 +63,5 @@ export const FileUploadFieldWithoutValidation = (props) => {
|
|
|
44
63
|
const bgColor = isReadOnly ? "bg-gray-200" : `bg-${color}-50`;
|
|
45
64
|
const textColor = isReadOnly ? "text-gray-500" : `text-${color}-900`;
|
|
46
65
|
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 });
|
|
66
|
+
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.message?.toString()] })), !error && hintMessage && (_jsx("p", { className: `mt-2 italic text-sm text-${color}-500`, children: hintMessage }))] }));
|
|
54
67
|
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { zodResolver } from "@hookform/resolvers/zod";
|
|
3
|
+
import { Form, useSubmit } from "@remix-run/react";
|
|
4
|
+
import { FormProvider, useForm, } from "react-hook-form";
|
|
5
|
+
import { z } from "zod";
|
|
6
|
+
const emptySchema = z.any();
|
|
7
|
+
export const ReactZodForm = (props) => {
|
|
8
|
+
const { children, method = "post", schema = emptySchema, onSubmit, id, } = props;
|
|
9
|
+
const submit = useSubmit();
|
|
10
|
+
const methods = useForm({
|
|
11
|
+
resolver: zodResolver(schema),
|
|
12
|
+
mode: "onSubmit",
|
|
13
|
+
});
|
|
14
|
+
const handleSubmit = (data, event) => {
|
|
15
|
+
if (onSubmit) {
|
|
16
|
+
onSubmit(data, event);
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
// If no onSubmit is provided, use Remix's submit function
|
|
20
|
+
submit(event?.target, { method });
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
return (_jsx(FormProvider, { ...methods, children: _jsx(Form, { onSubmit: onSubmit ? methods.handleSubmit(onSubmit) : undefined,
|
|
24
|
+
//onSubmit={methods.handleSubmit(handleSubmit)}
|
|
25
|
+
method: method, id: id, children: children }) }));
|
|
26
|
+
};
|
|
27
|
+
export default ReactZodForm;
|