@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,127 @@
1
+ import { ClockIconSVG, CloseSvgIcon, IdeaIconSVG } from "@zauru-sdk/icons";
2
+ import { useAppSelector } from "@zauru-sdk/redux";
3
+ import React, { useEffect, useState } from "react";
4
+
5
+ type Props = {
6
+ id?: string;
7
+ name: string;
8
+ formName?: string;
9
+ title?: string;
10
+ hint?: string;
11
+ helpText?: string;
12
+ defaultValue?: string;
13
+ onChange?: (value: string) => void;
14
+ tabIndex?: number;
15
+ error?: string;
16
+ disabled?: boolean;
17
+ };
18
+
19
+ export const FormTimePickerWithoutValidation = (props: Props) => {
20
+ const {
21
+ id,
22
+ name,
23
+ title,
24
+ defaultValue = "",
25
+ hint,
26
+ helpText,
27
+ onChange,
28
+ tabIndex,
29
+ error,
30
+ disabled = false,
31
+ } = props;
32
+
33
+ const [value, setValue] = useState<string>(defaultValue);
34
+ const [showTooltip, setShowTooltip] = useState<boolean>(false);
35
+
36
+ const color = error ? "red" : "gray";
37
+
38
+ const isReadOnly = disabled;
39
+ const bgColor = isReadOnly ? "bg-gray-200" : `bg-${color}-50`;
40
+ const textColor = isReadOnly ? "text-gray-500" : `text-${color}-500`;
41
+ const borderColor = isReadOnly ? "border-gray-300" : `border-${color}-200`;
42
+
43
+ useEffect(() => {
44
+ setValue(defaultValue);
45
+ }, [defaultValue]);
46
+
47
+ const clearValue = () => {
48
+ setValue("");
49
+ onChange && onChange("");
50
+ };
51
+
52
+ return (
53
+ <>
54
+ {title && (
55
+ <label
56
+ htmlFor={error ? `${name}-error` : `${name}-success`}
57
+ className={`block text-sm font-medium ${textColor}`}
58
+ >
59
+ {title}
60
+ </label>
61
+ )}
62
+ <div className="flex relative items-center">
63
+ <div className="absolute left-0 flex items-center pl-3 pointer-events-none">
64
+ <ClockIconSVG />
65
+ </div>
66
+ <input
67
+ id={id}
68
+ name={name}
69
+ tabIndex={tabIndex}
70
+ type="time"
71
+ onChange={(e: React.ChangeEvent<HTMLInputElement>) => {
72
+ setValue(e.target.value);
73
+ onChange && onChange(e.target.value);
74
+ }}
75
+ value={value}
76
+ pattern="\d{2}:\d{2}"
77
+ className={`${bgColor} ${borderColor} ${textColor} text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full pl-10 p-2.5`}
78
+ />
79
+ {value && (
80
+ <button
81
+ type="button"
82
+ onClick={clearValue}
83
+ className="absolute right-0 mr-10"
84
+ >
85
+ <CloseSvgIcon />
86
+ </button>
87
+ )}
88
+ {helpText && (
89
+ <div className="flex items-center relative ml-3">
90
+ <div
91
+ className="relative cursor-pointer"
92
+ onMouseEnter={() => setShowTooltip(true)}
93
+ onMouseLeave={() => setShowTooltip(false)}
94
+ >
95
+ <IdeaIconSVG />
96
+ {showTooltip && (
97
+ <div className="absolute -left-48 top-0 mt-8 p-2 bg-white border rounded shadow text-black">
98
+ {helpText}
99
+ </div>
100
+ )}
101
+ </div>
102
+ </div>
103
+ )}
104
+ </div>
105
+ {error && (
106
+ <p className={`mt-2 text-sm text-${color}-600 dark:text-${color}-500`}>
107
+ <span className="font-medium">Oops!</span> {error}
108
+ </p>
109
+ )}
110
+ {!error && hint && (
111
+ <p
112
+ className={`mt-2 italic text-sm text-${color}-500 dark:text-${color}-400`}
113
+ >
114
+ {hint}
115
+ </p>
116
+ )}
117
+ </>
118
+ );
119
+ };
120
+
121
+ export const FormTimePicker = (props: Props) => {
122
+ const { formValidations } = useAppSelector((state) => state.formValidation);
123
+ const error = formValidations[props.formName ?? "-1"]?.[props.name ?? "-1"];
124
+ props = { ...props, error };
125
+
126
+ return <FormTimePickerWithoutValidation {...props} />;
127
+ };
@@ -0,0 +1,79 @@
1
+ import { useAppSelector } from "@zauru-sdk/redux";
2
+ import { useState } from "react";
3
+
4
+ type Props = {
5
+ id?: string;
6
+ name: string;
7
+ formName?: string;
8
+ title?: string;
9
+ defaultValue?: boolean;
10
+ helpText?: string;
11
+ onChange?: (value: boolean) => void;
12
+ disabled?: boolean;
13
+ };
14
+
15
+ const YesNo = (props: Props) => {
16
+ const {
17
+ id,
18
+ name,
19
+ title,
20
+ defaultValue = false,
21
+ helpText,
22
+ onChange,
23
+ disabled,
24
+ } = props;
25
+
26
+ const { formValidations } = useAppSelector((state) => state.formValidation);
27
+ const error = formValidations[props.formName ?? "-1"]?.[props.name ?? "-1"];
28
+
29
+ const [value, setValue] = useState(defaultValue);
30
+
31
+ const color = error ? "red" : "gray";
32
+
33
+ const handleOnChange = () => {
34
+ if (disabled) return; // No hacer nada si está deshabilitado
35
+ const newValue = !value;
36
+ setValue(newValue);
37
+ onChange && onChange(newValue);
38
+ };
39
+
40
+ return (
41
+ <>
42
+ <label
43
+ className={`relative inline-flex items-center cursor-pointer ${
44
+ disabled ? "opacity-50" : ""
45
+ }`}
46
+ >
47
+ <input
48
+ type="checkbox"
49
+ id={id ?? name}
50
+ name={name}
51
+ checked={value}
52
+ value={value.toString()}
53
+ className="sr-only peer"
54
+ onChange={handleOnChange}
55
+ disabled={disabled}
56
+ />
57
+ {value.toString() === "false" && (
58
+ <input type="hidden" name={name} value="false" />
59
+ )}
60
+ <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"></div>
61
+ <span className="ml-3 text-sm font-medium text-gray-900">{title}</span>
62
+ </label>
63
+ {error && (
64
+ <p className={`mt-2 text-sm text-${color}-600 dark:text-${color}-500`}>
65
+ <span className="font-medium">Oops!</span> {error}
66
+ </p>
67
+ )}
68
+ {!error && helpText && (
69
+ <p
70
+ className={`mt-2 italic text-sm text-${color}-500 dark:text-${color}-400`}
71
+ >
72
+ {helpText}
73
+ </p>
74
+ )}
75
+ </>
76
+ );
77
+ };
78
+
79
+ 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,85 @@
1
+ import { useEffect } from "react";
2
+
3
+ const canUseDOM = (): boolean => {
4
+ if (
5
+ typeof window === "undefined" ||
6
+ !window.document ||
7
+ !window.document.createElement
8
+ ) {
9
+ return false;
10
+ }
11
+ return true;
12
+ };
13
+
14
+ export const logoutFromZendesk = () => {
15
+ if (canUseDOM() && (window as any).zE) {
16
+ (window as any).zE("messenger", "logoutUser");
17
+ } else {
18
+ console.warn("Zendesk is not initialized yet");
19
+ }
20
+ };
21
+
22
+ export const ZendeskAPI = (...args: any[]) => {
23
+ if (canUseDOM() && (window as any).zE) {
24
+ (window as any).zE.apply(null, args);
25
+ } else {
26
+ console.warn("Zendesk is not initialized yet");
27
+ }
28
+ };
29
+
30
+ interface ZendeskProps {
31
+ defer?: boolean;
32
+ onLoaded?: () => void;
33
+ token: string;
34
+ configuration: {
35
+ zendeskChatKey: string;
36
+ };
37
+ [key: string]: any; // Para propiedades adicionales que se pasen y se asignen a window.zESettings
38
+ }
39
+
40
+ const Zendesk: React.FC<ZendeskProps> = (props: ZendeskProps) => {
41
+ const { defer, configuration, token, ...other } = props;
42
+
43
+ useEffect(() => {
44
+ const insertScript = () => {
45
+ const zendeskScript = document.createElement("script");
46
+ if (defer) {
47
+ zendeskScript.defer = true;
48
+ } else {
49
+ zendeskScript.async = true;
50
+ }
51
+ zendeskScript.id = "ze-snippet";
52
+ zendeskScript.src = `https://static.zdassets.com/ekr/snippet.js?key=${configuration.zendeskChatKey}`;
53
+ zendeskScript.addEventListener("load", () => {
54
+ if (props.onLoaded) {
55
+ props.onLoaded();
56
+ }
57
+
58
+ (window as any).zE("messenger", "loginUser", function (callback: any) {
59
+ callback(token);
60
+ });
61
+ });
62
+ document.body.appendChild(zendeskScript);
63
+
64
+ return zendeskScript; // Devolvemos la referencia del script
65
+ };
66
+
67
+ let script: HTMLScriptElement | undefined; // Guardamos la referencia del script aquí
68
+
69
+ if (canUseDOM() && !(window as any).zE) {
70
+ script = insertScript();
71
+ (window as any).zESettings = other;
72
+ }
73
+
74
+ return () => {
75
+ if (script) {
76
+ // Si el script existe, lo eliminamos del DOM
77
+ script.remove();
78
+ }
79
+ };
80
+ }, [props, defer, other, configuration, token]);
81
+
82
+ return null;
83
+ };
84
+
85
+ export default Zendesk;
@@ -0,0 +1,2 @@
1
+ export * from "./Chat";
2
+ export * from "./zendesk.config";
@@ -0,0 +1,40 @@
1
+ import jwt from "jsonwebtoken";
2
+
3
+ export function zendeskJwt(
4
+ current_user: {
5
+ selected_entity_id: number;
6
+ id: number;
7
+ email: string;
8
+ name: string;
9
+ },
10
+ configuration: {
11
+ zendeskJWTSecret: string;
12
+ zendeskJWTKey: string;
13
+ }
14
+ ) {
15
+ // get the INFO
16
+ const jwtSecret = configuration.zendeskJWTSecret;
17
+ const jwtKey = configuration.zendeskJWTKey;
18
+ const expiresIn = Math.floor(Date.now() / 1000) + 60 * 60 * 24; // Expires in 1 day
19
+
20
+ // create the payload
21
+ const payload = {
22
+ external_id:
23
+ "z" +
24
+ current_user.selected_entity_id.toString() +
25
+ "-" +
26
+ current_user.id.toString(),
27
+ email: current_user.email,
28
+ name: current_user.name,
29
+ organization_id: current_user.selected_entity_id.toString(),
30
+ scope: "user",
31
+ exp: expiresIn,
32
+ };
33
+
34
+ const jwtHeader: jwt.JwtHeader = { kid: jwtKey, typ: "JWT", alg: "HS256" };
35
+
36
+ return jwt.sign(payload, jwtSecret, {
37
+ algorithm: "HS256",
38
+ header: jwtHeader,
39
+ });
40
+ }
package/src/index.ts CHANGED
@@ -2,9 +2,11 @@ export * from "./Alerts";
2
2
  export * from "./BlockUI";
3
3
  export * from "./Buttons";
4
4
  export * from "./Card";
5
- //export * from "./Chat";
5
+ export * from "./ConnectionState";
6
+ export * from "./Chat";
6
7
  export * from "./Containers";
7
8
  export * from "./Footer";
9
+ export * from "./Form";
8
10
  export * from "./Labels";
9
11
  export * from "./Layouts";
10
12
  export * from "./LineSeparator";
@@ -18,4 +20,4 @@ export * from "./Titles";
18
20
  export * from "./Tooltip";
19
21
  export * from "./WithTooltip";
20
22
  export * from "./Wizards";
21
- //export * from "./Zendesk";
23
+ export * from "./Zendesk";