@visns-studio/visns-components 4.7.1 → 4.7.3

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 (96) hide show
  1. package/package.json +13 -9
  2. package/src/components/cms/DataGrid.jsx +1461 -0
  3. package/src/components/cms/DropZone.jsx +349 -0
  4. package/src/components/cms/Field.jsx +802 -0
  5. package/src/components/cms/Form.jsx +476 -0
  6. package/src/components/cms/generic/CmsDetail.jsx +36 -0
  7. package/src/components/cms/generic/CmsIndex.jsx +73 -0
  8. package/src/components/cms/generic/CmsSort.jsx +125 -0
  9. package/src/components/cms/sorting/Item.jsx +115 -0
  10. package/src/components/cms/sorting/List.jsx +30 -0
  11. package/src/components/crm/AsyncSelect.jsx +125 -0
  12. package/src/components/crm/Autocomplete.jsx +174 -0
  13. package/src/components/crm/Breadcrumb.jsx +52 -0
  14. package/src/components/crm/Call.jsx +220 -0
  15. package/src/components/crm/DataGrid.jsx +2701 -0
  16. package/src/components/crm/Download.jsx +101 -0
  17. package/src/components/crm/Fetch.jsx +119 -0
  18. package/src/components/crm/Field.jsx +1557 -0
  19. package/src/components/crm/Form.jsx +1409 -0
  20. package/src/components/crm/Loader.jsx +29 -0
  21. package/src/components/crm/MultiSelect.jsx +78 -0
  22. package/src/components/crm/Navigation.jsx +619 -0
  23. package/src/components/crm/Notification.jsx +197 -0
  24. package/src/components/crm/QrCode.jsx +83 -0
  25. package/src/components/crm/Select.jsx +58 -0
  26. package/src/components/crm/SelectList.jsx +21 -0
  27. package/src/components/crm/TableFilter.jsx +198 -0
  28. package/src/components/crm/auth/Login.jsx +223 -0
  29. package/src/components/crm/auth/Profile.jsx +280 -0
  30. package/src/components/crm/auth/Reset.jsx +111 -0
  31. package/src/components/crm/auth/Verify.jsx +174 -0
  32. package/src/components/crm/auth/styles/Login.module.scss +243 -0
  33. package/src/components/crm/auth/styles/Profile.module.scss +222 -0
  34. package/src/components/crm/auth/styles/Reset.module.scss +216 -0
  35. package/src/components/crm/auth/styles/Verify.module.scss +216 -0
  36. package/src/components/crm/generic/AuditLog.jsx +108 -0
  37. package/src/components/crm/generic/AuditLogs.jsx +115 -0
  38. package/src/components/crm/generic/GenericAuth.jsx +166 -0
  39. package/src/components/crm/generic/GenericDashboard.jsx +42 -0
  40. package/src/components/crm/generic/GenericDetail.jsx +1499 -0
  41. package/src/components/crm/generic/GenericDynamic.jsx +915 -0
  42. package/src/components/crm/generic/GenericFormBuilder.jsx +1765 -0
  43. package/src/components/crm/generic/GenericIndex.jsx +376 -0
  44. package/src/components/crm/generic/GenericMain.jsx +129 -0
  45. package/src/components/crm/generic/GenericSort.jsx +188 -0
  46. package/src/components/crm/generic/NotificationList.jsx +64 -0
  47. package/src/components/crm/generic/styles/AuditLog.module.scss +147 -0
  48. package/src/components/crm/generic/styles/AuditLogs.module.scss +92 -0
  49. package/src/components/crm/generic/styles/GenericDetail.module.scss +634 -0
  50. package/src/components/crm/generic/styles/GenericDynamic.module.scss +932 -0
  51. package/src/components/crm/generic/styles/GenericFormBuilder.module.scss +944 -0
  52. package/src/components/crm/generic/styles/GenericIndex.module.scss +247 -0
  53. package/src/components/crm/generic/styles/GenericMain.module.scss +91 -0
  54. package/src/components/crm/generic/styles/GenericSort.module.scss +123 -0
  55. package/src/components/crm/generic/styles/NotificationList.module.scss +67 -0
  56. package/src/components/crm/sorting/Item.jsx +117 -0
  57. package/src/components/crm/sorting/List.jsx +32 -0
  58. package/src/components/crm/sorting/styles/Item.module.scss +68 -0
  59. package/src/components/crm/sorting/styles/List.module.scss +68 -0
  60. package/src/components/crm/styles/AsyncSelect.module.scss +8 -0
  61. package/src/components/crm/styles/Autocomplete.module.scss +44 -0
  62. package/src/components/crm/styles/DataGrid.module.scss +210 -0
  63. package/src/components/crm/styles/Field.module.scss +311 -0
  64. package/src/components/crm/styles/Form.module.scss +499 -0
  65. package/src/components/crm/styles/Loader.module.scss +94 -0
  66. package/src/components/crm/styles/MultiSelect.module.scss +8 -0
  67. package/src/components/crm/styles/Navigation.module.scss +978 -0
  68. package/src/components/crm/styles/Notification.module.scss +147 -0
  69. package/src/components/crm/styles/QrCode.module.scss +87 -0
  70. package/src/components/crm/styles/TableFilter.module.scss +52 -0
  71. package/src/components/styles/global.css +73 -0
  72. package/src/index.js +86 -0
  73. package/dist/104e5636d8ddb791614c.woff2 +0 -0
  74. package/dist/11fe6a83d647de5daf95.woff +0 -0
  75. package/dist/141e2a8c7836495afe2a.woff +0 -0
  76. package/dist/2ba5877f7079830b5383.woff +0 -0
  77. package/dist/2d6836f45b2037be41f3.woff +0 -0
  78. package/dist/399.0a0f3e0d21be1057d599.css +0 -8
  79. package/dist/399.b8f57fa3f8c0c10119e4.js +0 -1
  80. package/dist/47d566c3b1293dfd9d77.woff +0 -0
  81. package/dist/6282a13cbba671a71913.woff2 +0 -0
  82. package/dist/78266f551031aa9db127.woff +0 -0
  83. package/dist/7b7da89f1e3fdcbfe36c.woff2 +0 -0
  84. package/dist/7e78e8338af7efeda712.woff2 +0 -0
  85. package/dist/7fa387951673abf164b1.woff2 +0 -0
  86. package/dist/819d59862c2d0640aad8.woff +0 -0
  87. package/dist/b615e1a6c838ea059a56.woff +0 -0
  88. package/dist/b9b1aa739c660c4ce67c.woff2 +0 -0
  89. package/dist/c5f3640b11df9414facb.woff +0 -0
  90. package/dist/da26d162ff5af71d6590.woff2 +0 -0
  91. package/dist/dd5b2912dbf896310865.woff2 +0 -0
  92. package/dist/f282b331272463c1aa6c.woff2 +0 -0
  93. package/dist/main.83b033670d64419bb497.css +0 -1
  94. package/dist/main.b1723d17cd2d3513ab62.js +0 -1
  95. package/dist/report.html +0 -39
  96. package/dist/runtime.33c276593b23f8035b8d.js +0 -1
