@bigbinary/neeto-templates-frontend 2.0.1 → 2.1.0

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.
@@ -0,0 +1,633 @@
1
+ import { _ as _slicedToArray, u as useFetchTemplates, a as _toConsumableArray, b as useCreateTemplate } from './useTemplatesApi-81e0a50f.js';
2
+ import * as React from 'react';
3
+ import { useState, useRef, useCallback, useEffect, createElement } from 'react';
4
+ import { noop } from '@bigbinary/neeto-cist';
5
+ import Modal from '@bigbinary/neetoui/Modal';
6
+ import { _ as _defineProperty } from './query-ddc455b2.js';
7
+ import PageLoader from '@bigbinary/neeto-molecules/PageLoader';
8
+ import Search from '@bigbinary/neeto-molecules/Search';
9
+ import Spinner from '@bigbinary/neetoui/Spinner';
10
+ import Typography from '@bigbinary/neetoui/Typography';
11
+ import { useTranslation } from 'react-i18next';
12
+ import { jsxs, jsx } from 'react/jsx-runtime';
13
+ import classnames from 'classnames';
14
+ import { joinHyphenCase } from '@bigbinary/neeto-commons-frontend/utils';
15
+ import { useBreakpoints } from '@bigbinary/neeto-commons-frontend/react-utils';
16
+ import ResponsiveDevicePicker from '@bigbinary/neeto-molecules/ResponsiveDevicePicker';
17
+ import Button from '@bigbinary/neetoui/Button';
18
+ import '@bigbinary/neeto-tags-frontend';
19
+ import '@tanstack/react-query';
20
+ import 'ramda';
21
+ import 'axios';
22
+
23
+ var TEMPLATE_SCREENS = {
24
+ LIST: "List",
25
+ PREVIEW: "Preview"
26
+ };
27
+ var DEFAULT_CATEGORY = {
28
+ id: "all",
29
+ name: "All"
30
+ };
31
+ var INFINITE_SCROLL_DELAY = 500;
32
+ var RESPONSIVE_DEVICES = {
33
+ DESKTOP: "desktop",
34
+ TABLET: "tablet",
35
+ MOBILE: "mobile"
36
+ };
37
+
38
+ function createObserverCache() {
39
+ var cachesByRoot = new Map();
40
+
41
+ function getObserver(_ref) {
42
+ var root = _ref.root,
43
+ rootMargin = _ref.rootMargin,
44
+ threshold = _ref.threshold;
45
+ var cacheByRoot = cachesByRoot.get(root);
46
+
47
+ if (!cacheByRoot) {
48
+ cacheByRoot = new Map();
49
+ cachesByRoot.set(root, cacheByRoot);
50
+ }
51
+
52
+ var cacheKey = JSON.stringify({
53
+ rootMargin: rootMargin,
54
+ threshold: threshold
55
+ });
56
+ var cachedObserver = cacheByRoot.get(cacheKey);
57
+
58
+ if (!cachedObserver) {
59
+ var entryCallbacks = new Map();
60
+ var observer = new IntersectionObserver(function (entries) {
61
+ entries.forEach(function (entry) {
62
+ var callback = entryCallbacks.get(entry.target);
63
+ callback == null ? void 0 : callback(entry);
64
+ });
65
+ }, {
66
+ root: root,
67
+ rootMargin: rootMargin,
68
+ threshold: threshold
69
+ });
70
+ cachedObserver = {
71
+ observer: observer,
72
+ entryCallbacks: entryCallbacks
73
+ };
74
+ cacheByRoot.set(cacheKey, cachedObserver);
75
+ }
76
+
77
+ return {
78
+ observe: function observe(node, callback) {
79
+ var _cachedObserver, _cachedObserver2;
80
+
81
+ (_cachedObserver = cachedObserver) == null ? void 0 : _cachedObserver.entryCallbacks.set(node, callback);
82
+ (_cachedObserver2 = cachedObserver) == null ? void 0 : _cachedObserver2.observer.observe(node);
83
+ },
84
+ unobserve: function unobserve(node) {
85
+ var _cachedObserver3, _cachedObserver4;
86
+
87
+ (_cachedObserver3 = cachedObserver) == null ? void 0 : _cachedObserver3.entryCallbacks["delete"](node);
88
+ (_cachedObserver4 = cachedObserver) == null ? void 0 : _cachedObserver4.observer.unobserve(node);
89
+ }
90
+ };
91
+ }
92
+
93
+ return {
94
+ getObserver: getObserver
95
+ };
96
+ }
97
+
98
+ var DEFAULT_ROOT_MARGIN = '0px';
99
+ var DEFAULT_THRESHOLD = [0];
100
+ var observerCache = /*#__PURE__*/createObserverCache(); // For more info:
101
+ // https://developers.google.com/web/updates/2016/04/intersectionobserver
102
+ // https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API
103
+
104
+ function useIntersectionObserver(args) {
105
+ var _args$rootMargin, _args$threshold;
106
+
107
+ var rootMargin = (_args$rootMargin = args == null ? void 0 : args.rootMargin) != null ? _args$rootMargin : DEFAULT_ROOT_MARGIN;
108
+ var threshold = (_args$threshold = args == null ? void 0 : args.threshold) != null ? _args$threshold : DEFAULT_THRESHOLD;
109
+ var nodeRef = useRef(null);
110
+ var rootRef = useRef(null);
111
+ var observerRef = useRef(null);
112
+
113
+ var _useState = useState(),
114
+ entry = _useState[0],
115
+ setEntry = _useState[1];
116
+
117
+ var observe = useCallback(function () {
118
+ var node = nodeRef.current;
119
+
120
+ if (!node) {
121
+ setEntry(undefined);
122
+ return;
123
+ }
124
+
125
+ var observer = observerCache.getObserver({
126
+ root: rootRef.current,
127
+ rootMargin: rootMargin,
128
+ threshold: threshold
129
+ });
130
+ observer.observe(node, function (observedEntry) {
131
+ setEntry(observedEntry);
132
+ });
133
+ observerRef.current = observer;
134
+ }, [rootMargin, threshold]);
135
+ var unobserve = useCallback(function () {
136
+ var currentObserver = observerRef.current;
137
+ var node = nodeRef.current;
138
+
139
+ if (node) {
140
+ currentObserver == null ? void 0 : currentObserver.unobserve(node);
141
+ }
142
+
143
+ observerRef.current = null;
144
+ }, []); // React will call the ref callback with the DOM element when the component mounts,
145
+ // and call it with null when it unmounts.
146
+ // So, we don't need an useEffect etc to unobserve nodes.
147
+ // When nodeRef.current is null, it will be unobserved and observe function
148
+ // won't do anything.
149
+
150
+ var refCallback = useCallback(function (node) {
151
+ unobserve();
152
+ nodeRef.current = node;
153
+ observe();
154
+ }, [observe, unobserve]);
155
+ var rootRefCallback = useCallback(function (rootNode) {
156
+ unobserve();
157
+ rootRef.current = rootNode;
158
+ observe();
159
+ }, [observe, unobserve]);
160
+ return [refCallback, {
161
+ entry: entry,
162
+ rootRef: rootRefCallback
163
+ }];
164
+ }
165
+
166
+ function _extends$1() {
167
+ _extends$1 = Object.assign || function (target) {
168
+ for (var i = 1; i < arguments.length; i++) {
169
+ var source = arguments[i];
170
+
171
+ for (var key in source) {
172
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
173
+ target[key] = source[key];
174
+ }
175
+ }
176
+ }
177
+
178
+ return target;
179
+ };
180
+
181
+ return _extends$1.apply(this, arguments);
182
+ }
183
+
184
+ function useTrackVisibility(args) {
185
+ var _result$entry;
186
+
187
+ var _useIntersectionObser = useIntersectionObserver(args),
188
+ ref = _useIntersectionObser[0],
189
+ result = _useIntersectionObser[1];
190
+
191
+ var isVisible = Boolean((_result$entry = result.entry) == null ? void 0 : _result$entry.isIntersecting);
192
+
193
+ var _useState = useState(isVisible),
194
+ wasEverVisible = _useState[0],
195
+ setWasEverVisible = _useState[1];
196
+
197
+ if (isVisible && !wasEverVisible) {
198
+ setWasEverVisible(true);
199
+ }
200
+
201
+ return [ref, _extends$1({}, result, {
202
+ isVisible: isVisible,
203
+ wasEverVisible: wasEverVisible
204
+ })];
205
+ }
206
+
207
+ var DEFAULT_DELAY_IN_MS = 100;
208
+
209
+ function useInfiniteScroll(_ref) {
210
+ var loading = _ref.loading,
211
+ hasNextPage = _ref.hasNextPage,
212
+ onLoadMore = _ref.onLoadMore,
213
+ rootMargin = _ref.rootMargin,
214
+ disabled = _ref.disabled,
215
+ _ref$delayInMs = _ref.delayInMs,
216
+ delayInMs = _ref$delayInMs === void 0 ? DEFAULT_DELAY_IN_MS : _ref$delayInMs;
217
+
218
+ var _useTrackVisibility = useTrackVisibility({
219
+ rootMargin: rootMargin
220
+ }),
221
+ ref = _useTrackVisibility[0],
222
+ _useTrackVisibility$ = _useTrackVisibility[1],
223
+ rootRef = _useTrackVisibility$.rootRef,
224
+ isVisible = _useTrackVisibility$.isVisible;
225
+
226
+ var shouldLoadMore = !disabled && !loading && isVisible && hasNextPage; // eslint-disable-next-line consistent-return
227
+
228
+ useEffect(function () {
229
+ if (shouldLoadMore) {
230
+ // When we trigger 'onLoadMore' and new items are added to the list,
231
+ // right before they become rendered on the screen, 'loading' becomes false
232
+ // and 'isVisible' can be true for a brief time, based on the scroll position.
233
+ // So, it triggers 'onLoadMore' just after the first one is finished.
234
+ // We use a small delay here to prevent this kind of situations.
235
+ // It can be configured by hook args.
236
+ var timer = setTimeout(function () {
237
+ onLoadMore();
238
+ }, delayInMs);
239
+ return function () {
240
+ clearTimeout(timer);
241
+ };
242
+ }
243
+ }, [onLoadMore, shouldLoadMore, delayInMs]);
244
+ return [ref, {
245
+ rootRef: rootRef
246
+ }];
247
+ }
248
+
249
+ var _rect, _path;
250
+ function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
251
+ const SvgCustom = props => /*#__PURE__*/React.createElement("svg", _extends({
252
+ xmlns: "http://www.w3.org/2000/svg",
253
+ width: 46,
254
+ height: 46,
255
+ fill: "none"
256
+ }, props), _rect || (_rect = /*#__PURE__*/React.createElement("rect", {
257
+ width: 40,
258
+ height: 40,
259
+ x: 3,
260
+ y: 2,
261
+ fill: "#008068",
262
+ rx: 2
263
+ })), _path || (_path = /*#__PURE__*/React.createElement("path", {
264
+ fill: "#fff",
265
+ fillRule: "evenodd",
266
+ d: "M23.75 16a.75.75 0 0 0-1.5 0v5.25H17a.75.75 0 0 0 0 1.5h5.25V28a.75.75 0 0 0 1.5 0v-5.25H29a.75.75 0 0 0 0-1.5h-5.25V16Z",
267
+ clipRule: "evenodd"
268
+ })));
269
+
270
+ var BlankCard = function BlankCard(_ref) {
271
+ var Icon = _ref.icon,
272
+ title = _ref.title,
273
+ description = _ref.description,
274
+ _ref$onClick = _ref.onClick,
275
+ onClick = _ref$onClick === void 0 ? noop : _ref$onClick,
276
+ _ref$disabled = _ref.disabled,
277
+ disabled = _ref$disabled === void 0 ? false : _ref$disabled;
278
+ return /*#__PURE__*/jsxs("div", {
279
+ className: "neeto-ui-rounded-lg neeto-ui-bg-white hover:neeto-ui-bg-white neeto-ui-border-primary-500 flex cursor-pointer flex-col items-center justify-center border border-dashed p-6 outline-none transition-all duration-300 ease-in-out hover:border-solid focus:border-solid",
280
+ "data-cy": "start-from-scratch-button",
281
+ tabIndex: 0,
282
+ onClick: !disabled ? onClick : noop,
283
+ children: [/*#__PURE__*/jsx("div", {
284
+ className: "neeto-ui-text-primary-500 mb-4",
285
+ children: /*#__PURE__*/jsx(Icon, {
286
+ size: 40
287
+ })
288
+ }), /*#__PURE__*/jsx(Typography, {
289
+ className: "text-center",
290
+ lineHeight: "normal",
291
+ style: "h5",
292
+ weight: "semibold",
293
+ children: title
294
+ }), /*#__PURE__*/jsx(Typography, {
295
+ className: "neeto-ui-text-gray-600 text-center",
296
+ lineHeight: "leading-4",
297
+ style: "body3",
298
+ children: description
299
+ })]
300
+ });
301
+ };
302
+
303
+ var Card = function Card(_ref) {
304
+ var template = _ref.template,
305
+ onClick = _ref.onClick;
306
+ return /*#__PURE__*/jsxs("div", {
307
+ onClick: onClick,
308
+ className: "neeto-template neeto-template-thumbnail neeto-ui-bg-white neeto-ui-shadow-xs hover:neeto-ui-border-gray-500 focus:neeto-ui-border-gray-500 neeto-ui-rounded-lg flex cursor-pointer flex-col overflow-hidden border outline-none transition-colors duration-300 ease-in-out",
309
+ "data-cy": "template-card",
310
+ tabIndex: 0,
311
+ children: [/*#__PURE__*/jsx("div", {
312
+ className: "neeto-template__header relative overflow-hidden",
313
+ children: /*#__PURE__*/jsx("img", {
314
+ className: "neeto-template__image",
315
+ "data-cy": "template-thumbnail-image",
316
+ src: template.imageUrl || "https://d2v7kzglnr2dnh.cloudfront.net/images/neetoForm/default-form-template.svg"
317
+ })
318
+ }), /*#__PURE__*/jsx("div", {
319
+ className: "neeto-template__description neeto-ui-bg-white flex items-center justify-between gap-2 rounded-b-lg px-3 py-1.5",
320
+ children: /*#__PURE__*/jsx(Typography, {
321
+ className: "neeto-template-thumbnail__title line-clamp-2",
322
+ "data-cy": "template-card-title",
323
+ lineHeight: "normal",
324
+ style: "h5",
325
+ children: template.title
326
+ })
327
+ })]
328
+ });
329
+ };
330
+
331
+ var CategoryItem = function CategoryItem(_ref) {
332
+ var label = _ref.label,
333
+ count = _ref.count,
334
+ isActive = _ref.isActive,
335
+ setCurrentCategory = _ref.setCurrentCategory;
336
+ return /*#__PURE__*/jsxs("button", {
337
+ "data-cy": "category-".concat(joinHyphenCase(label)),
338
+ tabIndex: 0,
339
+ className: classnames("neeto-ui-rounded-lg outline-none flex w-full items-center justify-between gap-2 border border-solid px-3 py-2 text-sm font-medium leading-4 transition-all duration-300 ease-in-out", {
340
+ "neeto-ui-text-gray-700 hover:neeto-ui-bg-gray-200 focus:neeto-ui-bg-gray-200 border-transparent": !isActive,
341
+ "neeto-ui-text-gray-800 neeto-ui-bg-white neeto-ui-border-gray-300 focus:neeto-ui-border-gray-500": isActive
342
+ }),
343
+ onClick: setCurrentCategory,
344
+ children: [/*#__PURE__*/jsx("span", {
345
+ children: label
346
+ }), /*#__PURE__*/jsx("span", {
347
+ children: count
348
+ })]
349
+ });
350
+ };
351
+
352
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
353
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
354
+ var List = function List(_ref) {
355
+ var setCurrentScreen = _ref.setCurrentScreen,
356
+ setSelectedTemplate = _ref.setSelectedTemplate,
357
+ onCreate = _ref.onCreate,
358
+ isCreating = _ref.isCreating,
359
+ afterCreate = _ref.afterCreate,
360
+ refetchResource = _ref.refetchResource;
361
+ var _useTranslation = useTranslation(),
362
+ t = _useTranslation.t;
363
+ var _useState = useState(DEFAULT_CATEGORY),
364
+ _useState2 = _slicedToArray(_useState, 2),
365
+ currentCategory = _useState2[0],
366
+ _setCurrentCategory = _useState2[1];
367
+ var _useState3 = useState(""),
368
+ _useState4 = _slicedToArray(_useState3, 2),
369
+ searchTerm = _useState4[0],
370
+ setSearchTerm = _useState4[1];
371
+ var _useFetchTemplates = useFetchTemplates({
372
+ searchTerm: searchTerm,
373
+ category: currentCategory
374
+ }),
375
+ _useFetchTemplates$ha = _useFetchTemplates.hasNextPage,
376
+ hasNextPage = _useFetchTemplates$ha === void 0 ? false : _useFetchTemplates$ha,
377
+ fetchNextPage = _useFetchTemplates.fetchNextPage,
378
+ isTemplatesLoading = _useFetchTemplates.isLoading,
379
+ _useFetchTemplates$da = _useFetchTemplates.data,
380
+ data = _useFetchTemplates$da === void 0 ? {} : _useFetchTemplates$da;
381
+ var _useInfiniteScroll = useInfiniteScroll({
382
+ loading: isTemplatesLoading,
383
+ hasNextPage: hasNextPage,
384
+ onLoadMore: fetchNextPage,
385
+ rootMargin: "0px 0px 700px 0px",
386
+ delayInMs: INFINITE_SCROLL_DELAY
387
+ }),
388
+ _useInfiniteScroll2 = _slicedToArray(_useInfiniteScroll, 2),
389
+ sentryRef = _useInfiniteScroll2[0],
390
+ rootRef = _useInfiniteScroll2[1].rootRef;
391
+ var handleCardClick = function handleCardClick(template) {
392
+ setCurrentScreen(TEMPLATE_SCREENS.PREVIEW);
393
+ setSelectedTemplate(template);
394
+ };
395
+ if (isTemplatesLoading) {
396
+ return /*#__PURE__*/jsx(PageLoader, {});
397
+ }
398
+ var _data$tags = data.tags,
399
+ tags = _data$tags === void 0 ? [] : _data$tags,
400
+ _data$templates = data.templates,
401
+ templates = _data$templates === void 0 ? [] : _data$templates,
402
+ _data$templatesCount = data.templatesCount,
403
+ templatesCount = _data$templatesCount === void 0 ? 0 : _data$templatesCount;
404
+ var categories = [_objectSpread(_objectSpread({}, DEFAULT_CATEGORY), {}, {
405
+ count: templatesCount
406
+ })].concat(_toConsumableArray(tags));
407
+ return /*#__PURE__*/jsxs("div", {
408
+ className: "neeto-ui-bg-gray-100 relative flex min-h-full items-start",
409
+ children: [/*#__PURE__*/jsxs("div", {
410
+ className: "sticky left-0 top-0 w-52 flex-shrink-0 space-y-8 py-6 pl-4 md:w-72 md:pl-10 lg:w-80 xl:pl-16",
411
+ children: [/*#__PURE__*/jsxs("div", {
412
+ className: "space-y-4",
413
+ children: [/*#__PURE__*/jsxs("div", {
414
+ className: "space-y-1",
415
+ children: [/*#__PURE__*/jsx(Typography, {
416
+ "data-cy": "create-new-form-title",
417
+ style: "h2",
418
+ weight: "semibold",
419
+ children: t("neetoTemplate.templates.createNewEntity")
420
+ }), /*#__PURE__*/jsx(Typography, {
421
+ lineHeight: "normal",
422
+ style: "body2",
423
+ children: t("neetoTemplate.templates.description")
424
+ })]
425
+ }), /*#__PURE__*/jsx(Search, {
426
+ autoFocus: true,
427
+ disableTrimOnBlur: true,
428
+ "data-cy": "template-search-input",
429
+ placeholder: t("neetoTemplate.templates.search"),
430
+ onSearch: function onSearch(value) {
431
+ return setSearchTerm(value);
432
+ }
433
+ })]
434
+ }), /*#__PURE__*/jsxs("div", {
435
+ className: "space-y-3",
436
+ children: [/*#__PURE__*/jsx(Typography, {
437
+ className: "uppercase",
438
+ "data-cy": "template-categories-label",
439
+ style: "h6",
440
+ children: t("neetoTemplate.templates.categories")
441
+ }), /*#__PURE__*/jsx("div", {
442
+ className: "space-y-2",
443
+ children: categories.map(function (_ref2) {
444
+ var id = _ref2.id,
445
+ name = _ref2.name,
446
+ count = _ref2.count;
447
+ return /*#__PURE__*/createElement(CategoryItem, {
448
+ count: count,
449
+ isActive: currentCategory.id === id,
450
+ key: id,
451
+ label: name,
452
+ setCurrentCategory: function setCurrentCategory() {
453
+ return _setCurrentCategory({
454
+ id: id,
455
+ name: name
456
+ });
457
+ }
458
+ });
459
+ })
460
+ })]
461
+ })]
462
+ }), /*#__PURE__*/jsx("div", {
463
+ className: "h-screen w-full overflow-y-auto py-8 pl-5 pr-4 md:pl-8 md:pr-20 xl:px-20",
464
+ ref: rootRef,
465
+ children: /*#__PURE__*/jsxs("div", {
466
+ className: "flex-grow space-y-6",
467
+ children: [/*#__PURE__*/jsxs("div", {
468
+ className: "grid grid-cols-1 gap-4 md:grid-cols-2 lg:grid-cols-3 lg:gap-5 xl:gap-6 2xl:grid-cols-4",
469
+ children: [/*#__PURE__*/jsx(BlankCard, {
470
+ description: t("neetoTemplate.templates.blankCard.description"),
471
+ disabled: isCreating,
472
+ icon: isCreating ? Spinner : SvgCustom,
473
+ title: t("neetoTemplate.templates.blankCard.title"),
474
+ onClick: onCreate
475
+ }), templates.map(function (template, index) {
476
+ return /*#__PURE__*/createElement(Card, {
477
+ afterCreate: afterCreate,
478
+ refetchResource: refetchResource,
479
+ template: template,
480
+ key: index,
481
+ onClick: function onClick() {
482
+ return handleCardClick(template);
483
+ }
484
+ });
485
+ })]
486
+ }), hasNextPage && /*#__PURE__*/jsx("div", {
487
+ className: "my-10 text-center",
488
+ ref: sentryRef,
489
+ children: /*#__PURE__*/jsx(Spinner, {})
490
+ })]
491
+ })
492
+ })]
493
+ });
494
+ };
495
+
496
+ var Preview = function Preview(_ref) {
497
+ var selectedTemplate = _ref.selectedTemplate,
498
+ setCurrentScreen = _ref.setCurrentScreen,
499
+ afterCreate = _ref.afterCreate,
500
+ refetchResource = _ref.refetchResource;
501
+ var _useTranslation = useTranslation(),
502
+ t = _useTranslation.t;
503
+ var _useBreakpoints = useBreakpoints(),
504
+ isSize = _useBreakpoints.isSize;
505
+ var _useCreateTemplate = useCreateTemplate(),
506
+ createTemplate = _useCreateTemplate.mutate,
507
+ isCreating = _useCreateTemplate.isPending;
508
+ var _useState = useState(RESPONSIVE_DEVICES.DESKTOP),
509
+ _useState2 = _slicedToArray(_useState, 2),
510
+ selectedDevice = _useState2[0],
511
+ setSelectedDevice = _useState2[1];
512
+ var handleCreateTemplate = function handleCreateTemplate() {
513
+ createTemplate({
514
+ id: selectedTemplate.id
515
+ }, {
516
+ onSuccess: function onSuccess(response) {
517
+ afterCreate(response);
518
+ refetchResource();
519
+ }
520
+ });
521
+ };
522
+ var title = selectedTemplate.title,
523
+ previewUrl = selectedTemplate.previewUrl;
524
+ return /*#__PURE__*/jsxs("div", {
525
+ className: "neeto-templates-full-page-preview flex h-full w-full flex-col",
526
+ children: [/*#__PURE__*/jsx("div", {
527
+ className: "neeto-templates-full-page-preview__header neeto-ui-border-gray-200 border-b px-4",
528
+ children: /*#__PURE__*/jsxs("div", {
529
+ className: "mx-auto flex w-full max-w-6xl items-center justify-between py-[9px]",
530
+ children: [/*#__PURE__*/jsx("div", {
531
+ className: "w-1/3",
532
+ children: /*#__PURE__*/jsx(Typography, {
533
+ className: "truncate leading-tight",
534
+ "data-cy": "preview-template-title",
535
+ style: "h3",
536
+ weight: "semibold",
537
+ children: title
538
+ })
539
+ }), /*#__PURE__*/jsx("div", {
540
+ className: "hidden flex-shrink-0 lg:flex",
541
+ children: /*#__PURE__*/jsx(ResponsiveDevicePicker, {
542
+ selectedDevice: selectedDevice,
543
+ onDeviceChange: setSelectedDevice
544
+ })
545
+ }), /*#__PURE__*/jsxs("div", {
546
+ className: "flex w-1/3 items-center justify-end gap-2",
547
+ children: [/*#__PURE__*/jsx(Button, {
548
+ className: "flex-shrink-0",
549
+ "data-cy": "preview-template-back-button",
550
+ style: "secondary",
551
+ label: isSize("mobile") ? t("neetoTemplate.templates.back") : t("neetoTemplate.templates.backToTemplates"),
552
+ onClick: function onClick() {
553
+ return setCurrentScreen(TEMPLATE_SCREENS.LIST);
554
+ }
555
+ }), /*#__PURE__*/jsx(Button, {
556
+ className: "flex-shrink-0",
557
+ "data-cy": "preview-use-template-button",
558
+ disabled: isCreating,
559
+ label: t("neetoTemplate.templates.editTemplate"),
560
+ loading: isCreating,
561
+ onClick: handleCreateTemplate
562
+ })]
563
+ })]
564
+ })
565
+ }), /*#__PURE__*/jsx("div", {
566
+ className: "neeto-ui-bg-gray-200 neeto-templates-full-page-preview__holder-wrapper min-h-0 flex-grow",
567
+ children: /*#__PURE__*/jsx("div", {
568
+ className: classnames("neeto-templates-full-page-preview__holder m-auto", {
569
+ "neeto-templates-full-page-preview__holder--desktop": selectedDevice === RESPONSIVE_DEVICES.DESKTOP,
570
+ "neeto-templates-full-page-preview__holder--tablet": selectedDevice === RESPONSIVE_DEVICES.TABLET,
571
+ "neeto-templates-full-page-preview__holder--mobile": selectedDevice === RESPONSIVE_DEVICES.MOBILE
572
+ }),
573
+ children: /*#__PURE__*/jsx("div", {
574
+ className: "neeto-templates-full-page-preview__device-border h-full w-full",
575
+ children: /*#__PURE__*/jsx("iframe", {
576
+ className: "neeto-templates-full-page-preview__iframe h-full w-full border-none",
577
+ "data-cy": "iframe-id",
578
+ src: previewUrl
579
+ })
580
+ })
581
+ })
582
+ })]
583
+ });
584
+ };
585
+
586
+ var CreateTemplateModal = function CreateTemplateModal(_ref) {
587
+ var isOpen = _ref.isOpen,
588
+ onClose = _ref.onClose,
589
+ isCreating = _ref.isCreating,
590
+ refetchResource = _ref.refetchResource,
591
+ _ref$onCreate = _ref.onCreate,
592
+ onCreate = _ref$onCreate === void 0 ? noop : _ref$onCreate,
593
+ _ref$afterCreate = _ref.afterCreate,
594
+ afterCreate = _ref$afterCreate === void 0 ? noop : _ref$afterCreate;
595
+ var _useState = useState(TEMPLATE_SCREENS.LIST),
596
+ _useState2 = _slicedToArray(_useState, 2),
597
+ currentScreen = _useState2[0],
598
+ setCurrentScreen = _useState2[1];
599
+ var _useState3 = useState({}),
600
+ _useState4 = _slicedToArray(_useState3, 2),
601
+ selectedTemplate = _useState4[0],
602
+ setSelectedTemplate = _useState4[1];
603
+ var onModalClose = function onModalClose() {
604
+ onClose();
605
+ setTimeout(function () {
606
+ setCurrentScreen(TEMPLATE_SCREENS.LIST);
607
+ }, 300); //To accommodate the animation duration.
608
+ };
609
+
610
+ return /*#__PURE__*/jsx(Modal, {
611
+ isOpen: isOpen,
612
+ className: "neeto-template-list h-screen w-screen overflow-y-auto",
613
+ closeButton: currentScreen === TEMPLATE_SCREENS.LIST,
614
+ size: "fullScreen",
615
+ onClose: onModalClose,
616
+ children: currentScreen === TEMPLATE_SCREENS.LIST ? /*#__PURE__*/jsx(List, {
617
+ afterCreate: afterCreate,
618
+ isCreating: isCreating,
619
+ onCreate: onCreate,
620
+ refetchResource: refetchResource,
621
+ setCurrentScreen: setCurrentScreen,
622
+ setSelectedTemplate: setSelectedTemplate
623
+ }) : /*#__PURE__*/jsx(Preview, {
624
+ afterCreate: afterCreate,
625
+ refetchResource: refetchResource,
626
+ selectedTemplate: selectedTemplate,
627
+ setCurrentScreen: setCurrentScreen
628
+ })
629
+ });
630
+ };
631
+
632
+ export { CreateTemplateModal as default };
633
+ //# sourceMappingURL=CreateTemplateModal.js.map