@bigbinary/neeto-approvals-frontend 0.4.0-beta1 → 0.4.0-beta2

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/dist/index.js CHANGED
@@ -1,24 +1,25 @@
1
- import * as React from 'react';
2
- import React__default, { useState, useEffect, useRef, createElement, useMemo } from 'react';
1
+ import React, { useState, useEffect, useRef, createElement, useMemo } from 'react';
3
2
  import { useMutationWithInvalidation, useDebounce, withT, useQueryParams } from '@bigbinary/neeto-commons-frontend/react-utils';
4
3
  import Container from '@bigbinary/neeto-molecules/Container';
5
4
  import { Link, useLocation, useHistory, Switch, Route, Redirect, useParams } from 'react-router-dom';
6
5
  import i18next, { t as t$1 } from 'i18next';
7
6
  import { DEFAULT_PAGE_INDEX, DEFAULT_PAGE_SIZE, PLURAL, SINGULAR } from '@bigbinary/neeto-commons-frontend/constants';
8
7
  import Button from '@bigbinary/neetoui/Button';
9
- import { capitalize, isPresent, findBy, camelToSnakeCase, removeBy, noop as noop$1 } from '@bigbinary/neeto-cist';
8
+ import { capitalize, isPresent, findBy, camelToSnakeCase, removeBy, noop } from '@bigbinary/neeto-cist';
10
9
  import TableWrapper from '@bigbinary/neeto-molecules/TableWrapper';
11
10
  import Table$1 from '@bigbinary/neetoui/Table';
12
11
  import NoData from '@bigbinary/neetoui/NoData';
13
12
  import { isEmpty, keys } from 'ramda';
14
13
  import { useTranslation, Trans } from 'react-i18next';
15
- import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
14
+ import { useQuery, keepPreviousData } from '@tanstack/react-query';
16
15
  import axios from 'axios';
17
16
  import Tag from '@bigbinary/neetoui/Tag';
18
17
  import DateFormat from '@bigbinary/neeto-molecules/DateFormat';
19
- import { isEditorEmpty, EditorContent, FormikEditor } from '@bigbinary/neeto-editor';
18
+ import { isEditorEmpty } from '@bigbinary/neeto-editor/utils';
20
19
  import * as yup from 'yup';
21
- import { dateFormat, withEventTargetValue } from '@bigbinary/neeto-commons-frontend/utils';
20
+ import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
21
+ import { dateFormat, withEventTargetValue, captureAnalyticsEvent } from '@bigbinary/neeto-commons-frontend/utils';
22
+ import EditorContent from '@bigbinary/neeto-editor/EditorContent';
22
23
  import Label from '@bigbinary/neetoui/Label';
23
24
  import Pane from '@bigbinary/neetoui/Pane';
24
25
  import Textarea from '@bigbinary/neetoui/Textarea';
@@ -35,6 +36,7 @@ import { useFormikContext } from 'formik';
35
36
  import ToggleFeatureCard from '@bigbinary/neeto-molecules/ToggleFeatureCard';
36
37
  import Input from '@bigbinary/neetoui/formik/Input';
37
38
  import Textarea$1 from '@bigbinary/neetoui/formik/Textarea';
39
+ import FormikEditor from '@bigbinary/neeto-editor/FormikEditor';
38
40
  import MoreDropdown from '@bigbinary/neeto-molecules/MoreDropdown';
39
41
  import NeetoHeader from '@bigbinary/neeto-molecules/Header';
40
42
  import NeetoUITab from '@bigbinary/neetoui/Tab';
@@ -156,868 +158,6 @@ var handleEmptyPage = function handleEmptyPage(data, pageProperties, handlePageC
156
158
  }
157
159
  };
158
160
 
