@topconsultnpm/sdkui-react-beta 6.11.50 → 6.11.52

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 (41) hide show
  1. package/lib/assets/icomoon.svg +96 -96
  2. package/lib/components/editors/TMFormulaEditor.d.ts +12 -0
  3. package/lib/components/editors/TMFormulaEditor.js +3 -3
  4. package/lib/components/forms/Login/ChangePassword.d.ts +8 -0
  5. package/lib/components/forms/Login/ChangePassword.js +22 -0
  6. package/lib/components/forms/Login/ChangePasswordInputs.d.ts +14 -0
  7. package/lib/components/forms/Login/ChangePasswordInputs.js +67 -0
  8. package/lib/components/forms/Login/Chooser.d.ts +28 -0
  9. package/lib/components/forms/Login/Chooser.js +145 -0
  10. package/lib/components/forms/Login/LOGINLocalizator.d.ts +29 -0
  11. package/lib/components/forms/Login/LOGINLocalizator.js +247 -0
  12. package/lib/components/forms/Login/LoginValidatorService.d.ts +50 -0
  13. package/lib/components/forms/Login/LoginValidatorService.js +162 -0
  14. package/lib/components/forms/Login/Menu.d.ts +10 -0
  15. package/lib/components/forms/Login/Menu.js +48 -0
  16. package/lib/components/forms/Login/OTPReader.d.ts +14 -0
  17. package/lib/components/forms/Login/OTPReader.js +90 -0
  18. package/lib/components/forms/Login/PasswordStrengthChecker.d.ts +7 -0
  19. package/lib/components/forms/Login/PasswordStrengthChecker.js +45 -0
  20. package/lib/components/forms/Login/RapidAccessLogin.d.ts +25 -0
  21. package/lib/components/forms/Login/RapidAccessLogin.js +292 -0
  22. package/lib/components/forms/Login/RecoverPasswordFlow.d.ts +11 -0
  23. package/lib/components/forms/Login/RecoverPasswordFlow.js +95 -0
  24. package/lib/components/forms/Login/SelectBox.d.ts +23 -0
  25. package/lib/components/forms/Login/SelectBox.js +95 -0
  26. package/lib/components/forms/Login/StepIndicator.d.ts +7 -0
  27. package/lib/components/forms/Login/StepIndicator.js +19 -0
  28. package/lib/components/forms/Login/TMLoginForm.d.ts +43 -0
  29. package/lib/components/forms/Login/TMLoginForm.js +642 -0
  30. package/lib/components/forms/Login/TextBox.d.ts +27 -0
  31. package/lib/components/forms/Login/TextBox.js +111 -0
  32. package/lib/components/forms/TMLoginForm.js +9 -10
  33. package/lib/components/index.d.ts +1 -1
  34. package/lib/components/index.js +1 -1
  35. package/lib/helper/helpers.d.ts +1 -0
  36. package/lib/helper/helpers.js +5 -0
  37. package/lib/stories/TMSDKUI_Localizator.stories.d.ts +4 -0
  38. package/lib/stories/TMSDKUI_Localizator.stories.js +123 -0
  39. package/package.json +1 -1
  40. package/lib/components/forms/TMLoginPopupSaveLoginInfo.d.ts +0 -42
  41. package/lib/components/forms/TMLoginPopupSaveLoginInfo.js +0 -425
