@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.
- package/CHANGELOG.md +8 -0
- package/dist/Chat/ChatLayout.d.ts +17 -0
- package/dist/Chat/ChatLayout.js +28 -0
- package/dist/Chat/ChatMessageHistory.d.ts +12 -0
- package/dist/Chat/ChatMessageHistory.js +53 -0
- package/dist/Chat/index.d.ts +2 -0
- package/dist/Chat/index.js +2 -0
- package/dist/ConnectionState/ConnectionState.d.ts +2 -0
- package/dist/ConnectionState/ConnectionState.js +22 -0
- package/dist/ConnectionState/index.d.ts +1 -0
- package/dist/ConnectionState/index.js +1 -0
- package/dist/DynamicTable/BasicPrintDynamicTable.d.ts +10 -0
- package/dist/DynamicTable/BasicPrintDynamicTable.js +27 -0
- package/dist/DynamicTable/DynamicPrintTable.d.ts +23 -0
- package/dist/DynamicTable/DynamicPrintTable.js +132 -0
- package/dist/DynamicTable/GenericDynamicTable.d.ts +21 -0
- package/dist/DynamicTable/GenericDynamicTable.js +195 -0
- package/dist/DynamicTable/index.d.ts +24 -0
- package/dist/DynamicTable/index.js +193 -0
- package/dist/Footer/Footer.js +2 -2
- package/dist/Form/Checkbox/index.d.ts +17 -0
- package/dist/Form/Checkbox/index.js +34 -0
- package/dist/Form/Checklist/index.d.ts +14 -0
- package/dist/Form/Checklist/index.js +10 -0
- package/dist/Form/DatePicker/index.d.ts +18 -0
- package/dist/Form/DatePicker/index.js +31 -0
- package/dist/Form/DynamicBaculoForm/index.d.ts +18 -0
- package/dist/Form/DynamicBaculoForm/index.js +138 -0
- package/dist/Form/FieldContainer/DoubleFieldContainer.d.ts +8 -0
- package/dist/Form/FieldContainer/DoubleFieldContainer.js +14 -0
- package/dist/Form/FieldContainer/QuadrupleFieldContainer.d.ts +7 -0
- package/dist/Form/FieldContainer/QuadrupleFieldContainer.js +14 -0
- package/dist/Form/FieldContainer/TripleFieldContainer.d.ts +7 -0
- package/dist/Form/FieldContainer/TripleFieldContainer.js +14 -0
- package/dist/Form/FieldContainer/index.d.ts +3 -0
- package/dist/Form/FieldContainer/index.js +3 -0
- package/dist/Form/FileUpload/index.d.ts +21 -0
- package/dist/Form/FileUpload/index.js +54 -0
- package/dist/Form/FormButtons/index.d.ts +16 -0
- package/dist/Form/FormButtons/index.js +5 -0
- package/dist/Form/FormLayout/index.d.ts +11 -0
- package/dist/Form/FormLayout/index.js +7 -0
- package/dist/Form/SelectField/index.d.ts +27 -0
- package/dist/Form/SelectField/index.js +74 -0
- package/dist/Form/TextArea/index.d.ts +23 -0
- package/dist/Form/TextArea/index.js +36 -0
- package/dist/Form/TextField/index.d.ts +25 -0
- package/dist/Form/TextField/index.js +70 -0
- package/dist/Form/TimePicker/index.d.ts +16 -0
- package/dist/Form/TimePicker/index.js +31 -0
- package/dist/Form/YesNo/index.d.ts +12 -0
- package/dist/Form/YesNo/index.js +19 -0
- package/dist/Form/index.d.ts +13 -0
- package/dist/Form/index.js +13 -0
- package/dist/Zendesk/Chat.d.ts +14 -0
- package/dist/Zendesk/Chat.js +64 -0
- package/dist/Zendesk/index.d.ts +2 -0
- package/dist/Zendesk/index.js +2 -0
- package/dist/Zendesk/zendesk.config.d.ts +9 -0
- package/dist/Zendesk/zendesk.config.js +24 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +4 -2
- package/package.json +5 -5
- package/src/Chat/ChatLayout.tsx +133 -0
- package/src/Chat/ChatMessageHistory.tsx +142 -0
- package/src/Chat/index.ts +2 -0
- package/src/ConnectionState/ConnectionState.tsx +29 -0
- package/src/ConnectionState/index.tsx +1 -0
- package/src/DynamicTable/BasicPrintDynamicTable.tsx +73 -0
- package/src/DynamicTable/DynamicPrintTable.tsx +290 -0
- package/src/DynamicTable/GenericDynamicTable.tsx +455 -0
- package/src/DynamicTable/index.tsx +407 -0
- package/src/Footer/Footer.tsx +3 -3
- package/src/Form/Checkbox/index.tsx +96 -0
- package/src/Form/Checklist/index.tsx +35 -0
- package/src/Form/DatePicker/index.tsx +132 -0
- package/src/Form/DynamicBaculoForm/index.tsx +359 -0
- package/src/Form/FieldContainer/DoubleFieldContainer.tsx +35 -0
- package/src/Form/FieldContainer/QuadrupleFieldContainer.tsx +36 -0
- package/src/Form/FieldContainer/TripleFieldContainer.tsx +35 -0
- package/src/Form/FieldContainer/index.ts +3 -0
- package/src/Form/FileUpload/index.tsx +184 -0
- package/src/Form/FormButtons/index.tsx +78 -0
- package/src/Form/FormLayout/index.tsx +37 -0
- package/src/Form/SelectField/index.tsx +237 -0
- package/src/Form/TextArea/index.tsx +125 -0
- package/src/Form/TextField/index.tsx +194 -0
- package/src/Form/TimePicker/index.tsx +127 -0
- package/src/Form/YesNo/index.tsx +79 -0
- package/src/Form/index.ts +13 -0
- package/src/Zendesk/Chat.tsx +85 -0
- package/src/Zendesk/index.ts +2 -0
- package/src/Zendesk/zendesk.config.ts +40 -0
- package/src/index.ts +4 -2
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
import React, { useEffect, useCallback, useState, type ReactNode } from "react";
|
|
2
|
+
import { TextFieldWithoutValidation } from "src";
|
|
3
|
+
import { SelectFieldWithoutValidation } from "src";
|
|
4
|
+
import type { SingleValue } from "react-select";
|
|
5
|
+
import { useAppSelector } from "@zauru-sdk/redux";
|
|
6
|
+
import { SelectFieldOption } from "@zauru-sdk/types";
|
|
7
|
+
|
|
8
|
+
export type TableStateItem = {
|
|
9
|
+
item_id: string | undefined;
|
|
10
|
+
quantity: number | undefined;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export type FormatedItem = {
|
|
14
|
+
label: string;
|
|
15
|
+
value: number;
|
|
16
|
+
template: string;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
type Props = {
|
|
20
|
+
name: string;
|
|
21
|
+
formName?: string;
|
|
22
|
+
className?: string;
|
|
23
|
+
items: FormatedItem[];
|
|
24
|
+
onChange?: (tableState?: TableStateItem[]) => void;
|
|
25
|
+
forwardedRef?: React.RefObject<{
|
|
26
|
+
insertItems: (items: FormatedItem[]) => void;
|
|
27
|
+
getTableState: (
|
|
28
|
+
updatedData?: ReactNode[][]
|
|
29
|
+
) => TableStateItem[] | undefined;
|
|
30
|
+
}>;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const errorAnimation = {
|
|
34
|
+
hidden: { opacity: 0, y: -10 },
|
|
35
|
+
visible: { opacity: 1, y: 0 },
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const DynamicPrintTable = ({ forwardedRef, ...props }: Props) => {
|
|
39
|
+
const { items, onChange, className } = props;
|
|
40
|
+
const { formValidations } = useAppSelector((state) => state.formValidation);
|
|
41
|
+
|
|
42
|
+
const createItemSelect = (
|
|
43
|
+
rowIndex: number,
|
|
44
|
+
defaultValue?: SelectFieldOption
|
|
45
|
+
) => (
|
|
46
|
+
<SelectFieldWithoutValidation
|
|
47
|
+
key={rowIndex}
|
|
48
|
+
name="item_select"
|
|
49
|
+
isClearable
|
|
50
|
+
onChange={(value: SingleValue<SelectFieldOption>) => {
|
|
51
|
+
const selectedItem = items?.find((x) => x.value === value?.value);
|
|
52
|
+
updateRow(rowIndex, selectedItem);
|
|
53
|
+
}}
|
|
54
|
+
options={items}
|
|
55
|
+
defaultValue={defaultValue}
|
|
56
|
+
/>
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
const createItemQuantity = (rowIndex: number, defaultValue?: number) => (
|
|
60
|
+
<TextFieldWithoutValidation
|
|
61
|
+
key={rowIndex}
|
|
62
|
+
name="item_quantity"
|
|
63
|
+
type="number"
|
|
64
|
+
integer
|
|
65
|
+
defaultValue={defaultValue ?? 1}
|
|
66
|
+
min={1}
|
|
67
|
+
onChange={(value: string) => {
|
|
68
|
+
updateRow(rowIndex, undefined, Number(value));
|
|
69
|
+
}}
|
|
70
|
+
/>
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
const createTemplateName = (rowIndex: number, defaultValue?: string) => (
|
|
74
|
+
<div key={rowIndex}>
|
|
75
|
+
{defaultValue != "" ? defaultValue : "No hay etiqueta"}
|
|
76
|
+
</div>
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
const createRow = (
|
|
80
|
+
rowIndex: number,
|
|
81
|
+
item?: FormatedItem,
|
|
82
|
+
quantity?: number
|
|
83
|
+
) => {
|
|
84
|
+
const itemCreated = createItemSelect(rowIndex, item ?? undefined);
|
|
85
|
+
const quantityCreated = createItemQuantity(rowIndex, quantity ?? 1);
|
|
86
|
+
const templateCreated = createTemplateName(
|
|
87
|
+
rowIndex,
|
|
88
|
+
item ? item.template : "Seleccione un item para visualizar su etiqueta."
|
|
89
|
+
);
|
|
90
|
+
return [itemCreated, quantityCreated, templateCreated];
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
const [tableData, setTableData] = useState<ReactNode[][] | undefined>([]);
|
|
94
|
+
const [isInitialItemAdded, setIsInitialItemAdded] = useState<boolean>(false);
|
|
95
|
+
|
|
96
|
+
const insertItems = useCallback(
|
|
97
|
+
(newItems: FormatedItem[]) => {
|
|
98
|
+
setTableData((prevData) => [
|
|
99
|
+
...(prevData ?? []),
|
|
100
|
+
...newItems.map((item, index) => {
|
|
101
|
+
const rowIndex = (prevData?.length ?? 0) + index;
|
|
102
|
+
const [itemCreated, quantityCreated, templateCreated] = createRow(
|
|
103
|
+
rowIndex,
|
|
104
|
+
item
|
|
105
|
+
);
|
|
106
|
+
updateRow(rowIndex, item, 1);
|
|
107
|
+
return [itemCreated, quantityCreated, templateCreated];
|
|
108
|
+
}),
|
|
109
|
+
]);
|
|
110
|
+
},
|
|
111
|
+
[items]
|
|
112
|
+
);
|
|
113
|
+
|
|
114
|
+
const getTableState = (temp?: ReactNode[][]) => {
|
|
115
|
+
const updatedData = temp ?? tableData;
|
|
116
|
+
const tableState = updatedData?.map((rowData) => {
|
|
117
|
+
const firstElement = rowData[0];
|
|
118
|
+
const item_id = React.isValidElement(firstElement)
|
|
119
|
+
? firstElement.props.defaultValue?.value
|
|
120
|
+
: undefined;
|
|
121
|
+
|
|
122
|
+
const secondElement = rowData[1];
|
|
123
|
+
const quantity = React.isValidElement(secondElement)
|
|
124
|
+
? secondElement.props.defaultValue
|
|
125
|
+
: undefined;
|
|
126
|
+
|
|
127
|
+
return {
|
|
128
|
+
item_id,
|
|
129
|
+
quantity,
|
|
130
|
+
} as TableStateItem;
|
|
131
|
+
});
|
|
132
|
+
return tableState;
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
const updateRow = (
|
|
136
|
+
rowIndex: number,
|
|
137
|
+
item?: FormatedItem,
|
|
138
|
+
quantity?: number
|
|
139
|
+
) => {
|
|
140
|
+
setTableData((prevData) => {
|
|
141
|
+
const updatedData = prevData?.map((_, index) => {
|
|
142
|
+
if (index === rowIndex) {
|
|
143
|
+
const firstElement = prevData[index][0];
|
|
144
|
+
const selectedItem =
|
|
145
|
+
item ??
|
|
146
|
+
(React.isValidElement(firstElement)
|
|
147
|
+
? items?.find(
|
|
148
|
+
(x) => x.value === firstElement.props.defaultValue?.value
|
|
149
|
+
)
|
|
150
|
+
: undefined);
|
|
151
|
+
|
|
152
|
+
const secondElement = prevData[index][1];
|
|
153
|
+
const newQuantity = quantity
|
|
154
|
+
? quantity
|
|
155
|
+
: React.isValidElement(secondElement)
|
|
156
|
+
? secondElement.props.defaultValue
|
|
157
|
+
: undefined;
|
|
158
|
+
|
|
159
|
+
return createRow(rowIndex, selectedItem, newQuantity);
|
|
160
|
+
} else {
|
|
161
|
+
return prevData[index];
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
if (onChange) {
|
|
166
|
+
const tableState = getTableState(updatedData);
|
|
167
|
+
|
|
168
|
+
onChange(tableState);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
return updatedData;
|
|
172
|
+
});
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
const addRow = () => {
|
|
176
|
+
setTableData((prevData) => [
|
|
177
|
+
...(prevData ?? []),
|
|
178
|
+
createRow(prevData?.length ?? 0),
|
|
179
|
+
]);
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
const removeRow = (rowIndex: number) => {
|
|
183
|
+
setTableData((prevData) =>
|
|
184
|
+
prevData?.filter((_, index) => index !== rowIndex)
|
|
185
|
+
);
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
React.useImperativeHandle(forwardedRef, () => ({
|
|
189
|
+
insertItems,
|
|
190
|
+
getTableState,
|
|
191
|
+
}));
|
|
192
|
+
|
|
193
|
+
const pastelGrayBackground = {
|
|
194
|
+
backgroundColor: "#B69E99",
|
|
195
|
+
} as React.CSSProperties;
|
|
196
|
+
|
|
197
|
+
const renderHeader = () => (
|
|
198
|
+
<tr style={{ ...pastelGrayBackground }}>
|
|
199
|
+
<th className="text-left align-middle p-2">Item</th>
|
|
200
|
+
<th className="text-left align-middle p-2">Cantidad</th>
|
|
201
|
+
<th className="text-left align-middle p-2">Etiqueta</th>
|
|
202
|
+
<th className="w-16"></th>
|
|
203
|
+
</tr>
|
|
204
|
+
);
|
|
205
|
+
|
|
206
|
+
const renderRow = (rowData: ReactNode[], rowIndex: number) => (
|
|
207
|
+
<tr key={rowIndex}>
|
|
208
|
+
{rowData.map((cellData, cellIndex) => (
|
|
209
|
+
<td key={cellIndex} className="align-middle p-2">
|
|
210
|
+
{cellData}
|
|
211
|
+
</td>
|
|
212
|
+
))}
|
|
213
|
+
{rowIndex !== 0 && (
|
|
214
|
+
<td className="align-middle w-16">
|
|
215
|
+
<button
|
|
216
|
+
className="bg-red-500 hover:bg-red-600 font-bold py-1 px-2 rounded ml-2"
|
|
217
|
+
onClick={(
|
|
218
|
+
event: React.MouseEvent<HTMLButtonElement, MouseEvent>
|
|
219
|
+
) => {
|
|
220
|
+
event.preventDefault();
|
|
221
|
+
event.stopPropagation();
|
|
222
|
+
removeRow(rowIndex);
|
|
223
|
+
}}
|
|
224
|
+
type="button"
|
|
225
|
+
>
|
|
226
|
+
x
|
|
227
|
+
</button>
|
|
228
|
+
</td>
|
|
229
|
+
)}
|
|
230
|
+
</tr>
|
|
231
|
+
);
|
|
232
|
+
|
|
233
|
+
const renderRows = () => {
|
|
234
|
+
return tableData?.map((rowData, rowIndex) => renderRow(rowData, rowIndex));
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
const error = formValidations[props.formName ?? "-1"][props.name];
|
|
238
|
+
const borderColor = error ? "border-red-500" : "border-transparent";
|
|
239
|
+
|
|
240
|
+
useEffect(() => {
|
|
241
|
+
if (!isInitialItemAdded && items?.length > 0) {
|
|
242
|
+
insertItems([items[0]]);
|
|
243
|
+
setIsInitialItemAdded(true);
|
|
244
|
+
}
|
|
245
|
+
}, [isInitialItemAdded, items, insertItems]);
|
|
246
|
+
|
|
247
|
+
return (
|
|
248
|
+
<div
|
|
249
|
+
className={`${className} ${borderColor} border-2`}
|
|
250
|
+
style={{ overflowX: "auto" }}
|
|
251
|
+
>
|
|
252
|
+
{!!error && <div className="text-red-500 text-sm mb-2">{error}</div>}
|
|
253
|
+
<table className="w-full">
|
|
254
|
+
<thead>{renderHeader()}</thead>
|
|
255
|
+
<tbody>{renderRows()}</tbody>
|
|
256
|
+
<tfoot>
|
|
257
|
+
<tr>
|
|
258
|
+
<td className="align-middle">
|
|
259
|
+
<button
|
|
260
|
+
className="bg-blue-500 hover:bg-blue-600 font-bold py-2 px-4 rounded"
|
|
261
|
+
onClick={(
|
|
262
|
+
event: React.MouseEvent<HTMLButtonElement, MouseEvent>
|
|
263
|
+
) => {
|
|
264
|
+
event.preventDefault();
|
|
265
|
+
event.stopPropagation();
|
|
266
|
+
addRow();
|
|
267
|
+
}}
|
|
268
|
+
type="button"
|
|
269
|
+
>
|
|
270
|
+
+
|
|
271
|
+
</button>
|
|
272
|
+
</td>
|
|
273
|
+
<td colSpan={2}>
|
|
274
|
+
Total de etiquetas a imprimir:{" "}
|
|
275
|
+
{tableData?.reduce((sum, x) => {
|
|
276
|
+
const val = React.isValidElement(x[1])
|
|
277
|
+
? x[1]?.props?.defaultValue
|
|
278
|
+
: undefined;
|
|
279
|
+
if (!sum) return val;
|
|
280
|
+
return sum + val;
|
|
281
|
+
}, 0)}
|
|
282
|
+
</td>
|
|
283
|
+
</tr>
|
|
284
|
+
</tfoot>
|
|
285
|
+
</table>
|
|
286
|
+
</div>
|
|
287
|
+
);
|
|
288
|
+
};
|
|
289
|
+
|
|
290
|
+
export default React.forwardRef(DynamicPrintTable);
|