159
- // src/subscribable.ts
160
- var Subscribable = class {
161
- constructor() {
162
- this.listeners = /* @__PURE__ */ new Set();
163
- this.subscribe = this.subscribe.bind(this);
164
- }
165
- subscribe(listener) {
166
- this.listeners.add(listener);
167
- this.onSubscribe();
168
- return () => {
169
- this.listeners.delete(listener);
170
- this.onUnsubscribe();
171
- };
172
- }
173
- hasListeners() {
174
- return this.listeners.size > 0;
175
- }
176
- onSubscribe() {
177
- }
178
- onUnsubscribe() {
179
- }
180
- };
181
-
182
- // src/utils.ts
183
- var isServer = typeof window === "undefined" || "Deno" in globalThis;
184
- function noop() {
185
- return void 0;
186
- }
187
- function isValidTimeout(value) {
188
- return typeof value === "number" && value >= 0 && value !== Infinity;
189
- }
190
- function timeUntilStale(updatedAt, staleTime) {
191
- return Math.max(updatedAt + (staleTime || 0) - Date.now(), 0);
192
- }
193
- function replaceEqualDeep(a, b) {
194
- if (a === b) {
195
- return a;
196
- }
197
- const array = isPlainArray(a) && isPlainArray(b);
198
- if (array || isPlainObject(a) && isPlainObject(b)) {
199
- const aItems = array ? a : Object.keys(a);
200
- const aSize = aItems.length;
201
- const bItems = array ? b : Object.keys(b);
202
- const bSize = bItems.length;
203
- const copy = array ? [] : {};
204
- let equalItems = 0;
205
- for (let i = 0; i < bSize; i++) {
206
- const key = array ? i : bItems[i];
207
- if ((!array && aItems.includes(key) || array) && a[key] === void 0 && b[key] === void 0) {
208
- copy[key] = void 0;
209
- equalItems++;
210
- } else {
211
- copy[key] = replaceEqualDeep(a[key], b[key]);
212
- if (copy[key] === a[key] && a[key] !== void 0) {
213
- equalItems++;
214
- }
215
- }
216
- }
217
- return aSize === bSize && equalItems === aSize ? a : copy;
218
- }
219
- return b;
220
- }
221
- function shallowEqualObjects(a, b) {
222
- if (!b || Object.keys(a).length !== Object.keys(b).length) {
223
- return false;
224
- }
225
- for (const key in a) {
226
- if (a[key] !== b[key]) {
227
- return false;
228
- }
229
- }
230
- return true;
231
- }
232
- function isPlainArray(value) {
233
- return Array.isArray(value) && value.length === Object.keys(value).length;
234
- }
235
- function isPlainObject(o) {
236
- if (!hasObjectPrototype(o)) {
237
- return false;
238
- }
239
- const ctor = o.constructor;
240
- if (ctor === void 0) {
241
- return true;
242
- }
243
- const prot = ctor.prototype;
244
- if (!hasObjectPrototype(prot)) {
245
- return false;
246
- }
247
- if (!prot.hasOwnProperty("isPrototypeOf")) {
248
- return false;
249
- }
250
- if (Object.getPrototypeOf(o) !== Object.prototype) {
251
- return false;
252
- }
253
- return true;
254
- }
255
- function hasObjectPrototype(o) {
256
- return Object.prototype.toString.call(o) === "[object Object]";
257
- }
258
- function replaceData(prevData, data, options) {
259
- if (typeof options.structuralSharing === "function") {
260
- return options.structuralSharing(prevData, data);
261
- } else if (options.structuralSharing !== false) {
262
- return replaceEqualDeep(prevData, data);
263
- }
264
- return data;
265
- }
266
- function keepPreviousData(previousData) {
267
- return previousData;
268
- }
269
-
270
- // src/focusManager.ts
271
- var FocusManager = class extends Subscribable {
272
- #focused;
273
- #cleanup;
274
- #setup;
275
- constructor() {
276
- super();
277
- this.#setup = (onFocus) => {
278
- if (!isServer && window.addEventListener) {
279
- const listener = () => onFocus();
280
- window.addEventListener("visibilitychange", listener, false);
281
- return () => {
282
- window.removeEventListener("visibilitychange", listener);
283
- };
284
- }
285
- return;
286
- };
287
- }
288
- onSubscribe() {
289
- if (!this.#cleanup) {
290
- this.setEventListener(this.#setup);
291
- }
292
- }
293
- onUnsubscribe() {
294
- if (!this.hasListeners()) {
295
- this.#cleanup?.();
296
- this.#cleanup = void 0;
297
- }
298
- }
299
- setEventListener(setup) {
300
- this.#setup = setup;
301
- this.#cleanup?.();
302
- this.#cleanup = setup((focused) => {
303
- if (typeof focused === "boolean") {
304
- this.setFocused(focused);
305
- } else {
306
- this.onFocus();
307
- }
308
- });
309
- }
310
- setFocused(focused) {
311
- const changed = this.#focused !== focused;
312
- if (changed) {
313
- this.#focused = focused;
314
- this.onFocus();
315
- }
316
- }
317
- onFocus() {
318
- const isFocused = this.isFocused();
319
- this.listeners.forEach((listener) => {
320
- listener(isFocused);
321
- });
322
- }
323
- isFocused() {
324
- if (typeof this.#focused === "boolean") {
325
- return this.#focused;
326
- }
327
- return globalThis.document?.visibilityState !== "hidden";
328
- }
329
- };
330
- var focusManager = new FocusManager();
331
-
332
- // src/onlineManager.ts
333
- var OnlineManager = class extends Subscribable {
334
- #online = true;
335
- #cleanup;
336
- #setup;
337
- constructor() {
338
- super();
339
- this.#setup = (onOnline) => {
340
- if (!isServer && window.addEventListener) {
341
- const onlineListener = () => onOnline(true);
342
- const offlineListener = () => onOnline(false);
343
- window.addEventListener("online", onlineListener, false);
344
- window.addEventListener("offline", offlineListener, false);
345
- return () => {
346
- window.removeEventListener("online", onlineListener);
347
- window.removeEventListener("offline", offlineListener);
348
- };
349
- }
350
- return;
351
- };
352
- }
353
- onSubscribe() {
354
- if (!this.#cleanup) {
355
- this.setEventListener(this.#setup);
356
- }
357
- }
358
- onUnsubscribe() {
359
- if (!this.hasListeners()) {
360
- this.#cleanup?.();
361
- this.#cleanup = void 0;
362
- }
363
- }
364
- setEventListener(setup) {
365
- this.#setup = setup;
366
- this.#cleanup?.();
367
- this.#cleanup = setup(this.setOnline.bind(this));
368
- }
369
- setOnline(online) {
370
- const changed = this.#online !== online;
371
- if (changed) {
372
- this.#online = online;
373
- this.listeners.forEach((listener) => {
374
- listener(online);
375
- });
376
- }
377
- }
378
- isOnline() {
379
- return this.#online;
380
- }
381
- };
382
- var onlineManager = new OnlineManager();
383
-
384
- // src/retryer.ts
385
- function canFetch(networkMode) {
386
- return (networkMode ?? "online") === "online" ? onlineManager.isOnline() : true;
387
- }
388
-
389
- // src/notifyManager.ts
390
- function createNotifyManager() {
391
- let queue = [];
392
- let transactions = 0;
393
- let notifyFn = (callback) => {
394
- callback();
395
- };
396
- let batchNotifyFn = (callback) => {
397
- callback();
398
- };
399
- let scheduleFn = (cb) => setTimeout(cb, 0);
400
- const setScheduler = (fn) => {
401
- scheduleFn = fn;
402
- };
403
- const batch = (callback) => {
404
- let result;
405
- transactions++;
406
- try {
407
- result = callback();
408
- } finally {
409
- transactions--;
410
- if (!transactions) {
411
- flush();
412
- }
413
- }
414
- return result;
415
- };
416
- const schedule = (callback) => {
417
- if (transactions) {
418
- queue.push(callback);
419
- } else {
420
- scheduleFn(() => {
421
- notifyFn(callback);
422
- });
423
- }
424
- };
425
- const batchCalls = (callback) => {
426
- return (...args) => {
427
- schedule(() => {
428
- callback(...args);
429
- });
430
- };
431
- };
432
- const flush = () => {
433
- const originalQueue = queue;
434
- queue = [];
435
- if (originalQueue.length) {
436
- scheduleFn(() => {
437
- batchNotifyFn(() => {
438
- originalQueue.forEach((callback) => {
439
- notifyFn(callback);
440
- });
441
- });
442
- });
443
- }
444
- };
445
- const setNotifyFunction = (fn) => {
446
- notifyFn = fn;
447
- };
448
- const setBatchNotifyFunction = (fn) => {
449
- batchNotifyFn = fn;
450
- };
451
- return {
452
- batch,
453
- batchCalls,
454
- schedule,
455
- setNotifyFunction,
456
- setBatchNotifyFunction,
457
- setScheduler
458
- };
459
- }
460
- var notifyManager = createNotifyManager();
461
-
462
- // src/query.ts
463
- function fetchState(data, options) {
464
- return {
465
- fetchFailureCount: 0,
466
- fetchFailureReason: null,
467
- fetchStatus: canFetch(options.networkMode) ? "fetching" : "paused",
468
- ...data === void 0 && {
469
- error: null,
470
- status: "pending"
471
- }
472
- };
473
- }
474
-
475
- // src/queryObserver.ts
476
- var QueryObserver = class extends Subscribable {
477
- constructor(client, options) {
478
- super();
479
- this.options = options;
480
- this.#client = client;
481
- this.#selectError = null;
482
- this.bindMethods();
483
- this.setOptions(options);
484
- }
485
- #client;
486
- #currentQuery = void 0;
487
- #currentQueryInitialState = void 0;
488
- #currentResult = void 0;
489
- #currentResultState;
490
- #currentResultOptions;
491
- #selectError;
492
- #selectFn;
493
- #selectResult;
494
- // This property keeps track of the last query with defined data.
495
- // It will be used to pass the previous data and query to the placeholder function between renders.
496
- #lastQueryWithDefinedData;
497
- #staleTimeoutId;
498
- #refetchIntervalId;
499
- #currentRefetchInterval;
500
- #trackedProps = /* @__PURE__ */ new Set();
501
- bindMethods() {
502
- this.refetch = this.refetch.bind(this);
503
- }
504
- onSubscribe() {
505
- if (this.listeners.size === 1) {
506
- this.#currentQuery.addObserver(this);
507
- if (shouldFetchOnMount(this.#currentQuery, this.options)) {
508
- this.#executeFetch();
509
- } else {
510
- this.updateResult();
511
- }
512
- this.#updateTimers();
513
- }
514
- }
515
- onUnsubscribe() {
516
- if (!this.hasListeners()) {
517
- this.destroy();
518
- }
519
- }
520
- shouldFetchOnReconnect() {
521
- return shouldFetchOn(
522
- this.#currentQuery,
523
- this.options,
524
- this.options.refetchOnReconnect
525
- );
526
- }
527
- shouldFetchOnWindowFocus() {
528
- return shouldFetchOn(
529
- this.#currentQuery,
530
- this.options,
531
- this.options.refetchOnWindowFocus
532
- );
533
- }
534
- destroy() {
535
- this.listeners = /* @__PURE__ */ new Set();
536
- this.#clearStaleTimeout();
537
- this.#clearRefetchInterval();
538
- this.#currentQuery.removeObserver(this);
539
- }
540
- setOptions(options, notifyOptions) {
541
- const prevOptions = this.options;
542
- const prevQuery = this.#currentQuery;
543
- this.options = this.#client.defaultQueryOptions(options);
544
- if (this.options.enabled !== void 0 && typeof this.options.enabled !== "boolean") {
545
- throw new Error("Expected enabled to be a boolean");
546
- }
547
- this.#updateQuery();
548
- this.#currentQuery.setOptions(this.options);
549
- if (prevOptions._defaulted && !shallowEqualObjects(this.options, prevOptions)) {
550
- this.#client.getQueryCache().notify({
551
- type: "observerOptionsUpdated",
552
- query: this.#currentQuery,
553
- observer: this
554
- });
555
- }
556
- const mounted = this.hasListeners();
557
- if (mounted && shouldFetchOptionally(
558
- this.#currentQuery,
559
- prevQuery,
560
- this.options,
561
- prevOptions
562
- )) {
563
- this.#executeFetch();
564
- }
565
- this.updateResult(notifyOptions);
566
- if (mounted && (this.#currentQuery !== prevQuery || this.options.enabled !== prevOptions.enabled || this.options.staleTime !== prevOptions.staleTime)) {
567
- this.#updateStaleTimeout();
568
- }
569
- const nextRefetchInterval = this.#computeRefetchInterval();
570
- if (mounted && (this.#currentQuery !== prevQuery || this.options.enabled !== prevOptions.enabled || nextRefetchInterval !== this.#currentRefetchInterval)) {
571
- this.#updateRefetchInterval(nextRefetchInterval);
572
- }
573
- }
574
- getOptimisticResult(options) {
575
- const query = this.#client.getQueryCache().build(this.#client, options);
576
- const result = this.createResult(query, options);
577
- if (shouldAssignObserverCurrentProperties(this, result)) {
578
- this.#currentResult = result;
579
- this.#currentResultOptions = this.options;
580
- this.#currentResultState = this.#currentQuery.state;
581
- }
582
- return result;
583
- }
584
- getCurrentResult() {
585
- return this.#currentResult;
586
- }
587
- trackResult(result, onPropTracked) {
588
- const trackedResult = {};
589
- Object.keys(result).forEach((key) => {
590
- Object.defineProperty(trackedResult, key, {
591
- configurable: false,
592
- enumerable: true,
593
- get: () => {
594
- this.trackProp(key);
595
- onPropTracked?.(key);
596
- return result[key];
597
- }
598
- });
599
- });
600
- return trackedResult;
601
- }
602
- trackProp(key) {
603
- this.#trackedProps.add(key);
604
- }
605
- getCurrentQuery() {
606
- return this.#currentQuery;
607
- }
608
- refetch({ ...options } = {}) {
609
- return this.fetch({
610
- ...options
611
- });
612
- }
613
- fetchOptimistic(options) {
614
- const defaultedOptions = this.#client.defaultQueryOptions(options);
615
- const query = this.#client.getQueryCache().build(this.#client, defaultedOptions);
616
- query.isFetchingOptimistic = true;
617
- return query.fetch().then(() => this.createResult(query, defaultedOptions));
618
- }
619
- fetch(fetchOptions) {
620
- return this.#executeFetch({
621
- ...fetchOptions,
622
- cancelRefetch: fetchOptions.cancelRefetch ?? true
623
- }).then(() => {
624
- this.updateResult();
625
- return this.#currentResult;
626
- });
627
- }
628
- #executeFetch(fetchOptions) {
629
- this.#updateQuery();
630
- let promise = this.#currentQuery.fetch(
631
- this.options,
632
- fetchOptions
633
- );
634
- if (!fetchOptions?.throwOnError) {
635
- promise = promise.catch(noop);
636
- }
637
- return promise;
638
- }
639
- #updateStaleTimeout() {
640
- this.#clearStaleTimeout();
641
- if (isServer || this.#currentResult.isStale || !isValidTimeout(this.options.staleTime)) {
642
- return;
643
- }
644
- const time = timeUntilStale(
645
- this.#currentResult.dataUpdatedAt,
646
- this.options.staleTime
647
- );
648
- const timeout = time + 1;
649
- this.#staleTimeoutId = setTimeout(() => {
650
- if (!this.#currentResult.isStale) {
651
- this.updateResult();
652
- }
653
- }, timeout);
654
- }
655
- #computeRefetchInterval() {
656
- return (typeof this.options.refetchInterval === "function" ? this.options.refetchInterval(this.#currentQuery) : this.options.refetchInterval) ?? false;
657
- }
658
- #updateRefetchInterval(nextInterval) {
659
- this.#clearRefetchInterval();
660
- this.#currentRefetchInterval = nextInterval;
661
- if (isServer || this.options.enabled === false || !isValidTimeout(this.#currentRefetchInterval) || this.#currentRefetchInterval === 0) {
662
- return;
663
- }
664
- this.#refetchIntervalId = setInterval(() => {
665
- if (this.options.refetchIntervalInBackground || focusManager.isFocused()) {
666
- this.#executeFetch();
667
- }
668
- }, this.#currentRefetchInterval);
669
- }
670
- #updateTimers() {
671
- this.#updateStaleTimeout();
672
- this.#updateRefetchInterval(this.#computeRefetchInterval());
673
- }
674
- #clearStaleTimeout() {
675
- if (this.#staleTimeoutId) {
676
- clearTimeout(this.#staleTimeoutId);
677
- this.#staleTimeoutId = void 0;
678
- }
679
- }
680
- #clearRefetchInterval() {
681
- if (this.#refetchIntervalId) {
682
- clearInterval(this.#refetchIntervalId);
683
- this.#refetchIntervalId = void 0;
684
- }
685
- }
686
- createResult(query, options) {
687
- const prevQuery = this.#currentQuery;
688
- const prevOptions = this.options;
689
- const prevResult = this.#currentResult;
690
- const prevResultState = this.#currentResultState;
691
- const prevResultOptions = this.#currentResultOptions;
692
- const queryChange = query !== prevQuery;
693
- const queryInitialState = queryChange ? query.state : this.#currentQueryInitialState;
694
- const { state } = query;
695
- let newState = { ...state };
696
- let isPlaceholderData = false;
697
- let data;
698
- if (options._optimisticResults) {
699
- const mounted = this.hasListeners();
700
- const fetchOnMount = !mounted && shouldFetchOnMount(query, options);
701
- const fetchOptionally = mounted && shouldFetchOptionally(query, prevQuery, options, prevOptions);
702
- if (fetchOnMount || fetchOptionally) {
703
- newState = {
704
- ...newState,
705
- ...fetchState(state.data, query.options)
706
- };
707
- }
708
- if (options._optimisticResults === "isRestoring") {
709
- newState.fetchStatus = "idle";
710
- }
711
- }
712
- let { error, errorUpdatedAt, status } = newState;
713
- if (options.select && newState.data !== void 0) {
714
- if (prevResult && newState.data === prevResultState?.data && options.select === this.#selectFn) {
715
- data = this.#selectResult;
716
- } else {
717
- try {
718
- this.#selectFn = options.select;
719
- data = options.select(newState.data);
720
- data = replaceData(prevResult?.data, data, options);
721
- this.#selectResult = data;
722
- this.#selectError = null;
723
- } catch (selectError) {
724
- this.#selectError = selectError;
725
- }
726
- }
727
- } else {
728
- data = newState.data;
729
- }
730
- if (options.placeholderData !== void 0 && data === void 0 && status === "pending") {
731
- let placeholderData;
732
- if (prevResult?.isPlaceholderData && options.placeholderData === prevResultOptions?.placeholderData) {
733
- placeholderData = prevResult.data;
734
- } else {
735
- placeholderData = typeof options.placeholderData === "function" ? options.placeholderData(
736
- this.#lastQueryWithDefinedData?.state.data,
737
- this.#lastQueryWithDefinedData
738
- ) : options.placeholderData;
739
- if (options.select && placeholderData !== void 0) {
740
- try {
741
- placeholderData = options.select(placeholderData);
742
- this.#selectError = null;
743
- } catch (selectError) {
744
- this.#selectError = selectError;
745
- }
746
- }
747
- }
748
- if (placeholderData !== void 0) {
749
- status = "success";
750
- data = replaceData(
751
- prevResult?.data,
752
- placeholderData,
753
- options
754
- );
755
- isPlaceholderData = true;
756
- }
757
- }
758
- if (this.#selectError) {
759
- error = this.#selectError;
760
- data = this.#selectResult;
761
- errorUpdatedAt = Date.now();
762
- status = "error";
763
- }
764
- const isFetching = newState.fetchStatus === "fetching";
765
- const isPending = status === "pending";
766
- const isError = status === "error";
767
- const isLoading = isPending && isFetching;
768
- const hasData = data !== void 0;
769
- const result = {
770
- status,
771
- fetchStatus: newState.fetchStatus,
772
- isPending,
773
- isSuccess: status === "success",
774
- isError,
775
- isInitialLoading: isLoading,
776
- isLoading,
777
- data,
778
- dataUpdatedAt: newState.dataUpdatedAt,
779
- error,
780
- errorUpdatedAt,
781
- failureCount: newState.fetchFailureCount,
782
- failureReason: newState.fetchFailureReason,
783
- errorUpdateCount: newState.errorUpdateCount,
784
- isFetched: newState.dataUpdateCount > 0 || newState.errorUpdateCount > 0,
785
- isFetchedAfterMount: newState.dataUpdateCount > queryInitialState.dataUpdateCount || newState.errorUpdateCount > queryInitialState.errorUpdateCount,
786
- isFetching,
787
- isRefetching: isFetching && !isPending,
788
- isLoadingError: isError && !hasData,
789
- isPaused: newState.fetchStatus === "paused",
790
- isPlaceholderData,
791
- isRefetchError: isError && hasData,
792
- isStale: isStale(query, options),
793
- refetch: this.refetch
794
- };
795
- return result;
796
- }
797
- updateResult(notifyOptions) {
798
- const prevResult = this.#currentResult;
799
- const nextResult = this.createResult(this.#currentQuery, this.options);
800
- this.#currentResultState = this.#currentQuery.state;
801
- this.#currentResultOptions = this.options;
802
- if (this.#currentResultState.data !== void 0) {
803
- this.#lastQueryWithDefinedData = this.#currentQuery;
804
- }
805
- if (shallowEqualObjects(nextResult, prevResult)) {
806
- return;
807
- }
808
- this.#currentResult = nextResult;
809
- const defaultNotifyOptions = {};
810
- const shouldNotifyListeners = () => {
811
- if (!prevResult) {
812
- return true;
813
- }
814
- const { notifyOnChangeProps } = this.options;
815
- const notifyOnChangePropsValue = typeof notifyOnChangeProps === "function" ? notifyOnChangeProps() : notifyOnChangeProps;
816
- if (notifyOnChangePropsValue === "all" || !notifyOnChangePropsValue && !this.#trackedProps.size) {
817
- return true;
818
- }
819
- const includedProps = new Set(
820
- notifyOnChangePropsValue ?? this.#trackedProps
821
- );
822
- if (this.options.throwOnError) {
823
- includedProps.add("error");
824
- }
825
- return Object.keys(this.#currentResult).some((key) => {
826
- const typedKey = key;
827
- const changed = this.#currentResult[typedKey] !== prevResult[typedKey];
828
- return changed && includedProps.has(typedKey);
829
- });
830
- };
831
- if (notifyOptions?.listeners !== false && shouldNotifyListeners()) {
832
- defaultNotifyOptions.listeners = true;
833
- }
834
- this.#notify({ ...defaultNotifyOptions, ...notifyOptions });
835
- }
836
- #updateQuery() {
837
- const query = this.#client.getQueryCache().build(this.#client, this.options);
838
- if (query === this.#currentQuery) {
839
- return;
840
- }
841
- const prevQuery = this.#currentQuery;
842
- this.#currentQuery = query;
843
- this.#currentQueryInitialState = query.state;
844
- if (this.hasListeners()) {
845
- prevQuery?.removeObserver(this);
846
- query.addObserver(this);
847
- }
848
- }
849
- onQueryUpdate() {
850
- this.updateResult();
851
- if (this.hasListeners()) {
852
- this.#updateTimers();
853
- }
854
- }
855
- #notify(notifyOptions) {
856
- notifyManager.batch(() => {
857
- if (notifyOptions.listeners) {
858
- this.listeners.forEach((listener) => {
859
- listener(this.#currentResult);
860
- });
861
- }
862
- this.#client.getQueryCache().notify({
863
- query: this.#currentQuery,
864
- type: "observerResultsUpdated"
865
- });
866
- });
867
- }
868
- };
869
- function shouldLoadOnMount(query, options) {
870
- return options.enabled !== false && query.state.data === void 0 && !(query.state.status === "error" && options.retryOnMount === false);
871
- }
872
- function shouldFetchOnMount(query, options) {
873
- return shouldLoadOnMount(query, options) || query.state.data !== void 0 && shouldFetchOn(query, options, options.refetchOnMount);
874
- }
875
- function shouldFetchOn(query, options, field) {
876
- if (options.enabled !== false) {
877
- const value = typeof field === "function" ? field(query) : field;
878
- return value === "always" || value !== false && isStale(query, options);
879
- }
880
- return false;
881
- }
882
- function shouldFetchOptionally(query, prevQuery, options, prevOptions) {
883
- return (query !== prevQuery || prevOptions.enabled === false) && (!options.suspense || query.state.status !== "error") && isStale(query, options);
884
- }
885
- function isStale(query, options) {
886
- return options.enabled !== false && query.isStaleByTime(options.staleTime);
887
- }
888
- function shouldAssignObserverCurrentProperties(observer, optimisticResult) {
889
- if (!shallowEqualObjects(observer.getCurrentResult(), optimisticResult)) {
890
- return true;
891
- }
892
- return false;
893
- }
894
-
895
- var QueryClientContext = React.createContext(
896
- void 0
897
- );
898
- var useQueryClient = (queryClient) => {
899
- const client = React.useContext(QueryClientContext);
900
- if (queryClient) {
901
- return queryClient;
902
- }
903
- if (!client) {
904
- throw new Error("No QueryClient set, use QueryClientProvider to set one");
905
- }
906
- return client;
907
- };
908
-
909
- var IsRestoringContext = React.createContext(false);
910
- var useIsRestoring = () => React.useContext(IsRestoringContext);
911
- IsRestoringContext.Provider;
912
-
913
- function createValue() {
914
- let isReset = false;
915
- return {
916
- clearReset: () => {
917
- isReset = false;
918
- },
919
- reset: () => {
920
- isReset = true;
921
- },
922
- isReset: () => {
923
- return isReset;
924
- }
925
- };
926
- }
927
- var QueryErrorResetBoundaryContext = React.createContext(createValue());
928
- var useQueryErrorResetBoundary = () => React.useContext(QueryErrorResetBoundaryContext);
929
-
930
- // src/utils.ts
931
- function shouldThrowError(throwError, params) {
932
- if (typeof throwError === "function") {
933
- return throwError(...params);
934
- }
935
- return !!throwError;
936
- }
937
-
938
- var ensurePreventErrorBoundaryRetry = (options, errorResetBoundary) => {
939
- if (options.suspense || options.throwOnError) {
940
- if (!errorResetBoundary.isReset()) {
941
- options.retryOnMount = false;
942
- }
943
- }
944
- };
945
- var useClearResetErrorBoundary = (errorResetBoundary) => {
946
- React.useEffect(() => {
947
- errorResetBoundary.clearReset();
948
- }, [errorResetBoundary]);
949
- };
950
- var getHasError = ({
951
- result,
952
- errorResetBoundary,
953
- throwOnError,
954
- query
955
- }) => {
956
- return result.isError && !errorResetBoundary.isReset() && !result.isFetching && query && shouldThrowError(throwOnError, [result.error, query]);
957
- };
958
-
959
- // src/suspense.ts
960
- var ensureStaleTime = (defaultedOptions) => {
961
- if (defaultedOptions.suspense) {
962
- if (typeof defaultedOptions.staleTime !== "number") {
963
- defaultedOptions.staleTime = 1e3;
964
- }
965
- }
966
- };
967
- var shouldSuspend = (defaultedOptions, result) => defaultedOptions?.suspense && result.isPending;
968
- var fetchOptimistic = (defaultedOptions, observer, errorResetBoundary) => observer.fetchOptimistic(defaultedOptions).catch(() => {
969
- errorResetBoundary.clearReset();
970
- });
971
-
972
- function useBaseQuery(options, Observer, queryClient) {
973
- const client = useQueryClient(queryClient);
974
- const isRestoring = useIsRestoring();
975
- const errorResetBoundary = useQueryErrorResetBoundary();
976
- const defaultedOptions = client.defaultQueryOptions(options);
977
- defaultedOptions._optimisticResults = isRestoring ? "isRestoring" : "optimistic";
978
- ensureStaleTime(defaultedOptions);
979
- ensurePreventErrorBoundaryRetry(defaultedOptions, errorResetBoundary);
980
- useClearResetErrorBoundary(errorResetBoundary);
981
- const [observer] = React.useState(
982
- () => new Observer(
983
- client,
984
- defaultedOptions
985
- )
986
- );
987
- const result = observer.getOptimisticResult(defaultedOptions);
988
- React.useSyncExternalStore(
989
- React.useCallback(
990
- (onStoreChange) => {
991
- const unsubscribe = isRestoring ? () => void 0 : observer.subscribe(notifyManager.batchCalls(onStoreChange));
992
- observer.updateResult();
993
- return unsubscribe;
994
- },
995
- [observer, isRestoring]
996
- ),
997
- () => observer.getCurrentResult(),
998
- () => observer.getCurrentResult()
999
- );
1000
- React.useEffect(() => {
1001
- observer.setOptions(defaultedOptions, { listeners: false });
1002
- }, [defaultedOptions, observer]);
1003
- if (shouldSuspend(defaultedOptions, result)) {
1004
- throw fetchOptimistic(defaultedOptions, observer, errorResetBoundary);
1005
- }
1006
- if (getHasError({
1007
- result,
1008
- errorResetBoundary,
1009
- throwOnError: defaultedOptions.throwOnError,
1010
- query: client.getQueryCache().get(defaultedOptions.queryHash)
1011
- })) {
1012
- throw result.error;
1013
- }
1014
- return !defaultedOptions.notifyOnChangeProps ? observer.trackResult(result) : result;
1015
- }
1016
-
1017
- function useQuery(options, queryClient) {
1018
- return useBaseQuery(options, QueryObserver, queryClient);
1019
- }
1020
-
1021
161
  var BASE_URL = "neeto_approvals";