@@ -0,0 +1,125 @@
1
+ import React, { useState, useEffect } from 'react';
2
+ import { useLocation } from 'react-router-dom';
3
+ import Reveal from 'react-reveal/Reveal';
4
+ import { arrayMoveImmutable } from 'array-move';
5
+ import { toast } from 'react-toastify';
6
+ import CustomFetch from '../../crm/Fetch';
7
+ import SortableList from '../sorting/List';
8
+
9
+ const ChildSort = ({ item, url }) => {
10
+ const [data, setData] = useState(item.child);
11
+
12
+ const onSortEnd = ({ oldIndex, newIndex }) => {
13
+ setData((prevItem) => arrayMoveImmutable(prevItem, oldIndex, newIndex));
14
+ };
15
+
16
+ useEffect(() => {
17
+ if (data.length > 0) {
18
+ CustomFetch(
19
+ url + '/sort_update',
20
+ 'POST',
21
+ {
22
+ list: data,
23
+ },
24
+ function (result) {
25
+ if (result.error === '') {
26
+ } else {
27
+ toast.error(String(result.error));
28
+ }
29
+ }
30
+ );
31
+ }
32
+ }, [data]);
33
+
34
+ return (
35
+ <>
36
+ <h1>{item.label}</h1>
37
+ <SortableList
38
+ items={data}
39
+ onSortEnd={onSortEnd}
40
+ axis="xy"
41
+ helperClass="dragitem"
42
+ showImage={true}
43
+ transitionDuration={250}
44
+ useDragHandle
45
+ />
46
+ </>
47
+ );
48
+ };
49
+
50
+ const CmsSort = ({ setting, category = false }) => {
51
+ const location = useLocation();
52
+ const { form } = setting;
53
+ const [data, setData] = useState([]);
54
+ const url = form.url;
55
+
56
+ const onSortEnd = ({ oldIndex, newIndex }) => {
57
+ setData((prevItem) => arrayMoveImmutable(prevItem, oldIndex, newIndex));
58
+ };
59
+
60
+ useEffect(() => {
61
+ if (category === false) {
62
+ if (data.length > 0) {
63
+ CustomFetch(
64
+ url + '/sort_update',
65
+ 'POST',
66
+ {
67
+ list: data,
68
+ },
69
+ function (result) {
70
+ if (result.error === '') {
71
+ } else {
72
+ toast.error(String(result.error));
73
+ }
74
+ }
75
+ );
76
+ }
77
+ }
78
+ }, [data]);
79
+
80
+ useEffect(() => {
81
+ CustomFetch(url + '/sort_list', 'POST', {}, function (result) {
82
+ setData(result);
83
+ });
84
+ }, []);
85
+
86
+ return (
87
+ <Reveal effect="fadeInUp">
88
+ <div className="grid">
89
+ <div className="grid__row">
90
+ <div className="grid__full cmstitle">
91
+ <h1>{form.sort.title}</h1>
92
+ </div>
93
+ </div>
94
+ </div>
95
+ <div className="grid">
96
+ <div className="grid__row">
97
+ <div className="grid__full">
98
+ {category === false ? (
99
+ <SortableList
100
+ items={data}
101
+ onSortEnd={onSortEnd}
102
+ axis="xy"
103
+ helperClass="dragitem"
104
+ showImage={true}
105
+ transitionDuration={250}
106
+ useDragHandle
107
+ />
108
+ ) : (
109
+ data.length > 0 &&
110
+ data.map((item) => (
111
+ <ChildSort
112
+ key={`category-${item.id}`}
113
+ item={item}
114
+ url={url}
115
+ />
116
+ ))
117
+ )}
118
+ </div>
119
+ </div>
120
+ </div>
121
+ </Reveal>
122
+ );
123
+ };
124
+
125
+ export default CmsSort;
@@ -0,0 +1,115 @@
1
+ import React from 'react';
2
+ import { SortableElement, sortableHandle } from 'react-sortable-hoc';
3
+ import { ChevronVertical, Pencil, TrashCan } from 'akar-icons';
4
+
5
+ const DragHandle = sortableHandle(() => (
6
+ <ChevronVertical className="drag-handle" strokeWidth={1} size={26} />
7
+ ));
8
+
9
+ // Utility function to truncate text
10
+ const truncateText = (text, maxLength) => {
11
+ if (text && text.length > maxLength) {
12
+ return `${text.substring(0, maxLength)}...`;
13
+ }
14
+ return text;
15
+ };
16
+
17
+ const SortableItem = ({
18
+ containerIndex,
19
+ handleClick,
20
+ handleEdit,
21
+ handleDelete,
22
+ showImage,
23
+ value,
24
+ }) => {
25
+ const renderImage = (d) => {
26
+ let htmlContainer = '';
27
+
28
+ if (showImage) {
29
+ const imageUrl = d.image_url || d.file_url;
30
+ htmlContainer = imageUrl ? (
31
+ <div className="sortimg">
32
+ <img src={imageUrl} alt="" />
33
+ </div>
34
+ ) : (
35
+ <div className="sortimg">
36
+ {/* Placeholder image */}
37
+ <img
38
+ src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAJYAAACWCAYAAAA8AXHiAAAJ3UlEQVR4nO3b60/aXhwG8KflJijIJQgTt8y5mLkxl73w//8HzBbdXLLFqJsg3rjKnUJ/L0wJpYUC9ovbL8/nlRbac077tOf0tCiHh4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kQgGi0QwWCSCwSIRDBaJYLBIBINFIhgsEvEfmhiBahNiQpEAAAAASUVORK5CYII="
39
+ alt="Placeholder"
40
+ />
41
+ </div>
42
+ );
43
+ }
44
+
45
+ return htmlContainer;
46
+ };
47
+
48
+ const renderEditButton = () => {
49
+ if (!handleEdit) return null;
50
+
51
+ if (showImage) {
52
+ if (
53
+ value.hasOwnProperty('file_title') &&
54
+ value.hasOwnProperty('file_description')
55
+ ) {
56
+ return <EditButton />;
57
+ }
58
+ return null;
59
+ }
60
+
61
+ return <EditButton />;
62
+ };
63
+
64
+ const EditButton = () => (
65
+ <Pencil
66
+ className="delete pencil-edit"
67
+ strokeWidth={1}
68
+ size={26}
69
+ onClick={(e) => {
70
+ e.preventDefault();
71
+ e.stopPropagation();
72
+ handleEdit(value);
73
+ }}
74
+ />
75
+ );
76
+
77
+ return (
78
+ <li
79
+ onClick={(e) => {
80
+ e.preventDefault();
81
+ if (handleClick) {
82
+ handleClick(containerIndex);
83
+ }
84
+ }}
85
+ >
86
+ <DragHandle />
87
+ {truncateText(
88
+ value.label || value.file_title || value.file_name,
89
+ 30
90
+ )}
91
+
92
+ {renderImage(value)}
93
+
94
+ {renderEditButton()}
95
+
96
+ {handleDelete && (
97
+ <TrashCan
98
+ className="delete"
99
+ strokeWidth={1}
100
+ size={26}
101
+ onClick={(e) => {
102
+ e.preventDefault();
103
+ e.stopPropagation();
104
+ handleDelete(
105
+ value.id || containerIndex,
106
+ value.label || value.file_name
107
+ );
108
+ }}
109
+ />
110
+ )}
111
+ </li>
112
+ );
113
+ };
114
+
115
+ export default SortableElement(SortableItem);
@@ -0,0 +1,30 @@
1
+ import React from 'react';
2
+ import VisnsSortableItem from './Item';
3
+ import { SortableContainer } from 'react-sortable-hoc';
4
+
5
+ const SortableList = ({
6
+ handleClick,
7
+ handleDelete,
8
+ handleEdit,
9
+ items,
10
+ showImage,
11
+ }) => {
12
+ return (
13
+ <ul className="sortlist">
14
+ {items.map((value, index) => (
15
+ <VisnsSortableItem
16
+ key={`item-${index}`}
17
+ containerIndex={index}
18
+ index={index}
19
+ handleClick={handleClick}
20
+ handleDelete={handleDelete}
21
+ handleEdit={handleEdit}
22
+ showImage={showImage}
23
+ value={value}
24
+ />
25
+ ))}
26
+ </ul>
27
+ );
28
+ };
29
+
30
+ export default SortableContainer(SortableList);
@@ -0,0 +1,125 @@
1
+ import React, { useEffect, useState, useCallback } from 'react';
2
+ import CustomFetch from './Fetch';
3
+ import SelectList from './SelectList';
4
+ import AsyncSelect from 'react-select/async';
5
+ import { debounce } from 'lodash';
6
+ import styles from './styles/AsyncSelect.module.scss';
7
+
8
+ function VisnsAsyncSelect({
9
+ fields = [],
10
+ inputValue,
11
+ onChange,
12
+ orderBy,
13
+ onKeyDown,
14
+ placeholder,
15
+ settings,
16
+ }) {
17
+ const loadSuggestedOptions = useCallback(
18
+ debounce((inputValue, callback) => {
19
+ if (inputValue.length >= 3) {
20
+ loadOptions(inputValue).then((options) => callback(options));
21
+ } else {
22
+ callback([]); // Return empty array if input is less than 3 characters
23
+ }
24
+ }, 500),
25
+ []
26
+ );
27
+
28
+ const loadOptions = (inputValue) => {
29
+ if (inputValue.length >= 3) {
30
+ return new Promise((resolve, reject) => {
31
+ let data = [];
32
+
33
+ // Prepare payload
34
+ let payload = {
35
+ where: [
36
+ {
37
+ id: 'async',
38
+ value: inputValue,
39
+ },
40
+ ],
41
+ };
42
+
43
+ // Check and set fields from settings if fields prop is null or empty
44
+ if (fields && fields.length > 0) {
45
+ payload.fields = fields;
46
+ } else if (settings.fields && settings.fields.length > 0) {
47
+ payload.fields = settings.fields;
48
+ }
49
+
50
+ // Check and set orderBy from settings if orderBy prop is null or empty
51
+ if (orderBy) {
52
+ payload.orderBy = orderBy;
53
+ } else if (settings.orderBy) {
54
+ payload.orderBy = settings.orderBy;
55
+ }
56
+
57
+ // Fetch data
58
+ CustomFetch(
59
+ settings.url,
60
+ 'POST',
61
+ payload,
62
+ function (result) {
63
+ result.data.forEach((a) => {
64
+ let _optionItem = {
65
+ value: a.id,
66
+ label: a.label,
67
+ };
68
+
69
+ Object.keys(a).forEach((b) => {
70
+ if (b !== 'id') {
71
+ _optionItem = {
72
+ ..._optionItem,
73
+ [b]: a[b],
74
+ };
75
+ }
76
+ });
77
+
78
+ data.push(_optionItem);
79
+ });
80
+
81
+ resolve(data);
82
+ },
83
+ function (error) {
84
+ reject(String(error));
85
+ }
86
+ );
87
+ });
88
+ } else {
89
+ return Promise.resolve([]); // Return empty array if input is less than 3 characters
90
+ }
91
+ };
92
+
93
+ return (
94
+ <AsyncSelect
95
+ isClearable
96
+ cacheOptions
97
+ loadOptions={loadSuggestedOptions}
98
+ defaultOptions
99
+ className={styles.visns__ms}
100
+ onChange={(inputValue, action) => {
101
+ onChange(inputValue, action, settings.id);
102
+ }}
103
+ onKeyDown={(e) => {
104
+ if (onKeyDown) {
105
+ onKeyDown(e);
106
+ }
107
+ }}
108
+ components={{ SelectList }}
109
+ styles={{
110
+ menu: (styles) => ({
111
+ ...styles,
112
+ zIndex: 9999,
113
+ }),
114
+ input: (styles) => ({
115
+ ...styles,
116
+ padding: 0,
117
+ }),
118
+ }}
119
+ value={inputValue}
120
+ placeholder={placeholder ? placeholder : 'Select...'}
121
+ />
122
+ );
123
+ }
124
+
125
+ export default VisnsAsyncSelect;
@@ -0,0 +1,174 @@
1
+ import React, { useState, useEffect } from 'react';
2
+ import axios from 'axios';
3
+ import AwesomeDebouncePromise from 'awesome-debounce-promise';
4
+ import { ToggleOffFill, ToggleOnFill } from 'akar-icons';
5
+ import styles from './styles/Autocomplete.module.scss';
6
+
7
+ const VisnsAutocomplete = (props) => {
8
+ const {
9
+ api,
10
+ country,
11
+ field,
12
+ inputValue,
13
+ mapbox,
14
+ onSelect,
15
+ setFormData,
16
+ style,
17
+ } = props;
18
+ const [search, setSearch] = useState('');
19
+ const [results, setResults] = useState([]);
20
+ const [isLoading, setIsLoading] = useState(false);
21
+ const [overwrite, setOverwrite] = useState(false);
22
+
23
+ const performSearch = (id, value) => {
24
+ if (id > 0) {
25
+ if (value === '') {
26
+ setResults([]);
27
+ setIsLoading(false);
28
+ } else {
29
+ let url = `https://api.mapbox.com/geocoding/v5/mapbox.places/${value}.json?types=address,poi&access_token=${api}`;
30
+
31
+ if (country) {
32
+ url += `&country=${country}`;
33
+ }
34
+
35
+ if (mapbox) {
36
+ if (mapbox.proximity) {
37
+ url += `&proximity=${mapbox.proximity}`;
38
+ }
39
+
40
+ if (mapbox.bbox) {
41
+ url += `&bbox=${mapbox.bbox}`;
42
+ }
43
+ }
44
+
45
+ axios
46
+ .get(url)
47
+ .then((response) => {
48
+ setResults(response.data.features);
49
+ setIsLoading(false);
50
+ })
51
+ .catch(function (error) {
52
+ console.log(error);
53
+ });
54
+ }
55
+ }
56
+ };
57
+
58
+ const handleSearchChange = async (e) => {
59
+ if (e) {
60
+ setSearch(e.target.value);
61
+ setFormData((prevState) => ({
62
+ ...prevState,
63
+ [field]: e.target.value,
64
+ }));
65
+
66
+ if (overwrite === false) {
67
+ setIsLoading(true);
68
+ }
69
+
70
+ if (overwrite === false) {
71
+ await performSearchDebounced(1, e.target.value);
72
+ }
73
+ }
74
+ };
75
+
76
+ const performSearchDebounced = AwesomeDebouncePromise(performSearch, 500, {
77
+ key: (id, value) => id,
78
+ });
79
+
80
+ const handleItemClicked = (place) => {
81
+ const address =
82
+ place.address !== undefined && place.address !== null
83
+ ? place.address
84
+ : '';
85
+ const text =
86
+ place.text !== undefined && place.text !== null ? place.text : '';
87
+
88
+ const search = address && text ? `${address} ${text}` : text;
89
+ setSearch(search);
90
+ setResults([]);
91
+ onSelect(place, field);
92
+ };
93
+
94
+ const handleOverwrite = () => {
95
+ if (overwrite === false) {
96
+ setOverwrite(true);
97
+ setResults([]);
98
+ } else {
99
+ setOverwrite(false);
100
+ }
101
+ };
102
+
103
+ useEffect(() => {
104
+ if (overwrite === false) {
105
+ if (search !== '') {
106
+ performSearch();
107
+ }
108
+ }
109
+ }, [overwrite]);
110
+
111
+ useEffect(() => {
112
+ setSearch(inputValue);
113
+ }, [inputValue]);
114
+
115
+ return (
116
+ <>
117
+ <div className={styles.AutocompletePlace}>
118
+ <input
119
+ className={styles['AutocompletePlace-input']}
120
+ style={{
121
+ height:
122
+ style && style.multi_select_height
123
+ ? style.multi_select_height
124
+ : '52px',
125
+ }}
126
+ type="text"
127
+ value={search || ''}
128
+ onChange={handleSearchChange}
129
+ placeholder="Type an address"
130
+ autoComplete="off"
131
+ />
132
+ {overwrite === false ? (
133
+ <ToggleOffFill
134
+ data-tooltip-id="system-tooltip"
135
+ data-tooltip-content="Disable Autocomplete"
136
+ strokeWidth={2}
137
+ size={24}
138
+ onClick={handleOverwrite}
139
+ />
140
+ ) : (
141
+ <ToggleOnFill
142
+ data-tooltip-id="system-tooltip"
143
+ data-tooltip-content="Enable Autocomplete"
144
+ strokeWidth={2}
145
+ size={24}
146
+ onClick={handleOverwrite}
147
+ className={styles.toggleActive}
148
+ />
149
+ )}
150
+ {results.length > 0 ? (
151
+ <ul className="AutocompletePlace-results">
152
+ {results.map((place) => (
153
+ <li
154
+ key={place.id}
155
+ className={styles['AutocompletePlace-items']}
156
+ onClick={() => handleItemClicked(place)}
157
+ >
158
+ {place.place_name}
159
+ </li>
160
+ ))}
161
+
162
+ {isLoading && (
163
+ <li className={styles['AutocompletePlace-items']}>
164
+ Loading...
165
+ </li>
166
+ )}
167
+ </ul>
168
+ ) : null}
169
+ </div>
170
+ </>
171
+ );
172
+ };
173
+
174
+ export default VisnsAutocomplete;
@@ -0,0 +1,52 @@
1
+ import React from 'react';
2
+ import { Link } from 'react-router-dom';
3
+ import { CircleChevronRight } from 'akar-icons';
4
+
5
+ function Breadcrumb({ data, page }) {
6
+ const getNestedData = (data, keys) =>
7
+ keys.reduce((acc, key) => (acc && acc[key] ? acc[key] : null), data);
8
+
9
+ const nestedData =
10
+ data && page.parentTitleKey
11
+ ? getNestedData(data, page.parentTitleKey)
12
+ : null;
13
+
14
+ return (
15
+ <h1>
16
+ {page?.parentTitle && page?.parentUrl && (
17
+ <>
18
+ <Link to={page.parentUrl}>{page.parentTitle}</Link>
19
+ <CircleChevronRight strokeWidth={2} size={18} />
20
+ </>
21
+ )}
22
+
23
+ {nestedData ? (
24
+ <>
25
+ <Link
26
+ to={`${page.parentUrl}/${getNestedData(
27
+ data,
28
+ page.parentUrlKey
29
+ )}`}
30
+ >
31
+ {nestedData}
32
+ </Link>
33
+ <CircleChevronRight strokeWidth={2} size={18} />
34
+ </>
35
+ ) : (
36
+ page &&
37
+ page.title && (
38
+ <>
39
+ <Link to={page.previousUrl}>{page.title}</Link>
40
+ <CircleChevronRight strokeWidth={2} size={18} />
41
+ </>
42
+ )
43
+ )}
44
+
45
+ {page.titleKey && data && data[page.titleKey] && (
46
+ <>{data[page.titleKey]}</>
47
+ )}
48
+ </h1>
49
+ );
50
+ }
51
+
52
+ export default Breadcrumb;