@layerfi/components 0.1.52 → 0.1.54
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/esm/index.js +1316 -1269
- package/dist/esm/index.js.map +4 -4
- package/dist/index.d.ts +15 -6
- package/dist/index.js +1411 -1363
- package/dist/index.js.map +4 -4
- package/package.json +1 -1
- package/.idea/codeStyles/Project.xml +0 -61
- package/.idea/codeStyles/codeStyleConfig.xml +0 -5
- package/.idea/layer-react.iml +0 -9
- package/.idea/misc.xml +0 -6
- package/.idea/modules.xml +0 -8
- package/.idea/vcs.xml +0 -6
package/dist/index.js
CHANGED
|
@@ -52,12 +52,13 @@ __export(src_exports, {
|
|
|
52
52
|
StatementOfCashFlow: () => StatementOfCashFlow,
|
|
53
53
|
Tasks: () => Tasks,
|
|
54
54
|
useBankTransactionsContext: () => useBankTransactionsContext,
|
|
55
|
+
useDataSync: () => useDataSync,
|
|
55
56
|
useLayerContext: () => useLayerContext
|
|
56
57
|
});
|
|
57
58
|
module.exports = __toCommonJS(src_exports);
|
|
58
59
|
|
|
59
60
|
// src/providers/LayerProvider/LayerProvider.tsx
|
|
60
|
-
var
|
|
61
|
+
var import_react13 = __toESM(require("react"));
|
|
61
62
|
|
|
62
63
|
// src/api/util.ts
|
|
63
64
|
var formStringFromObject = (object) => Object.entries(object).map(([k, v]) => `${encodeURIComponent(k)}=${encodeURIComponent(v)}`).join("&");
|
|
@@ -206,9 +207,12 @@ var getBankTransactions = get(
|
|
|
206
207
|
businessId,
|
|
207
208
|
cursor,
|
|
208
209
|
categorized,
|
|
210
|
+
direction,
|
|
211
|
+
startDate,
|
|
212
|
+
endDate,
|
|
209
213
|
sortBy = "date",
|
|
210
214
|
sortOrder = "DESC"
|
|
211
|
-
}) => `/v1/businesses/${businessId}/bank-transactions?${cursor ? `cursor=${cursor}&` : ""}${categorized !== void 0 && categorized !== "" ? `categorized=${categorized}&` : ""}sort_by=${sortBy}&sort_order=${sortOrder}&limit=200`
|
|
215
|
+
}) => `/v1/businesses/${businessId}/bank-transactions?${cursor !== void 0 && cursor !== "" ? `cursor=${cursor}&` : ""}${categorized !== void 0 && categorized !== "" ? `categorized=${categorized}&` : ""}${direction !== void 0 ? `direction=${direction}&` : ""}${startDate !== void 0 && startDate !== "" ? `start_date=${startDate}&` : ""}${endDate !== void 0 && endDate !== "" ? `end_date=${endDate}&` : ""}sort_by=${sortBy}&sort_order=${sortOrder}&limit=200`
|
|
212
216
|
);
|
|
213
217
|
var categorizeBankTransaction = put(
|
|
214
218
|
({ businessId, bankTransactionId }) => `/v1/businesses/${businessId}/bank-transactions/${bankTransactionId}/categorize`
|
|
@@ -549,6 +553,7 @@ var LayerContext = (0, import_react4.createContext)({
|
|
|
549
553
|
syncTimestamps: {},
|
|
550
554
|
readTimestamps: {},
|
|
551
555
|
hasBeenTouched: () => false,
|
|
556
|
+
expireDataCaches: () => void 0,
|
|
552
557
|
eventCallbacks: {}
|
|
553
558
|
});
|
|
554
559
|
var useLayerContext = () => (0, import_react4.useContext)(LayerContext);
|
|
@@ -605,9 +610,19 @@ var DEPENDENCIES = {
|
|
|
605
610
|
["CHART_OF_ACCOUNTS" /* CHART_OF_ACCOUNTS */]: ALL_TOUCHABLE,
|
|
606
611
|
["JOURNAL" /* JOURNAL */]: ALL_TOUCHABLE,
|
|
607
612
|
["LEDGER_ACCOUNTS" /* LEDGER_ACCOUNTS */]: ALL_TOUCHABLE,
|
|
608
|
-
["LINKED_ACCOUNTS" /* LINKED_ACCOUNTS */]:
|
|
613
|
+
["LINKED_ACCOUNTS" /* LINKED_ACCOUNTS */]: [
|
|
614
|
+
"BUSINESS" /* BUSINESS */,
|
|
615
|
+
"LINKED_ACCOUNTS" /* LINKED_ACCOUNTS */,
|
|
616
|
+
"CHART_OF_ACCOUNTS" /* CHART_OF_ACCOUNTS */
|
|
617
|
+
],
|
|
609
618
|
["PROFIT_AND_LOSS" /* PROFIT_AND_LOSS */]: ALL_TOUCHABLE,
|
|
610
|
-
["STATEMENT_OF_CASH_FLOWS" /* STATEMENT_OF_CASH_FLOWS */]: ALL_TOUCHABLE
|
|
619
|
+
["STATEMENT_OF_CASH_FLOWS" /* STATEMENT_OF_CASH_FLOWS */]: ALL_TOUCHABLE,
|
|
620
|
+
["BANK_TRANSACTIONS" /* BANK_TRANSACTIONS */]: [
|
|
621
|
+
"LINKED_ACCOUNTS" /* LINKED_ACCOUNTS */,
|
|
622
|
+
"BANK_TRANSACTIONS" /* BANK_TRANSACTIONS */,
|
|
623
|
+
"BUSINESS" /* BUSINESS */,
|
|
624
|
+
"CHART_OF_ACCOUNTS" /* CHART_OF_ACCOUNTS */
|
|
625
|
+
]
|
|
611
626
|
};
|
|
612
627
|
var readTimestampsG = {};
|
|
613
628
|
var useDataSync = () => {
|
|
@@ -619,7 +634,8 @@ var useDataSync = () => {
|
|
|
619
634
|
["LEDGER_ACCOUNTS" /* LEDGER_ACCOUNTS */]: initialTimestamp,
|
|
620
635
|
["LINKED_ACCOUNTS" /* LINKED_ACCOUNTS */]: initialTimestamp,
|
|
621
636
|
["PROFIT_AND_LOSS" /* PROFIT_AND_LOSS */]: initialTimestamp,
|
|
622
|
-
["STATEMENT_OF_CASH_FLOWS" /* STATEMENT_OF_CASH_FLOWS */]: initialTimestamp
|
|
637
|
+
["STATEMENT_OF_CASH_FLOWS" /* STATEMENT_OF_CASH_FLOWS */]: initialTimestamp,
|
|
638
|
+
["BANK_TRANSACTIONS" /* BANK_TRANSACTIONS */]: initialTimestamp
|
|
623
639
|
});
|
|
624
640
|
const [readTimestamps, setReadTimestamps] = (0, import_react7.useState)({});
|
|
625
641
|
const touch = (model) => {
|
|
@@ -649,12 +665,26 @@ var useDataSync = () => {
|
|
|
649
665
|
})
|
|
650
666
|
);
|
|
651
667
|
};
|
|
668
|
+
const resetCaches = () => {
|
|
669
|
+
const now = Date.now();
|
|
670
|
+
setSyncTimestamps({
|
|
671
|
+
["BALANCE_SHEET" /* BALANCE_SHEET */]: now,
|
|
672
|
+
["CHART_OF_ACCOUNTS" /* CHART_OF_ACCOUNTS */]: now,
|
|
673
|
+
["JOURNAL" /* JOURNAL */]: now,
|
|
674
|
+
["LEDGER_ACCOUNTS" /* LEDGER_ACCOUNTS */]: now,
|
|
675
|
+
["LINKED_ACCOUNTS" /* LINKED_ACCOUNTS */]: now,
|
|
676
|
+
["PROFIT_AND_LOSS" /* PROFIT_AND_LOSS */]: now,
|
|
677
|
+
["STATEMENT_OF_CASH_FLOWS" /* STATEMENT_OF_CASH_FLOWS */]: now,
|
|
678
|
+
["BANK_TRANSACTIONS" /* BANK_TRANSACTIONS */]: now
|
|
679
|
+
});
|
|
680
|
+
};
|
|
652
681
|
return {
|
|
653
682
|
touch,
|
|
654
683
|
read,
|
|
655
684
|
syncTimestamps,
|
|
656
685
|
readTimestamps,
|
|
657
|
-
hasBeenTouched
|
|
686
|
+
hasBeenTouched,
|
|
687
|
+
resetCaches
|
|
658
688
|
};
|
|
659
689
|
};
|
|
660
690
|
|
|
@@ -680,16 +710,16 @@ var useDrawer = () => {
|
|
|
680
710
|
};
|
|
681
711
|
|
|
682
712
|
// src/providers/BankTransactionsProvider/BankTransactionsProvider.tsx
|
|
683
|
-
var
|
|
713
|
+
var import_react12 = __toESM(require("react"));
|
|
684
714
|
|
|
685
715
|
// src/contexts/BankTransactionsContext/BankTransactionsContext.tsx
|
|
686
716
|
var import_react9 = require("react");
|
|
687
717
|
|
|
688
718
|
// src/types/bank_transactions.ts
|
|
689
|
-
var Direction = /* @__PURE__ */ ((
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
return
|
|
719
|
+
var Direction = /* @__PURE__ */ ((Direction2) => {
|
|
720
|
+
Direction2["CREDIT"] = "CREDIT";
|
|
721
|
+
Direction2["DEBIT"] = "DEBIT";
|
|
722
|
+
return Direction2;
|
|
693
723
|
})(Direction || {});
|
|
694
724
|
var DisplayState = /* @__PURE__ */ ((DisplayState2) => {
|
|
695
725
|
DisplayState2["all"] = "all";
|
|
@@ -721,6 +751,7 @@ var BankTransactionsContext = (0, import_react9.createContext)({
|
|
|
721
751
|
pagination: void 0
|
|
722
752
|
},
|
|
723
753
|
updateOneLocal: () => void 0,
|
|
754
|
+
shouldHideAfterCategorize: () => false,
|
|
724
755
|
removeAfterCategorize: () => void 0,
|
|
725
756
|
activate: () => void 0,
|
|
726
757
|
display: "review" /* review */,
|
|
@@ -731,1278 +762,1289 @@ var BankTransactionsContext = (0, import_react9.createContext)({
|
|
|
731
762
|
var useBankTransactionsContext = () => (0, import_react9.useContext)(BankTransactionsContext);
|
|
732
763
|
|
|
733
764
|
// src/hooks/useBankTransactions/useBankTransactions.tsx
|
|
734
|
-
var
|
|
735
|
-
|
|
736
|
-
// src/components/BankTransactions/constants.ts
|
|
737
|
-
var CategorizedCategories = [
|
|
738
|
-
"CATEGORIZED" /* CATEGORIZED */,
|
|
739
|
-
"JOURNALING" /* JOURNALING */,
|
|
740
|
-
"SPLIT" /* SPLIT */,
|
|
741
|
-
"MATCHED" /* MATCHED */
|
|
742
|
-
];
|
|
743
|
-
var ReviewCategories = [
|
|
744
|
-
"READY_FOR_INPUT" /* READY_FOR_INPUT */,
|
|
745
|
-
"LAYER_REVIEW" /* LAYER_REVIEW */
|
|
746
|
-
];
|
|
765
|
+
var import_react11 = require("react");
|
|
747
766
|
|
|
748
|
-
// src/
|
|
749
|
-
var
|
|
750
|
-
|
|
751
|
-
bankTransaction.categorization_status
|
|
752
|
-
);
|
|
753
|
-
const inReview = ReviewCategories.includes(
|
|
754
|
-
bankTransaction.categorization_status
|
|
755
|
-
);
|
|
756
|
-
return scope === "all" /* all */ || scope === "review" /* review */ && inReview || scope === "categorized" /* categorized */ && categorized;
|
|
757
|
-
};
|
|
758
|
-
var isCategorized = (bankTransaction) => CategorizedCategories.includes(bankTransaction.categorization_status);
|
|
767
|
+
// src/hooks/useLinkedAccounts/useLinkedAccounts.ts
|
|
768
|
+
var import_react10 = require("react");
|
|
769
|
+
var import_react_plaid_link = require("react-plaid-link");
|
|
759
770
|
|
|
760
|
-
// src/hooks/
|
|
761
|
-
var
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
771
|
+
// src/hooks/useLinkedAccounts/mockData.ts
|
|
772
|
+
var LINKED_ACCOUNTS_MOCK_DATA = [
|
|
773
|
+
{
|
|
774
|
+
id: "d800ada8-8075-4436-a712-08efabcbd51a",
|
|
775
|
+
external_account_external_id: "0Br385JmgbTryJn8nEBnUb4A5ydv06U9Vbqqq",
|
|
776
|
+
external_account_source: "PLAID",
|
|
777
|
+
external_account_name: "Citi Double Cash\xAE Card",
|
|
778
|
+
mask: "1234",
|
|
779
|
+
latest_balance_timestamp: {
|
|
780
|
+
external_account_external_id: "0Br385JmgbTryJn8nEBnUb4A5ydv06U9Vbqqq",
|
|
781
|
+
external_account_source: "PLAID",
|
|
782
|
+
balance: 435121,
|
|
783
|
+
at: "2024-04-03T13:00:00Z",
|
|
784
|
+
created_at: "2024-04-06T22:47:59.715458Z"
|
|
785
|
+
},
|
|
786
|
+
current_ledger_balance: 373717,
|
|
787
|
+
institution: {
|
|
788
|
+
name: "Chase",
|
|
789
|
+
logo: ""
|
|
790
|
+
},
|
|
791
|
+
connection_id: "0Br385JmgbTryJn8nEBnUb4A5ydv06U9Vbqqq",
|
|
792
|
+
connection_external_id: "11111",
|
|
793
|
+
connection_needs_repair_as_of: null,
|
|
794
|
+
requires_user_confirmation_as_of: null,
|
|
795
|
+
is_syncing: true
|
|
796
|
+
},
|
|
797
|
+
{
|
|
798
|
+
id: "f98ec50a-c370-484d-a35b-d00207436075",
|
|
799
|
+
external_account_external_id: "0Br385JmgbTryJn8nEBnUb4A5ydv06U9Vbqqq",
|
|
800
|
+
external_account_source: "PLAID",
|
|
801
|
+
external_account_name: "Citi Double Cash\xAE Card",
|
|
802
|
+
mask: "1234",
|
|
803
|
+
latest_balance_timestamp: {
|
|
804
|
+
external_account_external_id: "0Br385JmgbTryJn8nEBnUb4A5ydv06U9Vbqqq",
|
|
805
|
+
external_account_source: "PLAID",
|
|
806
|
+
balance: 435121,
|
|
807
|
+
at: "2024-04-03T13:00:00Z",
|
|
808
|
+
created_at: "2024-04-06T16:44:35.715458Z"
|
|
809
|
+
},
|
|
810
|
+
current_ledger_balance: 373717,
|
|
811
|
+
institution: {
|
|
812
|
+
name: "Chase",
|
|
813
|
+
logo: ""
|
|
814
|
+
},
|
|
815
|
+
connection_id: "0Br385JmgbTryJn8nEBnUb4A5ydv06U9Vbqqq",
|
|
816
|
+
connection_external_id: "11111",
|
|
817
|
+
connection_needs_repair_as_of: null,
|
|
818
|
+
requires_user_confirmation_as_of: null,
|
|
819
|
+
is_syncing: false
|
|
820
|
+
},
|
|
821
|
+
{
|
|
822
|
+
id: "843f1748-fdaa-422d-a73d-2489a40c8dc7",
|
|
823
|
+
external_account_external_id: "0Br385JmgbTryJn8nEBnUb4A5ydv06U9Vbqqq",
|
|
824
|
+
external_account_source: "PLAID",
|
|
825
|
+
external_account_name: "Citi Double Cash\xAE Card",
|
|
826
|
+
mask: "1234",
|
|
827
|
+
latest_balance_timestamp: {
|
|
828
|
+
external_account_external_id: "0Br385JmgbTryJn8nEBnUb4A5ydv06U9Vbqqq",
|
|
829
|
+
external_account_source: "PLAID",
|
|
830
|
+
balance: 435121,
|
|
831
|
+
at: "2024-04-03T13:00:00Z",
|
|
832
|
+
created_at: "2024-04-06T16:44:35.715458Z"
|
|
833
|
+
},
|
|
834
|
+
current_ledger_balance: 373717,
|
|
835
|
+
institution: {
|
|
836
|
+
name: "Chase",
|
|
837
|
+
logo: ""
|
|
838
|
+
},
|
|
839
|
+
connection_id: "0Br385JmgbTryJn8nEBnUb4A5ydv06U9Vbqqq",
|
|
840
|
+
connection_external_id: "11111",
|
|
841
|
+
connection_needs_repair_as_of: "2024-03-06T16:44:35.715458Z",
|
|
842
|
+
requires_user_confirmation_as_of: null,
|
|
843
|
+
is_syncing: false
|
|
844
|
+
},
|
|
845
|
+
{
|
|
846
|
+
id: "8f430e29-e339-4d71-a08a-fce469c7a7c1",
|
|
847
|
+
external_account_external_id: "0Br385JmgbTryJn8nEBnUb4A5ydv06U9Vbqqq",
|
|
848
|
+
external_account_source: "PLAID",
|
|
849
|
+
external_account_name: "Citi Double Cash\xAE Card",
|
|
850
|
+
mask: "1234",
|
|
851
|
+
latest_balance_timestamp: {
|
|
852
|
+
external_account_external_id: "0Br385JmgbTryJn8nEBnUb4A5ydv06U9Vbqqq",
|
|
853
|
+
external_account_source: "PLAID",
|
|
854
|
+
balance: 435121,
|
|
855
|
+
at: "2024-04-03T13:00:00Z",
|
|
856
|
+
created_at: "2024-04-06T16:44:35.715458Z"
|
|
857
|
+
},
|
|
858
|
+
current_ledger_balance: 373717,
|
|
859
|
+
institution: {
|
|
860
|
+
name: "Chase",
|
|
861
|
+
logo: ""
|
|
862
|
+
},
|
|
863
|
+
connection_id: "0Br385JmgbTryJn8nEBnUb4A5ydv06U9Vbqqq",
|
|
864
|
+
connection_external_id: "11111",
|
|
865
|
+
connection_needs_repair_as_of: null,
|
|
866
|
+
requires_user_confirmation_as_of: "2024-03-06T16:44:35.715458Z",
|
|
867
|
+
is_syncing: false
|
|
803
868
|
}
|
|
804
|
-
|
|
805
|
-
(tx) => filterVisibility(filter, tx) || filter === "all" /* all */ || filter === "review" /* review */ && tx.recently_categorized || filter === "categorized" /* categorized */ && tx.recently_categorized
|
|
806
|
-
);
|
|
807
|
-
};
|
|
808
|
-
var appplyDateRangeFilter = (data, filter) => {
|
|
809
|
-
return data?.filter((x) => {
|
|
810
|
-
const txDate = (0, import_date_fns.parseISO)(x.date);
|
|
811
|
-
if (filter?.startDate && filter?.endDate) {
|
|
812
|
-
return txDate >= filter.startDate && txDate <= filter.endDate;
|
|
813
|
-
}
|
|
814
|
-
if (filter?.startDate) {
|
|
815
|
-
return txDate >= filter.startDate;
|
|
816
|
-
}
|
|
817
|
-
if (filter?.endDate) {
|
|
818
|
-
return txDate <= filter.endDate;
|
|
819
|
-
}
|
|
820
|
-
});
|
|
821
|
-
};
|
|
869
|
+
];
|
|
822
870
|
|
|
823
|
-
// src/hooks/
|
|
824
|
-
var
|
|
825
|
-
var
|
|
871
|
+
// src/hooks/useLinkedAccounts/useLinkedAccounts.ts
|
|
872
|
+
var import_swr = __toESM(require("swr"));
|
|
873
|
+
var DEBUG = true;
|
|
874
|
+
var USE_MOCK_RESPONSE_DATA = false;
|
|
875
|
+
var useLinkedAccounts = () => {
|
|
826
876
|
const {
|
|
827
877
|
auth,
|
|
828
878
|
businessId,
|
|
829
879
|
apiUrl,
|
|
830
|
-
|
|
880
|
+
usePlaidSandbox,
|
|
831
881
|
touch,
|
|
832
882
|
read,
|
|
833
883
|
syncTimestamps,
|
|
834
|
-
hasBeenTouched
|
|
835
|
-
eventCallbacks
|
|
884
|
+
hasBeenTouched
|
|
836
885
|
} = useLayerContext();
|
|
837
|
-
const
|
|
838
|
-
const [filters, setTheFilters] = (0, import_react10.useState)(
|
|
839
|
-
scope ? { categorizationStatus: scope } : void 0
|
|
840
|
-
);
|
|
841
|
-
const display = (0, import_react10.useMemo)(() => {
|
|
842
|
-
if (filters?.categorizationStatus === "review" /* review */) {
|
|
843
|
-
return "review" /* review */;
|
|
844
|
-
} else if (filters?.categorizationStatus === "all" /* all */) {
|
|
845
|
-
return "all" /* all */;
|
|
846
|
-
}
|
|
847
|
-
return "categorized" /* categorized */;
|
|
848
|
-
}, [filters?.categorizationStatus]);
|
|
849
|
-
const [active, setActive] = (0, import_react10.useState)(false);
|
|
886
|
+
const [linkToken, setLinkToken] = (0, import_react10.useState)(null);
|
|
850
887
|
const [loadingStatus, setLoadingStatus] = (0, import_react10.useState)("initial");
|
|
851
|
-
const
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
}
|
|
855
|
-
if (!prevData?.meta?.pagination?.cursor) {
|
|
856
|
-
return [
|
|
857
|
-
businessId && auth?.access_token && `bank-transactions-${businessId}`,
|
|
858
|
-
void 0
|
|
859
|
-
];
|
|
860
|
-
}
|
|
861
|
-
return [
|
|
862
|
-
businessId && auth?.access_token && `bank-transactions-${businessId}-${prevData.meta.pagination.cursor}`,
|
|
863
|
-
prevData.meta.pagination.cursor
|
|
864
|
-
];
|
|
865
|
-
};
|
|
888
|
+
const USE_PLAID_SANDBOX = usePlaidSandbox ?? true;
|
|
889
|
+
const [linkMode, setLinkMode] = (0, import_react10.useState)("add");
|
|
890
|
+
const queryKey = businessId && auth?.access_token && `linked-accounts-${businessId}`;
|
|
866
891
|
const {
|
|
867
|
-
data:
|
|
892
|
+
data: responseData,
|
|
868
893
|
isLoading,
|
|
869
894
|
isValidating,
|
|
870
895
|
error: responseError,
|
|
871
|
-
mutate
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
if (auth?.access_token) {
|
|
878
|
-
return Layer.getBankTransactions(apiUrl, auth?.access_token, {
|
|
879
|
-
params: {
|
|
880
|
-
businessId,
|
|
881
|
-
cursor: nextCursor
|
|
882
|
-
}
|
|
883
|
-
}).call(false);
|
|
884
|
-
}
|
|
885
|
-
return {};
|
|
886
|
-
},
|
|
887
|
-
{
|
|
888
|
-
initialSize: 1,
|
|
889
|
-
revalidateFirstPage: false
|
|
890
|
-
}
|
|
896
|
+
mutate
|
|
897
|
+
} = (0, import_swr.default)(
|
|
898
|
+
queryKey,
|
|
899
|
+
Layer.getLinkedAccounts(apiUrl, auth?.access_token, {
|
|
900
|
+
params: { businessId }
|
|
901
|
+
})
|
|
891
902
|
);
|
|
892
|
-
|
|
893
|
-
if (
|
|
894
|
-
|
|
903
|
+
(0, import_react10.useEffect)(() => {
|
|
904
|
+
if (!isLoading && responseData?.data.external_accounts) {
|
|
905
|
+
setLoadingStatus("complete");
|
|
906
|
+
return;
|
|
895
907
|
}
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
if (rawResponseData && rawResponseData.length > 0) {
|
|
900
|
-
return rawResponseData[rawResponseData.length - 1].meta;
|
|
901
|
-
}
|
|
902
|
-
return void 0;
|
|
903
|
-
}, [rawResponseData]);
|
|
904
|
-
const hasMore = (0, import_react10.useMemo)(() => {
|
|
905
|
-
if (rawResponseData && rawResponseData.length > 0) {
|
|
906
|
-
const lastElement = rawResponseData[rawResponseData.length - 1];
|
|
907
|
-
return Boolean(
|
|
908
|
-
lastElement.meta?.pagination?.cursor && lastElement.meta?.pagination?.has_more
|
|
909
|
-
);
|
|
910
|
-
}
|
|
911
|
-
return false;
|
|
912
|
-
}, [rawResponseData]);
|
|
913
|
-
const accountsList = (0, import_react10.useMemo)(
|
|
914
|
-
() => data ? collectAccounts(data) : [],
|
|
915
|
-
[data]
|
|
916
|
-
);
|
|
917
|
-
(0, import_react10.useEffect)(() => {
|
|
918
|
-
if (isLoading && loadingStatus === "initial") {
|
|
919
|
-
setLoadingStatus("loading");
|
|
920
|
-
return;
|
|
908
|
+
if (isLoading && loadingStatus === "initial") {
|
|
909
|
+
setLoadingStatus("loading");
|
|
910
|
+
return;
|
|
921
911
|
}
|
|
922
912
|
if (!isLoading && loadingStatus === "loading") {
|
|
923
913
|
setLoadingStatus("complete");
|
|
924
|
-
return;
|
|
925
914
|
}
|
|
926
915
|
}, [isLoading]);
|
|
927
|
-
const
|
|
928
|
-
|
|
916
|
+
const fetchPlaidLinkToken = async () => {
|
|
917
|
+
if (auth?.access_token) {
|
|
918
|
+
const linkToken2 = (await Layer.getPlaidLinkToken(apiUrl, auth.access_token, {
|
|
919
|
+
params: { businessId }
|
|
920
|
+
})).data.link_token;
|
|
921
|
+
setLinkMode("add");
|
|
922
|
+
setLinkToken(linkToken2);
|
|
923
|
+
}
|
|
929
924
|
};
|
|
930
|
-
const
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
925
|
+
const fetchPlaidUpdateModeLinkToken = async (plaidItemPlaidId) => {
|
|
926
|
+
if (auth?.access_token) {
|
|
927
|
+
const linkToken2 = (await Layer.getPlaidUpdateModeLinkToken(apiUrl, auth.access_token, {
|
|
928
|
+
params: { businessId },
|
|
929
|
+
body: { plaid_item_id: plaidItemPlaidId }
|
|
930
|
+
})).data.link_token;
|
|
931
|
+
setLinkMode("update");
|
|
932
|
+
setLinkToken(linkToken2);
|
|
933
|
+
}
|
|
934
|
+
};
|
|
935
|
+
const exchangePlaidPublicToken2 = async (publicToken, metadata) => {
|
|
936
|
+
await Layer.exchangePlaidPublicToken(apiUrl, auth?.access_token, {
|
|
937
|
+
params: { businessId },
|
|
938
|
+
body: { public_token: publicToken, institution: metadata.institution }
|
|
934
939
|
});
|
|
940
|
+
refetchAccounts();
|
|
935
941
|
};
|
|
936
|
-
const
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
942
|
+
const { open: plaidLinkStart, ready: plaidLinkReady } = (0, import_react_plaid_link.usePlaidLink)({
|
|
943
|
+
token: linkToken,
|
|
944
|
+
// If in update mode, we don't need to exchange the public token for an access token.
|
|
945
|
+
// The existing access token will automatically become valid again
|
|
946
|
+
onSuccess: async (publicToken, metadata) => {
|
|
947
|
+
if (linkMode == "add") {
|
|
948
|
+
exchangePlaidPublicToken2(publicToken, metadata);
|
|
949
|
+
} else {
|
|
950
|
+
await updateConnectionStatus2();
|
|
951
|
+
refetchAccounts();
|
|
952
|
+
setLinkMode("add");
|
|
953
|
+
touch("LINKED_ACCOUNTS" /* LINKED_ACCOUNTS */);
|
|
954
|
+
}
|
|
955
|
+
},
|
|
956
|
+
onExit: () => setLinkMode("add"),
|
|
957
|
+
env: USE_PLAID_SANDBOX ? "sandbox" : void 0
|
|
958
|
+
});
|
|
959
|
+
(0, import_react10.useEffect)(() => {
|
|
960
|
+
if (plaidLinkReady) {
|
|
961
|
+
plaidLinkStart();
|
|
949
962
|
}
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
963
|
+
}, [plaidLinkStart, plaidLinkReady]);
|
|
964
|
+
const mockResponseData = {
|
|
965
|
+
data: LINKED_ACCOUNTS_MOCK_DATA,
|
|
966
|
+
meta: {},
|
|
967
|
+
error: void 0
|
|
968
|
+
};
|
|
969
|
+
const addConnection = (source) => {
|
|
970
|
+
if (source === "PLAID") {
|
|
971
|
+
fetchPlaidLinkToken();
|
|
972
|
+
} else {
|
|
973
|
+
console.error(
|
|
974
|
+
`Adding a connection with source ${source} not yet supported`
|
|
954
975
|
);
|
|
955
976
|
}
|
|
956
|
-
|
|
957
|
-
|
|
977
|
+
};
|
|
978
|
+
const repairConnection = async (source, connectionExternalId) => {
|
|
979
|
+
if (source === "PLAID") {
|
|
980
|
+
await fetchPlaidUpdateModeLinkToken(connectionExternalId);
|
|
981
|
+
} else {
|
|
982
|
+
console.error(
|
|
983
|
+
`Repairing a connection with source ${source} not yet supported`
|
|
984
|
+
);
|
|
958
985
|
}
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
986
|
+
};
|
|
987
|
+
const removeConnection = async (source, connectionExternalId) => {
|
|
988
|
+
if (source === "PLAID") {
|
|
989
|
+
await unlinkPlaidItem2(connectionExternalId);
|
|
990
|
+
await refetchAccounts();
|
|
991
|
+
} else {
|
|
992
|
+
console.error(
|
|
993
|
+
`Removing a connection with source ${source} not yet supported`
|
|
994
|
+
);
|
|
965
995
|
}
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
if (newBT?.recently_categorized === true && notify) {
|
|
979
|
-
addToast({ content: "Transaction saved" });
|
|
980
|
-
}
|
|
981
|
-
}).catch((err) => {
|
|
982
|
-
const newBT = data?.find(
|
|
983
|
-
(x) => x.business_id === businessId && x.id === id
|
|
996
|
+
};
|
|
997
|
+
const unlinkAccount2 = async (source, accountId) => {
|
|
998
|
+
DEBUG && console.log("unlinking account");
|
|
999
|
+
if (source === "PLAID") {
|
|
1000
|
+
await Layer.unlinkAccount(apiUrl, auth?.access_token, {
|
|
1001
|
+
params: { businessId, accountId }
|
|
1002
|
+
});
|
|
1003
|
+
await refetchAccounts();
|
|
1004
|
+
touch("LINKED_ACCOUNTS" /* LINKED_ACCOUNTS */);
|
|
1005
|
+
} else {
|
|
1006
|
+
console.error(
|
|
1007
|
+
`Unlinking an account with source ${source} not yet supported`
|
|
984
1008
|
);
|
|
985
|
-
|
|
986
|
-
updateOneLocal({
|
|
987
|
-
...newBT,
|
|
988
|
-
error: err.message,
|
|
989
|
-
processing: false
|
|
990
|
-
});
|
|
991
|
-
}
|
|
992
|
-
}).finally(() => {
|
|
993
|
-
touch("BANK_TRANSACTIONS" /* BANK_TRANSACTIONS */);
|
|
994
|
-
eventCallbacks?.onTransactionCategorized?.(id);
|
|
995
|
-
});
|
|
1009
|
+
}
|
|
996
1010
|
};
|
|
997
|
-
const
|
|
998
|
-
|
|
999
|
-
if (
|
|
1000
|
-
|
|
1011
|
+
const confirmAccount = async (source, accountId) => {
|
|
1012
|
+
DEBUG && console.log("confirming account");
|
|
1013
|
+
if (source === "PLAID") {
|
|
1014
|
+
await Layer.confirmConnection(apiUrl, auth?.access_token, {
|
|
1015
|
+
params: {
|
|
1016
|
+
businessId,
|
|
1017
|
+
accountId
|
|
1018
|
+
}
|
|
1019
|
+
});
|
|
1020
|
+
await refetchAccounts();
|
|
1021
|
+
touch("LINKED_ACCOUNTS" /* LINKED_ACCOUNTS */);
|
|
1022
|
+
} else {
|
|
1023
|
+
console.error(
|
|
1024
|
+
`Confirming an account with source ${source} not yet supported`
|
|
1025
|
+
);
|
|
1001
1026
|
}
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1027
|
+
};
|
|
1028
|
+
const denyAccount = async (source, accountId) => {
|
|
1029
|
+
DEBUG && console.log("confirming account");
|
|
1030
|
+
if (source === "PLAID") {
|
|
1031
|
+
await Layer.denyConnection(apiUrl, auth?.access_token, {
|
|
1032
|
+
params: {
|
|
1033
|
+
businessId,
|
|
1034
|
+
accountId
|
|
1035
|
+
}
|
|
1036
|
+
});
|
|
1037
|
+
await refetchAccounts();
|
|
1038
|
+
touch("LINKED_ACCOUNTS" /* LINKED_ACCOUNTS */);
|
|
1039
|
+
} else {
|
|
1040
|
+
console.error(
|
|
1041
|
+
`Denying an account with source ${source} not yet supported`
|
|
1008
1042
|
);
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
}
|
|
1023
|
-
|
|
1024
|
-
|
|
1043
|
+
}
|
|
1044
|
+
};
|
|
1045
|
+
const breakConnection = async (source, connectionExternalId) => {
|
|
1046
|
+
DEBUG && console.log("Breaking sandbox plaid item connection");
|
|
1047
|
+
if (source === "PLAID") {
|
|
1048
|
+
await Layer.breakPlaidItemConnection(apiUrl, auth?.access_token, {
|
|
1049
|
+
params: {
|
|
1050
|
+
businessId,
|
|
1051
|
+
plaidItemPlaidId: connectionExternalId
|
|
1052
|
+
}
|
|
1053
|
+
});
|
|
1054
|
+
await refetchAccounts();
|
|
1055
|
+
touch("LINKED_ACCOUNTS" /* LINKED_ACCOUNTS */);
|
|
1056
|
+
} else {
|
|
1057
|
+
console.error(
|
|
1058
|
+
`Breaking a sandbox connection with source ${source} not yet supported`
|
|
1025
1059
|
);
|
|
1026
|
-
|
|
1027
|
-
updateOneLocal({
|
|
1028
|
-
...newBT,
|
|
1029
|
-
error: err.message,
|
|
1030
|
-
processing: false
|
|
1031
|
-
});
|
|
1032
|
-
}
|
|
1033
|
-
}).finally(() => {
|
|
1034
|
-
touch("BANK_TRANSACTIONS" /* BANK_TRANSACTIONS */);
|
|
1035
|
-
eventCallbacks?.onTransactionCategorized?.(id);
|
|
1036
|
-
});
|
|
1060
|
+
}
|
|
1037
1061
|
};
|
|
1038
|
-
const
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
}
|
|
1062
|
+
const refetchAccounts = async () => {
|
|
1063
|
+
DEBUG && console.log("refetching accounts...");
|
|
1064
|
+
await mutate();
|
|
1065
|
+
};
|
|
1066
|
+
const syncAccounts = async () => {
|
|
1067
|
+
DEBUG && console.log("resyncing accounts...");
|
|
1068
|
+
await Layer.syncConnection(apiUrl, auth?.access_token, {
|
|
1069
|
+
params: { businessId }
|
|
1046
1070
|
});
|
|
1047
|
-
mutate(updatedData, { revalidate: false });
|
|
1048
1071
|
};
|
|
1049
|
-
const
|
|
1072
|
+
const updateConnectionStatus2 = async () => {
|
|
1073
|
+
DEBUG && console.log("updating connection status...");
|
|
1074
|
+
await Layer.updateConnectionStatus(apiUrl, auth?.access_token, {
|
|
1075
|
+
params: { businessId }
|
|
1076
|
+
});
|
|
1050
1077
|
};
|
|
1051
|
-
const
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1078
|
+
const unlinkPlaidItem2 = async (plaidItemPlaidId) => {
|
|
1079
|
+
DEBUG && console.log("unlinking plaid item");
|
|
1080
|
+
await Layer.unlinkPlaidItem(apiUrl, auth?.access_token, {
|
|
1081
|
+
params: { businessId, plaidItemPlaidId }
|
|
1082
|
+
});
|
|
1083
|
+
await refetchAccounts();
|
|
1084
|
+
touch("LINKED_ACCOUNTS" /* LINKED_ACCOUNTS */);
|
|
1058
1085
|
};
|
|
1059
1086
|
(0, import_react10.useEffect)(() => {
|
|
1060
|
-
if (isLoading || isValidating) {
|
|
1061
|
-
read("
|
|
1087
|
+
if (queryKey && (isLoading || isValidating)) {
|
|
1088
|
+
read("LINKED_ACCOUNTS" /* LINKED_ACCOUNTS */, queryKey);
|
|
1062
1089
|
}
|
|
1063
1090
|
}, [isLoading, isValidating]);
|
|
1064
1091
|
(0, import_react10.useEffect)(() => {
|
|
1065
|
-
if (hasBeenTouched(
|
|
1066
|
-
|
|
1092
|
+
if (queryKey && hasBeenTouched(queryKey)) {
|
|
1093
|
+
refetchAccounts();
|
|
1067
1094
|
}
|
|
1068
1095
|
}, [syncTimestamps]);
|
|
1069
1096
|
return {
|
|
1070
|
-
data:
|
|
1071
|
-
metadata: lastMetadata,
|
|
1072
|
-
loadingStatus,
|
|
1097
|
+
data: USE_MOCK_RESPONSE_DATA ? mockResponseData.data : responseData?.data.external_accounts,
|
|
1073
1098
|
isLoading,
|
|
1099
|
+
loadingStatus,
|
|
1074
1100
|
isValidating,
|
|
1075
|
-
refetch,
|
|
1076
1101
|
error: responseError,
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
hasMore
|
|
1102
|
+
addConnection,
|
|
1103
|
+
removeConnection,
|
|
1104
|
+
repairConnection,
|
|
1105
|
+
refetchAccounts,
|
|
1106
|
+
unlinkAccount: unlinkAccount2,
|
|
1107
|
+
confirmAccount,
|
|
1108
|
+
denyAccount,
|
|
1109
|
+
breakConnection,
|
|
1110
|
+
syncAccounts,
|
|
1111
|
+
updateConnectionStatus: updateConnectionStatus2
|
|
1088
1112
|
};
|
|
1089
1113
|
};
|
|
1090
1114
|
|
|
1091
|
-
// src/
|
|
1092
|
-
var
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
return /* @__PURE__ */ import_react11.default.createElement(BankTransactionsContext.Provider, { value: bankTransactionsContextData }, children);
|
|
1097
|
-
};
|
|
1098
|
-
|
|
1099
|
-
// src/config/theme.ts
|
|
1100
|
-
var SHADES = {
|
|
1101
|
-
50: { s: 1, l: 98 },
|
|
1102
|
-
100: { s: 1, l: 96 },
|
|
1103
|
-
200: { s: 1, l: 94 },
|
|
1104
|
-
300: { s: 2, l: 92 },
|
|
1105
|
-
500: { s: 5, l: 53 },
|
|
1106
|
-
600: { s: 7, l: 40 },
|
|
1107
|
-
700: { s: 9, l: 27 },
|
|
1108
|
-
800: { s: 12, l: 20 },
|
|
1109
|
-
1e3: { s: 20, l: 7 }
|
|
1110
|
-
};
|
|
1111
|
-
var COLORS = {
|
|
1112
|
-
dark: {
|
|
1113
|
-
h: 0,
|
|
1114
|
-
s: 0,
|
|
1115
|
-
l: 7
|
|
1116
|
-
},
|
|
1117
|
-
light: {
|
|
1118
|
-
h: 0,
|
|
1119
|
-
s: 0,
|
|
1120
|
-
l: 100
|
|
1121
|
-
}
|
|
1122
|
-
};
|
|
1123
|
-
|
|
1124
|
-
// src/utils/colors.ts
|
|
1125
|
-
var parseStylesFromThemeConfig = (theme) => {
|
|
1126
|
-
let styles = {};
|
|
1127
|
-
if (!theme) {
|
|
1128
|
-
return styles;
|
|
1129
|
-
}
|
|
1130
|
-
if (theme.colors) {
|
|
1131
|
-
const darkColor = parseColorFromTheme("dark", theme.colors.dark);
|
|
1132
|
-
const lightColor = parseColorFromTheme("light", theme.colors.light);
|
|
1133
|
-
const textColor = parseTextColorFromTheme(theme.colors.text);
|
|
1134
|
-
styles = { ...styles, ...darkColor, ...lightColor, ...textColor };
|
|
1135
|
-
}
|
|
1136
|
-
return styles;
|
|
1137
|
-
};
|
|
1138
|
-
var parseTextColorFromTheme = (color) => {
|
|
1139
|
-
if (!color) {
|
|
1140
|
-
return {};
|
|
1115
|
+
// src/hooks/useBankTransactions/utils.ts
|
|
1116
|
+
var collectAccounts = (transactions) => {
|
|
1117
|
+
const accounts = [];
|
|
1118
|
+
if (!transactions) {
|
|
1119
|
+
return accounts;
|
|
1141
1120
|
}
|
|
1142
|
-
|
|
1143
|
-
if (
|
|
1144
|
-
|
|
1121
|
+
transactions.forEach((x) => {
|
|
1122
|
+
if (!accounts.find((y) => y.id === x.source_account_id)) {
|
|
1123
|
+
accounts.push({
|
|
1124
|
+
id: x.source_account_id,
|
|
1125
|
+
name: x.account_name || ""
|
|
1126
|
+
});
|
|
1145
1127
|
}
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
return {};
|
|
1149
|
-
}
|
|
1128
|
+
});
|
|
1129
|
+
return accounts.sort((a, b) => a.name.localeCompare(b.name));
|
|
1150
1130
|
};
|
|
1151
|
-
var
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
try {
|
|
1156
|
-
if ("h" in color && "s" in color && "l" in color) {
|
|
1157
|
-
return {
|
|
1158
|
-
[`--color-${colorName}-h`]: color.h,
|
|
1159
|
-
[`--color-${colorName}-s`]: color.s,
|
|
1160
|
-
[`--color-${colorName}-l`]: color.l
|
|
1161
|
-
};
|
|
1131
|
+
var applyAmountFilter = (data, filter) => {
|
|
1132
|
+
return data?.filter((x) => {
|
|
1133
|
+
if ((filter?.min || filter?.min === 0) && (filter?.max || filter?.max === 0)) {
|
|
1134
|
+
return x.amount >= filter.min * 100 && x.amount <= filter.max * 100;
|
|
1162
1135
|
}
|
|
1163
|
-
if (
|
|
1164
|
-
|
|
1165
|
-
return {
|
|
1166
|
-
[`--color-${colorName}-h`]: h,
|
|
1167
|
-
[`--color-${colorName}-s`]: `${s}%`,
|
|
1168
|
-
[`--color-${colorName}-l`]: `${l}%`
|
|
1169
|
-
};
|
|
1136
|
+
if (filter?.min || filter?.min === 0) {
|
|
1137
|
+
return x.amount >= filter.min * 100;
|
|
1170
1138
|
}
|
|
1171
|
-
if (
|
|
1172
|
-
|
|
1173
|
-
if (!rgb) {
|
|
1174
|
-
return {};
|
|
1175
|
-
}
|
|
1176
|
-
const { h, s, l } = rgbToHsl({
|
|
1177
|
-
r: rgb.r.toString(),
|
|
1178
|
-
g: rgb.g.toString(),
|
|
1179
|
-
b: rgb.b.toString()
|
|
1180
|
-
});
|
|
1181
|
-
return {
|
|
1182
|
-
[`--color-${colorName}-h`]: h,
|
|
1183
|
-
[`--color-${colorName}-s`]: `${s}%`,
|
|
1184
|
-
[`--color-${colorName}-l`]: `${l}%`
|
|
1185
|
-
};
|
|
1139
|
+
if (filter?.max || filter?.max === 0) {
|
|
1140
|
+
return x.amount <= filter.max * 100;
|
|
1186
1141
|
}
|
|
1187
|
-
|
|
1188
|
-
} catch (_err) {
|
|
1189
|
-
return {};
|
|
1190
|
-
}
|
|
1142
|
+
});
|
|
1191
1143
|
};
|
|
1192
|
-
var
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1144
|
+
var applyAccountFilter = (data, filter) => data?.filter((x) => filter && filter.includes(x.source_account_id));
|
|
1145
|
+
|
|
1146
|
+
// src/hooks/useBankTransactions/useBankTransactions.tsx
|
|
1147
|
+
var import_infinite = __toESM(require("swr/infinite"));
|
|
1148
|
+
var INITIAL_POLL_INTERVAL_MS = 1e3;
|
|
1149
|
+
var POLL_INTERVAL_AFTER_TXNS_RECEIVED_MS = 5e3;
|
|
1150
|
+
function useTriggerOnChange(data, anyAccountSyncing, callback) {
|
|
1151
|
+
const prevDataRef = (0, import_react11.useRef)();
|
|
1152
|
+
(0, import_react11.useEffect)(() => {
|
|
1153
|
+
if (anyAccountSyncing && prevDataRef.current !== void 0 && prevDataRef.current !== data) {
|
|
1154
|
+
callback(data);
|
|
1155
|
+
}
|
|
1156
|
+
prevDataRef.current = data;
|
|
1157
|
+
}, [data, anyAccountSyncing, callback]);
|
|
1158
|
+
}
|
|
1159
|
+
var filtersSettingString = (filters) => {
|
|
1160
|
+
return `bank-transactions${filters?.categorizationStatus ? `-categorizationStatus-${filters.categorizationStatus}` : `-categorizationStatus-${"all" /* all */}`}${filters?.direction?.length === 1 ? `-direction-${filters.direction.join("-")}` : ""}${filters?.dateRange?.startDate ? `-startDate-${filters.dateRange.startDate.toISOString()}` : ""}${filters?.dateRange?.endDate ? `-endDate-${filters.dateRange.endDate.toISOString()}` : ""}`;
|
|
1161
|
+
};
|
|
1162
|
+
var useBankTransactions = (params) => {
|
|
1163
|
+
const {
|
|
1164
|
+
auth,
|
|
1165
|
+
businessId,
|
|
1166
|
+
apiUrl,
|
|
1167
|
+
addToast,
|
|
1168
|
+
touch,
|
|
1169
|
+
read,
|
|
1170
|
+
syncTimestamps,
|
|
1171
|
+
hasBeenTouched,
|
|
1172
|
+
eventCallbacks
|
|
1173
|
+
} = useLayerContext();
|
|
1174
|
+
const { scope = void 0 } = params ?? {};
|
|
1175
|
+
const [filters, setTheFilters] = (0, import_react11.useState)(
|
|
1176
|
+
scope ? { categorizationStatus: scope } : void 0
|
|
1177
|
+
);
|
|
1178
|
+
const display = (0, import_react11.useMemo)(() => {
|
|
1179
|
+
if (filters?.categorizationStatus === "review" /* review */) {
|
|
1180
|
+
return "review" /* review */;
|
|
1181
|
+
} else if (filters?.categorizationStatus === "all" /* all */) {
|
|
1182
|
+
return "all" /* all */;
|
|
1203
1183
|
}
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1184
|
+
return "categorized" /* categorized */;
|
|
1185
|
+
}, [filters?.categorizationStatus]);
|
|
1186
|
+
const [active, setActive] = (0, import_react11.useState)(false);
|
|
1187
|
+
const [loadingStatus, setLoadingStatus] = (0, import_react11.useState)("initial");
|
|
1188
|
+
const getKey = (index, prevData) => {
|
|
1189
|
+
if (!auth?.access_token || !active) {
|
|
1190
|
+
return [false, void 0];
|
|
1211
1191
|
}
|
|
1212
|
-
if (
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
const { h, s, l } = rgbToHsl({
|
|
1218
|
-
r: rgb.r.toString(),
|
|
1219
|
-
g: rgb.g.toString(),
|
|
1220
|
-
b: rgb.b.toString()
|
|
1221
|
-
});
|
|
1222
|
-
return {
|
|
1223
|
-
h,
|
|
1224
|
-
s,
|
|
1225
|
-
l
|
|
1226
|
-
};
|
|
1192
|
+
if (index === 0) {
|
|
1193
|
+
return [
|
|
1194
|
+
businessId && auth?.access_token && `${filtersSettingString(filters)}-${businessId}`,
|
|
1195
|
+
void 0
|
|
1196
|
+
];
|
|
1227
1197
|
}
|
|
1228
|
-
return
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
};
|
|
1233
|
-
var rgbToHsl = (color) => {
|
|
1234
|
-
let r = Number(color.r);
|
|
1235
|
-
let g = Number(color.g);
|
|
1236
|
-
let b = Number(color.b);
|
|
1237
|
-
r /= 255;
|
|
1238
|
-
g /= 255;
|
|
1239
|
-
b /= 255;
|
|
1240
|
-
const l = Math.max(r, g, b);
|
|
1241
|
-
const s = l - Math.min(r, g, b);
|
|
1242
|
-
const h = s ? l === r ? (g - b) / s : l === g ? 2 + (b - r) / s : 4 + (r - g) / s : 0;
|
|
1243
|
-
return {
|
|
1244
|
-
h: 60 * h < 0 ? 60 * h + 360 : 60 * h,
|
|
1245
|
-
s: 100 * (s ? l <= 0.5 ? s / (2 * l - s) : s / (2 - (2 * l - s)) : 0),
|
|
1246
|
-
l: 100 * (2 * l - s) / 2
|
|
1198
|
+
return [
|
|
1199
|
+
businessId && auth?.access_token && `${filtersSettingString(filters)}-${businessId}-${prevData?.meta?.pagination?.cursor}`,
|
|
1200
|
+
prevData?.meta?.pagination?.cursor.toString()
|
|
1201
|
+
];
|
|
1247
1202
|
};
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
}
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
hsl: lightColor,
|
|
1273
|
-
rgb: hslToRgb(lightColor),
|
|
1274
|
-
hex: hslToHex(lightColor)
|
|
1275
|
-
},
|
|
1276
|
-
500: buildColorShade(500, darkColor),
|
|
1277
|
-
600: buildColorShade(600, darkColor),
|
|
1278
|
-
700: buildColorShade(700, darkColor),
|
|
1279
|
-
800: buildColorShade(800, darkColor),
|
|
1280
|
-
900: {
|
|
1281
|
-
hsl: darkColor,
|
|
1282
|
-
rgb: hslToRgb(darkColor),
|
|
1283
|
-
hex: hslToHex(darkColor)
|
|
1203
|
+
const {
|
|
1204
|
+
data: rawResponseData,
|
|
1205
|
+
isLoading,
|
|
1206
|
+
isValidating,
|
|
1207
|
+
error: responseError,
|
|
1208
|
+
mutate,
|
|
1209
|
+
size,
|
|
1210
|
+
setSize
|
|
1211
|
+
} = (0, import_infinite.default)(
|
|
1212
|
+
getKey,
|
|
1213
|
+
async ([_query, nextCursor]) => {
|
|
1214
|
+
if (auth?.access_token) {
|
|
1215
|
+
return Layer.getBankTransactions(apiUrl, auth?.access_token, {
|
|
1216
|
+
params: {
|
|
1217
|
+
businessId,
|
|
1218
|
+
cursor: nextCursor ?? "",
|
|
1219
|
+
categorized: filters?.categorizationStatus ? filters?.categorizationStatus === "categorized" /* categorized */ ? "true" : filters?.categorizationStatus === "review" /* review */ ? "false" : "" : "",
|
|
1220
|
+
direction: filters?.direction?.length === 1 ? filters.direction[0] === "CREDIT" /* CREDIT */ ? "INFLOW" : "OUTFLOW" : void 0,
|
|
1221
|
+
startDate: filters?.dateRange?.startDate?.toISOString() ?? void 0,
|
|
1222
|
+
endDate: filters?.dateRange?.endDate?.toISOString() ?? void 0
|
|
1223
|
+
}
|
|
1224
|
+
}).call(false);
|
|
1225
|
+
}
|
|
1226
|
+
return {};
|
|
1284
1227
|
},
|
|
1285
|
-
|
|
1228
|
+
{
|
|
1229
|
+
initialSize: 1,
|
|
1230
|
+
revalidateFirstPage: false
|
|
1231
|
+
}
|
|
1232
|
+
);
|
|
1233
|
+
const data = (0, import_react11.useMemo)(() => {
|
|
1234
|
+
if (rawResponseData && rawResponseData.length > 0) {
|
|
1235
|
+
return rawResponseData?.map((x) => x?.data).flat().filter((x) => !!x);
|
|
1236
|
+
}
|
|
1237
|
+
return void 0;
|
|
1238
|
+
}, [rawResponseData]);
|
|
1239
|
+
const lastMetadata = (0, import_react11.useMemo)(() => {
|
|
1240
|
+
if (rawResponseData && rawResponseData.length > 0) {
|
|
1241
|
+
return rawResponseData[rawResponseData.length - 1].meta;
|
|
1242
|
+
}
|
|
1243
|
+
return void 0;
|
|
1244
|
+
}, [rawResponseData]);
|
|
1245
|
+
const hasMore = (0, import_react11.useMemo)(() => {
|
|
1246
|
+
if (rawResponseData && rawResponseData.length > 0) {
|
|
1247
|
+
const lastElement = rawResponseData[rawResponseData.length - 1];
|
|
1248
|
+
return Boolean(
|
|
1249
|
+
lastElement.meta?.pagination?.cursor && lastElement.meta?.pagination?.has_more
|
|
1250
|
+
);
|
|
1251
|
+
}
|
|
1252
|
+
return false;
|
|
1253
|
+
}, [rawResponseData]);
|
|
1254
|
+
const accountsList = (0, import_react11.useMemo)(
|
|
1255
|
+
() => data ? collectAccounts(data) : [],
|
|
1256
|
+
[data]
|
|
1257
|
+
);
|
|
1258
|
+
(0, import_react11.useEffect)(() => {
|
|
1259
|
+
if (isLoading && loadingStatus === "initial") {
|
|
1260
|
+
setLoadingStatus("loading");
|
|
1261
|
+
return;
|
|
1262
|
+
}
|
|
1263
|
+
if (!isLoading && loadingStatus === "loading") {
|
|
1264
|
+
setLoadingStatus("complete");
|
|
1265
|
+
return;
|
|
1266
|
+
}
|
|
1267
|
+
}, [isLoading]);
|
|
1268
|
+
const activate = () => {
|
|
1269
|
+
setActive(true);
|
|
1286
1270
|
};
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
return { hsl, rgb, hex };
|
|
1293
|
-
};
|
|
1294
|
-
var hueToRgb = (p, q, t) => {
|
|
1295
|
-
if (t < 0)
|
|
1296
|
-
t += 1;
|
|
1297
|
-
if (t > 1)
|
|
1298
|
-
t -= 1;
|
|
1299
|
-
if (t < 1 / 6)
|
|
1300
|
-
return p + (q - p) * 6 * t;
|
|
1301
|
-
if (t < 1 / 2)
|
|
1302
|
-
return q;
|
|
1303
|
-
if (t < 2 / 3)
|
|
1304
|
-
return p + (q - p) * (2 / 3 - t) * 6;
|
|
1305
|
-
return p;
|
|
1306
|
-
};
|
|
1307
|
-
var hslToRgb = (hsl) => {
|
|
1308
|
-
let r, g, b;
|
|
1309
|
-
let l = hsl.l / 100;
|
|
1310
|
-
let s = hsl.s / 100;
|
|
1311
|
-
if (hsl.s === 0) {
|
|
1312
|
-
r = g = b = l;
|
|
1313
|
-
} else {
|
|
1314
|
-
const q = l < 0.5 ? l * (1 + s) : l + s - l * s;
|
|
1315
|
-
const p = 2 * l - q;
|
|
1316
|
-
r = hueToRgb(p, q, hsl.h + 1 / 3);
|
|
1317
|
-
g = hueToRgb(p, q, hsl.h);
|
|
1318
|
-
b = hueToRgb(p, q, hsl.h - 1 / 3);
|
|
1319
|
-
}
|
|
1320
|
-
return {
|
|
1321
|
-
r: Math.round(r * 255),
|
|
1322
|
-
g: Math.round(g * 255),
|
|
1323
|
-
b: Math.round(b * 255)
|
|
1271
|
+
const setFilters = (value) => {
|
|
1272
|
+
setTheFilters({
|
|
1273
|
+
...filters,
|
|
1274
|
+
...value ?? {}
|
|
1275
|
+
});
|
|
1324
1276
|
};
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1277
|
+
const filteredData = (0, import_react11.useMemo)(() => {
|
|
1278
|
+
let filtered = data;
|
|
1279
|
+
if (!filtered) {
|
|
1280
|
+
return;
|
|
1281
|
+
}
|
|
1282
|
+
if (filters?.amount?.min || filters?.amount?.max) {
|
|
1283
|
+
filtered = applyAmountFilter(filtered, filters.amount);
|
|
1284
|
+
}
|
|
1285
|
+
if (filters?.account) {
|
|
1286
|
+
filtered = applyAccountFilter(filtered, filters.account);
|
|
1287
|
+
}
|
|
1288
|
+
return filtered;
|
|
1289
|
+
}, [filters, data]);
|
|
1290
|
+
const categorize = (id, newCategory, notify) => {
|
|
1291
|
+
const foundBT = data?.find((x) => x.business_id === businessId && x.id === id);
|
|
1292
|
+
if (foundBT) {
|
|
1293
|
+
updateOneLocal({ ...foundBT, processing: true, error: void 0 });
|
|
1294
|
+
}
|
|
1295
|
+
return Layer.categorizeBankTransaction(apiUrl, auth.access_token, {
|
|
1296
|
+
params: { businessId, bankTransactionId: id },
|
|
1297
|
+
body: newCategory
|
|
1298
|
+
}).then(({ data: newBT, errors }) => {
|
|
1299
|
+
if (newBT) {
|
|
1300
|
+
newBT.recently_categorized = true;
|
|
1301
|
+
updateOneLocal(newBT);
|
|
1302
|
+
}
|
|
1303
|
+
if (errors) {
|
|
1304
|
+
console.error(errors);
|
|
1305
|
+
throw errors;
|
|
1306
|
+
}
|
|
1307
|
+
if (newBT?.recently_categorized === true && notify) {
|
|
1308
|
+
addToast({ content: "Transaction saved" });
|
|
1309
|
+
}
|
|
1310
|
+
}).catch((err) => {
|
|
1311
|
+
const newBT = data?.find(
|
|
1312
|
+
(x) => x.business_id === businessId && x.id === id
|
|
1313
|
+
);
|
|
1314
|
+
if (newBT) {
|
|
1315
|
+
updateOneLocal({
|
|
1316
|
+
...newBT,
|
|
1317
|
+
error: err.message,
|
|
1318
|
+
processing: false
|
|
1319
|
+
});
|
|
1320
|
+
}
|
|
1321
|
+
}).finally(() => {
|
|
1322
|
+
touch("BANK_TRANSACTIONS" /* BANK_TRANSACTIONS */);
|
|
1323
|
+
eventCallbacks?.onTransactionCategorized?.(id);
|
|
1324
|
+
});
|
|
1334
1325
|
};
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1326
|
+
const match = (id, matchId, notify) => {
|
|
1327
|
+
const foundBT = data?.find((x) => x.business_id === businessId && x.id === id);
|
|
1328
|
+
if (foundBT) {
|
|
1329
|
+
updateOneLocal({ ...foundBT, processing: true, error: void 0 });
|
|
1330
|
+
}
|
|
1331
|
+
return Layer.matchBankTransaction(apiUrl, auth.access_token, {
|
|
1332
|
+
params: { businessId, bankTransactionId: id },
|
|
1333
|
+
body: { match_id: matchId, type: "Confirm_Match" /* CONFIRM_MATCH */ }
|
|
1334
|
+
}).then(({ data: bt, errors }) => {
|
|
1335
|
+
const newBT = data?.find(
|
|
1336
|
+
(x) => x.business_id === businessId && x.id === id
|
|
1337
|
+
);
|
|
1338
|
+
if (newBT) {
|
|
1339
|
+
newBT.recently_categorized = true;
|
|
1340
|
+
newBT.match = bt;
|
|
1341
|
+
newBT.categorization_status = "MATCHED" /* MATCHED */;
|
|
1342
|
+
updateOneLocal(newBT);
|
|
1343
|
+
}
|
|
1344
|
+
if (errors) {
|
|
1345
|
+
console.error(errors);
|
|
1346
|
+
throw errors;
|
|
1347
|
+
}
|
|
1348
|
+
if (newBT?.recently_categorized === true && notify) {
|
|
1349
|
+
addToast({ content: "Transaction saved" });
|
|
1350
|
+
}
|
|
1351
|
+
}).catch((err) => {
|
|
1352
|
+
const newBT = data?.find(
|
|
1353
|
+
(x) => x.business_id === businessId && x.id === id
|
|
1354
|
+
);
|
|
1355
|
+
if (newBT) {
|
|
1356
|
+
updateOneLocal({
|
|
1357
|
+
...newBT,
|
|
1358
|
+
error: err.message,
|
|
1359
|
+
processing: false
|
|
1360
|
+
});
|
|
1361
|
+
}
|
|
1362
|
+
}).finally(() => {
|
|
1363
|
+
touch("BANK_TRANSACTIONS" /* BANK_TRANSACTIONS */);
|
|
1364
|
+
eventCallbacks?.onTransactionCategorized?.(id);
|
|
1365
|
+
});
|
|
1366
|
+
};
|
|
1367
|
+
const updateOneLocal = (newBankTransaction) => {
|
|
1368
|
+
const updatedData = rawResponseData?.map((page) => {
|
|
1359
1369
|
return {
|
|
1360
|
-
...
|
|
1361
|
-
|
|
1362
|
-
(
|
|
1370
|
+
...page,
|
|
1371
|
+
data: page.data?.map(
|
|
1372
|
+
(bt) => bt.id === newBankTransaction.id ? newBankTransaction : bt
|
|
1363
1373
|
)
|
|
1364
1374
|
};
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
...state,
|
|
1368
|
-
toasts: state.toasts.filter((t) => t.id !== action.payload.toast.id)
|
|
1369
|
-
};
|
|
1370
|
-
default:
|
|
1371
|
-
return state;
|
|
1372
|
-
}
|
|
1373
|
-
};
|
|
1374
|
-
var LayerEnvironment = {
|
|
1375
|
-
production: {
|
|
1376
|
-
url: "https://auth.layerfi.com/oauth2/token",
|
|
1377
|
-
scope: "https://api.layerfi.com/production",
|
|
1378
|
-
apiUrl: "https://api.layerfi.com"
|
|
1379
|
-
},
|
|
1380
|
-
sandbox: {
|
|
1381
|
-
url: "https://auth.layerfi.com/oauth2/token",
|
|
1382
|
-
scope: "https://sandbox.layerfi.com/sandbox",
|
|
1383
|
-
apiUrl: "https://sandbox.layerfi.com"
|
|
1384
|
-
},
|
|
1385
|
-
staging: {
|
|
1386
|
-
url: "https://auth.layerfi.com/oauth2/token",
|
|
1387
|
-
scope: "https://sandbox.layerfi.com/sandbox",
|
|
1388
|
-
apiUrl: "https://sandbox.layerfi.com"
|
|
1389
|
-
},
|
|
1390
|
-
internalStaging: {
|
|
1391
|
-
url: "https://auth.layerfi.com/oauth2/token",
|
|
1392
|
-
scope: "https://sandbox.layerfi.com/sandbox",
|
|
1393
|
-
apiUrl: "https://staging.layerfi.com"
|
|
1394
|
-
}
|
|
1395
|
-
};
|
|
1396
|
-
var LayerProvider = ({
|
|
1397
|
-
appId,
|
|
1398
|
-
appSecret,
|
|
1399
|
-
businessId,
|
|
1400
|
-
children,
|
|
1401
|
-
businessAccessToken,
|
|
1402
|
-
environment = "production",
|
|
1403
|
-
theme,
|
|
1404
|
-
usePlaidSandbox,
|
|
1405
|
-
onError,
|
|
1406
|
-
eventCallbacks
|
|
1407
|
-
}) => {
|
|
1408
|
-
const defaultSWRConfig = {
|
|
1409
|
-
revalidateInterval: 0,
|
|
1410
|
-
revalidateOnFocus: false,
|
|
1411
|
-
revalidateOnReconnect: false,
|
|
1412
|
-
revalidateIfStale: false
|
|
1375
|
+
});
|
|
1376
|
+
mutate(updatedData, { revalidate: false });
|
|
1413
1377
|
};
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
const
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
businessId,
|
|
1425
|
-
business: void 0,
|
|
1426
|
-
categories: [],
|
|
1427
|
-
apiUrl,
|
|
1428
|
-
theme,
|
|
1429
|
-
colors,
|
|
1430
|
-
usePlaidSandbox,
|
|
1431
|
-
onboardingStep: void 0,
|
|
1432
|
-
environment,
|
|
1433
|
-
toasts: [],
|
|
1434
|
-
eventCallbacks: {}
|
|
1435
|
-
});
|
|
1436
|
-
const { touch, syncTimestamps, read, readTimestamps, hasBeenTouched } = useDataSync();
|
|
1437
|
-
const { data: auth } = appId !== void 0 && appSecret !== void 0 ? (0, import_swr.default)(
|
|
1438
|
-
businessAccessToken === void 0 && appId !== void 0 && appSecret !== void 0 && (0, import_date_fns2.isBefore)(state.auth.expires_at, /* @__PURE__ */ new Date()) && "authenticate",
|
|
1439
|
-
Layer.authenticate({
|
|
1440
|
-
appId,
|
|
1441
|
-
appSecret,
|
|
1442
|
-
authenticationUrl: url,
|
|
1443
|
-
scope
|
|
1444
|
-
}),
|
|
1445
|
-
defaultSWRConfig
|
|
1446
|
-
) : { data: void 0 };
|
|
1447
|
-
(0, import_react12.useEffect)(() => {
|
|
1448
|
-
if (businessAccessToken) {
|
|
1449
|
-
dispatch({
|
|
1450
|
-
type: "LayerContext.setAuth" /* setAuth */,
|
|
1451
|
-
payload: {
|
|
1452
|
-
auth: {
|
|
1453
|
-
access_token: businessAccessToken,
|
|
1454
|
-
token_type: "Bearer",
|
|
1455
|
-
expires_in: 3600,
|
|
1456
|
-
expires_at: (0, import_date_fns2.add)(/* @__PURE__ */ new Date(), { seconds: 3600 })
|
|
1457
|
-
}
|
|
1458
|
-
}
|
|
1459
|
-
});
|
|
1460
|
-
} else if (auth?.access_token) {
|
|
1461
|
-
dispatch({
|
|
1462
|
-
type: "LayerContext.setAuth" /* setAuth */,
|
|
1463
|
-
payload: {
|
|
1464
|
-
auth: {
|
|
1465
|
-
...auth,
|
|
1466
|
-
expires_at: (0, import_date_fns2.add)(/* @__PURE__ */ new Date(), { seconds: auth.expires_in })
|
|
1467
|
-
}
|
|
1468
|
-
}
|
|
1378
|
+
const shouldHideAfterCategorize = (bankTransaction) => {
|
|
1379
|
+
return filters?.categorizationStatus === "review" /* review */;
|
|
1380
|
+
};
|
|
1381
|
+
const removeAfterCategorize = (bankTransaction) => {
|
|
1382
|
+
if (shouldHideAfterCategorize(bankTransaction)) {
|
|
1383
|
+
const updatedData = rawResponseData?.map((page) => {
|
|
1384
|
+
return {
|
|
1385
|
+
...page,
|
|
1386
|
+
data: page.data?.filter((bt) => bt.id !== bankTransaction.id)
|
|
1387
|
+
};
|
|
1469
1388
|
});
|
|
1389
|
+
mutate(updatedData, { revalidate: false });
|
|
1470
1390
|
}
|
|
1471
|
-
}
|
|
1472
|
-
const
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
...defaultSWRConfig,
|
|
1479
|
-
onSuccess: (response) => {
|
|
1480
|
-
if (response?.data?.categories?.length) {
|
|
1481
|
-
dispatch({
|
|
1482
|
-
type: "LayerContext.setCategories" /* setCategories */,
|
|
1483
|
-
payload: { categories: response.data.categories || [] }
|
|
1484
|
-
});
|
|
1485
|
-
}
|
|
1486
|
-
}
|
|
1391
|
+
};
|
|
1392
|
+
const refetch = () => {
|
|
1393
|
+
mutate();
|
|
1394
|
+
};
|
|
1395
|
+
const fetchMore = () => {
|
|
1396
|
+
if (hasMore) {
|
|
1397
|
+
setSize(size + 1);
|
|
1487
1398
|
}
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1399
|
+
};
|
|
1400
|
+
const getCacheKey = (txnFilters) => {
|
|
1401
|
+
return filtersSettingString(txnFilters);
|
|
1402
|
+
};
|
|
1403
|
+
(0, import_react11.useEffect)(() => {
|
|
1404
|
+
if (isLoading || isValidating) {
|
|
1405
|
+
read("BANK_TRANSACTIONS" /* BANK_TRANSACTIONS */, getCacheKey(filters));
|
|
1495
1406
|
}
|
|
1496
|
-
}, [
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
params: { businessId }
|
|
1501
|
-
}),
|
|
1502
|
-
{
|
|
1503
|
-
...defaultSWRConfig,
|
|
1504
|
-
onSuccess: (response) => {
|
|
1505
|
-
if (response?.data) {
|
|
1506
|
-
dispatch({
|
|
1507
|
-
type: "LayerContext.setBusiness" /* setBusiness */,
|
|
1508
|
-
payload: { business: response.data || [] }
|
|
1509
|
-
});
|
|
1510
|
-
}
|
|
1511
|
-
}
|
|
1407
|
+
}, [isLoading, isValidating]);
|
|
1408
|
+
(0, import_react11.useEffect)(() => {
|
|
1409
|
+
if (hasBeenTouched(getCacheKey(filters))) {
|
|
1410
|
+
refetch();
|
|
1512
1411
|
}
|
|
1412
|
+
}, [syncTimestamps, filters]);
|
|
1413
|
+
const { data: linkedAccounts, refetchAccounts } = useLinkedAccounts();
|
|
1414
|
+
const anyAccountSyncing = (0, import_react11.useMemo)(
|
|
1415
|
+
() => Boolean(linkedAccounts?.some((item) => item.is_syncing)),
|
|
1416
|
+
[linkedAccounts]
|
|
1513
1417
|
);
|
|
1514
|
-
(0,
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1418
|
+
const [pollIntervalMs, setPollIntervalMs] = (0, import_react11.useState)(INITIAL_POLL_INTERVAL_MS);
|
|
1419
|
+
const transactionsNotSynced = (0, import_react11.useMemo)(
|
|
1420
|
+
() => loadingStatus === "complete" && anyAccountSyncing && (!data || data?.length === 0),
|
|
1421
|
+
[data, anyAccountSyncing, loadingStatus]
|
|
1422
|
+
);
|
|
1423
|
+
let intervalId = void 0;
|
|
1424
|
+
const [refreshTrigger, setRefreshTrigger] = (0, import_react11.useState)(-1);
|
|
1425
|
+
(0, import_react11.useEffect)(() => {
|
|
1426
|
+
if (refreshTrigger !== -1) {
|
|
1427
|
+
refetch();
|
|
1428
|
+
refetchAccounts();
|
|
1520
1429
|
}
|
|
1521
|
-
}, [
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
});
|
|
1531
|
-
};
|
|
1532
|
-
const setLightColor = (color) => {
|
|
1533
|
-
setTheme({
|
|
1534
|
-
...state.theme ?? {},
|
|
1535
|
-
colors: {
|
|
1536
|
-
...state.theme?.colors ?? {},
|
|
1537
|
-
light: color
|
|
1538
|
-
}
|
|
1539
|
-
});
|
|
1540
|
-
};
|
|
1541
|
-
const setDarkColor = (color) => {
|
|
1542
|
-
setTheme({
|
|
1543
|
-
...state.theme ?? {},
|
|
1544
|
-
colors: {
|
|
1545
|
-
...state.theme?.colors ?? {},
|
|
1546
|
-
dark: color
|
|
1430
|
+
}, [refreshTrigger]);
|
|
1431
|
+
(0, import_react11.useEffect)(() => {
|
|
1432
|
+
if (anyAccountSyncing) {
|
|
1433
|
+
intervalId = setInterval(() => {
|
|
1434
|
+
setRefreshTrigger(Math.random());
|
|
1435
|
+
}, pollIntervalMs);
|
|
1436
|
+
} else {
|
|
1437
|
+
if (intervalId) {
|
|
1438
|
+
clearInterval(intervalId);
|
|
1547
1439
|
}
|
|
1548
|
-
}
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
...state.theme ?? {},
|
|
1553
|
-
colors: {
|
|
1554
|
-
...state.theme?.colors ?? {},
|
|
1555
|
-
text: color
|
|
1440
|
+
}
|
|
1441
|
+
return () => {
|
|
1442
|
+
if (intervalId) {
|
|
1443
|
+
clearInterval(intervalId);
|
|
1556
1444
|
}
|
|
1557
|
-
}
|
|
1558
|
-
};
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
dispatch({ type: "LayerContext.removeToast" /* removeToast */, payload: { toast } });
|
|
1564
|
-
};
|
|
1565
|
-
const setToastExit = (toast) => {
|
|
1566
|
-
dispatch({ type: "LayerContext.setToastExit" /* setToastExit */, payload: { toast } });
|
|
1567
|
-
};
|
|
1568
|
-
const addToast = (toast) => {
|
|
1569
|
-
const id = `${Date.now()}-${Math.random()}`;
|
|
1570
|
-
const newToast = { id, isExiting: false, ...toast };
|
|
1571
|
-
setToast(newToast);
|
|
1572
|
-
setTimeout(() => {
|
|
1573
|
-
removeToast(newToast);
|
|
1574
|
-
setTimeout(() => {
|
|
1575
|
-
setToastExit(newToast);
|
|
1576
|
-
}, 1e3);
|
|
1577
|
-
}, toast.duration || 2e3);
|
|
1578
|
-
};
|
|
1579
|
-
const setColors = (colors2) => setTheme({
|
|
1580
|
-
...state.theme ?? {},
|
|
1581
|
-
colors: colors2
|
|
1445
|
+
};
|
|
1446
|
+
}, [anyAccountSyncing, transactionsNotSynced, pollIntervalMs]);
|
|
1447
|
+
useTriggerOnChange(data, anyAccountSyncing, (newTransactionList) => {
|
|
1448
|
+
clearInterval(intervalId);
|
|
1449
|
+
setPollIntervalMs(POLL_INTERVAL_AFTER_TXNS_RECEIVED_MS);
|
|
1450
|
+
touch("BANK_TRANSACTIONS" /* BANK_TRANSACTIONS */);
|
|
1582
1451
|
});
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1452
|
+
return {
|
|
1453
|
+
data: filteredData,
|
|
1454
|
+
metadata: lastMetadata,
|
|
1455
|
+
loadingStatus,
|
|
1456
|
+
isLoading,
|
|
1457
|
+
isValidating,
|
|
1458
|
+
refetch,
|
|
1459
|
+
error: responseError,
|
|
1460
|
+
categorize,
|
|
1461
|
+
match,
|
|
1462
|
+
updateOneLocal,
|
|
1463
|
+
shouldHideAfterCategorize,
|
|
1464
|
+
removeAfterCategorize,
|
|
1465
|
+
filters,
|
|
1466
|
+
setFilters,
|
|
1467
|
+
accountsList,
|
|
1468
|
+
activate,
|
|
1469
|
+
display,
|
|
1470
|
+
fetchMore,
|
|
1471
|
+
hasMore
|
|
1588
1472
|
};
|
|
1589
|
-
const setOnboardingStep = (value) => dispatch({
|
|
1590
|
-
type: "LayerContext.setOnboardingStep" /* setOnboardingStep */,
|
|
1591
|
-
payload: { onboardingStep: value }
|
|
1592
|
-
});
|
|
1593
|
-
const drawerContextData = useDrawer();
|
|
1594
|
-
return /* @__PURE__ */ import_react12.default.createElement(import_swr.SWRConfig, { value: defaultSWRConfig }, /* @__PURE__ */ import_react12.default.createElement(
|
|
1595
|
-
LayerContext.Provider,
|
|
1596
|
-
{
|
|
1597
|
-
value: {
|
|
1598
|
-
...state,
|
|
1599
|
-
setTheme,
|
|
1600
|
-
getColor,
|
|
1601
|
-
setLightColor,
|
|
1602
|
-
setDarkColor,
|
|
1603
|
-
setTextColor,
|
|
1604
|
-
setColors,
|
|
1605
|
-
setOnboardingStep,
|
|
1606
|
-
addToast,
|
|
1607
|
-
removeToast,
|
|
1608
|
-
onError: errorHandler.onError,
|
|
1609
|
-
touch,
|
|
1610
|
-
read,
|
|
1611
|
-
syncTimestamps,
|
|
1612
|
-
readTimestamps,
|
|
1613
|
-
hasBeenTouched,
|
|
1614
|
-
eventCallbacks
|
|
1615
|
-
}
|
|
1616
|
-
},
|
|
1617
|
-
/* @__PURE__ */ import_react12.default.createElement(BankTransactionsProvider, null, /* @__PURE__ */ import_react12.default.createElement(DrawerContext.Provider, { value: drawerContextData }, children, /* @__PURE__ */ import_react12.default.createElement(GlobalWidgets, null)))
|
|
1618
|
-
));
|
|
1619
1473
|
};
|
|
1620
1474
|
|
|
1621
|
-
// src/
|
|
1622
|
-
var
|
|
1475
|
+
// src/providers/BankTransactionsProvider/BankTransactionsProvider.tsx
|
|
1476
|
+
var BankTransactionsProvider = ({
|
|
1477
|
+
children
|
|
1478
|
+
}) => {
|
|
1479
|
+
const bankTransactionsContextData = useBankTransactions();
|
|
1480
|
+
return /* @__PURE__ */ import_react12.default.createElement(BankTransactionsContext.Provider, { value: bankTransactionsContextData }, children);
|
|
1481
|
+
};
|
|
1623
1482
|
|
|
1624
|
-
// src/
|
|
1625
|
-
var
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
},
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
},
|
|
1642
|
-
unlinkAccount: () => {
|
|
1643
|
-
},
|
|
1644
|
-
denyAccount: () => {
|
|
1645
|
-
},
|
|
1646
|
-
confirmAccount: () => {
|
|
1647
|
-
},
|
|
1648
|
-
breakConnection: () => {
|
|
1483
|
+
// src/config/theme.ts
|
|
1484
|
+
var SHADES = {
|
|
1485
|
+
50: { s: 1, l: 98 },
|
|
1486
|
+
100: { s: 1, l: 96 },
|
|
1487
|
+
200: { s: 1, l: 94 },
|
|
1488
|
+
300: { s: 2, l: 92 },
|
|
1489
|
+
500: { s: 5, l: 53 },
|
|
1490
|
+
600: { s: 7, l: 40 },
|
|
1491
|
+
700: { s: 9, l: 27 },
|
|
1492
|
+
800: { s: 12, l: 20 },
|
|
1493
|
+
1e3: { s: 20, l: 7 }
|
|
1494
|
+
};
|
|
1495
|
+
var COLORS = {
|
|
1496
|
+
dark: {
|
|
1497
|
+
h: 0,
|
|
1498
|
+
s: 0,
|
|
1499
|
+
l: 7
|
|
1649
1500
|
},
|
|
1650
|
-
|
|
1501
|
+
light: {
|
|
1502
|
+
h: 0,
|
|
1503
|
+
s: 0,
|
|
1504
|
+
l: 100
|
|
1651
1505
|
}
|
|
1652
|
-
}
|
|
1653
|
-
|
|
1654
|
-
// src/providers/LinkedAccountsProvider/LinkedAccountsProvider.tsx
|
|
1655
|
-
var import_react15 = __toESM(require("react"));
|
|
1656
|
-
|
|
1657
|
-
// src/hooks/useLinkedAccounts/useLinkedAccounts.ts
|
|
1658
|
-
var import_react14 = require("react");
|
|
1659
|
-
var import_react_plaid_link = require("react-plaid-link");
|
|
1506
|
+
};
|
|
1660
1507
|
|
|
1661
|
-
// src/
|
|
1662
|
-
var
|
|
1663
|
-
{
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
external_account_source: "PLAID",
|
|
1667
|
-
external_account_name: "Citi Double Cash\xAE Card",
|
|
1668
|
-
mask: "1234",
|
|
1669
|
-
latest_balance_timestamp: {
|
|
1670
|
-
external_account_external_id: "0Br385JmgbTryJn8nEBnUb4A5ydv06U9Vbqqq",
|
|
1671
|
-
external_account_source: "PLAID",
|
|
1672
|
-
balance: 435121,
|
|
1673
|
-
at: "2024-04-03T13:00:00Z",
|
|
1674
|
-
created_at: "2024-04-06T22:47:59.715458Z"
|
|
1675
|
-
},
|
|
1676
|
-
current_ledger_balance: 373717,
|
|
1677
|
-
institution: {
|
|
1678
|
-
name: "Chase",
|
|
1679
|
-
logo: ""
|
|
1680
|
-
},
|
|
1681
|
-
connection_id: "0Br385JmgbTryJn8nEBnUb4A5ydv06U9Vbqqq",
|
|
1682
|
-
connection_external_id: "11111",
|
|
1683
|
-
connection_needs_repair_as_of: null,
|
|
1684
|
-
requires_user_confirmation_as_of: null,
|
|
1685
|
-
is_syncing: true
|
|
1686
|
-
},
|
|
1687
|
-
{
|
|
1688
|
-
id: "f98ec50a-c370-484d-a35b-d00207436075",
|
|
1689
|
-
external_account_external_id: "0Br385JmgbTryJn8nEBnUb4A5ydv06U9Vbqqq",
|
|
1690
|
-
external_account_source: "PLAID",
|
|
1691
|
-
external_account_name: "Citi Double Cash\xAE Card",
|
|
1692
|
-
mask: "1234",
|
|
1693
|
-
latest_balance_timestamp: {
|
|
1694
|
-
external_account_external_id: "0Br385JmgbTryJn8nEBnUb4A5ydv06U9Vbqqq",
|
|
1695
|
-
external_account_source: "PLAID",
|
|
1696
|
-
balance: 435121,
|
|
1697
|
-
at: "2024-04-03T13:00:00Z",
|
|
1698
|
-
created_at: "2024-04-06T16:44:35.715458Z"
|
|
1699
|
-
},
|
|
1700
|
-
current_ledger_balance: 373717,
|
|
1701
|
-
institution: {
|
|
1702
|
-
name: "Chase",
|
|
1703
|
-
logo: ""
|
|
1704
|
-
},
|
|
1705
|
-
connection_id: "0Br385JmgbTryJn8nEBnUb4A5ydv06U9Vbqqq",
|
|
1706
|
-
connection_external_id: "11111",
|
|
1707
|
-
connection_needs_repair_as_of: null,
|
|
1708
|
-
requires_user_confirmation_as_of: null,
|
|
1709
|
-
is_syncing: false
|
|
1710
|
-
},
|
|
1711
|
-
{
|
|
1712
|
-
id: "843f1748-fdaa-422d-a73d-2489a40c8dc7",
|
|
1713
|
-
external_account_external_id: "0Br385JmgbTryJn8nEBnUb4A5ydv06U9Vbqqq",
|
|
1714
|
-
external_account_source: "PLAID",
|
|
1715
|
-
external_account_name: "Citi Double Cash\xAE Card",
|
|
1716
|
-
mask: "1234",
|
|
1717
|
-
latest_balance_timestamp: {
|
|
1718
|
-
external_account_external_id: "0Br385JmgbTryJn8nEBnUb4A5ydv06U9Vbqqq",
|
|
1719
|
-
external_account_source: "PLAID",
|
|
1720
|
-
balance: 435121,
|
|
1721
|
-
at: "2024-04-03T13:00:00Z",
|
|
1722
|
-
created_at: "2024-04-06T16:44:35.715458Z"
|
|
1723
|
-
},
|
|
1724
|
-
current_ledger_balance: 373717,
|
|
1725
|
-
institution: {
|
|
1726
|
-
name: "Chase",
|
|
1727
|
-
logo: ""
|
|
1728
|
-
},
|
|
1729
|
-
connection_id: "0Br385JmgbTryJn8nEBnUb4A5ydv06U9Vbqqq",
|
|
1730
|
-
connection_external_id: "11111",
|
|
1731
|
-
connection_needs_repair_as_of: "2024-03-06T16:44:35.715458Z",
|
|
1732
|
-
requires_user_confirmation_as_of: null,
|
|
1733
|
-
is_syncing: false
|
|
1734
|
-
},
|
|
1735
|
-
{
|
|
1736
|
-
id: "8f430e29-e339-4d71-a08a-fce469c7a7c1",
|
|
1737
|
-
external_account_external_id: "0Br385JmgbTryJn8nEBnUb4A5ydv06U9Vbqqq",
|
|
1738
|
-
external_account_source: "PLAID",
|
|
1739
|
-
external_account_name: "Citi Double Cash\xAE Card",
|
|
1740
|
-
mask: "1234",
|
|
1741
|
-
latest_balance_timestamp: {
|
|
1742
|
-
external_account_external_id: "0Br385JmgbTryJn8nEBnUb4A5ydv06U9Vbqqq",
|
|
1743
|
-
external_account_source: "PLAID",
|
|
1744
|
-
balance: 435121,
|
|
1745
|
-
at: "2024-04-03T13:00:00Z",
|
|
1746
|
-
created_at: "2024-04-06T16:44:35.715458Z"
|
|
1747
|
-
},
|
|
1748
|
-
current_ledger_balance: 373717,
|
|
1749
|
-
institution: {
|
|
1750
|
-
name: "Chase",
|
|
1751
|
-
logo: ""
|
|
1752
|
-
},
|
|
1753
|
-
connection_id: "0Br385JmgbTryJn8nEBnUb4A5ydv06U9Vbqqq",
|
|
1754
|
-
connection_external_id: "11111",
|
|
1755
|
-
connection_needs_repair_as_of: null,
|
|
1756
|
-
requires_user_confirmation_as_of: "2024-03-06T16:44:35.715458Z",
|
|
1757
|
-
is_syncing: false
|
|
1508
|
+
// src/utils/colors.ts
|
|
1509
|
+
var parseStylesFromThemeConfig = (theme) => {
|
|
1510
|
+
let styles = {};
|
|
1511
|
+
if (!theme) {
|
|
1512
|
+
return styles;
|
|
1758
1513
|
}
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
hasBeenTouched
|
|
1775
|
-
} = useLayerContext();
|
|
1776
|
-
const [linkToken, setLinkToken] = (0, import_react14.useState)(null);
|
|
1777
|
-
const [loadingStatus, setLoadingStatus] = (0, import_react14.useState)("initial");
|
|
1778
|
-
const USE_PLAID_SANDBOX = usePlaidSandbox ?? true;
|
|
1779
|
-
const [linkMode, setLinkMode] = (0, import_react14.useState)("add");
|
|
1780
|
-
const queryKey = businessId && auth?.access_token && `linked-accounts-${businessId}`;
|
|
1781
|
-
const {
|
|
1782
|
-
data: responseData,
|
|
1783
|
-
isLoading,
|
|
1784
|
-
isValidating,
|
|
1785
|
-
error: responseError,
|
|
1786
|
-
mutate
|
|
1787
|
-
} = (0, import_swr2.default)(
|
|
1788
|
-
queryKey,
|
|
1789
|
-
Layer.getLinkedAccounts(apiUrl, auth?.access_token, {
|
|
1790
|
-
params: { businessId }
|
|
1791
|
-
})
|
|
1792
|
-
);
|
|
1793
|
-
(0, import_react14.useEffect)(() => {
|
|
1794
|
-
if (!isLoading && responseData?.data.external_accounts) {
|
|
1795
|
-
setLoadingStatus("complete");
|
|
1796
|
-
return;
|
|
1514
|
+
if (theme.colors) {
|
|
1515
|
+
const darkColor = parseColorFromTheme("dark", theme.colors.dark);
|
|
1516
|
+
const lightColor = parseColorFromTheme("light", theme.colors.light);
|
|
1517
|
+
const textColor = parseTextColorFromTheme(theme.colors.text);
|
|
1518
|
+
styles = { ...styles, ...darkColor, ...lightColor, ...textColor };
|
|
1519
|
+
}
|
|
1520
|
+
return styles;
|
|
1521
|
+
};
|
|
1522
|
+
var parseTextColorFromTheme = (color) => {
|
|
1523
|
+
if (!color) {
|
|
1524
|
+
return {};
|
|
1525
|
+
}
|
|
1526
|
+
try {
|
|
1527
|
+
if ("hex" in color) {
|
|
1528
|
+
return { "--text-color-primary": color.hex };
|
|
1797
1529
|
}
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1530
|
+
return {};
|
|
1531
|
+
} catch (_err) {
|
|
1532
|
+
return {};
|
|
1533
|
+
}
|
|
1534
|
+
};
|
|
1535
|
+
var parseColorFromTheme = (colorName, color) => {
|
|
1536
|
+
if (!color) {
|
|
1537
|
+
return {};
|
|
1538
|
+
}
|
|
1539
|
+
try {
|
|
1540
|
+
if ("h" in color && "s" in color && "l" in color) {
|
|
1541
|
+
return {
|
|
1542
|
+
[`--color-${colorName}-h`]: color.h,
|
|
1543
|
+
[`--color-${colorName}-s`]: color.s,
|
|
1544
|
+
[`--color-${colorName}-l`]: color.l
|
|
1545
|
+
};
|
|
1801
1546
|
}
|
|
1802
|
-
if (
|
|
1803
|
-
|
|
1547
|
+
if ("r" in color && "g" in color && "b" in color) {
|
|
1548
|
+
const { h, s, l } = rgbToHsl(color);
|
|
1549
|
+
return {
|
|
1550
|
+
[`--color-${colorName}-h`]: h,
|
|
1551
|
+
[`--color-${colorName}-s`]: `${s}%`,
|
|
1552
|
+
[`--color-${colorName}-l`]: `${l}%`
|
|
1553
|
+
};
|
|
1804
1554
|
}
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
}
|
|
1811
|
-
|
|
1812
|
-
|
|
1555
|
+
if ("hex" in color) {
|
|
1556
|
+
const rgb = hexToRgb(color.hex);
|
|
1557
|
+
if (!rgb) {
|
|
1558
|
+
return {};
|
|
1559
|
+
}
|
|
1560
|
+
const { h, s, l } = rgbToHsl({
|
|
1561
|
+
r: rgb.r.toString(),
|
|
1562
|
+
g: rgb.g.toString(),
|
|
1563
|
+
b: rgb.b.toString()
|
|
1564
|
+
});
|
|
1565
|
+
return {
|
|
1566
|
+
[`--color-${colorName}-h`]: h,
|
|
1567
|
+
[`--color-${colorName}-s`]: `${s}%`,
|
|
1568
|
+
[`--color-${colorName}-l`]: `${l}%`
|
|
1569
|
+
};
|
|
1813
1570
|
}
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1571
|
+
return {};
|
|
1572
|
+
} catch (_err) {
|
|
1573
|
+
return {};
|
|
1574
|
+
}
|
|
1575
|
+
};
|
|
1576
|
+
var parseColorFromThemeToHsl = (color) => {
|
|
1577
|
+
if (!color) {
|
|
1578
|
+
return;
|
|
1579
|
+
}
|
|
1580
|
+
try {
|
|
1581
|
+
if ("h" in color && "s" in color && "l" in color) {
|
|
1582
|
+
return {
|
|
1583
|
+
h: Number(color.h),
|
|
1584
|
+
s: Number(color.s),
|
|
1585
|
+
l: Number(color.l)
|
|
1586
|
+
};
|
|
1587
|
+
}
|
|
1588
|
+
if ("r" in color && "g" in color && "b" in color) {
|
|
1589
|
+
const { h, s, l } = rgbToHsl(color);
|
|
1590
|
+
return {
|
|
1591
|
+
h,
|
|
1592
|
+
s,
|
|
1593
|
+
l
|
|
1594
|
+
};
|
|
1823
1595
|
}
|
|
1596
|
+
if ("hex" in color) {
|
|
1597
|
+
const rgb = hexToRgb(color.hex);
|
|
1598
|
+
if (!rgb) {
|
|
1599
|
+
return void 0;
|
|
1600
|
+
}
|
|
1601
|
+
const { h, s, l } = rgbToHsl({
|
|
1602
|
+
r: rgb.r.toString(),
|
|
1603
|
+
g: rgb.g.toString(),
|
|
1604
|
+
b: rgb.b.toString()
|
|
1605
|
+
});
|
|
1606
|
+
return {
|
|
1607
|
+
h,
|
|
1608
|
+
s,
|
|
1609
|
+
l
|
|
1610
|
+
};
|
|
1611
|
+
}
|
|
1612
|
+
return;
|
|
1613
|
+
} catch (_err) {
|
|
1614
|
+
return;
|
|
1615
|
+
}
|
|
1616
|
+
};
|
|
1617
|
+
var rgbToHsl = (color) => {
|
|
1618
|
+
let r = Number(color.r);
|
|
1619
|
+
let g = Number(color.g);
|
|
1620
|
+
let b = Number(color.b);
|
|
1621
|
+
r /= 255;
|
|
1622
|
+
g /= 255;
|
|
1623
|
+
b /= 255;
|
|
1624
|
+
const l = Math.max(r, g, b);
|
|
1625
|
+
const s = l - Math.min(r, g, b);
|
|
1626
|
+
const h = s ? l === r ? (g - b) / s : l === g ? 2 + (b - r) / s : 4 + (r - g) / s : 0;
|
|
1627
|
+
return {
|
|
1628
|
+
h: 60 * h < 0 ? 60 * h + 360 : 60 * h,
|
|
1629
|
+
s: 100 * (s ? l <= 0.5 ? s / (2 * l - s) : s / (2 - (2 * l - s)) : 0),
|
|
1630
|
+
l: 100 * (2 * l - s) / 2
|
|
1824
1631
|
};
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1632
|
+
};
|
|
1633
|
+
var hexToRgb = (hex) => {
|
|
1634
|
+
const values = hex.replace(
|
|
1635
|
+
/^#?([a-f\d])([a-f\d])([a-f\d])$/i,
|
|
1636
|
+
(m, r, g, b) => "#" + r + r + g + g + b + b
|
|
1637
|
+
).substring(1).match(/.{2}/g)?.map((x) => parseInt(x, 16));
|
|
1638
|
+
if (!values) {
|
|
1639
|
+
return;
|
|
1640
|
+
}
|
|
1641
|
+
return {
|
|
1642
|
+
r: values[0],
|
|
1643
|
+
g: values[1],
|
|
1644
|
+
b: values[2]
|
|
1645
|
+
};
|
|
1646
|
+
};
|
|
1647
|
+
var buildColorsPalette = (theme) => {
|
|
1648
|
+
const darkColor = parseColorFromThemeToHsl(theme?.colors?.dark) ?? COLORS.dark;
|
|
1649
|
+
const lightColor = parseColorFromThemeToHsl(theme?.colors?.light) ?? COLORS.light;
|
|
1650
|
+
return {
|
|
1651
|
+
50: buildColorShade(50, darkColor),
|
|
1652
|
+
100: buildColorShade(100, darkColor),
|
|
1653
|
+
200: buildColorShade(200, darkColor),
|
|
1654
|
+
300: buildColorShade(300, darkColor),
|
|
1655
|
+
400: {
|
|
1656
|
+
hsl: lightColor,
|
|
1657
|
+
rgb: hslToRgb(lightColor),
|
|
1658
|
+
hex: hslToHex(lightColor)
|
|
1659
|
+
},
|
|
1660
|
+
500: buildColorShade(500, darkColor),
|
|
1661
|
+
600: buildColorShade(600, darkColor),
|
|
1662
|
+
700: buildColorShade(700, darkColor),
|
|
1663
|
+
800: buildColorShade(800, darkColor),
|
|
1664
|
+
900: {
|
|
1665
|
+
hsl: darkColor,
|
|
1666
|
+
rgb: hslToRgb(darkColor),
|
|
1667
|
+
hex: hslToHex(darkColor)
|
|
1668
|
+
},
|
|
1669
|
+
1e3: buildColorShade(1e3, darkColor)
|
|
1670
|
+
};
|
|
1671
|
+
};
|
|
1672
|
+
var buildColorShade = (shade, darkColorHsl) => {
|
|
1673
|
+
const hsl = { h: darkColorHsl.h, ...SHADES[shade] };
|
|
1674
|
+
const rgb = hslToRgb(hsl);
|
|
1675
|
+
const hex = hslToHex(hsl);
|
|
1676
|
+
return { hsl, rgb, hex };
|
|
1677
|
+
};
|
|
1678
|
+
var hueToRgb = (p, q, t) => {
|
|
1679
|
+
if (t < 0)
|
|
1680
|
+
t += 1;
|
|
1681
|
+
if (t > 1)
|
|
1682
|
+
t -= 1;
|
|
1683
|
+
if (t < 1 / 6)
|
|
1684
|
+
return p + (q - p) * 6 * t;
|
|
1685
|
+
if (t < 1 / 2)
|
|
1686
|
+
return q;
|
|
1687
|
+
if (t < 2 / 3)
|
|
1688
|
+
return p + (q - p) * (2 / 3 - t) * 6;
|
|
1689
|
+
return p;
|
|
1690
|
+
};
|
|
1691
|
+
var hslToRgb = (hsl) => {
|
|
1692
|
+
let r, g, b;
|
|
1693
|
+
let l = hsl.l / 100;
|
|
1694
|
+
let s = hsl.s / 100;
|
|
1695
|
+
if (hsl.s === 0) {
|
|
1696
|
+
r = g = b = l;
|
|
1697
|
+
} else {
|
|
1698
|
+
const q = l < 0.5 ? l * (1 + s) : l + s - l * s;
|
|
1699
|
+
const p = 2 * l - q;
|
|
1700
|
+
r = hueToRgb(p, q, hsl.h + 1 / 3);
|
|
1701
|
+
g = hueToRgb(p, q, hsl.h);
|
|
1702
|
+
b = hueToRgb(p, q, hsl.h - 1 / 3);
|
|
1703
|
+
}
|
|
1704
|
+
return {
|
|
1705
|
+
r: Math.round(r * 255),
|
|
1706
|
+
g: Math.round(g * 255),
|
|
1707
|
+
b: Math.round(b * 255)
|
|
1708
|
+
};
|
|
1709
|
+
};
|
|
1710
|
+
var hslToHex = (hsl) => {
|
|
1711
|
+
const l = hsl.l / 100;
|
|
1712
|
+
const s = hsl.s;
|
|
1713
|
+
const a = s * Math.min(l, 1 - l) / 100;
|
|
1714
|
+
const f = (n) => {
|
|
1715
|
+
const k = (n + hsl.h / 30) % 12;
|
|
1716
|
+
const color = l - a * Math.max(Math.min(k - 3, 9 - k, 1), -1);
|
|
1717
|
+
return Math.round(255 * color).toString(16).padStart(2, "0");
|
|
1718
|
+
};
|
|
1719
|
+
return `#${f(0)}${f(8)}${f(4)}`;
|
|
1720
|
+
};
|
|
1721
|
+
|
|
1722
|
+
// src/providers/LayerProvider/LayerProvider.tsx
|
|
1723
|
+
var import_date_fns = require("date-fns");
|
|
1724
|
+
var import_swr2 = __toESM(require("swr"));
|
|
1725
|
+
var reducer = (state, action) => {
|
|
1726
|
+
switch (action.type) {
|
|
1727
|
+
case "LayerContext.setAuth" /* setAuth */:
|
|
1728
|
+
case "LayerContext.setBusiness" /* setBusiness */:
|
|
1729
|
+
case "LayerContext.setCategories" /* setCategories */:
|
|
1730
|
+
case "LayerContext.setTheme" /* setTheme */:
|
|
1731
|
+
case "LayerContext.setOnboardingStep" /* setOnboardingStep */:
|
|
1732
|
+
case "LayerContext.setColors" /* setColors */:
|
|
1733
|
+
return { ...state, ...action.payload };
|
|
1734
|
+
case "LayerContext.setToast" /* setToast */:
|
|
1735
|
+
return {
|
|
1736
|
+
...state,
|
|
1737
|
+
toasts: [
|
|
1738
|
+
...state.toasts,
|
|
1739
|
+
{ ...action.payload.toast, isExiting: false }
|
|
1740
|
+
]
|
|
1741
|
+
};
|
|
1742
|
+
case "LayerContext.setToastExit" /* setToastExit */:
|
|
1743
|
+
return {
|
|
1744
|
+
...state,
|
|
1745
|
+
toasts: state.toasts.map(
|
|
1746
|
+
(toast) => toast.id === action.payload.toast.id ? { ...toast, isExiting: false } : toast
|
|
1747
|
+
)
|
|
1748
|
+
};
|
|
1749
|
+
case "LayerContext.removeToast" /* removeToast */:
|
|
1750
|
+
return {
|
|
1751
|
+
...state,
|
|
1752
|
+
toasts: state.toasts.filter((t) => t.id !== action.payload.toast.id)
|
|
1753
|
+
};
|
|
1754
|
+
default:
|
|
1755
|
+
return state;
|
|
1756
|
+
}
|
|
1757
|
+
};
|
|
1758
|
+
var LayerEnvironment = {
|
|
1759
|
+
production: {
|
|
1760
|
+
url: "https://auth.layerfi.com/oauth2/token",
|
|
1761
|
+
scope: "https://api.layerfi.com/production",
|
|
1762
|
+
apiUrl: "https://api.layerfi.com"
|
|
1763
|
+
},
|
|
1764
|
+
sandbox: {
|
|
1765
|
+
url: "https://auth.layerfi.com/oauth2/token",
|
|
1766
|
+
scope: "https://sandbox.layerfi.com/sandbox",
|
|
1767
|
+
apiUrl: "https://sandbox.layerfi.com"
|
|
1768
|
+
},
|
|
1769
|
+
staging: {
|
|
1770
|
+
url: "https://auth.layerfi.com/oauth2/token",
|
|
1771
|
+
scope: "https://sandbox.layerfi.com/sandbox",
|
|
1772
|
+
apiUrl: "https://sandbox.layerfi.com"
|
|
1773
|
+
},
|
|
1774
|
+
internalStaging: {
|
|
1775
|
+
url: "https://auth.layerfi.com/oauth2/token",
|
|
1776
|
+
scope: "https://sandbox.layerfi.com/sandbox",
|
|
1777
|
+
apiUrl: "https://staging.layerfi.com"
|
|
1778
|
+
}
|
|
1779
|
+
};
|
|
1780
|
+
var LayerProvider = ({
|
|
1781
|
+
appId,
|
|
1782
|
+
appSecret,
|
|
1783
|
+
businessId,
|
|
1784
|
+
children,
|
|
1785
|
+
businessAccessToken,
|
|
1786
|
+
environment = "production",
|
|
1787
|
+
theme,
|
|
1788
|
+
usePlaidSandbox,
|
|
1789
|
+
onError,
|
|
1790
|
+
eventCallbacks
|
|
1791
|
+
}) => {
|
|
1792
|
+
const defaultSWRConfig = {
|
|
1793
|
+
revalidateInterval: 0,
|
|
1794
|
+
revalidateOnFocus: false,
|
|
1795
|
+
revalidateOnReconnect: false,
|
|
1796
|
+
revalidateIfStale: false
|
|
1831
1797
|
};
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
refetchAccounts();
|
|
1842
|
-
setLinkMode("add");
|
|
1843
|
-
touch("LINKED_ACCOUNTS" /* LINKED_ACCOUNTS */);
|
|
1844
|
-
}
|
|
1798
|
+
errorHandler.setOnError(onError);
|
|
1799
|
+
const colors = buildColorsPalette(theme);
|
|
1800
|
+
const { url, scope, apiUrl } = LayerEnvironment[environment];
|
|
1801
|
+
const [state, dispatch] = (0, import_react13.useReducer)(reducer, {
|
|
1802
|
+
auth: {
|
|
1803
|
+
access_token: "",
|
|
1804
|
+
token_type: "",
|
|
1805
|
+
expires_in: 0,
|
|
1806
|
+
expires_at: new Date(2e3, 1, 1)
|
|
1845
1807
|
},
|
|
1846
|
-
|
|
1847
|
-
|
|
1808
|
+
businessId,
|
|
1809
|
+
business: void 0,
|
|
1810
|
+
categories: [],
|
|
1811
|
+
apiUrl,
|
|
1812
|
+
theme,
|
|
1813
|
+
colors,
|
|
1814
|
+
usePlaidSandbox,
|
|
1815
|
+
onboardingStep: void 0,
|
|
1816
|
+
environment,
|
|
1817
|
+
toasts: [],
|
|
1818
|
+
eventCallbacks: {}
|
|
1848
1819
|
});
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
await unlinkPlaidItem2(connectionExternalId);
|
|
1880
|
-
await refetchAccounts();
|
|
1881
|
-
} else {
|
|
1882
|
-
console.error(
|
|
1883
|
-
`Removing a connection with source ${source} not yet supported`
|
|
1884
|
-
);
|
|
1885
|
-
}
|
|
1886
|
-
};
|
|
1887
|
-
const unlinkAccount2 = async (source, accountId) => {
|
|
1888
|
-
DEBUG && console.log("unlinking account");
|
|
1889
|
-
if (source === "PLAID") {
|
|
1890
|
-
await Layer.unlinkAccount(apiUrl, auth?.access_token, {
|
|
1891
|
-
params: { businessId, accountId }
|
|
1820
|
+
const {
|
|
1821
|
+
touch,
|
|
1822
|
+
syncTimestamps,
|
|
1823
|
+
read,
|
|
1824
|
+
readTimestamps,
|
|
1825
|
+
hasBeenTouched,
|
|
1826
|
+
resetCaches
|
|
1827
|
+
} = useDataSync();
|
|
1828
|
+
const { data: auth } = appId !== void 0 && appSecret !== void 0 ? (0, import_swr2.default)(
|
|
1829
|
+
businessAccessToken === void 0 && appId !== void 0 && appSecret !== void 0 && (0, import_date_fns.isBefore)(state.auth.expires_at, /* @__PURE__ */ new Date()) && "authenticate",
|
|
1830
|
+
Layer.authenticate({
|
|
1831
|
+
appId,
|
|
1832
|
+
appSecret,
|
|
1833
|
+
authenticationUrl: url,
|
|
1834
|
+
scope
|
|
1835
|
+
}),
|
|
1836
|
+
defaultSWRConfig
|
|
1837
|
+
) : { data: void 0 };
|
|
1838
|
+
(0, import_react13.useEffect)(() => {
|
|
1839
|
+
if (businessAccessToken) {
|
|
1840
|
+
dispatch({
|
|
1841
|
+
type: "LayerContext.setAuth" /* setAuth */,
|
|
1842
|
+
payload: {
|
|
1843
|
+
auth: {
|
|
1844
|
+
access_token: businessAccessToken,
|
|
1845
|
+
token_type: "Bearer",
|
|
1846
|
+
expires_in: 3600,
|
|
1847
|
+
expires_at: (0, import_date_fns.add)(/* @__PURE__ */ new Date(), { seconds: 3600 })
|
|
1848
|
+
}
|
|
1849
|
+
}
|
|
1892
1850
|
});
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
const confirmAccount = async (source, accountId) => {
|
|
1902
|
-
DEBUG && console.log("confirming account");
|
|
1903
|
-
if (source === "PLAID") {
|
|
1904
|
-
await Layer.confirmConnection(apiUrl, auth?.access_token, {
|
|
1905
|
-
params: {
|
|
1906
|
-
businessId,
|
|
1907
|
-
accountId
|
|
1851
|
+
} else if (auth?.access_token) {
|
|
1852
|
+
dispatch({
|
|
1853
|
+
type: "LayerContext.setAuth" /* setAuth */,
|
|
1854
|
+
payload: {
|
|
1855
|
+
auth: {
|
|
1856
|
+
...auth,
|
|
1857
|
+
expires_at: (0, import_date_fns.add)(/* @__PURE__ */ new Date(), { seconds: auth.expires_in })
|
|
1858
|
+
}
|
|
1908
1859
|
}
|
|
1909
1860
|
});
|
|
1910
|
-
await refetchAccounts();
|
|
1911
|
-
touch("LINKED_ACCOUNTS" /* LINKED_ACCOUNTS */);
|
|
1912
|
-
} else {
|
|
1913
|
-
console.error(
|
|
1914
|
-
`Confirming an account with source ${source} not yet supported`
|
|
1915
|
-
);
|
|
1916
1861
|
}
|
|
1917
|
-
};
|
|
1918
|
-
const
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1862
|
+
}, [businessAccessToken, auth?.access_token]);
|
|
1863
|
+
const { data: categoriesData } = (0, import_swr2.default)(
|
|
1864
|
+
businessId && state.auth?.access_token && `categories-${businessId}`,
|
|
1865
|
+
Layer.getCategories(apiUrl, state.auth?.access_token, {
|
|
1866
|
+
params: { businessId }
|
|
1867
|
+
}),
|
|
1868
|
+
{
|
|
1869
|
+
...defaultSWRConfig,
|
|
1870
|
+
onSuccess: (response) => {
|
|
1871
|
+
if (response?.data?.categories?.length) {
|
|
1872
|
+
dispatch({
|
|
1873
|
+
type: "LayerContext.setCategories" /* setCategories */,
|
|
1874
|
+
payload: { categories: response.data.categories || [] }
|
|
1875
|
+
});
|
|
1925
1876
|
}
|
|
1877
|
+
}
|
|
1878
|
+
}
|
|
1879
|
+
);
|
|
1880
|
+
(0, import_react13.useEffect)(() => {
|
|
1881
|
+
if (categoriesData?.data?.categories?.length) {
|
|
1882
|
+
dispatch({
|
|
1883
|
+
type: "LayerContext.setCategories" /* setCategories */,
|
|
1884
|
+
payload: { categories: categoriesData.data.categories || [] }
|
|
1926
1885
|
});
|
|
1927
|
-
await refetchAccounts();
|
|
1928
|
-
touch("LINKED_ACCOUNTS" /* LINKED_ACCOUNTS */);
|
|
1929
|
-
} else {
|
|
1930
|
-
console.error(
|
|
1931
|
-
`Denying an account with source ${source} not yet supported`
|
|
1932
|
-
);
|
|
1933
1886
|
}
|
|
1934
|
-
};
|
|
1935
|
-
const
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1887
|
+
}, [categoriesData]);
|
|
1888
|
+
const { data: businessData } = (0, import_swr2.default)(
|
|
1889
|
+
businessId && state?.auth?.access_token && `business-${businessId}`,
|
|
1890
|
+
Layer.getBusiness(apiUrl, state?.auth?.access_token, {
|
|
1891
|
+
params: { businessId }
|
|
1892
|
+
}),
|
|
1893
|
+
{
|
|
1894
|
+
...defaultSWRConfig,
|
|
1895
|
+
onSuccess: (response) => {
|
|
1896
|
+
if (response?.data) {
|
|
1897
|
+
dispatch({
|
|
1898
|
+
type: "LayerContext.setBusiness" /* setBusiness */,
|
|
1899
|
+
payload: { business: response.data || [] }
|
|
1900
|
+
});
|
|
1942
1901
|
}
|
|
1902
|
+
}
|
|
1903
|
+
}
|
|
1904
|
+
);
|
|
1905
|
+
(0, import_react13.useEffect)(() => {
|
|
1906
|
+
if (businessData?.data) {
|
|
1907
|
+
dispatch({
|
|
1908
|
+
type: "LayerContext.setBusiness" /* setBusiness */,
|
|
1909
|
+
payload: { business: businessData.data || [] }
|
|
1943
1910
|
});
|
|
1944
|
-
await refetchAccounts();
|
|
1945
|
-
touch("LINKED_ACCOUNTS" /* LINKED_ACCOUNTS */);
|
|
1946
|
-
} else {
|
|
1947
|
-
console.error(
|
|
1948
|
-
`Breaking a sandbox connection with source ${source} not yet supported`
|
|
1949
|
-
);
|
|
1950
1911
|
}
|
|
1912
|
+
}, [businessData]);
|
|
1913
|
+
const setTheme = (theme2) => {
|
|
1914
|
+
dispatch({
|
|
1915
|
+
type: "LayerContext.setTheme" /* setTheme */,
|
|
1916
|
+
payload: { theme: theme2 }
|
|
1917
|
+
});
|
|
1918
|
+
dispatch({
|
|
1919
|
+
type: "LayerContext.setColors" /* setColors */,
|
|
1920
|
+
payload: { colors: buildColorsPalette(theme2) }
|
|
1921
|
+
});
|
|
1951
1922
|
};
|
|
1952
|
-
const
|
|
1953
|
-
|
|
1954
|
-
|
|
1923
|
+
const setLightColor = (color) => {
|
|
1924
|
+
setTheme({
|
|
1925
|
+
...state.theme ?? {},
|
|
1926
|
+
colors: {
|
|
1927
|
+
...state.theme?.colors ?? {},
|
|
1928
|
+
light: color
|
|
1929
|
+
}
|
|
1930
|
+
});
|
|
1955
1931
|
};
|
|
1956
|
-
const
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1932
|
+
const setDarkColor = (color) => {
|
|
1933
|
+
setTheme({
|
|
1934
|
+
...state.theme ?? {},
|
|
1935
|
+
colors: {
|
|
1936
|
+
...state.theme?.colors ?? {},
|
|
1937
|
+
dark: color
|
|
1938
|
+
}
|
|
1960
1939
|
});
|
|
1961
1940
|
};
|
|
1962
|
-
const
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1941
|
+
const setTextColor = (color) => {
|
|
1942
|
+
setTheme({
|
|
1943
|
+
...state.theme ?? {},
|
|
1944
|
+
colors: {
|
|
1945
|
+
...state.theme?.colors ?? {},
|
|
1946
|
+
text: color
|
|
1947
|
+
}
|
|
1966
1948
|
});
|
|
1967
1949
|
};
|
|
1968
|
-
const
|
|
1969
|
-
|
|
1970
|
-
await Layer.unlinkPlaidItem(apiUrl, auth?.access_token, {
|
|
1971
|
-
params: { businessId, plaidItemPlaidId }
|
|
1972
|
-
});
|
|
1973
|
-
await refetchAccounts();
|
|
1974
|
-
touch("LINKED_ACCOUNTS" /* LINKED_ACCOUNTS */);
|
|
1950
|
+
const setToast = (toast) => {
|
|
1951
|
+
dispatch({ type: "LayerContext.setToast" /* setToast */, payload: { toast } });
|
|
1975
1952
|
};
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1953
|
+
const removeToast = (toast) => {
|
|
1954
|
+
dispatch({ type: "LayerContext.removeToast" /* removeToast */, payload: { toast } });
|
|
1955
|
+
};
|
|
1956
|
+
const setToastExit = (toast) => {
|
|
1957
|
+
dispatch({ type: "LayerContext.setToastExit" /* setToastExit */, payload: { toast } });
|
|
1958
|
+
};
|
|
1959
|
+
const addToast = (toast) => {
|
|
1960
|
+
const id = `${Date.now()}-${Math.random()}`;
|
|
1961
|
+
const newToast = { id, isExiting: false, ...toast };
|
|
1962
|
+
setToast(newToast);
|
|
1963
|
+
setTimeout(() => {
|
|
1964
|
+
removeToast(newToast);
|
|
1965
|
+
setTimeout(() => {
|
|
1966
|
+
setToastExit(newToast);
|
|
1967
|
+
}, 1e3);
|
|
1968
|
+
}, toast.duration || 2e3);
|
|
1969
|
+
};
|
|
1970
|
+
const setColors = (colors2) => setTheme({
|
|
1971
|
+
...state.theme ?? {},
|
|
1972
|
+
colors: colors2
|
|
1973
|
+
});
|
|
1974
|
+
const getColor = (shade) => {
|
|
1975
|
+
if (state.colors && shade in state.colors) {
|
|
1976
|
+
return state.colors[shade];
|
|
1984
1977
|
}
|
|
1985
|
-
|
|
1986
|
-
return {
|
|
1987
|
-
data: USE_MOCK_RESPONSE_DATA ? mockResponseData.data : responseData?.data.external_accounts,
|
|
1988
|
-
isLoading,
|
|
1989
|
-
loadingStatus,
|
|
1990
|
-
isValidating,
|
|
1991
|
-
error: responseError,
|
|
1992
|
-
addConnection,
|
|
1993
|
-
removeConnection,
|
|
1994
|
-
repairConnection,
|
|
1995
|
-
refetchAccounts,
|
|
1996
|
-
unlinkAccount: unlinkAccount2,
|
|
1997
|
-
confirmAccount,
|
|
1998
|
-
denyAccount,
|
|
1999
|
-
breakConnection,
|
|
2000
|
-
syncAccounts,
|
|
2001
|
-
updateConnectionStatus: updateConnectionStatus2
|
|
1978
|
+
return;
|
|
2002
1979
|
};
|
|
1980
|
+
const setOnboardingStep = (value) => dispatch({
|
|
1981
|
+
type: "LayerContext.setOnboardingStep" /* setOnboardingStep */,
|
|
1982
|
+
payload: { onboardingStep: value }
|
|
1983
|
+
});
|
|
1984
|
+
const drawerContextData = useDrawer();
|
|
1985
|
+
return /* @__PURE__ */ import_react13.default.createElement(import_swr2.SWRConfig, { value: defaultSWRConfig }, /* @__PURE__ */ import_react13.default.createElement(
|
|
1986
|
+
LayerContext.Provider,
|
|
1987
|
+
{
|
|
1988
|
+
value: {
|
|
1989
|
+
...state,
|
|
1990
|
+
setTheme,
|
|
1991
|
+
getColor,
|
|
1992
|
+
setLightColor,
|
|
1993
|
+
setDarkColor,
|
|
1994
|
+
setTextColor,
|
|
1995
|
+
setColors,
|
|
1996
|
+
setOnboardingStep,
|
|
1997
|
+
addToast,
|
|
1998
|
+
removeToast,
|
|
1999
|
+
onError: errorHandler.onError,
|
|
2000
|
+
touch,
|
|
2001
|
+
read,
|
|
2002
|
+
syncTimestamps,
|
|
2003
|
+
readTimestamps,
|
|
2004
|
+
expireDataCaches: resetCaches,
|
|
2005
|
+
hasBeenTouched,
|
|
2006
|
+
eventCallbacks
|
|
2007
|
+
}
|
|
2008
|
+
},
|
|
2009
|
+
/* @__PURE__ */ import_react13.default.createElement(BankTransactionsProvider, null, /* @__PURE__ */ import_react13.default.createElement(DrawerContext.Provider, { value: drawerContextData }, children, /* @__PURE__ */ import_react13.default.createElement(GlobalWidgets, null)))
|
|
2010
|
+
));
|
|
2003
2011
|
};
|
|
2004
2012
|
|
|
2013
|
+
// src/components/Onboarding/Onboarding.tsx
|
|
2014
|
+
var import_react39 = __toESM(require("react"));
|
|
2015
|
+
|
|
2016
|
+
// src/contexts/LinkedAccountsContext/LinkedAccountsContext.ts
|
|
2017
|
+
var import_react14 = require("react");
|
|
2018
|
+
var LinkedAccountsContext = (0, import_react14.createContext)({
|
|
2019
|
+
data: void 0,
|
|
2020
|
+
isLoading: false,
|
|
2021
|
+
loadingStatus: "initial",
|
|
2022
|
+
isValidating: false,
|
|
2023
|
+
error: void 0,
|
|
2024
|
+
updateConnectionStatus: () => {
|
|
2025
|
+
},
|
|
2026
|
+
addConnection: () => {
|
|
2027
|
+
},
|
|
2028
|
+
removeConnection: () => {
|
|
2029
|
+
},
|
|
2030
|
+
repairConnection: () => {
|
|
2031
|
+
},
|
|
2032
|
+
refetchAccounts: () => {
|
|
2033
|
+
},
|
|
2034
|
+
unlinkAccount: () => {
|
|
2035
|
+
},
|
|
2036
|
+
denyAccount: () => {
|
|
2037
|
+
},
|
|
2038
|
+
confirmAccount: () => {
|
|
2039
|
+
},
|
|
2040
|
+
breakConnection: () => {
|
|
2041
|
+
},
|
|
2042
|
+
syncAccounts: () => {
|
|
2043
|
+
}
|
|
2044
|
+
});
|
|
2045
|
+
|
|
2005
2046
|
// src/providers/LinkedAccountsProvider/LinkedAccountsProvider.tsx
|
|
2047
|
+
var import_react15 = __toESM(require("react"));
|
|
2006
2048
|
var LinkedAccountsProvider = ({
|
|
2007
2049
|
children
|
|
2008
2050
|
}) => {
|
|
@@ -2276,8 +2318,32 @@ var Sunrise = ({ size = 12, ...props }) => /* @__PURE__ */ React16.createElement
|
|
|
2276
2318
|
);
|
|
2277
2319
|
var Sunrise_default = Sunrise;
|
|
2278
2320
|
|
|
2321
|
+
// src/components/BankTransactions/constants.ts
|
|
2322
|
+
var CategorizedCategories = [
|
|
2323
|
+
"CATEGORIZED" /* CATEGORIZED */,
|
|
2324
|
+
"JOURNALING" /* JOURNALING */,
|
|
2325
|
+
"SPLIT" /* SPLIT */,
|
|
2326
|
+
"MATCHED" /* MATCHED */
|
|
2327
|
+
];
|
|
2328
|
+
var ReviewCategories = [
|
|
2329
|
+
"READY_FOR_INPUT" /* READY_FOR_INPUT */,
|
|
2330
|
+
"LAYER_REVIEW" /* LAYER_REVIEW */
|
|
2331
|
+
];
|
|
2332
|
+
|
|
2333
|
+
// src/components/BankTransactions/utils.ts
|
|
2334
|
+
var filterVisibility = (scope, bankTransaction) => {
|
|
2335
|
+
const categorized = CategorizedCategories.includes(
|
|
2336
|
+
bankTransaction.categorization_status
|
|
2337
|
+
);
|
|
2338
|
+
const inReview = ReviewCategories.includes(
|
|
2339
|
+
bankTransaction.categorization_status
|
|
2340
|
+
);
|
|
2341
|
+
return scope === "all" /* all */ || scope === "review" /* review */ && inReview || scope === "categorized" /* categorized */ && categorized;
|
|
2342
|
+
};
|
|
2343
|
+
var isCategorized = (bankTransaction) => CategorizedCategories.includes(bankTransaction.categorization_status);
|
|
2344
|
+
|
|
2279
2345
|
// src/utils/bankTransactions.ts
|
|
2280
|
-
var
|
|
2346
|
+
var import_date_fns2 = require("date-fns");
|
|
2281
2347
|
var hasMatch = (bankTransaction) => {
|
|
2282
2348
|
return Boolean(
|
|
2283
2349
|
bankTransaction?.suggested_matches && bankTransaction?.suggested_matches?.length > 0 || bankTransaction?.match
|
|
@@ -2305,7 +2371,7 @@ var countTransactionsToReview = ({
|
|
|
2305
2371
|
};
|
|
2306
2372
|
return transactions.filter((tx) => {
|
|
2307
2373
|
try {
|
|
2308
|
-
return filterVisibility("review" /* review */, tx) && (0,
|
|
2374
|
+
return filterVisibility("review" /* review */, tx) && (0, import_date_fns2.isWithinInterval)((0, import_date_fns2.parseISO)(tx.date), dateRangeInterval);
|
|
2309
2375
|
} catch (_err) {
|
|
2310
2376
|
return false;
|
|
2311
2377
|
}
|
|
@@ -4734,7 +4800,7 @@ var CategorySelectDrawerContent = ({
|
|
|
4734
4800
|
|
|
4735
4801
|
// src/components/CategorySelect/CategorySelect.tsx
|
|
4736
4802
|
var import_classnames23 = __toESM(require("classnames"));
|
|
4737
|
-
var
|
|
4803
|
+
var import_date_fns3 = require("date-fns");
|
|
4738
4804
|
var mapCategoryToOption2 = (category) => {
|
|
4739
4805
|
return {
|
|
4740
4806
|
type: "category" /* CATEGORY */,
|
|
@@ -4786,7 +4852,7 @@ var Option2 = (props) => {
|
|
|
4786
4852
|
...props,
|
|
4787
4853
|
className: `${props.className} Layer__select__option-content__match`
|
|
4788
4854
|
},
|
|
4789
|
-
/* @__PURE__ */ import_react54.default.createElement("div", { className: "Layer__select__option-content__match__main-row" }, /* @__PURE__ */ import_react54.default.createElement("span", { className: "Layer__select__option-content__match__date" }, props.data.payload.date && (0,
|
|
4855
|
+
/* @__PURE__ */ import_react54.default.createElement("div", { className: "Layer__select__option-content__match__main-row" }, /* @__PURE__ */ import_react54.default.createElement("span", { className: "Layer__select__option-content__match__date" }, props.data.payload.date && (0, import_date_fns3.format)((0, import_date_fns3.parseISO)(props.data.payload.date), DATE_FORMAT)), /* @__PURE__ */ import_react54.default.createElement("span", { className: "Layer__select__option-content__match__description" }, props.data.payload.display_name)),
|
|
4790
4856
|
/* @__PURE__ */ import_react54.default.createElement("div", { className: "Layer__select__option-content__match__amount-row" }, /* @__PURE__ */ import_react54.default.createElement("span", { className: "Layer__select__option-content__match__amount" }, "$", centsToDollars(props.data.payload.amount)))
|
|
4791
4857
|
);
|
|
4792
4858
|
}
|
|
@@ -5225,7 +5291,7 @@ var import_react61 = __toESM(require("react"));
|
|
|
5225
5291
|
|
|
5226
5292
|
// src/components/BankTransactionRow/MatchBadge.tsx
|
|
5227
5293
|
var import_react60 = __toESM(require("react"));
|
|
5228
|
-
var
|
|
5294
|
+
var import_date_fns4 = require("date-fns");
|
|
5229
5295
|
var MatchBadge = ({
|
|
5230
5296
|
bankTransaction,
|
|
5231
5297
|
classNamePrefix,
|
|
@@ -5238,7 +5304,7 @@ var MatchBadge = ({
|
|
|
5238
5304
|
Badge,
|
|
5239
5305
|
{
|
|
5240
5306
|
icon: /* @__PURE__ */ import_react60.default.createElement(MinimizeTwo_default, { size: 11 }),
|
|
5241
|
-
tooltip: /* @__PURE__ */ import_react60.default.createElement("span", { className: `${classNamePrefix}__match-tooltip` }, /* @__PURE__ */ import_react60.default.createElement("div", { className: `${classNamePrefix}__match-tooltip__date` }, (0,
|
|
5307
|
+
tooltip: /* @__PURE__ */ import_react60.default.createElement("span", { className: `${classNamePrefix}__match-tooltip` }, /* @__PURE__ */ import_react60.default.createElement("div", { className: `${classNamePrefix}__match-tooltip__date` }, (0, import_date_fns4.format)((0, import_date_fns4.parseISO)(date), dateFormat)), /* @__PURE__ */ import_react60.default.createElement("div", { className: `${classNamePrefix}__match-tooltip__description` }, bankTransaction.match?.details?.description ?? ""), /* @__PURE__ */ import_react60.default.createElement("div", { className: `${classNamePrefix}__match-tooltip__amount` }, "$", centsToDollars(amount)))
|
|
5242
5308
|
},
|
|
5243
5309
|
text
|
|
5244
5310
|
);
|
|
@@ -5248,7 +5314,7 @@ var MatchBadge = ({
|
|
|
5248
5314
|
|
|
5249
5315
|
// src/components/MatchForm/MatchForm.tsx
|
|
5250
5316
|
var import_classnames28 = __toESM(require("classnames"));
|
|
5251
|
-
var
|
|
5317
|
+
var import_date_fns5 = require("date-fns");
|
|
5252
5318
|
var MatchForm = ({
|
|
5253
5319
|
classNamePrefix,
|
|
5254
5320
|
bankTransaction,
|
|
@@ -5287,7 +5353,7 @@ var MatchForm = ({
|
|
|
5287
5353
|
{
|
|
5288
5354
|
className: `Layer__nowrap ${classNamePrefix}__match-table__date`
|
|
5289
5355
|
},
|
|
5290
|
-
/* @__PURE__ */ import_react61.default.createElement("span", null, (0,
|
|
5356
|
+
/* @__PURE__ */ import_react61.default.createElement("span", null, (0, import_date_fns5.format)((0, import_date_fns5.parseISO)(match.details.date), DATE_FORMAT)),
|
|
5291
5357
|
/* @__PURE__ */ import_react61.default.createElement("span", { className: "amount-next-to-date" }, "$", centsToDollars(match.details.amount))
|
|
5292
5358
|
),
|
|
5293
5359
|
/* @__PURE__ */ import_react61.default.createElement("div", { className: `${classNamePrefix}__match-table__desc` }, /* @__PURE__ */ import_react61.default.createElement(
|
|
@@ -5330,7 +5396,7 @@ var MatchForm = ({
|
|
|
5330
5396
|
// src/components/MatchForm/MatchFormMobile.tsx
|
|
5331
5397
|
var import_react62 = __toESM(require("react"));
|
|
5332
5398
|
var import_classnames29 = __toESM(require("classnames"));
|
|
5333
|
-
var
|
|
5399
|
+
var import_date_fns6 = require("date-fns");
|
|
5334
5400
|
var MatchFormMobile = ({
|
|
5335
5401
|
classNamePrefix,
|
|
5336
5402
|
bankTransaction,
|
|
@@ -5377,7 +5443,7 @@ var MatchFormMobile = ({
|
|
|
5377
5443
|
size: "sm" /* sm */,
|
|
5378
5444
|
as: "span"
|
|
5379
5445
|
},
|
|
5380
|
-
(0,
|
|
5446
|
+
(0, import_date_fns6.format)((0, import_date_fns6.parseISO)(match.details.date), MONTH_DAY_FORMAT)
|
|
5381
5447
|
))),
|
|
5382
5448
|
/* @__PURE__ */ import_react62.default.createElement("div", { className: `${classNamePrefix}__match-item__col-status` }, selectedMatchId && selectedMatchId === match.id ? /* @__PURE__ */ import_react62.default.createElement(
|
|
5383
5449
|
Check_default,
|
|
@@ -5659,7 +5725,7 @@ var import_classnames32 = __toESM(require("classnames"));
|
|
|
5659
5725
|
var isAlreadyMatched2 = (bankTransaction) => {
|
|
5660
5726
|
if (bankTransaction?.match) {
|
|
5661
5727
|
const foundMatch = bankTransaction.suggested_matches?.find(
|
|
5662
|
-
(x) => x.details.id === bankTransaction?.match?.details.id
|
|
5728
|
+
(x) => x.details.id === bankTransaction?.match?.details.id || x.details.id === bankTransaction?.match?.bank_transaction.id
|
|
5663
5729
|
);
|
|
5664
5730
|
return foundMatch?.id;
|
|
5665
5731
|
}
|
|
@@ -5697,7 +5763,7 @@ var ExpandedBankTransactionRow = (0, import_react66.forwardRef)(
|
|
|
5697
5763
|
bankTransaction.category ? "categorize" /* categorize */ : hasMatch(bankTransaction) ? "match" /* match */ : "categorize" /* categorize */
|
|
5698
5764
|
);
|
|
5699
5765
|
const [selectedMatchId, setSelectedMatchId] = (0, import_react66.useState)(
|
|
5700
|
-
isAlreadyMatched2(bankTransaction)
|
|
5766
|
+
isAlreadyMatched2(bankTransaction) ?? bankTransaction?.suggested_matches?.[0]?.id
|
|
5701
5767
|
);
|
|
5702
5768
|
const [matchFormError, setMatchFormError] = (0, import_react66.useState)();
|
|
5703
5769
|
const [splitFormError, setSplitFormError] = (0, import_react66.useState)();
|
|
@@ -5802,7 +5868,6 @@ var ExpandedBankTransactionRow = (0, import_react66.forwardRef)(
|
|
|
5802
5868
|
setSplitFormError(void 0);
|
|
5803
5869
|
};
|
|
5804
5870
|
const save = async () => {
|
|
5805
|
-
const endpoint = `/v1/businesses/${businessId}/bank-transactions/${bankTransaction.id}/metadata`;
|
|
5806
5871
|
if (showDescriptions && memoText != void 0) {
|
|
5807
5872
|
const result = await Layer.updateBankTransactionMetadata(
|
|
5808
5873
|
apiUrl,
|
|
@@ -5821,9 +5886,12 @@ var ExpandedBankTransactionRow = (0, import_react66.forwardRef)(
|
|
|
5821
5886
|
if (purpose === "match" /* match */) {
|
|
5822
5887
|
if (!selectedMatchId) {
|
|
5823
5888
|
setMatchFormError("Select an option to match the transaction");
|
|
5889
|
+
return;
|
|
5824
5890
|
} else if (selectedMatchId && selectedMatchId !== isAlreadyMatched2(bankTransaction)) {
|
|
5825
|
-
onMatchSubmit(selectedMatchId);
|
|
5891
|
+
await onMatchSubmit(selectedMatchId);
|
|
5892
|
+
return;
|
|
5826
5893
|
}
|
|
5894
|
+
close();
|
|
5827
5895
|
return;
|
|
5828
5896
|
}
|
|
5829
5897
|
if (!validateSplit(rowState)) {
|
|
@@ -6174,7 +6242,7 @@ var SplitTooltipDetails = ({
|
|
|
6174
6242
|
|
|
6175
6243
|
// src/components/BankTransactionRow/BankTransactionRow.tsx
|
|
6176
6244
|
var import_classnames33 = __toESM(require("classnames"));
|
|
6177
|
-
var
|
|
6245
|
+
var import_date_fns7 = require("date-fns");
|
|
6178
6246
|
var extractDescriptionForSplit = (category) => {
|
|
6179
6247
|
if (!category.entries) {
|
|
6180
6248
|
return "";
|
|
@@ -6209,9 +6277,9 @@ var BankTransactionRow = ({
|
|
|
6209
6277
|
const expandedRowRef = (0, import_react68.useRef)(null);
|
|
6210
6278
|
const [showRetry, setShowRetry] = (0, import_react68.useState)(false);
|
|
6211
6279
|
const {
|
|
6212
|
-
filters,
|
|
6213
6280
|
categorize: categorizeBankTransaction2,
|
|
6214
|
-
match: matchBankTransaction2
|
|
6281
|
+
match: matchBankTransaction2,
|
|
6282
|
+
shouldHideAfterCategorize
|
|
6215
6283
|
} = useBankTransactionsContext();
|
|
6216
6284
|
const [selectedCategory, setSelectedCategory] = (0, import_react68.useState)(
|
|
6217
6285
|
getDefaultSelectedCategory(bankTransaction)
|
|
@@ -6249,7 +6317,7 @@ var BankTransactionRow = ({
|
|
|
6249
6317
|
}
|
|
6250
6318
|
}, [bankTransaction.error]);
|
|
6251
6319
|
(0, import_react68.useEffect)(() => {
|
|
6252
|
-
if (editable && bankTransaction.recently_categorized) {
|
|
6320
|
+
if (editable && bankTransaction.recently_categorized && shouldHideAfterCategorize(bankTransaction)) {
|
|
6253
6321
|
setTimeout(() => {
|
|
6254
6322
|
removeTransaction(bankTransaction);
|
|
6255
6323
|
}, 300);
|
|
@@ -6282,7 +6350,7 @@ var BankTransactionRow = ({
|
|
|
6282
6350
|
const openClassName = open ? `${className}--expanded` : "";
|
|
6283
6351
|
const rowClassName = (0, import_classnames33.default)(
|
|
6284
6352
|
className,
|
|
6285
|
-
bankTransaction.recently_categorized && editable ? "Layer__bank-transaction-row--removing" : "",
|
|
6353
|
+
bankTransaction.recently_categorized && editable && shouldHideAfterCategorize(bankTransaction) ? "Layer__bank-transaction-row--removing" : "",
|
|
6286
6354
|
open ? openClassName : "",
|
|
6287
6355
|
initialLoad ? "initial-load" : "",
|
|
6288
6356
|
showComponent ? "show" : ""
|
|
@@ -6293,7 +6361,7 @@ var BankTransactionRow = ({
|
|
|
6293
6361
|
className: "Layer__table-cell Layer__bank-transaction-table__date-col",
|
|
6294
6362
|
...openRow
|
|
6295
6363
|
},
|
|
6296
|
-
/* @__PURE__ */ import_react68.default.createElement("span", { className: "Layer__table-cell-content" }, (0,
|
|
6364
|
+
/* @__PURE__ */ import_react68.default.createElement("span", { className: "Layer__table-cell-content" }, (0, import_date_fns7.format)((0, import_date_fns7.parseISO)(bankTransaction.date), dateFormat))
|
|
6297
6365
|
), /* @__PURE__ */ import_react68.default.createElement(
|
|
6298
6366
|
"td",
|
|
6299
6367
|
{
|
|
@@ -6382,8 +6450,8 @@ var BankTransactionRow = ({
|
|
|
6382
6450
|
bankTransaction,
|
|
6383
6451
|
dateFormat
|
|
6384
6452
|
}
|
|
6385
|
-
), /* @__PURE__ */ import_react68.default.createElement("span", { className: `${className}__category-text__text` }, `${(0,
|
|
6386
|
-
(0,
|
|
6453
|
+
), /* @__PURE__ */ import_react68.default.createElement("span", { className: `${className}__category-text__text` }, `${(0, import_date_fns7.format)(
|
|
6454
|
+
(0, import_date_fns7.parseISO)(bankTransaction.match.bank_transaction.date),
|
|
6387
6455
|
dateFormat
|
|
6388
6456
|
)}, ${bankTransaction.match?.details?.description}`)), bankTransaction?.categorization_status !== "MATCHED" /* MATCHED */ && bankTransaction?.categorization_status !== "SPLIT" /* SPLIT */ && /* @__PURE__ */ import_react68.default.createElement("span", { className: `${className}__category-text__text` }, bankTransaction?.category?.display_name)) : null,
|
|
6389
6457
|
!categorized && !open && showRetry ? /* @__PURE__ */ import_react68.default.createElement(
|
|
@@ -6458,7 +6526,7 @@ var BankTransactionRow = ({
|
|
|
6458
6526
|
|
|
6459
6527
|
// src/components/BankTransactionList/Assignment.tsx
|
|
6460
6528
|
var import_react69 = __toESM(require("react"));
|
|
6461
|
-
var
|
|
6529
|
+
var import_date_fns8 = require("date-fns");
|
|
6462
6530
|
var Assignment = ({ bankTransaction }) => {
|
|
6463
6531
|
if (bankTransaction.match && bankTransaction.categorization_status === "MATCHED" /* MATCHED */) {
|
|
6464
6532
|
return /* @__PURE__ */ import_react69.default.createElement(import_react69.default.Fragment, null, /* @__PURE__ */ import_react69.default.createElement(
|
|
@@ -6469,8 +6537,8 @@ var Assignment = ({ bankTransaction }) => {
|
|
|
6469
6537
|
dateFormat: DATE_FORMAT,
|
|
6470
6538
|
text: "Matched"
|
|
6471
6539
|
}
|
|
6472
|
-
), /* @__PURE__ */ import_react69.default.createElement(Text, { className: "Layer__bank-transaction-list-item__category-text__text" }, `${(0,
|
|
6473
|
-
(0,
|
|
6540
|
+
), /* @__PURE__ */ import_react69.default.createElement(Text, { className: "Layer__bank-transaction-list-item__category-text__text" }, `${(0, import_date_fns8.format)(
|
|
6541
|
+
(0, import_date_fns8.parseISO)(bankTransaction.match.bank_transaction.date),
|
|
6474
6542
|
DATE_FORMAT
|
|
6475
6543
|
)}, ${bankTransaction.match.bank_transaction.description ?? bankTransaction.match?.details?.description}`));
|
|
6476
6544
|
}
|
|
@@ -6495,7 +6563,7 @@ var Assignment = ({ bankTransaction }) => {
|
|
|
6495
6563
|
|
|
6496
6564
|
// src/components/BankTransactionList/BankTransactionListItem.tsx
|
|
6497
6565
|
var import_classnames34 = __toESM(require("classnames"));
|
|
6498
|
-
var
|
|
6566
|
+
var import_date_fns9 = require("date-fns");
|
|
6499
6567
|
var BankTransactionListItem = ({
|
|
6500
6568
|
index = 0,
|
|
6501
6569
|
dateFormat,
|
|
@@ -6510,7 +6578,11 @@ var BankTransactionListItem = ({
|
|
|
6510
6578
|
}) => {
|
|
6511
6579
|
const expandedRowRef = (0, import_react70.useRef)(null);
|
|
6512
6580
|
const [showRetry, setShowRetry] = (0, import_react70.useState)(false);
|
|
6513
|
-
const {
|
|
6581
|
+
const {
|
|
6582
|
+
categorize: categorizeBankTransaction2,
|
|
6583
|
+
match: matchBankTransaction2,
|
|
6584
|
+
shouldHideAfterCategorize
|
|
6585
|
+
} = useBankTransactionsContext();
|
|
6514
6586
|
const [selectedCategory, setSelectedCategory] = (0, import_react70.useState)(
|
|
6515
6587
|
getDefaultSelectedCategory(bankTransaction)
|
|
6516
6588
|
);
|
|
@@ -6532,7 +6604,7 @@ var BankTransactionListItem = ({
|
|
|
6532
6604
|
}
|
|
6533
6605
|
}, [bankTransaction.error]);
|
|
6534
6606
|
(0, import_react70.useEffect)(() => {
|
|
6535
|
-
if (editable && bankTransaction.recently_categorized) {
|
|
6607
|
+
if (editable && bankTransaction.recently_categorized && shouldHideAfterCategorize(bankTransaction)) {
|
|
6536
6608
|
setTimeout(() => {
|
|
6537
6609
|
removeTransaction(bankTransaction);
|
|
6538
6610
|
}, 300);
|
|
@@ -6560,11 +6632,11 @@ var BankTransactionListItem = ({
|
|
|
6560
6632
|
const openClassName = open ? `${className}--expanded` : "";
|
|
6561
6633
|
const rowClassName = (0, import_classnames34.default)(
|
|
6562
6634
|
className,
|
|
6563
|
-
bankTransaction.recently_categorized && editable ? "Layer__bank-transaction-row--removing" : "",
|
|
6635
|
+
bankTransaction.recently_categorized && editable && shouldHideAfterCategorize(bankTransaction) ? "Layer__bank-transaction-row--removing" : "",
|
|
6564
6636
|
open ? openClassName : "",
|
|
6565
6637
|
showComponent ? "show" : ""
|
|
6566
6638
|
);
|
|
6567
|
-
return /* @__PURE__ */ import_react70.default.createElement("li", { className: rowClassName }, /* @__PURE__ */ import_react70.default.createElement("span", { className: `${className}__heading` }, /* @__PURE__ */ import_react70.default.createElement("div", { className: `${className}__heading__main` }, /* @__PURE__ */ import_react70.default.createElement("span", { className: `${className}__heading-date` }, (0,
|
|
6639
|
+
return /* @__PURE__ */ import_react70.default.createElement("li", { className: rowClassName }, /* @__PURE__ */ import_react70.default.createElement("span", { className: `${className}__heading` }, /* @__PURE__ */ import_react70.default.createElement("div", { className: `${className}__heading__main` }, /* @__PURE__ */ import_react70.default.createElement("span", { className: `${className}__heading-date` }, (0, import_date_fns9.format)((0, import_date_fns9.parseISO)(bankTransaction.date), dateFormat)), /* @__PURE__ */ import_react70.default.createElement("span", { className: `${className}__heading-separator` }), /* @__PURE__ */ import_react70.default.createElement("span", { className: `${className}__heading-account-name` }, bankTransaction.account_name ?? "")), /* @__PURE__ */ import_react70.default.createElement(
|
|
6568
6640
|
"div",
|
|
6569
6641
|
{
|
|
6570
6642
|
onClick: toggleOpen,
|
|
@@ -7131,7 +7203,7 @@ var TransactionToOpenContext = (0, import_react78.createContext)({
|
|
|
7131
7203
|
|
|
7132
7204
|
// src/components/BankTransactionMobileList/BankTransactionMobileListItem.tsx
|
|
7133
7205
|
var import_classnames36 = __toESM(require("classnames"));
|
|
7134
|
-
var
|
|
7206
|
+
var import_date_fns10 = require("date-fns");
|
|
7135
7207
|
var DATE_FORMAT2 = "LLL d";
|
|
7136
7208
|
var getAssignedValue2 = (bankTransaction) => {
|
|
7137
7209
|
if (bankTransaction.categorization_status === "SPLIT" /* SPLIT */) {
|
|
@@ -7156,6 +7228,7 @@ var BankTransactionMobileListItem = ({
|
|
|
7156
7228
|
setTransactionIdToOpen,
|
|
7157
7229
|
clearTransactionIdToOpen
|
|
7158
7230
|
} = (0, import_react79.useContext)(TransactionToOpenContext);
|
|
7231
|
+
const { shouldHideAfterCategorize } = useBankTransactionsContext();
|
|
7159
7232
|
const formRowRef = useElementSize(
|
|
7160
7233
|
(_a, _b, { height: height2 }) => setHeight(height2)
|
|
7161
7234
|
);
|
|
@@ -7189,7 +7262,7 @@ var BankTransactionMobileListItem = ({
|
|
|
7189
7262
|
}, [transactionIdToOpen]);
|
|
7190
7263
|
(0, import_react79.useEffect)(() => {
|
|
7191
7264
|
if (!removeAnim && bankTransaction.recently_categorized) {
|
|
7192
|
-
if (editable) {
|
|
7265
|
+
if (editable && shouldHideAfterCategorize(bankTransaction)) {
|
|
7193
7266
|
setRemoveAnim(true);
|
|
7194
7267
|
openNext();
|
|
7195
7268
|
} else {
|
|
@@ -7222,7 +7295,7 @@ var BankTransactionMobileListItem = ({
|
|
|
7222
7295
|
}
|
|
7223
7296
|
}, []);
|
|
7224
7297
|
(0, import_react79.useEffect)(() => {
|
|
7225
|
-
if (editable && bankTransaction.recently_categorized) {
|
|
7298
|
+
if (editable && bankTransaction.recently_categorized && shouldHideAfterCategorize(bankTransaction)) {
|
|
7226
7299
|
setTimeout(() => {
|
|
7227
7300
|
removeTransaction(bankTransaction);
|
|
7228
7301
|
}, 300);
|
|
@@ -7253,7 +7326,7 @@ var BankTransactionMobileListItem = ({
|
|
|
7253
7326
|
},
|
|
7254
7327
|
isCredit(bankTransaction) ? "+$" : " $",
|
|
7255
7328
|
centsToDollars(bankTransaction.amount)
|
|
7256
|
-
), /* @__PURE__ */ import_react79.default.createElement("span", { className: `${className}__heading__date` }, (0,
|
|
7329
|
+
), /* @__PURE__ */ import_react79.default.createElement("span", { className: `${className}__heading__date` }, (0, import_date_fns10.format)((0, import_date_fns10.parseISO)(bankTransaction.date), DATE_FORMAT2))))
|
|
7257
7330
|
), categorizationEnabled(mode) ? /* @__PURE__ */ import_react79.default.createElement(
|
|
7258
7331
|
"div",
|
|
7259
7332
|
{
|
|
@@ -7776,11 +7849,11 @@ var DownloadCloud = ({ size = 18, ...props }) => /* @__PURE__ */ React103.create
|
|
|
7776
7849
|
var DownloadCloud_default = DownloadCloud;
|
|
7777
7850
|
|
|
7778
7851
|
// src/utils/business.ts
|
|
7779
|
-
var
|
|
7852
|
+
var import_date_fns11 = require("date-fns");
|
|
7780
7853
|
var getActivationDate = (business) => {
|
|
7781
7854
|
try {
|
|
7782
7855
|
if (business && business.activation_at) {
|
|
7783
|
-
return (0,
|
|
7856
|
+
return (0, import_date_fns11.parseISO)(business.activation_at);
|
|
7784
7857
|
}
|
|
7785
7858
|
return;
|
|
7786
7859
|
} catch (_err) {
|
|
@@ -7790,7 +7863,7 @@ var getActivationDate = (business) => {
|
|
|
7790
7863
|
var getEarliestDateToBrowse = (business) => {
|
|
7791
7864
|
const activationDate = getActivationDate(business);
|
|
7792
7865
|
if (activationDate) {
|
|
7793
|
-
return (0,
|
|
7866
|
+
return (0, import_date_fns11.startOfMonth)(activationDate);
|
|
7794
7867
|
}
|
|
7795
7868
|
return;
|
|
7796
7869
|
};
|
|
@@ -7802,7 +7875,7 @@ var isDateAllowedToBrowse = (date, business) => {
|
|
|
7802
7875
|
if (!activationDate) {
|
|
7803
7876
|
return true;
|
|
7804
7877
|
}
|
|
7805
|
-
return (0,
|
|
7878
|
+
return (0, import_date_fns11.differenceInCalendarMonths)((0, import_date_fns11.startOfMonth)(date), activationDate) >= 0;
|
|
7806
7879
|
};
|
|
7807
7880
|
|
|
7808
7881
|
// src/components/DatePicker/DatePicker.tsx
|
|
@@ -7811,7 +7884,7 @@ var import_react_datepicker = __toESM(require("react-datepicker"));
|
|
|
7811
7884
|
|
|
7812
7885
|
// src/components/DatePicker/DatePickerOptions.tsx
|
|
7813
7886
|
var import_react90 = __toESM(require("react"));
|
|
7814
|
-
var
|
|
7887
|
+
var import_date_fns12 = require("date-fns");
|
|
7815
7888
|
var DatePickerOptions = ({
|
|
7816
7889
|
options,
|
|
7817
7890
|
setSelectedDate
|
|
@@ -7826,8 +7899,8 @@ var DatePickerOptions = ({
|
|
|
7826
7899
|
key: option,
|
|
7827
7900
|
onClick: () => {
|
|
7828
7901
|
setSelectedDate([
|
|
7829
|
-
(0,
|
|
7830
|
-
(0,
|
|
7902
|
+
(0, import_date_fns12.startOfMonth)(/* @__PURE__ */ new Date()),
|
|
7903
|
+
(0, import_date_fns12.endOfMonth)(/* @__PURE__ */ new Date())
|
|
7831
7904
|
]);
|
|
7832
7905
|
}
|
|
7833
7906
|
},
|
|
@@ -7840,8 +7913,8 @@ var DatePickerOptions = ({
|
|
|
7840
7913
|
key: option,
|
|
7841
7914
|
onClick: () => {
|
|
7842
7915
|
setSelectedDate([
|
|
7843
|
-
(0,
|
|
7844
|
-
(0,
|
|
7916
|
+
(0, import_date_fns12.startOfMonth)((0, import_date_fns12.subMonths)(/* @__PURE__ */ new Date(), 1)),
|
|
7917
|
+
(0, import_date_fns12.endOfMonth)((0, import_date_fns12.subMonths)(/* @__PURE__ */ new Date(), 1))
|
|
7845
7918
|
]);
|
|
7846
7919
|
}
|
|
7847
7920
|
},
|
|
@@ -7854,8 +7927,8 @@ var DatePickerOptions = ({
|
|
|
7854
7927
|
key: option,
|
|
7855
7928
|
onClick: () => {
|
|
7856
7929
|
setSelectedDate([
|
|
7857
|
-
(0,
|
|
7858
|
-
(0,
|
|
7930
|
+
(0, import_date_fns12.startOfQuarter)(/* @__PURE__ */ new Date()),
|
|
7931
|
+
(0, import_date_fns12.endOfQuarter)(/* @__PURE__ */ new Date())
|
|
7859
7932
|
]);
|
|
7860
7933
|
}
|
|
7861
7934
|
},
|
|
@@ -7867,10 +7940,10 @@ var DatePickerOptions = ({
|
|
|
7867
7940
|
{
|
|
7868
7941
|
key: option,
|
|
7869
7942
|
onClick: () => {
|
|
7870
|
-
const lastQuarter = (0,
|
|
7943
|
+
const lastQuarter = (0, import_date_fns12.subQuarters)(/* @__PURE__ */ new Date(), 1);
|
|
7871
7944
|
setSelectedDate([
|
|
7872
|
-
(0,
|
|
7873
|
-
(0,
|
|
7945
|
+
(0, import_date_fns12.startOfQuarter)(lastQuarter),
|
|
7946
|
+
(0, import_date_fns12.endOfQuarter)(lastQuarter)
|
|
7874
7947
|
]);
|
|
7875
7948
|
}
|
|
7876
7949
|
},
|
|
@@ -7882,7 +7955,7 @@ var DatePickerOptions = ({
|
|
|
7882
7955
|
{
|
|
7883
7956
|
key: option,
|
|
7884
7957
|
onClick: () => {
|
|
7885
|
-
setSelectedDate([(0,
|
|
7958
|
+
setSelectedDate([(0, import_date_fns12.startOfYear)(/* @__PURE__ */ new Date()), (0, import_date_fns12.endOfYear)(/* @__PURE__ */ new Date())]);
|
|
7886
7959
|
}
|
|
7887
7960
|
},
|
|
7888
7961
|
"This year"
|
|
@@ -7893,8 +7966,8 @@ var DatePickerOptions = ({
|
|
|
7893
7966
|
{
|
|
7894
7967
|
key: option,
|
|
7895
7968
|
onClick: () => {
|
|
7896
|
-
const lastYear = (0,
|
|
7897
|
-
setSelectedDate([(0,
|
|
7969
|
+
const lastYear = (0, import_date_fns12.subYears)(/* @__PURE__ */ new Date(), 1);
|
|
7970
|
+
setSelectedDate([(0, import_date_fns12.startOfYear)(lastYear), (0, import_date_fns12.endOfYear)(lastYear)]);
|
|
7898
7971
|
}
|
|
7899
7972
|
},
|
|
7900
7973
|
"Last year"
|
|
@@ -8173,7 +8246,7 @@ var DatePicker = ({
|
|
|
8173
8246
|
|
|
8174
8247
|
// src/components/BankTransactions/BankTransactionsHeader.tsx
|
|
8175
8248
|
var import_classnames41 = __toESM(require("classnames"));
|
|
8176
|
-
var
|
|
8249
|
+
var import_date_fns13 = require("date-fns");
|
|
8177
8250
|
var DownloadButton = ({
|
|
8178
8251
|
downloadButtonTextOverride,
|
|
8179
8252
|
iconOnly
|
|
@@ -8279,8 +8352,8 @@ var BankTransactionsHeader = ({
|
|
|
8279
8352
|
onChange: (date) => {
|
|
8280
8353
|
if (!Array.isArray(date)) {
|
|
8281
8354
|
setDateRange({
|
|
8282
|
-
startDate: (0,
|
|
8283
|
-
endDate: (0,
|
|
8355
|
+
startDate: (0, import_date_fns13.startOfMonth)(date),
|
|
8356
|
+
endDate: (0, import_date_fns13.endOfMonth)(date)
|
|
8284
8357
|
});
|
|
8285
8358
|
}
|
|
8286
8359
|
},
|
|
@@ -8355,7 +8428,7 @@ var DataStates = ({
|
|
|
8355
8428
|
editable
|
|
8356
8429
|
}) => {
|
|
8357
8430
|
let title = editable ? "You are up to date with transactions!" : "You have no categorized transactions";
|
|
8358
|
-
let description = editable ? "All uncategorized
|
|
8431
|
+
let description = editable ? "All uncategorized transactions will be displayed here" : "All transactions will be displayed here once reviewed";
|
|
8359
8432
|
const showRefreshButton = bankTransactions?.length;
|
|
8360
8433
|
return /* @__PURE__ */ import_react93.default.createElement(import_react93.default.Fragment, null, !isLoading && !error && (bankTransactions === void 0 || bankTransactions !== void 0 && bankTransactions.length === 0) ? /* @__PURE__ */ import_react93.default.createElement("div", { className: "Layer__table-state-container" }, /* @__PURE__ */ import_react93.default.createElement(
|
|
8361
8434
|
DataState,
|
|
@@ -8380,10 +8453,9 @@ var DataStates = ({
|
|
|
8380
8453
|
};
|
|
8381
8454
|
|
|
8382
8455
|
// src/components/BankTransactions/BankTransactions.tsx
|
|
8383
|
-
var
|
|
8456
|
+
var import_date_fns14 = require("date-fns");
|
|
8384
8457
|
var COMPONENT_NAME2 = "bank-transactions";
|
|
8385
8458
|
var TEST_EMPTY_STATE = false;
|
|
8386
|
-
var POLL_INTERVAL = 1e3;
|
|
8387
8459
|
var categorizationEnabled = (mode) => {
|
|
8388
8460
|
if (mode === "bookkeeping-client") {
|
|
8389
8461
|
return false;
|
|
@@ -8412,8 +8484,8 @@ var BankTransactionsContent = ({
|
|
|
8412
8484
|
const [currentPage, setCurrentPage] = (0, import_react94.useState)(1);
|
|
8413
8485
|
const [initialLoad, setInitialLoad] = (0, import_react94.useState)(true);
|
|
8414
8486
|
const [dateRange, setDateRange] = (0, import_react94.useState)({
|
|
8415
|
-
startDate: (0,
|
|
8416
|
-
endDate: (0,
|
|
8487
|
+
startDate: (0, import_date_fns14.startOfMonth)(/* @__PURE__ */ new Date()),
|
|
8488
|
+
endDate: (0, import_date_fns14.endOfMonth)(/* @__PURE__ */ new Date())
|
|
8417
8489
|
});
|
|
8418
8490
|
const categorizeView = categorizeViewProp ?? categorizationEnabled(mode);
|
|
8419
8491
|
const {
|
|
@@ -8431,39 +8503,11 @@ var BankTransactionsContent = ({
|
|
|
8431
8503
|
fetchMore,
|
|
8432
8504
|
removeAfterCategorize
|
|
8433
8505
|
} = useBankTransactionsContext();
|
|
8434
|
-
const { data: linkedAccounts
|
|
8506
|
+
const { data: linkedAccounts } = useLinkedAccounts();
|
|
8435
8507
|
const isSyncing = (0, import_react94.useMemo)(
|
|
8436
8508
|
() => Boolean(linkedAccounts?.some((item) => item.is_syncing)),
|
|
8437
8509
|
[linkedAccounts]
|
|
8438
8510
|
);
|
|
8439
|
-
const transactionsNotSynced = (0, import_react94.useMemo)(
|
|
8440
|
-
() => loadingStatus === "complete" && isSyncing && (!data || data?.length === 0),
|
|
8441
|
-
[data, isSyncing, loadingStatus]
|
|
8442
|
-
);
|
|
8443
|
-
let intervalId = void 0;
|
|
8444
|
-
const [refreshTrigger, setRefreshTrigger] = (0, import_react94.useState)(-1);
|
|
8445
|
-
(0, import_react94.useEffect)(() => {
|
|
8446
|
-
if (refreshTrigger !== -1) {
|
|
8447
|
-
refetch();
|
|
8448
|
-
refetchAccounts();
|
|
8449
|
-
}
|
|
8450
|
-
}, [refreshTrigger]);
|
|
8451
|
-
(0, import_react94.useEffect)(() => {
|
|
8452
|
-
if (isSyncing) {
|
|
8453
|
-
intervalId = setInterval(() => {
|
|
8454
|
-
setRefreshTrigger(Math.random());
|
|
8455
|
-
}, POLL_INTERVAL);
|
|
8456
|
-
} else {
|
|
8457
|
-
if (intervalId) {
|
|
8458
|
-
clearInterval(intervalId);
|
|
8459
|
-
}
|
|
8460
|
-
}
|
|
8461
|
-
return () => {
|
|
8462
|
-
if (intervalId) {
|
|
8463
|
-
clearInterval(intervalId);
|
|
8464
|
-
}
|
|
8465
|
-
};
|
|
8466
|
-
}, [isSyncing, transactionsNotSynced]);
|
|
8467
8511
|
(0, import_react94.useEffect)(() => {
|
|
8468
8512
|
activate();
|
|
8469
8513
|
}, []);
|
|
@@ -8505,7 +8549,7 @@ var BankTransactionsContent = ({
|
|
|
8505
8549
|
const bankTransactions = TEST_EMPTY_STATE ? [] : (0, import_react94.useMemo)(() => {
|
|
8506
8550
|
if (monthlyView) {
|
|
8507
8551
|
return data?.filter(
|
|
8508
|
-
(x) => (0,
|
|
8552
|
+
(x) => (0, import_date_fns14.parseISO)(x.date) >= dateRange.startDate && (0, import_date_fns14.parseISO)(x.date) <= dateRange.endDate
|
|
8509
8553
|
);
|
|
8510
8554
|
}
|
|
8511
8555
|
const firstPageIndex = (currentPage - 1) * pageSize;
|
|
@@ -8790,14 +8834,14 @@ var applyShare = (items, total) => {
|
|
|
8790
8834
|
|
|
8791
8835
|
// src/hooks/useProfitAndLoss/useProfitAndLossLTM.tsx
|
|
8792
8836
|
var import_react97 = require("react");
|
|
8793
|
-
var
|
|
8837
|
+
var import_date_fns15 = require("date-fns");
|
|
8794
8838
|
var import_swr3 = __toESM(require("swr"));
|
|
8795
8839
|
var buildDates = ({ currentDate }) => {
|
|
8796
8840
|
return {
|
|
8797
|
-
startYear: (0,
|
|
8798
|
-
startMonth: (0,
|
|
8799
|
-
endYear: (0,
|
|
8800
|
-
endMonth: (0,
|
|
8841
|
+
startYear: (0, import_date_fns15.startOfMonth)(currentDate).getFullYear() - 1,
|
|
8842
|
+
startMonth: (0, import_date_fns15.startOfMonth)(currentDate).getMonth() + 1,
|
|
8843
|
+
endYear: (0, import_date_fns15.startOfMonth)(currentDate).getFullYear(),
|
|
8844
|
+
endMonth: (0, import_date_fns15.startOfMonth)(currentDate).getMonth() + 1
|
|
8801
8845
|
};
|
|
8802
8846
|
};
|
|
8803
8847
|
var buildMonthsArray = (startDate, endDate) => {
|
|
@@ -8811,7 +8855,7 @@ var buildMonthsArray = (startDate, endDate) => {
|
|
|
8811
8855
|
return dates;
|
|
8812
8856
|
};
|
|
8813
8857
|
var useProfitAndLossLTM = ({ currentDate, tagFilter, reportingBasis } = {
|
|
8814
|
-
currentDate: (0,
|
|
8858
|
+
currentDate: (0, import_date_fns15.startOfMonth)(Date.now())
|
|
8815
8859
|
}) => {
|
|
8816
8860
|
const {
|
|
8817
8861
|
businessId,
|
|
@@ -8854,7 +8898,7 @@ var useProfitAndLossLTM = ({ currentDate, tagFilter, reportingBasis } = {
|
|
|
8854
8898
|
);
|
|
8855
8899
|
(0, import_react97.useEffect)(() => {
|
|
8856
8900
|
const newData = data.slice();
|
|
8857
|
-
const newPeriod = buildMonthsArray((0,
|
|
8901
|
+
const newPeriod = buildMonthsArray((0, import_date_fns15.sub)(date, { years: 1 }), date);
|
|
8858
8902
|
if (newData && newPeriod) {
|
|
8859
8903
|
newPeriod.forEach((x) => {
|
|
8860
8904
|
if (!newData?.find(
|
|
@@ -8948,7 +8992,7 @@ var useProfitAndLossLTM = ({ currentDate, tagFilter, reportingBasis } = {
|
|
|
8948
8992
|
|
|
8949
8993
|
// src/hooks/useProfitAndLoss/useProfitAndLossQuery.tsx
|
|
8950
8994
|
var import_react98 = require("react");
|
|
8951
|
-
var
|
|
8995
|
+
var import_date_fns16 = require("date-fns");
|
|
8952
8996
|
var import_swr4 = __toESM(require("swr"));
|
|
8953
8997
|
var useProfitAndLossQuery = ({
|
|
8954
8998
|
startDate,
|
|
@@ -8956,8 +9000,8 @@ var useProfitAndLossQuery = ({
|
|
|
8956
9000
|
tagFilter,
|
|
8957
9001
|
reportingBasis
|
|
8958
9002
|
} = {
|
|
8959
|
-
startDate: (0,
|
|
8960
|
-
endDate: (0,
|
|
9003
|
+
startDate: (0, import_date_fns16.startOfMonth)(/* @__PURE__ */ new Date()),
|
|
9004
|
+
endDate: (0, import_date_fns16.endOfMonth)(/* @__PURE__ */ new Date())
|
|
8961
9005
|
}) => {
|
|
8962
9006
|
const { auth, businessId, apiUrl, syncTimestamps, read, hasBeenTouched } = useLayerContext();
|
|
8963
9007
|
const queryKey = businessId && startDate && endDate && auth?.access_token && `profit-and-loss-${businessId}-${startDate.valueOf()}-${endDate.valueOf()}-${tagFilter?.key}-${tagFilter?.values?.join(
|
|
@@ -8974,8 +9018,8 @@ var useProfitAndLossQuery = ({
|
|
|
8974
9018
|
Layer.getProfitAndLoss(apiUrl, auth?.access_token, {
|
|
8975
9019
|
params: {
|
|
8976
9020
|
businessId,
|
|
8977
|
-
startDate: (0,
|
|
8978
|
-
endDate: (0,
|
|
9021
|
+
startDate: (0, import_date_fns16.formatISO)(startDate.valueOf()),
|
|
9022
|
+
endDate: (0, import_date_fns16.formatISO)(endDate.valueOf()),
|
|
8979
9023
|
tagKey: tagFilter?.key,
|
|
8980
9024
|
tagValues: tagFilter?.values?.join(","),
|
|
8981
9025
|
reportingBasis
|
|
@@ -9007,21 +9051,21 @@ var useProfitAndLossQuery = ({
|
|
|
9007
9051
|
};
|
|
9008
9052
|
|
|
9009
9053
|
// src/hooks/useProfitAndLoss/useProfitAndLoss.tsx
|
|
9010
|
-
var
|
|
9054
|
+
var import_date_fns17 = require("date-fns");
|
|
9011
9055
|
var useProfitAndLoss = ({
|
|
9012
9056
|
startDate: initialStartDate,
|
|
9013
9057
|
endDate: initialEndDate,
|
|
9014
9058
|
tagFilter,
|
|
9015
9059
|
reportingBasis
|
|
9016
9060
|
} = {
|
|
9017
|
-
startDate: (0,
|
|
9018
|
-
endDate: (0,
|
|
9061
|
+
startDate: (0, import_date_fns17.startOfMonth)(/* @__PURE__ */ new Date()),
|
|
9062
|
+
endDate: (0, import_date_fns17.endOfMonth)(/* @__PURE__ */ new Date())
|
|
9019
9063
|
}) => {
|
|
9020
9064
|
const [startDate, setStartDate] = (0, import_react99.useState)(
|
|
9021
|
-
initialStartDate || (0,
|
|
9065
|
+
initialStartDate || (0, import_date_fns17.startOfMonth)(Date.now())
|
|
9022
9066
|
);
|
|
9023
9067
|
const [endDate, setEndDate] = (0, import_react99.useState)(
|
|
9024
|
-
initialEndDate || (0,
|
|
9068
|
+
initialEndDate || (0, import_date_fns17.endOfMonth)(Date.now())
|
|
9025
9069
|
);
|
|
9026
9070
|
const [filters, setFilters] = (0, import_react99.useState)({
|
|
9027
9071
|
expenses: void 0,
|
|
@@ -9035,7 +9079,7 @@ var useProfitAndLoss = ({
|
|
|
9035
9079
|
reportingBasis
|
|
9036
9080
|
});
|
|
9037
9081
|
const { data: summaryData } = useProfitAndLossLTM({
|
|
9038
|
-
currentDate: startDate ? startDate : (0,
|
|
9082
|
+
currentDate: startDate ? startDate : (0, import_date_fns17.startOfMonth)(/* @__PURE__ */ new Date())
|
|
9039
9083
|
});
|
|
9040
9084
|
const changeDateRange = ({
|
|
9041
9085
|
startDate: newStartDate,
|
|
@@ -9248,53 +9292,53 @@ var Indicator = ({
|
|
|
9248
9292
|
|
|
9249
9293
|
// src/components/ProfitAndLossChart/ProfitAndLossChart.tsx
|
|
9250
9294
|
var import_classnames42 = __toESM(require("classnames"));
|
|
9251
|
-
var
|
|
9295
|
+
var import_date_fns18 = require("date-fns");
|
|
9252
9296
|
var import_recharts = require("recharts");
|
|
9253
9297
|
var getChartWindow = ({
|
|
9254
9298
|
chartWindow,
|
|
9255
9299
|
currentYear,
|
|
9256
9300
|
currentMonth
|
|
9257
9301
|
}) => {
|
|
9258
|
-
const today = (0,
|
|
9259
|
-
const yearAgo = (0,
|
|
9260
|
-
const current = (0,
|
|
9261
|
-
if ((0,
|
|
9302
|
+
const today = (0, import_date_fns18.startOfMonth)(Date.now());
|
|
9303
|
+
const yearAgo = (0, import_date_fns18.sub)(today, { months: 11 });
|
|
9304
|
+
const current = (0, import_date_fns18.startOfMonth)(new Date(currentYear, currentMonth - 1, 1));
|
|
9305
|
+
if ((0, import_date_fns18.differenceInMonths)((0, import_date_fns18.startOfMonth)(chartWindow.start), current) < 0 && (0, import_date_fns18.differenceInMonths)((0, import_date_fns18.startOfMonth)(chartWindow.end), current) > 1) {
|
|
9262
9306
|
return chartWindow;
|
|
9263
9307
|
}
|
|
9264
|
-
if ((0,
|
|
9308
|
+
if ((0, import_date_fns18.differenceInMonths)((0, import_date_fns18.startOfMonth)(chartWindow.start), current) === 0) {
|
|
9265
9309
|
return {
|
|
9266
|
-
start: (0,
|
|
9267
|
-
end: (0,
|
|
9310
|
+
start: (0, import_date_fns18.startOfMonth)((0, import_date_fns18.sub)(current, { months: 1 })),
|
|
9311
|
+
end: (0, import_date_fns18.endOfMonth)((0, import_date_fns18.add)(current, { months: 11 }))
|
|
9268
9312
|
};
|
|
9269
9313
|
}
|
|
9270
|
-
if ((0,
|
|
9314
|
+
if ((0, import_date_fns18.differenceInMonths)((0, import_date_fns18.endOfMonth)(chartWindow.end), (0, import_date_fns18.endOfMonth)(current)) === 1 && (0, import_date_fns18.differenceInMonths)(today, current) >= 1) {
|
|
9271
9315
|
return {
|
|
9272
|
-
start: (0,
|
|
9273
|
-
end: (0,
|
|
9316
|
+
start: (0, import_date_fns18.startOfMonth)((0, import_date_fns18.sub)(current, { months: 10 })),
|
|
9317
|
+
end: (0, import_date_fns18.endOfMonth)((0, import_date_fns18.add)(current, { months: 2 }))
|
|
9274
9318
|
};
|
|
9275
9319
|
}
|
|
9276
|
-
if ((0,
|
|
9320
|
+
if ((0, import_date_fns18.differenceInMonths)(current, (0, import_date_fns18.startOfMonth)(chartWindow.end)) === 0 && (0, import_date_fns18.differenceInMonths)(current, (0, import_date_fns18.startOfMonth)(today)) > 0) {
|
|
9277
9321
|
return {
|
|
9278
|
-
start: (0,
|
|
9279
|
-
end: (0,
|
|
9322
|
+
start: (0, import_date_fns18.startOfMonth)((0, import_date_fns18.sub)(current, { months: 11 })),
|
|
9323
|
+
end: (0, import_date_fns18.endOfMonth)((0, import_date_fns18.add)(current, { months: 1 }))
|
|
9280
9324
|
};
|
|
9281
9325
|
}
|
|
9282
9326
|
if (current >= yearAgo) {
|
|
9283
9327
|
return {
|
|
9284
|
-
start: (0,
|
|
9285
|
-
end: (0,
|
|
9328
|
+
start: (0, import_date_fns18.startOfMonth)(yearAgo),
|
|
9329
|
+
end: (0, import_date_fns18.endOfMonth)(today)
|
|
9286
9330
|
};
|
|
9287
9331
|
}
|
|
9288
9332
|
if (Number(current) > Number(chartWindow.end)) {
|
|
9289
9333
|
return {
|
|
9290
|
-
start: (0,
|
|
9291
|
-
end: (0,
|
|
9334
|
+
start: (0, import_date_fns18.startOfMonth)((0, import_date_fns18.sub)(current, { months: 12 })),
|
|
9335
|
+
end: (0, import_date_fns18.endOfMonth)(current)
|
|
9292
9336
|
};
|
|
9293
9337
|
}
|
|
9294
|
-
if ((0,
|
|
9338
|
+
if ((0, import_date_fns18.differenceInMonths)(current, (0, import_date_fns18.startOfMonth)(chartWindow.start)) < 0) {
|
|
9295
9339
|
return {
|
|
9296
|
-
start: (0,
|
|
9297
|
-
end: (0,
|
|
9340
|
+
start: (0, import_date_fns18.startOfMonth)(current),
|
|
9341
|
+
end: (0, import_date_fns18.endOfMonth)((0, import_date_fns18.add)(current, { months: 11 }))
|
|
9298
9342
|
};
|
|
9299
9343
|
}
|
|
9300
9344
|
return chartWindow;
|
|
@@ -9330,8 +9374,8 @@ var ProfitAndLossChart = ({
|
|
|
9330
9374
|
});
|
|
9331
9375
|
const [barAnimActive, setBarAnimActive] = (0, import_react101.useState)(true);
|
|
9332
9376
|
const [chartWindow, setChartWindow] = (0, import_react101.useState)({
|
|
9333
|
-
start: (0,
|
|
9334
|
-
end: (0,
|
|
9377
|
+
start: (0, import_date_fns18.startOfMonth)((0, import_date_fns18.sub)(Date.now(), { months: 11 })),
|
|
9378
|
+
end: (0, import_date_fns18.endOfMonth)(Date.now())
|
|
9335
9379
|
});
|
|
9336
9380
|
const selectionMonth = (0, import_react101.useMemo)(
|
|
9337
9381
|
() => ({
|
|
@@ -9346,25 +9390,25 @@ var ProfitAndLossChart = ({
|
|
|
9346
9390
|
}
|
|
9347
9391
|
}, [dateRange]);
|
|
9348
9392
|
const { data, loaded, pullData } = useProfitAndLossLTM({
|
|
9349
|
-
currentDate: (0,
|
|
9393
|
+
currentDate: (0, import_date_fns18.startOfMonth)(Date.now())
|
|
9350
9394
|
});
|
|
9351
9395
|
const loadingValue = (0, import_react101.useMemo)(() => getLoadingValue(data), [data]);
|
|
9352
9396
|
(0, import_react101.useEffect)(() => {
|
|
9353
9397
|
if (loaded === "complete" && data) {
|
|
9354
9398
|
const foundCurrent = data.find(
|
|
9355
|
-
(x) => Number((0,
|
|
9399
|
+
(x) => Number((0, import_date_fns18.startOfMonth)(new Date(x.year, x.month - 1, 1))) >= Number(localDateRange.startDate) && Number((0, import_date_fns18.startOfMonth)(new Date(x.year, x.month - 1, 1))) < Number(localDateRange.endDate)
|
|
9356
9400
|
);
|
|
9357
9401
|
if (!foundCurrent) {
|
|
9358
|
-
const newDate = (0,
|
|
9402
|
+
const newDate = (0, import_date_fns18.startOfMonth)(localDateRange.startDate);
|
|
9359
9403
|
pullData(newDate);
|
|
9360
9404
|
return;
|
|
9361
9405
|
}
|
|
9362
9406
|
const foundBefore = data.find(
|
|
9363
|
-
(x) => Number((0,
|
|
9407
|
+
(x) => Number((0, import_date_fns18.startOfMonth)(new Date(x.year, x.month - 1, 1))) >= Number((0, import_date_fns18.sub)(localDateRange.startDate, { months: 1 })) && Number((0, import_date_fns18.startOfMonth)(new Date(x.year, x.month - 1, 1))) < Number((0, import_date_fns18.sub)(localDateRange.endDate, { months: 1 }))
|
|
9364
9408
|
);
|
|
9365
9409
|
if (!foundBefore) {
|
|
9366
|
-
const newDate = (0,
|
|
9367
|
-
(0,
|
|
9410
|
+
const newDate = (0, import_date_fns18.startOfMonth)(
|
|
9411
|
+
(0, import_date_fns18.sub)(localDateRange.startDate, { months: 1 })
|
|
9368
9412
|
);
|
|
9369
9413
|
pullData(newDate);
|
|
9370
9414
|
}
|
|
@@ -9387,7 +9431,7 @@ var ProfitAndLossChart = ({
|
|
|
9387
9431
|
}, 2e3);
|
|
9388
9432
|
}
|
|
9389
9433
|
}, [loaded]);
|
|
9390
|
-
const getMonthName = (pnl) => pnl ? (0,
|
|
9434
|
+
const getMonthName = (pnl) => pnl ? (0, import_date_fns18.format)(
|
|
9391
9435
|
new Date(pnl.year, pnl.month - 1, 1),
|
|
9392
9436
|
compactView ? "LLLLL" : "LLL"
|
|
9393
9437
|
) : "";
|
|
@@ -9412,9 +9456,9 @@ var ProfitAndLossChart = ({
|
|
|
9412
9456
|
const loadingData = [];
|
|
9413
9457
|
const today = Date.now();
|
|
9414
9458
|
for (let i = 11; i >= 0; i--) {
|
|
9415
|
-
const currentDate = (0,
|
|
9459
|
+
const currentDate = (0, import_date_fns18.sub)(today, { months: i });
|
|
9416
9460
|
loadingData.push({
|
|
9417
|
-
name: (0,
|
|
9461
|
+
name: (0, import_date_fns18.format)(currentDate, compactView ? "LLLLL" : "LLL"),
|
|
9418
9462
|
revenue: 0,
|
|
9419
9463
|
revenueUncategorized: 0,
|
|
9420
9464
|
totalExpensesInverse: 0,
|
|
@@ -9445,18 +9489,18 @@ var ProfitAndLossChart = ({
|
|
|
9445
9489
|
}
|
|
9446
9490
|
return x;
|
|
9447
9491
|
})?.filter(
|
|
9448
|
-
(x) => (0,
|
|
9449
|
-
(0,
|
|
9492
|
+
(x) => (0, import_date_fns18.differenceInMonths)(
|
|
9493
|
+
(0, import_date_fns18.startOfMonth)(new Date(x.year, x.month - 1, 1)),
|
|
9450
9494
|
chartWindow.start
|
|
9451
|
-
) >= 0 && (0,
|
|
9452
|
-
(0,
|
|
9495
|
+
) >= 0 && (0, import_date_fns18.differenceInMonths)(
|
|
9496
|
+
(0, import_date_fns18.startOfMonth)(new Date(x.year, x.month - 1, 1)),
|
|
9453
9497
|
chartWindow.start
|
|
9454
|
-
) < 12 && (0,
|
|
9498
|
+
) < 12 && (0, import_date_fns18.differenceInMonths)(
|
|
9455
9499
|
chartWindow.end,
|
|
9456
|
-
(0,
|
|
9457
|
-
) >= 0 && (0,
|
|
9500
|
+
(0, import_date_fns18.startOfMonth)(new Date(x.year, x.month - 1, 1))
|
|
9501
|
+
) >= 0 && (0, import_date_fns18.differenceInMonths)(
|
|
9458
9502
|
chartWindow.end,
|
|
9459
|
-
(0,
|
|
9503
|
+
(0, import_date_fns18.startOfMonth)(new Date(x.year, x.month - 1, 1))
|
|
9460
9504
|
) <= 12
|
|
9461
9505
|
).map((x) => summarizePnL(x));
|
|
9462
9506
|
}, [selectionMonth, chartWindow, data, loaded, compactView]);
|
|
@@ -9470,7 +9514,7 @@ var ProfitAndLossChart = ({
|
|
|
9470
9514
|
if (isMonthAllowed) {
|
|
9471
9515
|
changeDateRange({
|
|
9472
9516
|
startDate: new Date(year, month - 1, 1),
|
|
9473
|
-
endDate: (0,
|
|
9517
|
+
endDate: (0, import_date_fns18.endOfMonth)(new Date(year, month - 1, 1))
|
|
9474
9518
|
});
|
|
9475
9519
|
}
|
|
9476
9520
|
}
|
|
@@ -9887,7 +9931,7 @@ var ProfitAndLossChart = ({
|
|
|
9887
9931
|
|
|
9888
9932
|
// src/components/ProfitAndLossDatePicker/ProfitAndLossDatePicker.tsx
|
|
9889
9933
|
var import_react102 = __toESM(require("react"));
|
|
9890
|
-
var
|
|
9934
|
+
var import_date_fns19 = require("date-fns");
|
|
9891
9935
|
var ProfitAndLossDatePicker = () => {
|
|
9892
9936
|
const { business } = useLayerContext();
|
|
9893
9937
|
const { changeDateRange, dateRange } = (0, import_react102.useContext)(ProfitAndLoss.Context);
|
|
@@ -9900,8 +9944,8 @@ var ProfitAndLossDatePicker = () => {
|
|
|
9900
9944
|
onChange: (date) => {
|
|
9901
9945
|
if (!Array.isArray(date)) {
|
|
9902
9946
|
changeDateRange({
|
|
9903
|
-
startDate: (0,
|
|
9904
|
-
endDate: (0,
|
|
9947
|
+
startDate: (0, import_date_fns19.startOfMonth)(date),
|
|
9948
|
+
endDate: (0, import_date_fns19.endOfMonth)(date)
|
|
9905
9949
|
});
|
|
9906
9950
|
}
|
|
9907
9951
|
},
|
|
@@ -10646,7 +10690,7 @@ var Filters = ({
|
|
|
10646
10690
|
};
|
|
10647
10691
|
|
|
10648
10692
|
// src/components/ProfitAndLossDetailedCharts/ProfitAndLossDetailedCharts.tsx
|
|
10649
|
-
var
|
|
10693
|
+
var import_date_fns20 = require("date-fns");
|
|
10650
10694
|
var ProfitAndLossDetailedCharts = ({
|
|
10651
10695
|
scope,
|
|
10652
10696
|
hideClose = false,
|
|
@@ -10671,7 +10715,7 @@ var ProfitAndLossDetailedCharts = ({
|
|
|
10671
10715
|
const data = theScope === "revenue" ? filteredDataRevenue : filteredDataExpenses;
|
|
10672
10716
|
const total = theScope === "revenue" ? filteredTotalRevenue : filteredTotalExpenses;
|
|
10673
10717
|
const [hoveredItem, setHoveredItem] = (0, import_react106.useState)();
|
|
10674
|
-
return /* @__PURE__ */ import_react106.default.createElement("div", { className: "Layer__profit-and-loss-detailed-charts" }, /* @__PURE__ */ import_react106.default.createElement("header", { className: "Layer__profit-and-loss-detailed-charts__header" }, /* @__PURE__ */ import_react106.default.createElement("div", { className: "Layer__profit-and-loss-detailed-charts__head" }, /* @__PURE__ */ import_react106.default.createElement(Text, { size: "lg" /* lg */, weight: "bold" /* bold */, className: "title" }, humanizeTitle(theScope)), /* @__PURE__ */ import_react106.default.createElement(Text, { size: "sm" /* sm */, className: "date" }, (0,
|
|
10718
|
+
return /* @__PURE__ */ import_react106.default.createElement("div", { className: "Layer__profit-and-loss-detailed-charts" }, /* @__PURE__ */ import_react106.default.createElement("header", { className: "Layer__profit-and-loss-detailed-charts__header" }, /* @__PURE__ */ import_react106.default.createElement("div", { className: "Layer__profit-and-loss-detailed-charts__head" }, /* @__PURE__ */ import_react106.default.createElement(Text, { size: "lg" /* lg */, weight: "bold" /* bold */, className: "title" }, humanizeTitle(theScope)), /* @__PURE__ */ import_react106.default.createElement(Text, { size: "sm" /* sm */, className: "date" }, (0, import_date_fns20.format)(dateRange.startDate, "LLLL, y")), showDatePicker && /* @__PURE__ */ import_react106.default.createElement(ProfitAndLossDatePicker, null)), !hideClose && /* @__PURE__ */ import_react106.default.createElement(
|
|
10675
10719
|
Button,
|
|
10676
10720
|
{
|
|
10677
10721
|
rightIcon: /* @__PURE__ */ import_react106.default.createElement(X_default, null),
|
|
@@ -10679,7 +10723,7 @@ var ProfitAndLossDetailedCharts = ({
|
|
|
10679
10723
|
onClick: () => setSidebarScope(void 0),
|
|
10680
10724
|
variant: "secondary" /* secondary */
|
|
10681
10725
|
}
|
|
10682
|
-
)), /* @__PURE__ */ import_react106.default.createElement("header", { className: "Layer__profit-and-loss-detailed-charts__header--tablet" }, !hideClose && /* @__PURE__ */ import_react106.default.createElement(BackButton, { onClick: () => setSidebarScope(void 0) }), /* @__PURE__ */ import_react106.default.createElement("div", { className: "Layer__profit-and-loss-detailed-charts__head" }, /* @__PURE__ */ import_react106.default.createElement(Text, { size: "lg" /* lg */, weight: "bold" /* bold */, className: "title" }, humanizeTitle(theScope)), /* @__PURE__ */ import_react106.default.createElement(Text, { size: "sm" /* sm */, className: "date" }, (0,
|
|
10726
|
+
)), /* @__PURE__ */ import_react106.default.createElement("header", { className: "Layer__profit-and-loss-detailed-charts__header--tablet" }, !hideClose && /* @__PURE__ */ import_react106.default.createElement(BackButton, { onClick: () => setSidebarScope(void 0) }), /* @__PURE__ */ import_react106.default.createElement("div", { className: "Layer__profit-and-loss-detailed-charts__head" }, /* @__PURE__ */ import_react106.default.createElement(Text, { size: "lg" /* lg */, weight: "bold" /* bold */, className: "title" }, humanizeTitle(theScope)), /* @__PURE__ */ import_react106.default.createElement(Text, { size: "sm" /* sm */, className: "date" }, (0, import_date_fns20.format)(dateRange.startDate, "LLLL, y")))), /* @__PURE__ */ import_react106.default.createElement("div", { className: "Layer__profit-and-loss-detailed-charts__content" }, /* @__PURE__ */ import_react106.default.createElement(
|
|
10683
10727
|
DetailedChart,
|
|
10684
10728
|
{
|
|
10685
10729
|
filteredData: data,
|
|
@@ -11309,7 +11353,7 @@ var ProfitAndLossTableWithProvider = (props) => {
|
|
|
11309
11353
|
};
|
|
11310
11354
|
|
|
11311
11355
|
// src/components/ProfitAndLoss/ProfitAndLoss.tsx
|
|
11312
|
-
var
|
|
11356
|
+
var import_date_fns21 = require("date-fns");
|
|
11313
11357
|
var PNLContext = (0, import_react118.createContext)({
|
|
11314
11358
|
data: void 0,
|
|
11315
11359
|
filteredDataRevenue: [],
|
|
@@ -11320,8 +11364,8 @@ var PNLContext = (0, import_react118.createContext)({
|
|
|
11320
11364
|
isValidating: false,
|
|
11321
11365
|
error: void 0,
|
|
11322
11366
|
dateRange: {
|
|
11323
|
-
startDate: (0,
|
|
11324
|
-
endDate: (0,
|
|
11367
|
+
startDate: (0, import_date_fns21.startOfMonth)(/* @__PURE__ */ new Date()),
|
|
11368
|
+
endDate: (0, import_date_fns21.endOfMonth)(/* @__PURE__ */ new Date())
|
|
11325
11369
|
},
|
|
11326
11370
|
changeDateRange: () => {
|
|
11327
11371
|
},
|
|
@@ -11370,11 +11414,11 @@ var BalanceSheetContext = (0, import_react119.createContext)({
|
|
|
11370
11414
|
|
|
11371
11415
|
// src/hooks/useBalanceSheet/useBalanceSheet.tsx
|
|
11372
11416
|
var import_react120 = require("react");
|
|
11373
|
-
var
|
|
11417
|
+
var import_date_fns22 = require("date-fns");
|
|
11374
11418
|
var import_swr5 = __toESM(require("swr"));
|
|
11375
11419
|
var useBalanceSheet = (date = /* @__PURE__ */ new Date()) => {
|
|
11376
11420
|
const { auth, businessId, apiUrl, read, syncTimestamps, hasBeenTouched } = useLayerContext();
|
|
11377
|
-
const dateString = (0,
|
|
11421
|
+
const dateString = (0, import_date_fns22.format)((0, import_date_fns22.startOfDay)(date), "yyyy-MM-dd'T'HH:mm:ssXXX");
|
|
11378
11422
|
const queryKey = businessId && dateString && auth?.access_token && `balance-sheet-${businessId}-${dateString}`;
|
|
11379
11423
|
const { data, isLoading, isValidating, error, mutate } = (0, import_swr5.default)(
|
|
11380
11424
|
queryKey,
|
|
@@ -11583,7 +11627,7 @@ var BALANCE_SHEET_ROWS = [
|
|
|
11583
11627
|
];
|
|
11584
11628
|
|
|
11585
11629
|
// src/components/BalanceSheet/BalanceSheet.tsx
|
|
11586
|
-
var
|
|
11630
|
+
var import_date_fns23 = require("date-fns");
|
|
11587
11631
|
var COMPONENT_NAME3 = "balance-sheet";
|
|
11588
11632
|
var BalanceSheet = (props) => {
|
|
11589
11633
|
const balanceSheetContextData = useBalanceSheet(props.effectiveDate);
|
|
@@ -11601,13 +11645,13 @@ var BalanceSheetView = ({
|
|
|
11601
11645
|
asWidget = false,
|
|
11602
11646
|
stringOverrides
|
|
11603
11647
|
}) => {
|
|
11604
|
-
const [effectiveDate, setEffectiveDate] = (0, import_react127.useState)((0,
|
|
11648
|
+
const [effectiveDate, setEffectiveDate] = (0, import_react127.useState)((0, import_date_fns23.startOfDay)(/* @__PURE__ */ new Date()));
|
|
11605
11649
|
const { data, isLoading, refetch } = useBalanceSheet(effectiveDate);
|
|
11606
11650
|
(0, import_react127.useEffect)(() => {
|
|
11607
|
-
const d1 = effectiveDate && (0,
|
|
11608
|
-
const d2 = data?.effective_date && (0,
|
|
11609
|
-
(0,
|
|
11610
|
-
(0,
|
|
11651
|
+
const d1 = effectiveDate && (0, import_date_fns23.format)((0, import_date_fns23.startOfDay)(effectiveDate), "yyyy-MM-dd'T'HH:mm:ssXXX");
|
|
11652
|
+
const d2 = data?.effective_date && (0, import_date_fns23.format)(
|
|
11653
|
+
(0, import_date_fns23.startOfDay)(
|
|
11654
|
+
(0, import_date_fns23.parse)(data.effective_date, "yyyy-MM-dd'T'HH:mm:ssXXX", /* @__PURE__ */ new Date())
|
|
11611
11655
|
),
|
|
11612
11656
|
"yyyy-MM-dd'T'HH:mm:ssXXX"
|
|
11613
11657
|
);
|
|
@@ -11676,15 +11720,15 @@ var StatementOfCashFlowContext = (0, import_react128.createContext)({
|
|
|
11676
11720
|
|
|
11677
11721
|
// src/hooks/useStatementOfCashFlow/useStatementOfCashFlow.tsx
|
|
11678
11722
|
var import_react129 = require("react");
|
|
11679
|
-
var
|
|
11723
|
+
var import_date_fns24 = require("date-fns");
|
|
11680
11724
|
var import_swr6 = __toESM(require("swr"));
|
|
11681
11725
|
var useStatementOfCashFlow = (startDate = /* @__PURE__ */ new Date(), endDate = /* @__PURE__ */ new Date()) => {
|
|
11682
11726
|
const { auth, businessId, apiUrl, read, syncTimestamps, hasBeenTouched } = useLayerContext();
|
|
11683
|
-
const startDateString = (0,
|
|
11684
|
-
(0,
|
|
11727
|
+
const startDateString = (0, import_date_fns24.format)(
|
|
11728
|
+
(0, import_date_fns24.startOfDay)(startDate),
|
|
11685
11729
|
"yyyy-MM-dd'T'HH:mm:ssXXX"
|
|
11686
11730
|
);
|
|
11687
|
-
const endDateString = (0,
|
|
11731
|
+
const endDateString = (0, import_date_fns24.format)((0, import_date_fns24.startOfDay)(endDate), "yyyy-MM-dd'T'HH:mm:ssXXX");
|
|
11688
11732
|
const queryKey = businessId && startDateString && endDateString && auth?.access_token && `statement-of-cash-${businessId}-${startDateString}-${endDateString}`;
|
|
11689
11733
|
const { data, isLoading, isValidating, error, mutate } = (0, import_swr6.default)(
|
|
11690
11734
|
queryKey,
|
|
@@ -11813,7 +11857,7 @@ var STATEMENT_OF_CASH_FLOW_ROWS = [
|
|
|
11813
11857
|
];
|
|
11814
11858
|
|
|
11815
11859
|
// src/components/StatementOfCashFlow/StatementOfCashFlow.tsx
|
|
11816
|
-
var
|
|
11860
|
+
var import_date_fns25 = require("date-fns");
|
|
11817
11861
|
var COMPONENT_NAME4 = "statement-of-cash-flow";
|
|
11818
11862
|
var StatementOfCashFlow = ({ stringOverrides }) => {
|
|
11819
11863
|
const cashContextData = useStatementOfCashFlow();
|
|
@@ -11821,19 +11865,19 @@ var StatementOfCashFlow = ({ stringOverrides }) => {
|
|
|
11821
11865
|
};
|
|
11822
11866
|
var StatementOfCashFlowView = ({ stringOverrides }) => {
|
|
11823
11867
|
const [startDate, setStartDate] = (0, import_react131.useState)(
|
|
11824
|
-
(0,
|
|
11868
|
+
(0, import_date_fns25.startOfDay)((0, import_date_fns25.subWeeks)(/* @__PURE__ */ new Date(), 4))
|
|
11825
11869
|
);
|
|
11826
|
-
const [endDate, setEndDate] = (0, import_react131.useState)((0,
|
|
11870
|
+
const [endDate, setEndDate] = (0, import_react131.useState)((0, import_date_fns25.startOfDay)(/* @__PURE__ */ new Date()));
|
|
11827
11871
|
const { data, isLoading, refetch } = useStatementOfCashFlow(
|
|
11828
11872
|
startDate,
|
|
11829
11873
|
endDate
|
|
11830
11874
|
);
|
|
11831
11875
|
const handleDateChange = (dates) => {
|
|
11832
11876
|
if (dates[0]) {
|
|
11833
|
-
setStartDate((0,
|
|
11877
|
+
setStartDate((0, import_date_fns25.startOfDay)(dates[0]));
|
|
11834
11878
|
}
|
|
11835
11879
|
if (dates[1]) {
|
|
11836
|
-
setEndDate((0,
|
|
11880
|
+
setEndDate((0, import_date_fns25.startOfDay)(dates[1]));
|
|
11837
11881
|
}
|
|
11838
11882
|
if (dates[0] && dates[1]) {
|
|
11839
11883
|
refetch();
|
|
@@ -11869,7 +11913,7 @@ var import_react149 = __toESM(require("react"));
|
|
|
11869
11913
|
|
|
11870
11914
|
// src/contexts/ChartOfAccountsContext/ChartOfAccountsContext.tsx
|
|
11871
11915
|
var import_react132 = require("react");
|
|
11872
|
-
var
|
|
11916
|
+
var import_date_fns26 = require("date-fns");
|
|
11873
11917
|
var ChartOfAccountsContext = (0, import_react132.createContext)(
|
|
11874
11918
|
{
|
|
11875
11919
|
data: void 0,
|
|
@@ -11892,8 +11936,8 @@ var ChartOfAccountsContext = (0, import_react132.createContext)(
|
|
|
11892
11936
|
submitForm: () => {
|
|
11893
11937
|
},
|
|
11894
11938
|
dateRange: {
|
|
11895
|
-
startDate: (0,
|
|
11896
|
-
endDate: (0,
|
|
11939
|
+
startDate: (0, import_date_fns26.startOfMonth)(/* @__PURE__ */ new Date()),
|
|
11940
|
+
endDate: (0, import_date_fns26.endOfMonth)(/* @__PURE__ */ new Date())
|
|
11897
11941
|
},
|
|
11898
11942
|
changeDateRange: () => {
|
|
11899
11943
|
}
|
|
@@ -12128,7 +12172,7 @@ var LEDGER_ACCOUNT_SUBTYPES_FOR_TYPE = {
|
|
|
12128
12172
|
};
|
|
12129
12173
|
|
|
12130
12174
|
// src/hooks/useChartOfAccounts/useChartOfAccounts.tsx
|
|
12131
|
-
var
|
|
12175
|
+
var import_date_fns27 = require("date-fns");
|
|
12132
12176
|
var import_swr7 = __toESM(require("swr"));
|
|
12133
12177
|
var validate = (formData) => {
|
|
12134
12178
|
const errors = [];
|
|
@@ -12209,8 +12253,8 @@ var validateName = (formData) => {
|
|
|
12209
12253
|
var flattenAccounts = (accounts) => accounts.flatMap((a) => [a, flattenAccounts(a.sub_accounts || [])]).flat().filter((id) => id);
|
|
12210
12254
|
var useChartOfAccounts = ({ withDates, startDate: initialStartDate, endDate: initialEndDate } = {
|
|
12211
12255
|
withDates: false,
|
|
12212
|
-
startDate: (0,
|
|
12213
|
-
endDate: (0,
|
|
12256
|
+
startDate: (0, import_date_fns27.startOfMonth)(/* @__PURE__ */ new Date()),
|
|
12257
|
+
endDate: (0, import_date_fns27.endOfMonth)(/* @__PURE__ */ new Date())
|
|
12214
12258
|
}) => {
|
|
12215
12259
|
const {
|
|
12216
12260
|
auth,
|
|
@@ -12225,10 +12269,10 @@ var useChartOfAccounts = ({ withDates, startDate: initialStartDate, endDate: ini
|
|
|
12225
12269
|
const [sendingForm, setSendingForm] = (0, import_react134.useState)(false);
|
|
12226
12270
|
const [apiError, setApiError] = (0, import_react134.useState)(void 0);
|
|
12227
12271
|
const [startDate, setStartDate] = (0, import_react134.useState)(
|
|
12228
|
-
initialStartDate ?? (0,
|
|
12272
|
+
initialStartDate ?? (0, import_date_fns27.startOfMonth)(Date.now())
|
|
12229
12273
|
);
|
|
12230
12274
|
const [endDate, setEndDate] = (0, import_react134.useState)(
|
|
12231
|
-
initialEndDate ?? (0,
|
|
12275
|
+
initialEndDate ?? (0, import_date_fns27.endOfMonth)(Date.now())
|
|
12232
12276
|
);
|
|
12233
12277
|
const queryKey = businessId && auth?.access_token && `chart-of-accounts-${businessId}-${startDate?.valueOf()}-${endDate?.valueOf()}`;
|
|
12234
12278
|
const { data, isLoading, isValidating, error, mutate } = (0, import_swr7.default)(
|
|
@@ -12236,8 +12280,8 @@ var useChartOfAccounts = ({ withDates, startDate: initialStartDate, endDate: ini
|
|
|
12236
12280
|
Layer.getLedgerAccountBalances(apiUrl, auth?.access_token, {
|
|
12237
12281
|
params: {
|
|
12238
12282
|
businessId,
|
|
12239
|
-
startDate: withDates && startDate ? (0,
|
|
12240
|
-
endDate: withDates && endDate ? (0,
|
|
12283
|
+
startDate: withDates && startDate ? (0, import_date_fns27.formatISO)(startDate.valueOf()) : void 0,
|
|
12284
|
+
endDate: withDates && endDate ? (0, import_date_fns27.formatISO)(endDate.valueOf()) : void 0
|
|
12241
12285
|
}
|
|
12242
12286
|
})
|
|
12243
12287
|
);
|
|
@@ -12292,7 +12336,10 @@ var useChartOfAccounts = ({ withDates, startDate: initialStartDate, endDate: ini
|
|
|
12292
12336
|
}
|
|
12293
12337
|
const data2 = {
|
|
12294
12338
|
name: form.data.name ?? "",
|
|
12295
|
-
stable_name: form.data.stable_name
|
|
12339
|
+
stable_name: form.data.stable_name ? {
|
|
12340
|
+
type: "StableName",
|
|
12341
|
+
stable_name: form.data.stable_name
|
|
12342
|
+
} : void 0,
|
|
12296
12343
|
parent_id: form.data.parent ? {
|
|
12297
12344
|
type: "AccountId",
|
|
12298
12345
|
id: form.data.parent.value
|
|
@@ -12502,7 +12549,7 @@ var import_react141 = __toESM(require("react"));
|
|
|
12502
12549
|
|
|
12503
12550
|
// src/components/ChartOfAccountsDatePicker/ChartOfAccountsDatePicker.tsx
|
|
12504
12551
|
var import_react136 = __toESM(require("react"));
|
|
12505
|
-
var
|
|
12552
|
+
var import_date_fns28 = require("date-fns");
|
|
12506
12553
|
var ChartOfAccountsDatePicker = () => {
|
|
12507
12554
|
const { changeDateRange, dateRange } = (0, import_react136.useContext)(ChartOfAccountsContext);
|
|
12508
12555
|
return /* @__PURE__ */ import_react136.default.createElement(
|
|
@@ -12513,8 +12560,8 @@ var ChartOfAccountsDatePicker = () => {
|
|
|
12513
12560
|
onChange: (date) => {
|
|
12514
12561
|
if (!Array.isArray(date)) {
|
|
12515
12562
|
changeDateRange({
|
|
12516
|
-
startDate: (0,
|
|
12517
|
-
endDate: (0,
|
|
12563
|
+
startDate: (0, import_date_fns28.startOfMonth)(date),
|
|
12564
|
+
endDate: (0, import_date_fns28.endOfMonth)(date)
|
|
12518
12565
|
});
|
|
12519
12566
|
}
|
|
12520
12567
|
}
|
|
@@ -13064,7 +13111,7 @@ var Card = ({ children, className }) => {
|
|
|
13064
13111
|
|
|
13065
13112
|
// src/components/DateTime/DateTime.tsx
|
|
13066
13113
|
var import_react143 = __toESM(require("react"));
|
|
13067
|
-
var
|
|
13114
|
+
var import_date_fns29 = require("date-fns");
|
|
13068
13115
|
var DateTime = ({
|
|
13069
13116
|
value,
|
|
13070
13117
|
format: format7,
|
|
@@ -13074,10 +13121,10 @@ var DateTime = ({
|
|
|
13074
13121
|
onlyTime
|
|
13075
13122
|
}) => {
|
|
13076
13123
|
if (format7) {
|
|
13077
|
-
return /* @__PURE__ */ import_react143.default.createElement(Text, { className: "Layer__datetime" }, (0,
|
|
13124
|
+
return /* @__PURE__ */ import_react143.default.createElement(Text, { className: "Layer__datetime" }, (0, import_date_fns29.format)((0, import_date_fns29.parseISO)(value), format7));
|
|
13078
13125
|
}
|
|
13079
|
-
const date = (0,
|
|
13080
|
-
const time = (0,
|
|
13126
|
+
const date = (0, import_date_fns29.format)((0, import_date_fns29.parseISO)(value), dateFormat ?? DATE_FORMAT);
|
|
13127
|
+
const time = (0, import_date_fns29.format)((0, import_date_fns29.parseISO)(value), timeFormat ?? TIME_FORMAT);
|
|
13081
13128
|
return /* @__PURE__ */ import_react143.default.createElement(Text, { className: "Layer__datetime" }, !onlyTime && /* @__PURE__ */ import_react143.default.createElement(
|
|
13082
13129
|
Text,
|
|
13083
13130
|
{
|
|
@@ -13242,7 +13289,7 @@ var LedgerAccountEntryDetails = ({ stringOverrides }) => {
|
|
|
13242
13289
|
// src/components/LedgerAccount/LedgerAccountRow.tsx
|
|
13243
13290
|
var import_react147 = __toESM(require("react"));
|
|
13244
13291
|
var import_classnames55 = __toESM(require("classnames"));
|
|
13245
|
-
var
|
|
13292
|
+
var import_date_fns30 = require("date-fns");
|
|
13246
13293
|
var LedgerAccountRow = ({
|
|
13247
13294
|
row,
|
|
13248
13295
|
index,
|
|
@@ -13281,7 +13328,7 @@ var LedgerAccountRow = ({
|
|
|
13281
13328
|
}
|
|
13282
13329
|
}
|
|
13283
13330
|
},
|
|
13284
|
-
/* @__PURE__ */ import_react147.default.createElement("td", { className: "Layer__table-cell Layer__ledger-account-table__tablet-main-col" }, /* @__PURE__ */ import_react147.default.createElement("span", { className: "Layer__table-cell-content" }, /* @__PURE__ */ import_react147.default.createElement("div", { className: "Layer__ledger-account-table__tablet-main-col__date" }, /* @__PURE__ */ import_react147.default.createElement(Text, null, row.date && (0,
|
|
13331
|
+
/* @__PURE__ */ import_react147.default.createElement("td", { className: "Layer__table-cell Layer__ledger-account-table__tablet-main-col" }, /* @__PURE__ */ import_react147.default.createElement("span", { className: "Layer__table-cell-content" }, /* @__PURE__ */ import_react147.default.createElement("div", { className: "Layer__ledger-account-table__tablet-main-col__date" }, /* @__PURE__ */ import_react147.default.createElement(Text, null, row.date && (0, import_date_fns30.format)((0, import_date_fns30.parseISO)(row.date), DATE_FORMAT)), /* @__PURE__ */ import_react147.default.createElement(
|
|
13285
13332
|
Text,
|
|
13286
13333
|
{
|
|
13287
13334
|
weight: "normal" /* normal */,
|
|
@@ -13314,7 +13361,7 @@ var LedgerAccountRow = ({
|
|
|
13314
13361
|
}
|
|
13315
13362
|
}
|
|
13316
13363
|
},
|
|
13317
|
-
/* @__PURE__ */ import_react147.default.createElement("td", { className: "Layer__table-cell Layer__ledger-account-table__tablet-main-col" }, /* @__PURE__ */ import_react147.default.createElement("span", { className: "Layer__table-cell-content" }, /* @__PURE__ */ import_react147.default.createElement("div", { className: "Layer__ledger-account-table__tablet-main-col__date" }, /* @__PURE__ */ import_react147.default.createElement(Text, null, row.date && (0,
|
|
13364
|
+
/* @__PURE__ */ import_react147.default.createElement("td", { className: "Layer__table-cell Layer__ledger-account-table__tablet-main-col" }, /* @__PURE__ */ import_react147.default.createElement("span", { className: "Layer__table-cell-content" }, /* @__PURE__ */ import_react147.default.createElement("div", { className: "Layer__ledger-account-table__tablet-main-col__date" }, /* @__PURE__ */ import_react147.default.createElement(Text, null, row.date && (0, import_date_fns30.format)((0, import_date_fns30.parseISO)(row.date), DATE_FORMAT)), /* @__PURE__ */ import_react147.default.createElement(
|
|
13318
13365
|
Text,
|
|
13319
13366
|
{
|
|
13320
13367
|
weight: "normal" /* normal */,
|
|
@@ -13343,7 +13390,7 @@ var LedgerAccountRow = ({
|
|
|
13343
13390
|
}
|
|
13344
13391
|
}
|
|
13345
13392
|
},
|
|
13346
|
-
/* @__PURE__ */ import_react147.default.createElement("td", { className: "Layer__table-cell" }, /* @__PURE__ */ import_react147.default.createElement("span", { className: "Layer__table-cell-content" }, row.date && (0,
|
|
13393
|
+
/* @__PURE__ */ import_react147.default.createElement("td", { className: "Layer__table-cell" }, /* @__PURE__ */ import_react147.default.createElement("span", { className: "Layer__table-cell-content" }, row.date && (0, import_date_fns30.format)((0, import_date_fns30.parseISO)(row.date), DATE_FORMAT))),
|
|
13347
13394
|
/* @__PURE__ */ import_react147.default.createElement("td", { className: "Layer__table-cell" }, /* @__PURE__ */ import_react147.default.createElement("span", { className: "Layer__table-cell-content" }, row.entry_id.substring(0, 5))),
|
|
13348
13395
|
/* @__PURE__ */ import_react147.default.createElement("td", { className: "Layer__table-cell" }, /* @__PURE__ */ import_react147.default.createElement("span", { className: "Layer__table-cell-content" }, row.source?.display_description ?? "")),
|
|
13349
13396
|
/* @__PURE__ */ import_react147.default.createElement("td", { className: "Layer__table-cell Layer__table-cell--primary" }, /* @__PURE__ */ import_react147.default.createElement("span", { className: "Layer__table-cell-content Layer__table-cell--amount" }, row.direction === "DEBIT" /* DEBIT */ && `$${centsToDollars(row?.amount || 0)}`)),
|
|
@@ -13853,7 +13900,7 @@ var import_react157 = __toESM(require("react"));
|
|
|
13853
13900
|
// src/components/JournalRow/JournalRow.tsx
|
|
13854
13901
|
var import_react152 = __toESM(require("react"));
|
|
13855
13902
|
var import_classnames57 = __toESM(require("classnames"));
|
|
13856
|
-
var
|
|
13903
|
+
var import_date_fns31 = require("date-fns");
|
|
13857
13904
|
var INDENTATION2 = 24;
|
|
13858
13905
|
var EXPANDED_STYLE3 = {
|
|
13859
13906
|
height: "100%",
|
|
@@ -13966,7 +14013,7 @@ var JournalRow = ({
|
|
|
13966
14013
|
)
|
|
13967
14014
|
))),
|
|
13968
14015
|
/* @__PURE__ */ import_react152.default.createElement("td", { className: "Layer__table-cell" }, /* @__PURE__ */ import_react152.default.createElement("span", { className: "Layer__table-cell-content" }, row.id.substring(0, 5))),
|
|
13969
|
-
/* @__PURE__ */ import_react152.default.createElement("td", { className: "Layer__table-cell" }, /* @__PURE__ */ import_react152.default.createElement("span", { className: "Layer__table-cell-content" }, row.date && (0,
|
|
14016
|
+
/* @__PURE__ */ import_react152.default.createElement("td", { className: "Layer__table-cell" }, /* @__PURE__ */ import_react152.default.createElement("span", { className: "Layer__table-cell-content" }, row.date && (0, import_date_fns31.format)((0, import_date_fns31.parseISO)(row.date), DATE_FORMAT))),
|
|
13970
14017
|
/* @__PURE__ */ import_react152.default.createElement("td", { className: "Layer__table-cell" }, /* @__PURE__ */ import_react152.default.createElement("span", { className: "Layer__table-cell-content" }, humanizeEnum(row.entry_type))),
|
|
13971
14018
|
/* @__PURE__ */ import_react152.default.createElement("td", { className: "Layer__table-cell" }, /* @__PURE__ */ import_react152.default.createElement("span", { className: "Layer__table-cell-content" }, `(${row.line_items.length})`)),
|
|
13972
14019
|
/* @__PURE__ */ import_react152.default.createElement("td", { className: "Layer__table-cell Layer__table-cell--primary" }, /* @__PURE__ */ import_react152.default.createElement("span", { className: "Layer__table-cell-content Layer__table-cell--amount" }, "$", centsToDollars(
|
|
@@ -14863,7 +14910,7 @@ var TasksList = ({ pageSize = 10 }) => {
|
|
|
14863
14910
|
// src/components/TasksPending/TasksPending.tsx
|
|
14864
14911
|
var import_react164 = __toESM(require("react"));
|
|
14865
14912
|
var import_classnames59 = __toESM(require("classnames"));
|
|
14866
|
-
var
|
|
14913
|
+
var import_date_fns32 = require("date-fns");
|
|
14867
14914
|
var import_recharts4 = require("recharts");
|
|
14868
14915
|
var TasksPending = () => {
|
|
14869
14916
|
const { data } = (0, import_react164.useContext)(TasksContext);
|
|
@@ -14881,7 +14928,7 @@ var TasksPending = () => {
|
|
|
14881
14928
|
const taskStatusClassName = (0, import_classnames59.default)(
|
|
14882
14929
|
completedTasks && completedTasks > 0 ? "Layer__tasks-pending-bar__status--done" : "Layer__tasks-pending-bar__status--pending"
|
|
14883
14930
|
);
|
|
14884
|
-
return /* @__PURE__ */ import_react164.default.createElement("div", { className: "Layer__tasks-pending" }, /* @__PURE__ */ import_react164.default.createElement(Text, { size: "lg" /* lg */ }, (0,
|
|
14931
|
+
return /* @__PURE__ */ import_react164.default.createElement("div", { className: "Layer__tasks-pending" }, /* @__PURE__ */ import_react164.default.createElement(Text, { size: "lg" /* lg */ }, (0, import_date_fns32.format)(Date.now(), "MMMM")), /* @__PURE__ */ import_react164.default.createElement("div", { className: "Layer__tasks-pending-bar" }, /* @__PURE__ */ import_react164.default.createElement(Text, { size: "sm" /* sm */ }, /* @__PURE__ */ import_react164.default.createElement("span", { className: taskStatusClassName }, completedTasks), "/", data?.length, " done"), /* @__PURE__ */ import_react164.default.createElement(import_recharts4.PieChart, { width: 24, height: 24, className: "mini-chart" }, /* @__PURE__ */ import_react164.default.createElement(
|
|
14885
14932
|
import_recharts4.Pie,
|
|
14886
14933
|
{
|
|
14887
14934
|
data: chartData,
|
|
@@ -15208,7 +15255,7 @@ var NotificationCard = ({
|
|
|
15208
15255
|
};
|
|
15209
15256
|
|
|
15210
15257
|
// src/components/TransactionToReviewCard/TransactionToReviewCard.tsx
|
|
15211
|
-
var
|
|
15258
|
+
var import_date_fns33 = require("date-fns");
|
|
15212
15259
|
var TransactionToReviewCard = ({
|
|
15213
15260
|
onClick,
|
|
15214
15261
|
usePnlDateRange
|
|
@@ -15217,7 +15264,7 @@ var TransactionToReviewCard = ({
|
|
|
15217
15264
|
const dateRange = usePnlDateRange ? contextDateRange : void 0;
|
|
15218
15265
|
const [toReview, setToReview] = (0, import_react171.useState)(0);
|
|
15219
15266
|
const { data, loaded, error, refetch } = useProfitAndLossLTM({
|
|
15220
|
-
currentDate: dateRange ? dateRange.startDate : (0,
|
|
15267
|
+
currentDate: dateRange ? dateRange.startDate : (0, import_date_fns33.startOfMonth)(/* @__PURE__ */ new Date())
|
|
15221
15268
|
});
|
|
15222
15269
|
(0, import_react171.useEffect)(() => {
|
|
15223
15270
|
checkTransactionsToReview();
|
|
@@ -15228,7 +15275,7 @@ var TransactionToReviewCard = ({
|
|
|
15228
15275
|
const checkTransactionsToReview = () => {
|
|
15229
15276
|
if (data && dateRange) {
|
|
15230
15277
|
const monthTx = data.filter(
|
|
15231
|
-
(x) => x.month - 1 === (0,
|
|
15278
|
+
(x) => x.month - 1 === (0, import_date_fns33.getMonth)(dateRange.startDate) && x.year === (0, import_date_fns33.getYear)(dateRange.startDate)
|
|
15232
15279
|
);
|
|
15233
15280
|
if (monthTx.length > 0) {
|
|
15234
15281
|
setToReview(monthTx[0].uncategorized_transactions);
|
|
@@ -15677,6 +15724,7 @@ var Components = ({
|
|
|
15677
15724
|
StatementOfCashFlow,
|
|
15678
15725
|
Tasks,
|
|
15679
15726
|
useBankTransactionsContext,
|
|
15727
|
+
useDataSync,
|
|
15680
15728
|
useLayerContext
|
|
15681
15729
|
});
|
|
15682
15730
|
//# sourceMappingURL=index.js.map
|