1022
162
  var TEMPLATE_URL = "".concat(BASE_URL, "/templates");
1023
163
 
@@ -1139,6 +279,9 @@ var REQUEST_FORM_VALIDATION_SCHEMA = yup.object().shape({
1139
279
  }),
1140
280
  approver: yup.object().required(t$1("neetoApprovals.validations.approver"))
1141
281
  });
282
+ var EVENTS = {
283
+ APPROVAL_TEMPLATE_CREATED: "approval_template_created"
284
+ };
1142
285
 
1143
286
  var HISTORY_TABLE_COLUMNS = [{
1144
287
  dataIndex: "approvalLabel",
@@ -1265,7 +408,7 @@ var getApprovalFilter = function getApprovalFilter() {
1265
408
  };
1266
409
  };
1267
410
 
1268
- var MemoizedEditorContent$1 = /*#__PURE__*/React__default.memo(EditorContent);
411
+ var MemoizedEditorContent$1 = /*#__PURE__*/React.memo(EditorContent);
1269
412
  var RequestDetailsPane = function RequestDetailsPane(_ref) {
1270
413
  var _window$globalProps, _window$globalProps2;
1271
414
  var isOpen = _ref.isOpen,
@@ -1658,10 +801,13 @@ var useFetchTemplate = function useFetchTemplate(_ref) {
1658
801
  enabled: !!id
1659
802
  });
1660
803
  };