@@ -1,425 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { useEffect, useRef, useState } from "react";
3
- import { Button, LoadIndicator, Popup } from "devextreme-react";
4
- import { cultureIDsDataSource, LOGIN_HISTORY_KEY } from "./TMLoginForm";
5
- import { AuthenticationModes, LocalStorageService, ResultTypes, SDK_Localizator, ValidationItem } from "@topconsultnpm/sdk-ts-beta";
6
- import { SDKUI_Localizator } from "../../helper/SDKUI_Localizator";
7
- import { ButtonNames, TMExceptionBoxManager, TMMessageBoxManager } from "../base/TMPopUp";
8
- import TMTooltip from "../base/TMTooltip";
9
- import { IconApplyAndClose, IconCloseOutline, IconDelete, IconExport, IconHide, IconImport, IconShow } from "../../helper";
10
- import { TMSearchBar } from "../sidebar/TMHeader";
11
- import TMButton from "../base/TMButton";
12
- import TMTextBox from "../editors/TMTextBox";
13
- const TMLoginPopupSaveLoginInfo = (props) => {
14
- const { setLoginHistory, visible, hidePopup, setEndpoint, setArchive, setAuthMode, setUsername, setPassword, setDomain, setDomainArternative, setOnBeHalfUsername, setOnBeHalfPassword, setLoadLoginInfoFromExternal, onChangeLanguage } = props;
15
- // State to manage loading status
16
- const [loading, setLoading] = useState(false);
17
- // State to store the search input text
18
- const [searchText, setSearchText] = useState('');
19
- // Retrieve the login history from local storage, sort by 'name', and return the sorted array (or an empty array if not found)
20
- const getSortedLoginHistory = () => {
21
- const loginHistory = LocalStorageService.getItem(LOGIN_HISTORY_KEY);
22
- return loginHistory?.sort((a, b) => a.name.localeCompare(b.name)) || [];
23
- };
24
- // State to store both the full login history and the filtered search history
25
- const [historyState, setHistoryState] = useState({
26
- loginHistory: getSortedLoginHistory(),
27
- searchedLoginHistory: getSortedLoginHistory(),
28
- });
29
- // Handle search input changes with a debounce effect, updating the searched login history after a delay
30
- useEffect(() => {
31
- let timeoutId;
32
- if (searchText.length > 0) {
33
- setLoading(true);
34
- timeoutId = setTimeout(() => {
35
- setHistoryState(prevState => ({
36
- ...prevState,
37
- searchedLoginHistory: historyState.loginHistory.filter(data => data.name.toLowerCase().includes(searchText.toLowerCase()))
38
- }));
39
- setLoading(false);
40
- }, 300);
41
- }
42
- else {
43
- setHistoryState(prevState => ({ ...prevState, loginHistory: historyState.loginHistory, searchedLoginHistory: historyState.loginHistory }));
44
- setLoading(false);
45
- }
46
- return () => {
47
- clearTimeout(timeoutId);
48
- };
49
- }, [searchText]);
50
- // Function to reload and update state
51
- const reloadHistoryState = () => {
52
- const updatedLoginHistory = getSortedLoginHistory();
53
- setHistoryState({
54
- loginHistory: updatedLoginHistory,
55
- searchedLoginHistory: updatedLoginHistory,
56
- });
57
- };
58
- // Populate the login form fields with data from the selected login history item
59
- const fillLoginForm = (data) => {
60
- setEndpoint(data.endpoint);
61
- setArchive(data.archive);
62
- setUsername(data.username);
63
- setPassword("");
64
- setAuthMode(data.authenticationMode);
65
- setDomain(data.domain);
66
- setDomainArternative(data.domainAlternative);
67
- setOnBeHalfUsername(data.onBehalfUsername);
68
- setOnBeHalfPassword("");
69
- if (onChangeLanguage)
70
- onChangeLanguage(data.language);
71
- hidePopup();
72
- setLoadLoginInfoFromExternal(true);
73
- };
74
- // Display a confirmation dialog for deleting an item from local storage and handle the deletion on confirmation
75
- const deleteItemFromLocalStorage = (name) => {
76
- const msg = SDKUI_Localizator.Delete_ConfirmFor1.replaceParams(name);
77
- TMMessageBoxManager.show({
78
- title: SDKUI_Localizator.Delete, message: msg, buttons: [ButtonNames.YES, ButtonNames.NO],
79
- onButtonClick: async (e) => {
80
- if (e !== ButtonNames.YES)
81
- return;
82
- try {
83
- LocalStorageService.deleteItemByField(LOGIN_HISTORY_KEY, "name", name);
84
- setLoginHistory(LocalStorageService.getItem(LOGIN_HISTORY_KEY) ?? []);
85
- reloadHistoryState();
86
- }
87
- catch (e) {
88
- TMExceptionBoxManager.show({ exception: e });
89
- }
90
- }
91
- });
92
- };
93
- // Clear the search text and close the popup
94
- const closePopup = () => {
95
- setSearchText('');
96
- hidePopup();
97
- };
98
- // Handles the click event for export functionality: exports the current login history to a timestamped file.
99
- const onExportCallback = () => {
100
- // Inner function to export data as a file with a generated filename: exports the provided data to a file, generating a filename with a timestamp
101
- const exportToFile = (data, filenamePrefix) => {
102
- const file = new Blob([JSON.stringify(data, null, 2)], { type: 'text/plain' });
103
- const element = document.createElement("a");
104
- const currentDate = new Date();
105
- const dateString = currentDate.toISOString().split('T')[0]; // YYYY-MM-DD
106
- const timeString = currentDate.toISOString().split('T')[1].split('.')[0].substring(0, 5); // HH:MM
107
- element.href = URL.createObjectURL(file);
108
- element.download = `${filenamePrefix}_${dateString}_${timeString}.txt`;
109
- document.body.appendChild(element);
110
- element.click();
111
- document.body.removeChild(element);
112
- };
113
- if (historyState.searchedLoginHistory.length > 0) {
114
- exportToFile(historyState.searchedLoginHistory, "TopMedia_SURFER_LOGIN_HISTORY");
115
- }
116
- else {
117
- alert(SDKUI_Localizator.NoCredentialsSaved);
118
- }
119
- };
120
- const onImportCallback = () => {
121
- // Inner function to create a file input element: creates a file input element, configures it to accept a specific file type, and triggers a callback when a file is selected.
122
- const createFileInput = (accept, onChange) => {
123
- const input = document.createElement("input");
124
- input.type = "file";
125
- input.accept = accept;
126
- input.addEventListener('change', (event) => {
127
- const file = event.target.files?.[0];
128
- if (file)
129
- onChange(file);
130
- });
131
- input.click();
132
- };
133
- // Inner function to handle file reading and parsing: reads and parses a file's content as JSON, handling success and error cases.
134
- const handleFileRead = (file, onSuccess, onError) => {
135
- const reader = new FileReader();
136
- reader.onload = () => {
137
- try {
138
- const fileContent = reader.result;
139
- const parsedData = JSON.parse(fileContent);
140
- onSuccess(parsedData);
141
- }
142
- catch (error) {
143
- onError();
144
- }
145
- };
146
- reader.readAsText(file);
147
- };
148
- // Inner function to generate modified data by appending new IDs and timestamp: generates a modified version of the parsed data by assigning new IDs, and appending timestamped names to each entry.
149
- const generateModifiedData = (parsedData, existingHistory) => {
150
- const maxId = Math.max(...existingHistory.map(item => Number(item.id) || 0), 0);
151
- return parsedData.map((item, index) => {
152
- const id = maxId + index + 1;
153
- const currentDate = new Date();
154
- const formattedDate = currentDate.toISOString().split('T')[0];
155
- const time = currentDate.toTimeString().split(' ')[0];
156
- return {
157
- ...item,
158
- name: `${item.name}_${formattedDate}_${time}`,
159
- id,
160
- preferred: false
161
- };
162
- });
163
- };
164
- // Inner function to update the application state with new history data: updates the application's history state with the new data and stores it in local storage.
165
- const updateHistoryState = (newData) => {
166
- setHistoryState((prevState) => {
167
- const updatedHistory = {
168
- loginHistory: [...prevState.loginHistory, ...newData],
169
- searchedLoginHistory: [...prevState.searchedLoginHistory, ...newData],
170
- };
171
- LocalStorageService.setItem(LOGIN_HISTORY_KEY, updatedHistory.loginHistory);
172
- return { ...prevState, ...updatedHistory };
173
- });
174
- };
175
- createFileInput(".txt", (file) => {
176
- handleFileRead(file, (parsedData) => {
177
- const modifiedData = generateModifiedData(parsedData, historyState.loginHistory);
178
- updateHistoryState(modifiedData);
179
- }, () => alert(SDKUI_Localizator.ErrorParsingFileContent));
180
- });
181
- };
182
- // titleRender function returns JSX to render a header with user interface components for import/export and closing the popup
183
- const titleRender = () => {
184
- return _jsxs("div", { style: { display: 'flex', justifyContent: 'space-between', alignItems: 'center', width: '100%' }, children: [_jsx("h3", { children: SDKUI_Localizator.SwitchUser }), _jsx("div", { style: { marginLeft: 'auto', gap: 10, display: 'flex', alignItems: 'center' }, children: _jsx(TMTooltip, { content: SDKUI_Localizator.Close, children: _jsx(IconCloseOutline, { style: { cursor: "pointer" }, onClick: hidePopup }) }) })] });
185
- };
186
- // Conditionally render popup content based on loading state, available login history, or display login items in an accordion
187
- const renderPopupContent = () => {
188
- if (loading) {
189
- return (_jsx("div", { style: { display: "flex", justifyContent: "center", alignItems: "center", height: "100%", width: "100%" }, children: _jsx(LoadIndicator, {}) }));
190
- }
191
- if (historyState.searchedLoginHistory.length === 0) {
192
- return (_jsx("div", { style: { display: "flex", justifyContent: "center", alignItems: "center", textAlign: "center", padding: "20px" }, children: SDKUI_Localizator.NoCredentialsSaved }));
193
- }
194
- return (_jsx("div", { style: { overflowY: "auto", maxHeight: "calc(100% - 60px)", padding: "0px 5px", margin: '0px 10px', border: "1px solid rgb(221, 221, 221)", borderRadius: '6px' }, children: historyState.searchedLoginHistory.map((data, index) => {
195
- return _jsx(TMItemTitleRender, { titleObj: { title: data.name }, id: index + 1, historyState: historyState, reloadHistoryState: reloadHistoryState, fillLoginForm: fillLoginForm, deleteItemFromLocalStorage: deleteItemFromLocalStorage, setSearchText: setSearchText }, data.name + '-' + index);
196
- }) }));
197
- };
198
- return (_jsxs(Popup, { maxWidth: 600, visible: visible, onHiding: closePopup, title: SDKUI_Localizator.SwitchUser, titleRender: titleRender, hideOnOutsideClick: false, showTitle: true, resizeEnabled: true, dragEnabled: true, showCloseButton: true, children: [_jsxs("div", { style: { padding: "10px", display: "flex", justifyContent: "space-between", alignItems: "center", width: "100%", position: "sticky", top: 0, backgroundColor: "#fff", zIndex: 1, }, children: [_jsx("div", { style: { display: "flex", flex: 1 }, children: _jsx(TMSearchBar, { maxWidth: "200px", marginLeft: "0px", onSearchValueChanged: (e) => setSearchText(e), searchValue: searchText }) }), _jsxs("div", { style: { display: "flex", alignItems: "center", marginRight: "5px", gap: 8 }, children: [_jsx(TMTooltip, { content: SDKUI_Localizator.Export, children: _jsx(TMButton, { label: SDKUI_Localizator.Export, color: 'primary', btnStyle: 'toolbar', icon: _jsx(IconExport, {}), onClick: onExportCallback }) }), _jsx(TMTooltip, { content: SDKUI_Localizator.Import, children: _jsx(TMButton, { label: SDKUI_Localizator.Import, color: 'secondary', btnStyle: 'toolbar', icon: _jsx(IconImport, {}), onClick: onImportCallback }) })] })] }), renderPopupContent()] }));
199
- };
200
- export default TMLoginPopupSaveLoginInfo;
201
- // Render a styled title with its ID and title content, using flex layout
202
- export const TMItemTitleRender = (props) => {
203
- const { titleObj, id, historyState, reloadHistoryState, fillLoginForm, deleteItemFromLocalStorage, setSearchText } = props;
204
- const historyItem = historyState.loginHistory.find(item => item.name === titleObj.title);
205
- const [preferred, setPreferred] = useState(historyItem?.preferred ?? false);
206
- const [isSelected, setIsSelected] = useState(false);
207
- const [showDetails, setShowDetails] = useState(false);
208
- const containerRef = useRef(null);
209
- const mobileBreakpoint = 768;
210
- const [isMobile, setIsMobile] = useState(false);
211
- useEffect(() => {
212
- const updateDimensions = (entries) => {
213
- for (let entry of entries) {
214
- const { width } = entry.contentRect;
215
- setIsMobile(width <= mobileBreakpoint);
216
- }
217
- };
218
- const resizeObserver = new ResizeObserver(updateDimensions);
219
- if (containerRef.current) {
220
- resizeObserver.observe(containerRef.current);
221
- }
222
- return () => {
223
- if (containerRef.current) {
224
- resizeObserver.unobserve(containerRef.current);
225
- }
226
- };
227
- }, [containerRef]);
228
- useEffect(() => {
229
- const mediaQuery = window.matchMedia('(max-width: 768px)');
230
- const handleResize = () => {
231
- setIsMobile(mediaQuery.matches);
232
- };
233
- mediaQuery.addEventListener('change', handleResize);
234
- handleResize();
235
- return () => {
236
- mediaQuery.removeEventListener('change', handleResize);
237
- };
238
- }, []);
239
- useEffect(() => {
240
- if (historyItem === undefined)
241
- return;
242
- setPreferred(historyItem.preferred ?? false);
243
- }, [historyItem?.preferred]);
244
- useEffect(() => {
245
- if (historyItem === undefined)
246
- return;
247
- if (preferred === historyItem.preferred)
248
- return;
249
- const historyStateUpdtated = historyState.loginHistory.map(history => {
250
- if (history.name === historyItem.name) {
251
- return { ...history, preferred };
252
- }
253
- return { ...history, preferred: false };
254
- });
255
- LocalStorageService.setItem(LOGIN_HISTORY_KEY, historyStateUpdtated);
256
- reloadHistoryState();
257
- }, [preferred]);
258
- const toogleShowDetails = (e) => {
259
- if (e === undefined)
260
- return;
261
- e.preventDefault();
262
- e.stopPropagation();
263
- setShowDetails(prevState => !prevState);
264
- };
265
- const onPreferredCallback = (e) => {
266
- if (e === undefined || e.event === undefined)
267
- return;
268
- e.event.preventDefault();
269
- e.event.stopPropagation();
270
- let msg = preferred ? SDKUI_Localizator.RemoveNamedPreferredCredentials.replaceParams(historyItem?.name) : SDKUI_Localizator.SetNamedCredentialsAsPreferred.replaceParams(historyItem?.name);
271
- TMMessageBoxManager.show({
272
- title: SDKUI_Localizator.SetAsFavorite, message: msg, buttons: [ButtonNames.YES, ButtonNames.NO],
273
- onButtonClick: async (e) => {
274
- if (e !== ButtonNames.YES)
275
- return;
276
- try {
277
- setPreferred((prev) => !prev);
278
- }
279
- catch (e) {
280
- TMExceptionBoxManager.show({ exception: e });
281
- }
282
- }
283
- });
284
- };
285
- const handleMouseEnter = () => {
286
- // Highlight the div on mouse enter
287
- setIsSelected(true);
288
- };
289
- const handleMouseLeave = () => {
290
- // Remove highlight when mouse leaves the div
291
- setIsSelected(false);
292
- };
293
- const onLoginCallback = (e) => {
294
- if (historyItem === undefined)
295
- return;
296
- if (e === undefined)
297
- return;
298
- // If it's a valid click on the parent div, proceed
299
- e.preventDefault();
300
- e.stopPropagation();
301
- // Assuming fillLoginForm is a function that handles the form filling
302
- fillLoginForm(historyItem);
303
- };
304
- const onDeleteCallback = (e) => {
305
- if (historyItem === undefined)
306
- return;
307
- if (e === undefined)
308
- return;
309
- // If it's a valid click on the parent div, proceed
310
- e.preventDefault();
311
- e.stopPropagation();
312
- deleteItemFromLocalStorage(historyItem.name);
313
- };
314
- // Function to truncate title for mobile devices
315
- const truncateForMobile = (title) => {
316
- return title.length > 20 ? `${title.substring(0, 20)}...` : title;
317
- };
318
- // Function to truncate title for non-mobile devices
319
- const truncateForDesktop = (title) => {
320
- return title.length > 45 ? `${title.substring(0, 45)}...` : title;
321
- };
322
- const truncatedTitle = isMobile ? truncateForMobile(titleObj.title) : truncateForDesktop(titleObj.title);
323
- return _jsxs("div", { ref: containerRef, children: [_jsxs("div", { onMouseEnter: handleMouseEnter, onMouseLeave: handleMouseLeave, onDoubleClick: onLoginCallback, style: {
324
- backgroundColor: isSelected ? '#F5F5F5' : 'transparent',
325
- display: "flex",
326
- fontFamily: "Arial, sans-serif",
327
- width: "100%",
328
- position: "relative",
329
- whiteSpace: "nowrap",
330
- cursor: "pointer",
331
- alignItems: "center",
332
- userSelect: "none",
333
- touchAction: "none",
334
- borderRadius: "4px",
335
- minHeight: "32px",
336
- padding: "6px 8px"
337
- }, children: [_jsx("div", { style: { display: "inline-block", whiteSpace: "nowrap", overflow: "hidden", textOverflow: "ellipsis", width: isMobile ? "72%" : "85%", verticalAlign: "top" }, children: _jsxs("div", { style: { display: "inline-flex", alignItems: "center" }, children: [_jsx(TMTooltip, { content: SDKUI_Localizator.SetAsFavorite, children: _jsxs("div", { style: { paddingTop: "5px", paddingBottom: "5px", paddingRight: "10px" }, children: [preferred && _jsx(Button, { width: 27, height: 27, style: { backgroundColor: '#EAD303', borderRadius: '50%', display: 'inline-flex', justifyContent: 'center', alignItems: 'center' }, icon: "favorites", onClick: onPreferredCallback }), !preferred && _jsx(Button, { width: 27, height: 27, style: { backgroundColor: 'transparent', borderRadius: '50%', display: 'inline-flex', justifyContent: 'center', alignItems: 'center' }, icon: "favorites", onClick: onPreferredCallback })] }) }), _jsx(TMTooltip, { content: titleObj.title, children: _jsxs("div", { style: { fontSize: isMobile ? "11px" : "12px" }, children: ["(", id, ")\u00A0", _jsx("span", { style: { fontWeight: "bold" }, children: truncatedTitle })] }) })] }) }), _jsx("div", { style: { display: "inline-block", position: "absolute", right: 0, textAlign: "right", verticalAlign: "top", whiteSpace: "nowrap" }, children: _jsxs("div", { style: { display: 'inline-flex', gap: '10px' }, children: [isMobile && _jsx(TMTooltip, { content: SDKUI_Localizator.ApplyAndClose, children: _jsx("div", { onClick: onLoginCallback, onDoubleClick: (e) => { e.preventDefault(); e.stopPropagation(); }, style: {
338
- width: 27,
339
- height: 27,
340
- backgroundColor: '#6EB735',
341
- borderRadius: '50%',
342
- display: 'inline-flex',
343
- justifyContent: 'center',
344
- alignItems: 'center',
345
- cursor: 'pointer'
346
- }, children: _jsx(IconApplyAndClose, { color: "#fff" }) }) }), _jsx(TMTooltip, { content: SDKUI_Localizator.ShowDetails, children: _jsx("div", { onClick: toogleShowDetails, onDoubleClick: (e) => { e.preventDefault(); e.stopPropagation(); }, style: {
347
- width: 27,
348
- height: 27,
349
- backgroundColor: '#2559A5',
350
- borderRadius: '50%',
351
- display: 'inline-flex',
352
- justifyContent: 'center',
353
- alignItems: 'center',
354
- cursor: 'pointer'
355
- }, children: showDetails ? _jsx(IconHide, { color: "#fff" }) : _jsx(IconShow, { color: "#fff" }) }) }), _jsx(TMTooltip, { content: SDKUI_Localizator.Delete, children: _jsx("div", { onClick: onDeleteCallback, onDoubleClick: (e) => { e.preventDefault(); e.stopPropagation(); }, style: {
356
- width: 27,
357
- height: 27,
358
- backgroundColor: '#ED153A',
359
- borderRadius: '50%',
360
- display: 'inline-flex',
361
- justifyContent: 'center',
362
- alignItems: 'center',
363
- cursor: 'pointer'
364
- }, children: _jsx(IconDelete, { color: "#fff" }) }) })] }) })] }), _jsx("div", { style: {
365
- marginTop: "10px",
366
- maxHeight: showDetails ? "500px" : "0", // Use max-height for transition
367
- opacity: showDetails ? 1 : 0,
368
- overflow: 'hidden',
369
- transition: showDetails ?
370
- 'max-height 1s ease-in-out, opacity 1s ease-in-out' : // Slow transition for showing
371
- 'max-height 0.5s ease-out, opacity 0.5s ease-out', // Fast transition for hiding
372
- transform: showDetails ? 'scaleY(1)' : 'scaleY(0)',
373
- transformOrigin: 'top', // Ensures the animation grows from top to bottom
374
- }, children: _jsx(TMLoginItemTemplate, { data: historyItem, reloadHistoryState: reloadHistoryState, setSearchText: setSearchText }) })] });
375
- };
376
- export const TMLoginItemTemplate = (props) => {
377
- const { data, reloadHistoryState, setSearchText } = props;
378
- const [name, setName] = useState(data.name);
379
- const [error, setError] = useState(false);
380
- const [validationItems, setValidationItems] = useState([]);
381
- const isNameMatching = data.name.trim().toLowerCase() === name.trim().toLowerCase();
382
- // Effect to handle validation side-effects (like setting error state)
383
- useEffect(() => {
384
- const validationsItems = getValidationItems();
385
- setValidationItems(validationsItems);
386
- setError(validationsItems.length > 0); // Set error state based on validation result
387
- }, [name]); // Only re-run when 'name' changes
388
- // Update the login history item name in local storage if no errors and name is different from the initial name
389
- const updateHandler = () => {
390
- if (error || (isNameMatching))
391
- return;
392
- if (!isNameMatching) {
393
- const dataToUpdate = { ...data, name };
394
- LocalStorageService.updateItemByField(LOGIN_HISTORY_KEY, "name", data.name, dataToUpdate);
395
- reloadHistoryState();
396
- setSearchText("");
397
- }
398
- };
399
- // Validation logic function
400
- const getValidationItems = () => {
401
- const validationsArray = [];
402
- if (isNameMatching)
403
- return validationsArray;
404
- if (name.length === 0)
405
- validationsArray.push(new ValidationItem(ResultTypes.ERROR, 'saveLoginName', SDK_Localizator.RequiredField));
406
- const findItemByField = LocalStorageService.findItemByField(LOGIN_HISTORY_KEY, "name", name);
407
- if (findItemByField) {
408
- validationsArray.push(new ValidationItem(ResultTypes.ERROR, 'saveLoginName', SDKUI_Localizator.DuplicateNameError));
409
- }
410
- return validationsArray;
411
- };
412
- const getAuthenticationModeTranslation = (authenticationMode) => {
413
- switch (authenticationMode) {
414
- case AuthenticationModes.Windows:
415
- return AuthenticationModes.Windows;
416
- case AuthenticationModes.WindowsThroughTopMedia:
417
- return SDKUI_Localizator.AuthMode_WindowsViaTopMedia;
418
- case AuthenticationModes.TopMediaOnBehalfOf:
419
- return SDKUI_Localizator.AuthMode_OnBehalfOf;
420
- default:
421
- return authenticationMode;
422
- }
423
- };
424
- return _jsx("div", { style: { display: 'flex', overflow: 'hidden', width: '100%', justifyContent: 'center', alignItems: 'center' }, children: _jsxs("div", { style: { padding: '2px', flex: 1 }, children: [_jsx(TMTextBox, { type: "text", label: SDKUI_Localizator.NameForAccess, value: name, readOnly: false, buttons: [{ text: `${SDKUI_Localizator.Save}`, icon: _jsx("i", { style: { color: (error || isNameMatching) ? "rgb(80,80,80)" : "#28a745", fontSize: 20 }, className: "dx-icon-save" }), onClick: updateHandler }], onValueChanged: (e) => setName(e.target.value), validationItems: validationItems }, "name"), (data.endpoint && data.endpoint?.Description) && _jsx(TMTextBox, { type: "text", label: SDKUI_Localizator.Endpoint, value: data.endpoint.Description + (' (' + data.endpoint.URL + ')'), readOnly: true, onValueChanged: (e) => setName(e.target.value) }), (data.archive && data.archive?.description) && _jsx(TMTextBox, { type: "text", label: SDKUI_Localizator.ArchiveID, value: data.archive.description + (' (' + (data.archive.id ?? '-') + ')'), readOnly: true }), _jsx(TMTextBox, { type: "text", label: SDKUI_Localizator.AuthMode, value: getAuthenticationModeTranslation(data.authenticationMode), readOnly: true }), data.domain.length > 0 && _jsx(TMTextBox, { type: "text", label: SDKUI_Localizator.Domain, value: data.domain, readOnly: true }), _jsx(TMTextBox, { type: "text", label: SDKUI_Localizator.UserName, value: data.username, readOnly: true }), _jsx(TMTextBox, { type: "text", label: SDKUI_Localizator.CultureID, value: cultureIDsDataSource.find(item => item.value === data.language)?.display ?? '', readOnly: true })] }) });
425
- };