1661
- var useCreateTemplate = function useCreateTemplate(options) {
1662
- return useMutationWithInvalidation(templatesApi.create, _objectSpread$8({
1663
- keysToInvalidate: [[QUERY_KEYS.TEMPLATES], [QUERY_KEYS.VIEWS]]
1664
- }, options));
804
+ var useCreateTemplate = function useCreateTemplate() {
805
+ return useMutationWithInvalidation(templatesApi.create, {
806
+ keysToInvalidate: [[QUERY_KEYS.TEMPLATES], [QUERY_KEYS.VIEWS]],
807
+ onSuccess: function onSuccess() {
808
+ return captureAnalyticsEvent(EVENTS.APPROVAL_TEMPLATE_CREATED);
809
+ }
810
+ });
1665
811
  };
1666
812
  var useUpdateTemplate = function useUpdateTemplate(options) {
1667
813
  return useMutationWithInvalidation(templatesApi.update, _objectSpread$8({
@@ -1763,7 +909,7 @@ var Form$2 = function Form(_ref) {
1763
909
  _ref$initialData = _ref.initialData,
1764
910
  initialData = _ref$initialData === void 0 ? {} : _ref$initialData,
1765
911
  _ref$onSubmit = _ref.onSubmit,
1766
- onSubmit = _ref$onSubmit === void 0 ? noop$1 : _ref$onSubmit,
912
+ onSubmit = _ref$onSubmit === void 0 ? noop : _ref$onSubmit,
1767
913
  _ref$isLoading = _ref.isLoading,
1768
914
  isLoading = _ref$isLoading === void 0 ? false : _ref$isLoading,
1769
915
  placeholders = _ref.placeholders;
@@ -1895,9 +1041,9 @@ var Field = function Field(_ref) {
1895
1041
  })]
1896
1042
  });
1897
1043
  };
1898
- var Field$1 = /*#__PURE__*/React__default.memo(Field);
1044
+ var Field$1 = /*#__PURE__*/React.memo(Field);
1899
1045
 
1900
- var MemoizedEditorContent = /*#__PURE__*/React__default.memo(EditorContent);
1046
+ var MemoizedEditorContent = /*#__PURE__*/React.memo(EditorContent);
1901
1047
  var TemplateDetails = function TemplateDetails(_ref) {
1902
1048
  var isOpen = _ref.isOpen,
1903
1049
  onClose = _ref.onClose,