@layerfi/components 0.1.52 → 0.1.53
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 +1290 -1249
- package/dist/esm/index.js.map +4 -4
- package/dist/index.d.ts +11 -5
- package/dist/index.js +1322 -1280
- 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,7 +762,7 @@ 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
|
|
765
|
+
var import_react11 = require("react");
|
|
735
766
|
|
|
736
767
|
// src/components/BankTransactions/constants.ts
|
|
737
768
|
var CategorizedCategories = [
|
|
@@ -745,493 +776,858 @@ var ReviewCategories = [
|
|
|
745
776
|
"LAYER_REVIEW" /* LAYER_REVIEW */
|
|
746
777
|
];
|
|
747
778
|
|
|
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);
|
|
779
|
+
// src/hooks/useLinkedAccounts/useLinkedAccounts.ts
|
|
780
|
+
var import_react10 = require("react");
|
|
781
|
+
var import_react_plaid_link = require("react-plaid-link");
|
|
759
782
|
|
|
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
|
-
|
|
783
|
+
// src/hooks/useLinkedAccounts/mockData.ts
|
|
784
|
+
var LINKED_ACCOUNTS_MOCK_DATA = [
|
|
785
|
+
{
|
|
786
|
+
id: "d800ada8-8075-4436-a712-08efabcbd51a",
|
|
787
|
+
external_account_external_id: "0Br385JmgbTryJn8nEBnUb4A5ydv06U9Vbqqq",
|
|
788
|
+
external_account_source: "PLAID",
|
|
789
|
+
external_account_name: "Citi Double Cash\xAE Card",
|
|
790
|
+
mask: "1234",
|
|
791
|
+
latest_balance_timestamp: {
|
|
792
|
+
external_account_external_id: "0Br385JmgbTryJn8nEBnUb4A5ydv06U9Vbqqq",
|
|
793
|
+
external_account_source: "PLAID",
|
|
794
|
+
balance: 435121,
|
|
795
|
+
at: "2024-04-03T13:00:00Z",
|
|
796
|
+
created_at: "2024-04-06T22:47:59.715458Z"
|
|
797
|
+
},
|
|
798
|
+
current_ledger_balance: 373717,
|
|
799
|
+
institution: {
|
|
800
|
+
name: "Chase",
|
|
801
|
+
logo: ""
|
|
802
|
+
},
|
|
803
|
+
connection_id: "0Br385JmgbTryJn8nEBnUb4A5ydv06U9Vbqqq",
|
|
804
|
+
connection_external_id: "11111",
|
|
805
|
+
connection_needs_repair_as_of: null,
|
|
806
|
+
requires_user_confirmation_as_of: null,
|
|
807
|
+
is_syncing: true
|
|
808
|
+
},
|
|
809
|
+
{
|
|
810
|
+
id: "f98ec50a-c370-484d-a35b-d00207436075",
|
|
811
|
+
external_account_external_id: "0Br385JmgbTryJn8nEBnUb4A5ydv06U9Vbqqq",
|
|
812
|
+
external_account_source: "PLAID",
|
|
813
|
+
external_account_name: "Citi Double Cash\xAE Card",
|
|
814
|
+
mask: "1234",
|
|
815
|
+
latest_balance_timestamp: {
|
|
816
|
+
external_account_external_id: "0Br385JmgbTryJn8nEBnUb4A5ydv06U9Vbqqq",
|
|
817
|
+
external_account_source: "PLAID",
|
|
818
|
+
balance: 435121,
|
|
819
|
+
at: "2024-04-03T13:00:00Z",
|
|
820
|
+
created_at: "2024-04-06T16:44:35.715458Z"
|
|
821
|
+
},
|
|
822
|
+
current_ledger_balance: 373717,
|
|
823
|
+
institution: {
|
|
824
|
+
name: "Chase",
|
|
825
|
+
logo: ""
|
|
826
|
+
},
|
|
827
|
+
connection_id: "0Br385JmgbTryJn8nEBnUb4A5ydv06U9Vbqqq",
|
|
828
|
+
connection_external_id: "11111",
|
|
829
|
+
connection_needs_repair_as_of: null,
|
|
830
|
+
requires_user_confirmation_as_of: null,
|
|
831
|
+
is_syncing: false
|
|
832
|
+
},
|
|
833
|
+
{
|
|
834
|
+
id: "843f1748-fdaa-422d-a73d-2489a40c8dc7",
|
|
835
|
+
external_account_external_id: "0Br385JmgbTryJn8nEBnUb4A5ydv06U9Vbqqq",
|
|
836
|
+
external_account_source: "PLAID",
|
|
837
|
+
external_account_name: "Citi Double Cash\xAE Card",
|
|
838
|
+
mask: "1234",
|
|
839
|
+
latest_balance_timestamp: {
|
|
840
|
+
external_account_external_id: "0Br385JmgbTryJn8nEBnUb4A5ydv06U9Vbqqq",
|
|
841
|
+
external_account_source: "PLAID",
|
|
842
|
+
balance: 435121,
|
|
843
|
+
at: "2024-04-03T13:00:00Z",
|
|
844
|
+
created_at: "2024-04-06T16:44:35.715458Z"
|
|
845
|
+
},
|
|
846
|
+
current_ledger_balance: 373717,
|
|
847
|
+
institution: {
|
|
848
|
+
name: "Chase",
|
|
849
|
+
logo: ""
|
|
850
|
+
},
|
|
851
|
+
connection_id: "0Br385JmgbTryJn8nEBnUb4A5ydv06U9Vbqqq",
|
|
852
|
+
connection_external_id: "11111",
|
|
853
|
+
connection_needs_repair_as_of: "2024-03-06T16:44:35.715458Z",
|
|
854
|
+
requires_user_confirmation_as_of: null,
|
|
855
|
+
is_syncing: false
|
|
856
|
+
},
|
|
857
|
+
{
|
|
858
|
+
id: "8f430e29-e339-4d71-a08a-fce469c7a7c1",
|
|
859
|
+
external_account_external_id: "0Br385JmgbTryJn8nEBnUb4A5ydv06U9Vbqqq",
|
|
860
|
+
external_account_source: "PLAID",
|
|
861
|
+
external_account_name: "Citi Double Cash\xAE Card",
|
|
862
|
+
mask: "1234",
|
|
863
|
+
latest_balance_timestamp: {
|
|
864
|
+
external_account_external_id: "0Br385JmgbTryJn8nEBnUb4A5ydv06U9Vbqqq",
|
|
865
|
+
external_account_source: "PLAID",
|
|
866
|
+
balance: 435121,
|
|
867
|
+
at: "2024-04-03T13:00:00Z",
|
|
868
|
+
created_at: "2024-04-06T16:44:35.715458Z"
|
|
869
|
+
},
|
|
870
|
+
current_ledger_balance: 373717,
|
|
871
|
+
institution: {
|
|
872
|
+
name: "Chase",
|
|
873
|
+
logo: ""
|
|
874
|
+
},
|
|
875
|
+
connection_id: "0Br385JmgbTryJn8nEBnUb4A5ydv06U9Vbqqq",
|
|
876
|
+
connection_external_id: "11111",
|
|
877
|
+
connection_needs_repair_as_of: null,
|
|
878
|
+
requires_user_confirmation_as_of: "2024-03-06T16:44:35.715458Z",
|
|
879
|
+
is_syncing: false
|
|
803
880
|
}
|
|
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
|
-
};
|
|
881
|
+
];
|
|
822
882
|
|
|
823
|
-
// src/hooks/
|
|
824
|
-
var
|
|
825
|
-
var
|
|
883
|
+
// src/hooks/useLinkedAccounts/useLinkedAccounts.ts
|
|
884
|
+
var import_swr = __toESM(require("swr"));
|
|
885
|
+
var DEBUG = true;
|
|
886
|
+
var USE_MOCK_RESPONSE_DATA = false;
|
|
887
|
+
var useLinkedAccounts = () => {
|
|
826
888
|
const {
|
|
827
889
|
auth,
|
|
828
890
|
businessId,
|
|
829
891
|
apiUrl,
|
|
830
|
-
|
|
892
|
+
usePlaidSandbox,
|
|
831
893
|
touch,
|
|
832
894
|
read,
|
|
833
895
|
syncTimestamps,
|
|
834
|
-
hasBeenTouched
|
|
835
|
-
eventCallbacks
|
|
896
|
+
hasBeenTouched
|
|
836
897
|
} = 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);
|
|
898
|
+
const [linkToken, setLinkToken] = (0, import_react10.useState)(null);
|
|
850
899
|
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
|
-
};
|
|
900
|
+
const USE_PLAID_SANDBOX = usePlaidSandbox ?? true;
|
|
901
|
+
const [linkMode, setLinkMode] = (0, import_react10.useState)("add");
|
|
902
|
+
const queryKey = businessId && auth?.access_token && `linked-accounts-${businessId}`;
|
|
866
903
|
const {
|
|
867
|
-
data:
|
|
904
|
+
data: responseData,
|
|
868
905
|
isLoading,
|
|
869
906
|
isValidating,
|
|
870
907
|
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
|
-
}
|
|
891
|
-
);
|
|
892
|
-
const data = (0, import_react10.useMemo)(() => {
|
|
893
|
-
if (rawResponseData && rawResponseData.length > 0) {
|
|
894
|
-
return rawResponseData?.map((x) => x?.data).flat().filter((x) => !!x);
|
|
895
|
-
}
|
|
896
|
-
return void 0;
|
|
897
|
-
}, [rawResponseData]);
|
|
898
|
-
const lastMetadata = (0, import_react10.useMemo)(() => {
|
|
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]
|
|
908
|
+
mutate
|
|
909
|
+
} = (0, import_swr.default)(
|
|
910
|
+
queryKey,
|
|
911
|
+
Layer.getLinkedAccounts(apiUrl, auth?.access_token, {
|
|
912
|
+
params: { businessId }
|
|
913
|
+
})
|
|
916
914
|
);
|
|
917
915
|
(0, import_react10.useEffect)(() => {
|
|
916
|
+
if (!isLoading && responseData?.data.external_accounts) {
|
|
917
|
+
setLoadingStatus("complete");
|
|
918
|
+
return;
|
|
919
|
+
}
|
|
918
920
|
if (isLoading && loadingStatus === "initial") {
|
|
919
921
|
setLoadingStatus("loading");
|
|
920
922
|
return;
|
|
921
923
|
}
|
|
922
924
|
if (!isLoading && loadingStatus === "loading") {
|
|
923
925
|
setLoadingStatus("complete");
|
|
924
|
-
return;
|
|
925
926
|
}
|
|
926
927
|
}, [isLoading]);
|
|
927
|
-
const
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
});
|
|
935
|
-
};
|
|
936
|
-
const filteredData = (0, import_react10.useMemo)(() => {
|
|
937
|
-
let filtered = data;
|
|
938
|
-
if (!filtered) {
|
|
939
|
-
return;
|
|
940
|
-
}
|
|
941
|
-
if (filters?.amount?.min || filters?.amount?.max) {
|
|
942
|
-
filtered = applyAmountFilter(filtered, filters.amount);
|
|
928
|
+
const fetchPlaidLinkToken = async () => {
|
|
929
|
+
if (auth?.access_token) {
|
|
930
|
+
const linkToken2 = (await Layer.getPlaidLinkToken(apiUrl, auth.access_token, {
|
|
931
|
+
params: { businessId }
|
|
932
|
+
})).data.link_token;
|
|
933
|
+
setLinkMode("add");
|
|
934
|
+
setLinkToken(linkToken2);
|
|
943
935
|
}
|
|
944
|
-
|
|
945
|
-
|
|
936
|
+
};
|
|
937
|
+
const fetchPlaidUpdateModeLinkToken = async (plaidItemPlaidId) => {
|
|
938
|
+
if (auth?.access_token) {
|
|
939
|
+
const linkToken2 = (await Layer.getPlaidUpdateModeLinkToken(apiUrl, auth.access_token, {
|
|
940
|
+
params: { businessId },
|
|
941
|
+
body: { plaid_item_id: plaidItemPlaidId }
|
|
942
|
+
})).data.link_token;
|
|
943
|
+
setLinkMode("update");
|
|
944
|
+
setLinkToken(linkToken2);
|
|
946
945
|
}
|
|
947
|
-
|
|
948
|
-
|
|
946
|
+
};
|
|
947
|
+
const exchangePlaidPublicToken2 = async (publicToken, metadata) => {
|
|
948
|
+
await Layer.exchangePlaidPublicToken(apiUrl, auth?.access_token, {
|
|
949
|
+
params: { businessId },
|
|
950
|
+
body: { public_token: publicToken, institution: metadata.institution }
|
|
951
|
+
});
|
|
952
|
+
refetchAccounts();
|
|
953
|
+
};
|
|
954
|
+
const { open: plaidLinkStart, ready: plaidLinkReady } = (0, import_react_plaid_link.usePlaidLink)({
|
|
955
|
+
token: linkToken,
|
|
956
|
+
// If in update mode, we don't need to exchange the public token for an access token.
|
|
957
|
+
// The existing access token will automatically become valid again
|
|
958
|
+
onSuccess: async (publicToken, metadata) => {
|
|
959
|
+
if (linkMode == "add") {
|
|
960
|
+
exchangePlaidPublicToken2(publicToken, metadata);
|
|
961
|
+
} else {
|
|
962
|
+
await updateConnectionStatus2();
|
|
963
|
+
refetchAccounts();
|
|
964
|
+
setLinkMode("add");
|
|
965
|
+
touch("LINKED_ACCOUNTS" /* LINKED_ACCOUNTS */);
|
|
966
|
+
}
|
|
967
|
+
},
|
|
968
|
+
onExit: () => setLinkMode("add"),
|
|
969
|
+
env: USE_PLAID_SANDBOX ? "sandbox" : void 0
|
|
970
|
+
});
|
|
971
|
+
(0, import_react10.useEffect)(() => {
|
|
972
|
+
if (plaidLinkReady) {
|
|
973
|
+
plaidLinkStart();
|
|
949
974
|
}
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
975
|
+
}, [plaidLinkStart, plaidLinkReady]);
|
|
976
|
+
const mockResponseData = {
|
|
977
|
+
data: LINKED_ACCOUNTS_MOCK_DATA,
|
|
978
|
+
meta: {},
|
|
979
|
+
error: void 0
|
|
980
|
+
};
|
|
981
|
+
const addConnection = (source) => {
|
|
982
|
+
if (source === "PLAID") {
|
|
983
|
+
fetchPlaidLinkToken();
|
|
984
|
+
} else {
|
|
985
|
+
console.error(
|
|
986
|
+
`Adding a connection with source ${source} not yet supported`
|
|
954
987
|
);
|
|
955
988
|
}
|
|
956
|
-
|
|
957
|
-
|
|
989
|
+
};
|
|
990
|
+
const repairConnection = async (source, connectionExternalId) => {
|
|
991
|
+
if (source === "PLAID") {
|
|
992
|
+
await fetchPlaidUpdateModeLinkToken(connectionExternalId);
|
|
993
|
+
} else {
|
|
994
|
+
console.error(
|
|
995
|
+
`Repairing a connection with source ${source} not yet supported`
|
|
996
|
+
);
|
|
958
997
|
}
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
998
|
+
};
|
|
999
|
+
const removeConnection = async (source, connectionExternalId) => {
|
|
1000
|
+
if (source === "PLAID") {
|
|
1001
|
+
await unlinkPlaidItem2(connectionExternalId);
|
|
1002
|
+
await refetchAccounts();
|
|
1003
|
+
} else {
|
|
1004
|
+
console.error(
|
|
1005
|
+
`Removing a connection with source ${source} not yet supported`
|
|
1006
|
+
);
|
|
965
1007
|
}
|
|
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
|
|
1008
|
+
};
|
|
1009
|
+
const unlinkAccount2 = async (source, accountId) => {
|
|
1010
|
+
DEBUG && console.log("unlinking account");
|
|
1011
|
+
if (source === "PLAID") {
|
|
1012
|
+
await Layer.unlinkAccount(apiUrl, auth?.access_token, {
|
|
1013
|
+
params: { businessId, accountId }
|
|
1014
|
+
});
|
|
1015
|
+
await refetchAccounts();
|
|
1016
|
+
touch("LINKED_ACCOUNTS" /* LINKED_ACCOUNTS */);
|
|
1017
|
+
} else {
|
|
1018
|
+
console.error(
|
|
1019
|
+
`Unlinking an account with source ${source} not yet supported`
|
|
984
1020
|
);
|
|
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
|
-
});
|
|
1021
|
+
}
|
|
996
1022
|
};
|
|
997
|
-
const
|
|
998
|
-
|
|
999
|
-
if (
|
|
1000
|
-
|
|
1023
|
+
const confirmAccount = async (source, accountId) => {
|
|
1024
|
+
DEBUG && console.log("confirming account");
|
|
1025
|
+
if (source === "PLAID") {
|
|
1026
|
+
await Layer.confirmConnection(apiUrl, auth?.access_token, {
|
|
1027
|
+
params: {
|
|
1028
|
+
businessId,
|
|
1029
|
+
accountId
|
|
1030
|
+
}
|
|
1031
|
+
});
|
|
1032
|
+
await refetchAccounts();
|
|
1033
|
+
touch("LINKED_ACCOUNTS" /* LINKED_ACCOUNTS */);
|
|
1034
|
+
} else {
|
|
1035
|
+
console.error(
|
|
1036
|
+
`Confirming an account with source ${source} not yet supported`
|
|
1037
|
+
);
|
|
1001
1038
|
}
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1039
|
+
};
|
|
1040
|
+
const denyAccount = async (source, accountId) => {
|
|
1041
|
+
DEBUG && console.log("confirming account");
|
|
1042
|
+
if (source === "PLAID") {
|
|
1043
|
+
await Layer.denyConnection(apiUrl, auth?.access_token, {
|
|
1044
|
+
params: {
|
|
1045
|
+
businessId,
|
|
1046
|
+
accountId
|
|
1047
|
+
}
|
|
1048
|
+
});
|
|
1049
|
+
await refetchAccounts();
|
|
1050
|
+
touch("LINKED_ACCOUNTS" /* LINKED_ACCOUNTS */);
|
|
1051
|
+
} else {
|
|
1052
|
+
console.error(
|
|
1053
|
+
`Denying an account with source ${source} not yet supported`
|
|
1008
1054
|
);
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
}
|
|
1023
|
-
|
|
1024
|
-
|
|
1055
|
+
}
|
|
1056
|
+
};
|
|
1057
|
+
const breakConnection = async (source, connectionExternalId) => {
|
|
1058
|
+
DEBUG && console.log("Breaking sandbox plaid item connection");
|
|
1059
|
+
if (source === "PLAID") {
|
|
1060
|
+
await Layer.breakPlaidItemConnection(apiUrl, auth?.access_token, {
|
|
1061
|
+
params: {
|
|
1062
|
+
businessId,
|
|
1063
|
+
plaidItemPlaidId: connectionExternalId
|
|
1064
|
+
}
|
|
1065
|
+
});
|
|
1066
|
+
await refetchAccounts();
|
|
1067
|
+
touch("LINKED_ACCOUNTS" /* LINKED_ACCOUNTS */);
|
|
1068
|
+
} else {
|
|
1069
|
+
console.error(
|
|
1070
|
+
`Breaking a sandbox connection with source ${source} not yet supported`
|
|
1025
1071
|
);
|
|
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
|
-
});
|
|
1072
|
+
}
|
|
1037
1073
|
};
|
|
1038
|
-
const
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
...page,
|
|
1042
|
-
data: page.data?.map(
|
|
1043
|
-
(bt) => bt.id === newBankTransaction.id ? newBankTransaction : bt
|
|
1044
|
-
)
|
|
1045
|
-
};
|
|
1046
|
-
});
|
|
1047
|
-
mutate(updatedData, { revalidate: false });
|
|
1074
|
+
const refetchAccounts = async () => {
|
|
1075
|
+
DEBUG && console.log("refetching accounts...");
|
|
1076
|
+
await mutate();
|
|
1048
1077
|
};
|
|
1049
|
-
const
|
|
1078
|
+
const syncAccounts = async () => {
|
|
1079
|
+
DEBUG && console.log("resyncing accounts...");
|
|
1080
|
+
await Layer.syncConnection(apiUrl, auth?.access_token, {
|
|
1081
|
+
params: { businessId }
|
|
1082
|
+
});
|
|
1050
1083
|
};
|
|
1051
|
-
const
|
|
1052
|
-
|
|
1084
|
+
const updateConnectionStatus2 = async () => {
|
|
1085
|
+
DEBUG && console.log("updating connection status...");
|
|
1086
|
+
await Layer.updateConnectionStatus(apiUrl, auth?.access_token, {
|
|
1087
|
+
params: { businessId }
|
|
1088
|
+
});
|
|
1053
1089
|
};
|
|
1054
|
-
const
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1090
|
+
const unlinkPlaidItem2 = async (plaidItemPlaidId) => {
|
|
1091
|
+
DEBUG && console.log("unlinking plaid item");
|
|
1092
|
+
await Layer.unlinkPlaidItem(apiUrl, auth?.access_token, {
|
|
1093
|
+
params: { businessId, plaidItemPlaidId }
|
|
1094
|
+
});
|
|
1095
|
+
await refetchAccounts();
|
|
1096
|
+
touch("LINKED_ACCOUNTS" /* LINKED_ACCOUNTS */);
|
|
1058
1097
|
};
|
|
1059
1098
|
(0, import_react10.useEffect)(() => {
|
|
1060
|
-
if (isLoading || isValidating) {
|
|
1061
|
-
read("
|
|
1099
|
+
if (queryKey && (isLoading || isValidating)) {
|
|
1100
|
+
read("LINKED_ACCOUNTS" /* LINKED_ACCOUNTS */, queryKey);
|
|
1062
1101
|
}
|
|
1063
1102
|
}, [isLoading, isValidating]);
|
|
1064
1103
|
(0, import_react10.useEffect)(() => {
|
|
1065
|
-
if (hasBeenTouched(
|
|
1066
|
-
|
|
1104
|
+
if (queryKey && hasBeenTouched(queryKey)) {
|
|
1105
|
+
refetchAccounts();
|
|
1067
1106
|
}
|
|
1068
1107
|
}, [syncTimestamps]);
|
|
1069
1108
|
return {
|
|
1070
|
-
data:
|
|
1071
|
-
metadata: lastMetadata,
|
|
1072
|
-
loadingStatus,
|
|
1109
|
+
data: USE_MOCK_RESPONSE_DATA ? mockResponseData.data : responseData?.data.external_accounts,
|
|
1073
1110
|
isLoading,
|
|
1111
|
+
loadingStatus,
|
|
1074
1112
|
isValidating,
|
|
1075
|
-
refetch,
|
|
1076
1113
|
error: responseError,
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
hasMore
|
|
1114
|
+
addConnection,
|
|
1115
|
+
removeConnection,
|
|
1116
|
+
repairConnection,
|
|
1117
|
+
refetchAccounts,
|
|
1118
|
+
unlinkAccount: unlinkAccount2,
|
|
1119
|
+
confirmAccount,
|
|
1120
|
+
denyAccount,
|
|
1121
|
+
breakConnection,
|
|
1122
|
+
syncAccounts,
|
|
1123
|
+
updateConnectionStatus: updateConnectionStatus2
|
|
1088
1124
|
};
|
|
1089
1125
|
};
|
|
1090
1126
|
|
|
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
|
|
1127
|
+
// src/hooks/useBankTransactions/utils.ts
|
|
1128
|
+
var collectAccounts = (transactions) => {
|
|
1129
|
+
const accounts = [];
|
|
1130
|
+
if (!transactions) {
|
|
1131
|
+
return accounts;
|
|
1121
1132
|
}
|
|
1133
|
+
transactions.forEach((x) => {
|
|
1134
|
+
if (!accounts.find((y) => y.id === x.source_account_id)) {
|
|
1135
|
+
accounts.push({
|
|
1136
|
+
id: x.source_account_id,
|
|
1137
|
+
name: x.account_name || ""
|
|
1138
|
+
});
|
|
1139
|
+
}
|
|
1140
|
+
});
|
|
1141
|
+
return accounts.sort((a, b) => a.name.localeCompare(b.name));
|
|
1142
|
+
};
|
|
1143
|
+
var applyAmountFilter = (data, filter) => {
|
|
1144
|
+
return data?.filter((x) => {
|
|
1145
|
+
if ((filter?.min || filter?.min === 0) && (filter?.max || filter?.max === 0)) {
|
|
1146
|
+
return x.amount >= filter.min * 100 && x.amount <= filter.max * 100;
|
|
1147
|
+
}
|
|
1148
|
+
if (filter?.min || filter?.min === 0) {
|
|
1149
|
+
return x.amount >= filter.min * 100;
|
|
1150
|
+
}
|
|
1151
|
+
if (filter?.max || filter?.max === 0) {
|
|
1152
|
+
return x.amount <= filter.max * 100;
|
|
1153
|
+
}
|
|
1154
|
+
});
|
|
1122
1155
|
};
|
|
1156
|
+
var applyAccountFilter = (data, filter) => data?.filter((x) => filter && filter.includes(x.source_account_id));
|
|
1123
1157
|
|
|
1124
|
-
// src/
|
|
1125
|
-
var
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
}
|
|
1136
|
-
|
|
1158
|
+
// src/hooks/useBankTransactions/useBankTransactions.tsx
|
|
1159
|
+
var import_infinite = __toESM(require("swr/infinite"));
|
|
1160
|
+
var INITIAL_POLL_INTERVAL_MS = 1e3;
|
|
1161
|
+
var POLL_INTERVAL_AFTER_TXNS_RECEIVED_MS = 5e3;
|
|
1162
|
+
function useTriggerOnChange(data, anyAccountSyncing, callback) {
|
|
1163
|
+
const prevDataRef = (0, import_react11.useRef)();
|
|
1164
|
+
(0, import_react11.useEffect)(() => {
|
|
1165
|
+
if (anyAccountSyncing && prevDataRef.current !== void 0 && prevDataRef.current !== data) {
|
|
1166
|
+
callback(data);
|
|
1167
|
+
}
|
|
1168
|
+
prevDataRef.current = data;
|
|
1169
|
+
}, [data, anyAccountSyncing, callback]);
|
|
1170
|
+
}
|
|
1171
|
+
var filtersSettingString = (filters) => {
|
|
1172
|
+
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()}` : ""}`;
|
|
1137
1173
|
};
|
|
1138
|
-
var
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1174
|
+
var useBankTransactions = (params) => {
|
|
1175
|
+
const {
|
|
1176
|
+
auth,
|
|
1177
|
+
businessId,
|
|
1178
|
+
apiUrl,
|
|
1179
|
+
addToast,
|
|
1180
|
+
touch,
|
|
1181
|
+
read,
|
|
1182
|
+
syncTimestamps,
|
|
1183
|
+
hasBeenTouched,
|
|
1184
|
+
eventCallbacks
|
|
1185
|
+
} = useLayerContext();
|
|
1186
|
+
const { scope = void 0 } = params ?? {};
|
|
1187
|
+
const [filters, setTheFilters] = (0, import_react11.useState)(
|
|
1188
|
+
scope ? { categorizationStatus: scope } : void 0
|
|
1189
|
+
);
|
|
1190
|
+
const display = (0, import_react11.useMemo)(() => {
|
|
1191
|
+
if (filters?.categorizationStatus === "review" /* review */) {
|
|
1192
|
+
return "review" /* review */;
|
|
1193
|
+
} else if (filters?.categorizationStatus === "all" /* all */) {
|
|
1194
|
+
return "all" /* all */;
|
|
1145
1195
|
}
|
|
1146
|
-
return
|
|
1147
|
-
}
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
return {};
|
|
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
|
-
};
|
|
1196
|
+
return "categorized" /* categorized */;
|
|
1197
|
+
}, [filters?.categorizationStatus]);
|
|
1198
|
+
const [active, setActive] = (0, import_react11.useState)(false);
|
|
1199
|
+
const [loadingStatus, setLoadingStatus] = (0, import_react11.useState)("initial");
|
|
1200
|
+
const getKey = (index, prevData) => {
|
|
1201
|
+
if (!auth?.access_token || !active) {
|
|
1202
|
+
return [false, void 0];
|
|
1162
1203
|
}
|
|
1163
|
-
if (
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
[`--color-${colorName}-l`]: `${l}%`
|
|
1169
|
-
};
|
|
1204
|
+
if (index === 0) {
|
|
1205
|
+
return [
|
|
1206
|
+
businessId && auth?.access_token && `${filtersSettingString(filters)}-${businessId}`,
|
|
1207
|
+
void 0
|
|
1208
|
+
];
|
|
1170
1209
|
}
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1210
|
+
return [
|
|
1211
|
+
businessId && auth?.access_token && `${filtersSettingString(filters)}-${businessId}-${prevData?.meta?.pagination?.cursor}`,
|
|
1212
|
+
prevData?.meta?.pagination?.cursor.toString()
|
|
1213
|
+
];
|
|
1214
|
+
};
|
|
1215
|
+
const {
|
|
1216
|
+
data: rawResponseData,
|
|
1217
|
+
isLoading,
|
|
1218
|
+
isValidating,
|
|
1219
|
+
error: responseError,
|
|
1220
|
+
mutate,
|
|
1221
|
+
size,
|
|
1222
|
+
setSize
|
|
1223
|
+
} = (0, import_infinite.default)(
|
|
1224
|
+
getKey,
|
|
1225
|
+
async ([_query, nextCursor]) => {
|
|
1226
|
+
if (auth?.access_token) {
|
|
1227
|
+
return Layer.getBankTransactions(apiUrl, auth?.access_token, {
|
|
1228
|
+
params: {
|
|
1229
|
+
businessId,
|
|
1230
|
+
cursor: nextCursor ?? "",
|
|
1231
|
+
categorized: filters?.categorizationStatus ? filters?.categorizationStatus === "categorized" /* categorized */ ? "true" : filters?.categorizationStatus === "review" /* review */ ? "false" : "" : "",
|
|
1232
|
+
direction: filters?.direction?.length === 1 ? filters.direction[0] === "CREDIT" /* CREDIT */ ? "INFLOW" : "OUTFLOW" : void 0,
|
|
1233
|
+
startDate: filters?.dateRange?.startDate?.toISOString() ?? void 0,
|
|
1234
|
+
endDate: filters?.dateRange?.endDate?.toISOString() ?? void 0
|
|
1235
|
+
}
|
|
1236
|
+
}).call(false);
|
|
1175
1237
|
}
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
return {
|
|
1182
|
-
[`--color-${colorName}-h`]: h,
|
|
1183
|
-
[`--color-${colorName}-s`]: `${s}%`,
|
|
1184
|
-
[`--color-${colorName}-l`]: `${l}%`
|
|
1185
|
-
};
|
|
1238
|
+
return {};
|
|
1239
|
+
},
|
|
1240
|
+
{
|
|
1241
|
+
initialSize: 1,
|
|
1242
|
+
revalidateFirstPage: false
|
|
1186
1243
|
}
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
};
|
|
1192
|
-
var parseColorFromThemeToHsl = (color) => {
|
|
1193
|
-
if (!color) {
|
|
1194
|
-
return;
|
|
1195
|
-
}
|
|
1196
|
-
try {
|
|
1197
|
-
if ("h" in color && "s" in color && "l" in color) {
|
|
1198
|
-
return {
|
|
1199
|
-
h: Number(color.h),
|
|
1200
|
-
s: Number(color.s),
|
|
1201
|
-
l: Number(color.l)
|
|
1202
|
-
};
|
|
1244
|
+
);
|
|
1245
|
+
const data = (0, import_react11.useMemo)(() => {
|
|
1246
|
+
if (rawResponseData && rawResponseData.length > 0) {
|
|
1247
|
+
return rawResponseData?.map((x) => x?.data).flat().filter((x) => !!x);
|
|
1203
1248
|
}
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
l
|
|
1210
|
-
};
|
|
1249
|
+
return void 0;
|
|
1250
|
+
}, [rawResponseData]);
|
|
1251
|
+
const lastMetadata = (0, import_react11.useMemo)(() => {
|
|
1252
|
+
if (rawResponseData && rawResponseData.length > 0) {
|
|
1253
|
+
return rawResponseData[rawResponseData.length - 1].meta;
|
|
1211
1254
|
}
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
b: rgb.b.toString()
|
|
1221
|
-
});
|
|
1222
|
-
return {
|
|
1223
|
-
h,
|
|
1224
|
-
s,
|
|
1225
|
-
l
|
|
1226
|
-
};
|
|
1255
|
+
return void 0;
|
|
1256
|
+
}, [rawResponseData]);
|
|
1257
|
+
const hasMore = (0, import_react11.useMemo)(() => {
|
|
1258
|
+
if (rawResponseData && rawResponseData.length > 0) {
|
|
1259
|
+
const lastElement = rawResponseData[rawResponseData.length - 1];
|
|
1260
|
+
return Boolean(
|
|
1261
|
+
lastElement.meta?.pagination?.cursor && lastElement.meta?.pagination?.has_more
|
|
1262
|
+
);
|
|
1227
1263
|
}
|
|
1228
|
-
return;
|
|
1229
|
-
}
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1264
|
+
return false;
|
|
1265
|
+
}, [rawResponseData]);
|
|
1266
|
+
const accountsList = (0, import_react11.useMemo)(
|
|
1267
|
+
() => data ? collectAccounts(data) : [],
|
|
1268
|
+
[data]
|
|
1269
|
+
);
|
|
1270
|
+
(0, import_react11.useEffect)(() => {
|
|
1271
|
+
if (isLoading && loadingStatus === "initial") {
|
|
1272
|
+
setLoadingStatus("loading");
|
|
1273
|
+
return;
|
|
1274
|
+
}
|
|
1275
|
+
if (!isLoading && loadingStatus === "loading") {
|
|
1276
|
+
setLoadingStatus("complete");
|
|
1277
|
+
return;
|
|
1278
|
+
}
|
|
1279
|
+
}, [isLoading]);
|
|
1280
|
+
const activate = () => {
|
|
1281
|
+
setActive(true);
|
|
1282
|
+
};
|
|
1283
|
+
const setFilters = (value) => {
|
|
1284
|
+
setTheFilters({
|
|
1285
|
+
...filters,
|
|
1286
|
+
...value ?? {}
|
|
1287
|
+
});
|
|
1288
|
+
};
|
|
1289
|
+
const filteredData = (0, import_react11.useMemo)(() => {
|
|
1290
|
+
let filtered = data;
|
|
1291
|
+
if (!filtered) {
|
|
1292
|
+
return;
|
|
1293
|
+
}
|
|
1294
|
+
if (filters?.amount?.min || filters?.amount?.max) {
|
|
1295
|
+
filtered = applyAmountFilter(filtered, filters.amount);
|
|
1296
|
+
}
|
|
1297
|
+
if (filters?.account) {
|
|
1298
|
+
filtered = applyAccountFilter(filtered, filters.account);
|
|
1299
|
+
}
|
|
1300
|
+
return filtered;
|
|
1301
|
+
}, [filters, data]);
|
|
1302
|
+
const categorize = (id, newCategory, notify) => {
|
|
1303
|
+
const foundBT = data?.find((x) => x.business_id === businessId && x.id === id);
|
|
1304
|
+
if (foundBT) {
|
|
1305
|
+
updateOneLocal({ ...foundBT, processing: true, error: void 0 });
|
|
1306
|
+
}
|
|
1307
|
+
return Layer.categorizeBankTransaction(apiUrl, auth.access_token, {
|
|
1308
|
+
params: { businessId, bankTransactionId: id },
|
|
1309
|
+
body: newCategory
|
|
1310
|
+
}).then(({ data: newBT, errors }) => {
|
|
1311
|
+
if (newBT) {
|
|
1312
|
+
newBT.recently_categorized = true;
|
|
1313
|
+
updateOneLocal(newBT);
|
|
1314
|
+
}
|
|
1315
|
+
if (errors) {
|
|
1316
|
+
console.error(errors);
|
|
1317
|
+
throw errors;
|
|
1318
|
+
}
|
|
1319
|
+
if (newBT?.recently_categorized === true && notify) {
|
|
1320
|
+
addToast({ content: "Transaction saved" });
|
|
1321
|
+
}
|
|
1322
|
+
}).catch((err) => {
|
|
1323
|
+
const newBT = data?.find(
|
|
1324
|
+
(x) => x.business_id === businessId && x.id === id
|
|
1325
|
+
);
|
|
1326
|
+
if (newBT) {
|
|
1327
|
+
updateOneLocal({
|
|
1328
|
+
...newBT,
|
|
1329
|
+
error: err.message,
|
|
1330
|
+
processing: false
|
|
1331
|
+
});
|
|
1332
|
+
}
|
|
1333
|
+
}).finally(() => {
|
|
1334
|
+
touch("BANK_TRANSACTIONS" /* BANK_TRANSACTIONS */);
|
|
1335
|
+
eventCallbacks?.onTransactionCategorized?.(id);
|
|
1336
|
+
});
|
|
1337
|
+
};
|
|
1338
|
+
const match = (id, matchId, notify) => {
|
|
1339
|
+
const foundBT = data?.find((x) => x.business_id === businessId && x.id === id);
|
|
1340
|
+
if (foundBT) {
|
|
1341
|
+
updateOneLocal({ ...foundBT, processing: true, error: void 0 });
|
|
1342
|
+
}
|
|
1343
|
+
return Layer.matchBankTransaction(apiUrl, auth.access_token, {
|
|
1344
|
+
params: { businessId, bankTransactionId: id },
|
|
1345
|
+
body: { match_id: matchId, type: "Confirm_Match" /* CONFIRM_MATCH */ }
|
|
1346
|
+
}).then(({ data: bt, errors }) => {
|
|
1347
|
+
const newBT = data?.find(
|
|
1348
|
+
(x) => x.business_id === businessId && x.id === id
|
|
1349
|
+
);
|
|
1350
|
+
if (newBT) {
|
|
1351
|
+
newBT.recently_categorized = true;
|
|
1352
|
+
newBT.match = bt;
|
|
1353
|
+
newBT.categorization_status = "MATCHED" /* MATCHED */;
|
|
1354
|
+
updateOneLocal(newBT);
|
|
1355
|
+
}
|
|
1356
|
+
if (errors) {
|
|
1357
|
+
console.error(errors);
|
|
1358
|
+
throw errors;
|
|
1359
|
+
}
|
|
1360
|
+
if (newBT?.recently_categorized === true && notify) {
|
|
1361
|
+
addToast({ content: "Transaction saved" });
|
|
1362
|
+
}
|
|
1363
|
+
}).catch((err) => {
|
|
1364
|
+
const newBT = data?.find(
|
|
1365
|
+
(x) => x.business_id === businessId && x.id === id
|
|
1366
|
+
);
|
|
1367
|
+
if (newBT) {
|
|
1368
|
+
updateOneLocal({
|
|
1369
|
+
...newBT,
|
|
1370
|
+
error: err.message,
|
|
1371
|
+
processing: false
|
|
1372
|
+
});
|
|
1373
|
+
}
|
|
1374
|
+
}).finally(() => {
|
|
1375
|
+
touch("BANK_TRANSACTIONS" /* BANK_TRANSACTIONS */);
|
|
1376
|
+
eventCallbacks?.onTransactionCategorized?.(id);
|
|
1377
|
+
});
|
|
1378
|
+
};
|
|
1379
|
+
const updateOneLocal = (newBankTransaction) => {
|
|
1380
|
+
const updatedData = rawResponseData?.map((page) => {
|
|
1381
|
+
return {
|
|
1382
|
+
...page,
|
|
1383
|
+
data: page.data?.map(
|
|
1384
|
+
(bt) => bt.id === newBankTransaction.id ? newBankTransaction : bt
|
|
1385
|
+
)
|
|
1386
|
+
};
|
|
1387
|
+
});
|
|
1388
|
+
mutate(updatedData, { revalidate: false });
|
|
1389
|
+
};
|
|
1390
|
+
const shouldHideAfterCategorize = (bankTransaction) => {
|
|
1391
|
+
return filters?.categorizationStatus === "review" /* review */ && ReviewCategories.includes(bankTransaction.categorization_status);
|
|
1392
|
+
};
|
|
1393
|
+
const removeAfterCategorize = (bankTransaction) => {
|
|
1394
|
+
if (shouldHideAfterCategorize(bankTransaction)) {
|
|
1395
|
+
const updatedData = rawResponseData?.map((page) => {
|
|
1396
|
+
return {
|
|
1397
|
+
...page,
|
|
1398
|
+
data: page.data?.filter((bt) => bt.id !== bankTransaction.id)
|
|
1399
|
+
};
|
|
1400
|
+
});
|
|
1401
|
+
mutate(updatedData, { revalidate: false });
|
|
1402
|
+
}
|
|
1403
|
+
};
|
|
1404
|
+
const refetch = () => {
|
|
1405
|
+
mutate();
|
|
1406
|
+
};
|
|
1407
|
+
const fetchMore = () => {
|
|
1408
|
+
if (hasMore) {
|
|
1409
|
+
setSize(size + 1);
|
|
1410
|
+
}
|
|
1411
|
+
};
|
|
1412
|
+
const getCacheKey = (txnFilters) => {
|
|
1413
|
+
return filtersSettingString(txnFilters);
|
|
1414
|
+
};
|
|
1415
|
+
(0, import_react11.useEffect)(() => {
|
|
1416
|
+
if (isLoading || isValidating) {
|
|
1417
|
+
read("BANK_TRANSACTIONS" /* BANK_TRANSACTIONS */, getCacheKey(filters));
|
|
1418
|
+
}
|
|
1419
|
+
}, [isLoading, isValidating]);
|
|
1420
|
+
(0, import_react11.useEffect)(() => {
|
|
1421
|
+
if (hasBeenTouched(getCacheKey(filters))) {
|
|
1422
|
+
refetch();
|
|
1423
|
+
}
|
|
1424
|
+
}, [syncTimestamps, filters]);
|
|
1425
|
+
const { data: linkedAccounts, refetchAccounts } = useLinkedAccounts();
|
|
1426
|
+
const anyAccountSyncing = (0, import_react11.useMemo)(
|
|
1427
|
+
() => Boolean(linkedAccounts?.some((item) => item.is_syncing)),
|
|
1428
|
+
[linkedAccounts]
|
|
1429
|
+
);
|
|
1430
|
+
const [pollIntervalMs, setPollIntervalMs] = (0, import_react11.useState)(INITIAL_POLL_INTERVAL_MS);
|
|
1431
|
+
const transactionsNotSynced = (0, import_react11.useMemo)(
|
|
1432
|
+
() => loadingStatus === "complete" && anyAccountSyncing && (!data || data?.length === 0),
|
|
1433
|
+
[data, anyAccountSyncing, loadingStatus]
|
|
1434
|
+
);
|
|
1435
|
+
let intervalId = void 0;
|
|
1436
|
+
const [refreshTrigger, setRefreshTrigger] = (0, import_react11.useState)(-1);
|
|
1437
|
+
(0, import_react11.useEffect)(() => {
|
|
1438
|
+
if (refreshTrigger !== -1) {
|
|
1439
|
+
refetch();
|
|
1440
|
+
refetchAccounts();
|
|
1441
|
+
}
|
|
1442
|
+
}, [refreshTrigger]);
|
|
1443
|
+
(0, import_react11.useEffect)(() => {
|
|
1444
|
+
if (anyAccountSyncing) {
|
|
1445
|
+
intervalId = setInterval(() => {
|
|
1446
|
+
setRefreshTrigger(Math.random());
|
|
1447
|
+
}, pollIntervalMs);
|
|
1448
|
+
} else {
|
|
1449
|
+
if (intervalId) {
|
|
1450
|
+
clearInterval(intervalId);
|
|
1451
|
+
}
|
|
1452
|
+
}
|
|
1453
|
+
return () => {
|
|
1454
|
+
if (intervalId) {
|
|
1455
|
+
clearInterval(intervalId);
|
|
1456
|
+
}
|
|
1457
|
+
};
|
|
1458
|
+
}, [anyAccountSyncing, transactionsNotSynced, pollIntervalMs]);
|
|
1459
|
+
useTriggerOnChange(data, anyAccountSyncing, (newTransactionList) => {
|
|
1460
|
+
clearInterval(intervalId);
|
|
1461
|
+
setPollIntervalMs(POLL_INTERVAL_AFTER_TXNS_RECEIVED_MS);
|
|
1462
|
+
touch("BANK_TRANSACTIONS" /* BANK_TRANSACTIONS */);
|
|
1463
|
+
});
|
|
1464
|
+
return {
|
|
1465
|
+
data: filteredData,
|
|
1466
|
+
metadata: lastMetadata,
|
|
1467
|
+
loadingStatus,
|
|
1468
|
+
isLoading,
|
|
1469
|
+
isValidating,
|
|
1470
|
+
refetch,
|
|
1471
|
+
error: responseError,
|
|
1472
|
+
categorize,
|
|
1473
|
+
match,
|
|
1474
|
+
updateOneLocal,
|
|
1475
|
+
shouldHideAfterCategorize,
|
|
1476
|
+
removeAfterCategorize,
|
|
1477
|
+
filters,
|
|
1478
|
+
setFilters,
|
|
1479
|
+
accountsList,
|
|
1480
|
+
activate,
|
|
1481
|
+
display,
|
|
1482
|
+
fetchMore,
|
|
1483
|
+
hasMore
|
|
1484
|
+
};
|
|
1485
|
+
};
|
|
1486
|
+
|
|
1487
|
+
// src/providers/BankTransactionsProvider/BankTransactionsProvider.tsx
|
|
1488
|
+
var BankTransactionsProvider = ({
|
|
1489
|
+
children
|
|
1490
|
+
}) => {
|
|
1491
|
+
const bankTransactionsContextData = useBankTransactions();
|
|
1492
|
+
return /* @__PURE__ */ import_react12.default.createElement(BankTransactionsContext.Provider, { value: bankTransactionsContextData }, children);
|
|
1493
|
+
};
|
|
1494
|
+
|
|
1495
|
+
// src/config/theme.ts
|
|
1496
|
+
var SHADES = {
|
|
1497
|
+
50: { s: 1, l: 98 },
|
|
1498
|
+
100: { s: 1, l: 96 },
|
|
1499
|
+
200: { s: 1, l: 94 },
|
|
1500
|
+
300: { s: 2, l: 92 },
|
|
1501
|
+
500: { s: 5, l: 53 },
|
|
1502
|
+
600: { s: 7, l: 40 },
|
|
1503
|
+
700: { s: 9, l: 27 },
|
|
1504
|
+
800: { s: 12, l: 20 },
|
|
1505
|
+
1e3: { s: 20, l: 7 }
|
|
1506
|
+
};
|
|
1507
|
+
var COLORS = {
|
|
1508
|
+
dark: {
|
|
1509
|
+
h: 0,
|
|
1510
|
+
s: 0,
|
|
1511
|
+
l: 7
|
|
1512
|
+
},
|
|
1513
|
+
light: {
|
|
1514
|
+
h: 0,
|
|
1515
|
+
s: 0,
|
|
1516
|
+
l: 100
|
|
1517
|
+
}
|
|
1518
|
+
};
|
|
1519
|
+
|
|
1520
|
+
// src/utils/colors.ts
|
|
1521
|
+
var parseStylesFromThemeConfig = (theme) => {
|
|
1522
|
+
let styles = {};
|
|
1523
|
+
if (!theme) {
|
|
1524
|
+
return styles;
|
|
1525
|
+
}
|
|
1526
|
+
if (theme.colors) {
|
|
1527
|
+
const darkColor = parseColorFromTheme("dark", theme.colors.dark);
|
|
1528
|
+
const lightColor = parseColorFromTheme("light", theme.colors.light);
|
|
1529
|
+
const textColor = parseTextColorFromTheme(theme.colors.text);
|
|
1530
|
+
styles = { ...styles, ...darkColor, ...lightColor, ...textColor };
|
|
1531
|
+
}
|
|
1532
|
+
return styles;
|
|
1533
|
+
};
|
|
1534
|
+
var parseTextColorFromTheme = (color) => {
|
|
1535
|
+
if (!color) {
|
|
1536
|
+
return {};
|
|
1537
|
+
}
|
|
1538
|
+
try {
|
|
1539
|
+
if ("hex" in color) {
|
|
1540
|
+
return { "--text-color-primary": color.hex };
|
|
1541
|
+
}
|
|
1542
|
+
return {};
|
|
1543
|
+
} catch (_err) {
|
|
1544
|
+
return {};
|
|
1545
|
+
}
|
|
1546
|
+
};
|
|
1547
|
+
var parseColorFromTheme = (colorName, color) => {
|
|
1548
|
+
if (!color) {
|
|
1549
|
+
return {};
|
|
1550
|
+
}
|
|
1551
|
+
try {
|
|
1552
|
+
if ("h" in color && "s" in color && "l" in color) {
|
|
1553
|
+
return {
|
|
1554
|
+
[`--color-${colorName}-h`]: color.h,
|
|
1555
|
+
[`--color-${colorName}-s`]: color.s,
|
|
1556
|
+
[`--color-${colorName}-l`]: color.l
|
|
1557
|
+
};
|
|
1558
|
+
}
|
|
1559
|
+
if ("r" in color && "g" in color && "b" in color) {
|
|
1560
|
+
const { h, s, l } = rgbToHsl(color);
|
|
1561
|
+
return {
|
|
1562
|
+
[`--color-${colorName}-h`]: h,
|
|
1563
|
+
[`--color-${colorName}-s`]: `${s}%`,
|
|
1564
|
+
[`--color-${colorName}-l`]: `${l}%`
|
|
1565
|
+
};
|
|
1566
|
+
}
|
|
1567
|
+
if ("hex" in color) {
|
|
1568
|
+
const rgb = hexToRgb(color.hex);
|
|
1569
|
+
if (!rgb) {
|
|
1570
|
+
return {};
|
|
1571
|
+
}
|
|
1572
|
+
const { h, s, l } = rgbToHsl({
|
|
1573
|
+
r: rgb.r.toString(),
|
|
1574
|
+
g: rgb.g.toString(),
|
|
1575
|
+
b: rgb.b.toString()
|
|
1576
|
+
});
|
|
1577
|
+
return {
|
|
1578
|
+
[`--color-${colorName}-h`]: h,
|
|
1579
|
+
[`--color-${colorName}-s`]: `${s}%`,
|
|
1580
|
+
[`--color-${colorName}-l`]: `${l}%`
|
|
1581
|
+
};
|
|
1582
|
+
}
|
|
1583
|
+
return {};
|
|
1584
|
+
} catch (_err) {
|
|
1585
|
+
return {};
|
|
1586
|
+
}
|
|
1587
|
+
};
|
|
1588
|
+
var parseColorFromThemeToHsl = (color) => {
|
|
1589
|
+
if (!color) {
|
|
1590
|
+
return;
|
|
1591
|
+
}
|
|
1592
|
+
try {
|
|
1593
|
+
if ("h" in color && "s" in color && "l" in color) {
|
|
1594
|
+
return {
|
|
1595
|
+
h: Number(color.h),
|
|
1596
|
+
s: Number(color.s),
|
|
1597
|
+
l: Number(color.l)
|
|
1598
|
+
};
|
|
1599
|
+
}
|
|
1600
|
+
if ("r" in color && "g" in color && "b" in color) {
|
|
1601
|
+
const { h, s, l } = rgbToHsl(color);
|
|
1602
|
+
return {
|
|
1603
|
+
h,
|
|
1604
|
+
s,
|
|
1605
|
+
l
|
|
1606
|
+
};
|
|
1607
|
+
}
|
|
1608
|
+
if ("hex" in color) {
|
|
1609
|
+
const rgb = hexToRgb(color.hex);
|
|
1610
|
+
if (!rgb) {
|
|
1611
|
+
return void 0;
|
|
1612
|
+
}
|
|
1613
|
+
const { h, s, l } = rgbToHsl({
|
|
1614
|
+
r: rgb.r.toString(),
|
|
1615
|
+
g: rgb.g.toString(),
|
|
1616
|
+
b: rgb.b.toString()
|
|
1617
|
+
});
|
|
1618
|
+
return {
|
|
1619
|
+
h,
|
|
1620
|
+
s,
|
|
1621
|
+
l
|
|
1622
|
+
};
|
|
1623
|
+
}
|
|
1624
|
+
return;
|
|
1625
|
+
} catch (_err) {
|
|
1626
|
+
return;
|
|
1627
|
+
}
|
|
1628
|
+
};
|
|
1629
|
+
var rgbToHsl = (color) => {
|
|
1630
|
+
let r = Number(color.r);
|
|
1235
1631
|
let g = Number(color.g);
|
|
1236
1632
|
let b = Number(color.b);
|
|
1237
1633
|
r /= 255;
|
|
@@ -1318,691 +1714,349 @@ var hslToRgb = (hsl) => {
|
|
|
1318
1714
|
b = hueToRgb(p, q, hsl.h - 1 / 3);
|
|
1319
1715
|
}
|
|
1320
1716
|
return {
|
|
1321
|
-
r: Math.round(r * 255),
|
|
1322
|
-
g: Math.round(g * 255),
|
|
1323
|
-
b: Math.round(b * 255)
|
|
1324
|
-
};
|
|
1325
|
-
};
|
|
1326
|
-
var hslToHex = (hsl) => {
|
|
1327
|
-
const l = hsl.l / 100;
|
|
1328
|
-
const s = hsl.s;
|
|
1329
|
-
const a = s * Math.min(l, 1 - l) / 100;
|
|
1330
|
-
const f = (n) => {
|
|
1331
|
-
const k = (n + hsl.h / 30) % 12;
|
|
1332
|
-
const color = l - a * Math.max(Math.min(k - 3, 9 - k, 1), -1);
|
|
1333
|
-
return Math.round(255 * color).toString(16).padStart(2, "0");
|
|
1334
|
-
};
|
|
1335
|
-
return `#${f(0)}${f(8)}${f(4)}`;
|
|
1336
|
-
};
|
|
1337
|
-
|
|
1338
|
-
// src/providers/LayerProvider/LayerProvider.tsx
|
|
1339
|
-
var import_date_fns2 = require("date-fns");
|
|
1340
|
-
var import_swr = __toESM(require("swr"));
|
|
1341
|
-
var reducer = (state, action) => {
|
|
1342
|
-
switch (action.type) {
|
|
1343
|
-
case "LayerContext.setAuth" /* setAuth */:
|
|
1344
|
-
case "LayerContext.setBusiness" /* setBusiness */:
|
|
1345
|
-
case "LayerContext.setCategories" /* setCategories */:
|
|
1346
|
-
case "LayerContext.setTheme" /* setTheme */:
|
|
1347
|
-
case "LayerContext.setOnboardingStep" /* setOnboardingStep */:
|
|
1348
|
-
case "LayerContext.setColors" /* setColors */:
|
|
1349
|
-
return { ...state, ...action.payload };
|
|
1350
|
-
case "LayerContext.setToast" /* setToast */:
|
|
1351
|
-
return {
|
|
1352
|
-
...state,
|
|
1353
|
-
toasts: [
|
|
1354
|
-
...state.toasts,
|
|
1355
|
-
{ ...action.payload.toast, isExiting: false }
|
|
1356
|
-
]
|
|
1357
|
-
};
|
|
1358
|
-
case "LayerContext.setToastExit" /* setToastExit */:
|
|
1359
|
-
return {
|
|
1360
|
-
...state,
|
|
1361
|
-
toasts: state.toasts.map(
|
|
1362
|
-
(toast) => toast.id === action.payload.toast.id ? { ...toast, isExiting: false } : toast
|
|
1363
|
-
)
|
|
1364
|
-
};
|
|
1365
|
-
case "LayerContext.removeToast" /* removeToast */:
|
|
1366
|
-
return {
|
|
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
|
|
1413
|
-
};
|
|
1414
|
-
errorHandler.setOnError(onError);
|
|
1415
|
-
const colors = buildColorsPalette(theme);
|
|
1416
|
-
const { url, scope, apiUrl } = LayerEnvironment[environment];
|
|
1417
|
-
const [state, dispatch] = (0, import_react12.useReducer)(reducer, {
|
|
1418
|
-
auth: {
|
|
1419
|
-
access_token: "",
|
|
1420
|
-
token_type: "",
|
|
1421
|
-
expires_in: 0,
|
|
1422
|
-
expires_at: new Date(2e3, 1, 1)
|
|
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
|
-
}
|
|
1469
|
-
});
|
|
1470
|
-
}
|
|
1471
|
-
}, [businessAccessToken, auth?.access_token]);
|
|
1472
|
-
const { data: categoriesData } = (0, import_swr.default)(
|
|
1473
|
-
businessId && state.auth?.access_token && `categories-${businessId}`,
|
|
1474
|
-
Layer.getCategories(apiUrl, state.auth?.access_token, {
|
|
1475
|
-
params: { businessId }
|
|
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
|
-
}
|
|
1487
|
-
}
|
|
1488
|
-
);
|
|
1489
|
-
(0, import_react12.useEffect)(() => {
|
|
1490
|
-
if (categoriesData?.data?.categories?.length) {
|
|
1491
|
-
dispatch({
|
|
1492
|
-
type: "LayerContext.setCategories" /* setCategories */,
|
|
1493
|
-
payload: { categories: categoriesData.data.categories || [] }
|
|
1494
|
-
});
|
|
1495
|
-
}
|
|
1496
|
-
}, [categoriesData]);
|
|
1497
|
-
const { data: businessData } = (0, import_swr.default)(
|
|
1498
|
-
businessId && state?.auth?.access_token && `business-${businessId}`,
|
|
1499
|
-
Layer.getBusiness(apiUrl, state?.auth?.access_token, {
|
|
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
|
-
}
|
|
1512
|
-
}
|
|
1513
|
-
);
|
|
1514
|
-
(0, import_react12.useEffect)(() => {
|
|
1515
|
-
if (businessData?.data) {
|
|
1516
|
-
dispatch({
|
|
1517
|
-
type: "LayerContext.setBusiness" /* setBusiness */,
|
|
1518
|
-
payload: { business: businessData.data || [] }
|
|
1519
|
-
});
|
|
1520
|
-
}
|
|
1521
|
-
}, [businessData]);
|
|
1522
|
-
const setTheme = (theme2) => {
|
|
1523
|
-
dispatch({
|
|
1524
|
-
type: "LayerContext.setTheme" /* setTheme */,
|
|
1525
|
-
payload: { theme: theme2 }
|
|
1526
|
-
});
|
|
1527
|
-
dispatch({
|
|
1528
|
-
type: "LayerContext.setColors" /* setColors */,
|
|
1529
|
-
payload: { colors: buildColorsPalette(theme2) }
|
|
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
|
|
1547
|
-
}
|
|
1548
|
-
});
|
|
1549
|
-
};
|
|
1550
|
-
const setTextColor = (color) => {
|
|
1551
|
-
setTheme({
|
|
1552
|
-
...state.theme ?? {},
|
|
1553
|
-
colors: {
|
|
1554
|
-
...state.theme?.colors ?? {},
|
|
1555
|
-
text: color
|
|
1556
|
-
}
|
|
1557
|
-
});
|
|
1558
|
-
};
|
|
1559
|
-
const setToast = (toast) => {
|
|
1560
|
-
dispatch({ type: "LayerContext.setToast" /* setToast */, payload: { toast } });
|
|
1561
|
-
};
|
|
1562
|
-
const removeToast = (toast) => {
|
|
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
|
|
1582
|
-
});
|
|
1583
|
-
const getColor = (shade) => {
|
|
1584
|
-
if (state.colors && shade in state.colors) {
|
|
1585
|
-
return state.colors[shade];
|
|
1586
|
-
}
|
|
1587
|
-
return;
|
|
1717
|
+
r: Math.round(r * 255),
|
|
1718
|
+
g: Math.round(g * 255),
|
|
1719
|
+
b: Math.round(b * 255)
|
|
1588
1720
|
};
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
const
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
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
|
-
));
|
|
1721
|
+
};
|
|
1722
|
+
var hslToHex = (hsl) => {
|
|
1723
|
+
const l = hsl.l / 100;
|
|
1724
|
+
const s = hsl.s;
|
|
1725
|
+
const a = s * Math.min(l, 1 - l) / 100;
|
|
1726
|
+
const f = (n) => {
|
|
1727
|
+
const k = (n + hsl.h / 30) % 12;
|
|
1728
|
+
const color = l - a * Math.max(Math.min(k - 3, 9 - k, 1), -1);
|
|
1729
|
+
return Math.round(255 * color).toString(16).padStart(2, "0");
|
|
1730
|
+
};
|
|
1731
|
+
return `#${f(0)}${f(8)}${f(4)}`;
|
|
1619
1732
|
};
|
|
1620
1733
|
|
|
1621
|
-
// src/
|
|
1622
|
-
var
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1734
|
+
// src/providers/LayerProvider/LayerProvider.tsx
|
|
1735
|
+
var import_date_fns = require("date-fns");
|
|
1736
|
+
var import_swr2 = __toESM(require("swr"));
|
|
1737
|
+
var reducer = (state, action) => {
|
|
1738
|
+
switch (action.type) {
|
|
1739
|
+
case "LayerContext.setAuth" /* setAuth */:
|
|
1740
|
+
case "LayerContext.setBusiness" /* setBusiness */:
|
|
1741
|
+
case "LayerContext.setCategories" /* setCategories */:
|
|
1742
|
+
case "LayerContext.setTheme" /* setTheme */:
|
|
1743
|
+
case "LayerContext.setOnboardingStep" /* setOnboardingStep */:
|
|
1744
|
+
case "LayerContext.setColors" /* setColors */:
|
|
1745
|
+
return { ...state, ...action.payload };
|
|
1746
|
+
case "LayerContext.setToast" /* setToast */:
|
|
1747
|
+
return {
|
|
1748
|
+
...state,
|
|
1749
|
+
toasts: [
|
|
1750
|
+
...state.toasts,
|
|
1751
|
+
{ ...action.payload.toast, isExiting: false }
|
|
1752
|
+
]
|
|
1753
|
+
};
|
|
1754
|
+
case "LayerContext.setToastExit" /* setToastExit */:
|
|
1755
|
+
return {
|
|
1756
|
+
...state,
|
|
1757
|
+
toasts: state.toasts.map(
|
|
1758
|
+
(toast) => toast.id === action.payload.toast.id ? { ...toast, isExiting: false } : toast
|
|
1759
|
+
)
|
|
1760
|
+
};
|
|
1761
|
+
case "LayerContext.removeToast" /* removeToast */:
|
|
1762
|
+
return {
|
|
1763
|
+
...state,
|
|
1764
|
+
toasts: state.toasts.filter((t) => t.id !== action.payload.toast.id)
|
|
1765
|
+
};
|
|
1766
|
+
default:
|
|
1767
|
+
return state;
|
|
1651
1768
|
}
|
|
1652
|
-
}
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
var import_react14 = require("react");
|
|
1659
|
-
var import_react_plaid_link = require("react-plaid-link");
|
|
1660
|
-
|
|
1661
|
-
// src/hooks/useLinkedAccounts/mockData.ts
|
|
1662
|
-
var LINKED_ACCOUNTS_MOCK_DATA = [
|
|
1663
|
-
{
|
|
1664
|
-
id: "d800ada8-8075-4436-a712-08efabcbd51a",
|
|
1665
|
-
external_account_external_id: "0Br385JmgbTryJn8nEBnUb4A5ydv06U9Vbqqq",
|
|
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
|
|
1769
|
+
};
|
|
1770
|
+
var LayerEnvironment = {
|
|
1771
|
+
production: {
|
|
1772
|
+
url: "https://auth.layerfi.com/oauth2/token",
|
|
1773
|
+
scope: "https://api.layerfi.com/production",
|
|
1774
|
+
apiUrl: "https://api.layerfi.com"
|
|
1686
1775
|
},
|
|
1687
|
-
{
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
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
|
|
1776
|
+
sandbox: {
|
|
1777
|
+
url: "https://auth.layerfi.com/oauth2/token",
|
|
1778
|
+
scope: "https://sandbox.layerfi.com/sandbox",
|
|
1779
|
+
apiUrl: "https://sandbox.layerfi.com"
|
|
1710
1780
|
},
|
|
1711
|
-
{
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
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
|
|
1781
|
+
staging: {
|
|
1782
|
+
url: "https://auth.layerfi.com/oauth2/token",
|
|
1783
|
+
scope: "https://sandbox.layerfi.com/sandbox",
|
|
1784
|
+
apiUrl: "https://sandbox.layerfi.com"
|
|
1734
1785
|
},
|
|
1735
|
-
{
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
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
|
|
1786
|
+
internalStaging: {
|
|
1787
|
+
url: "https://auth.layerfi.com/oauth2/token",
|
|
1788
|
+
scope: "https://sandbox.layerfi.com/sandbox",
|
|
1789
|
+
apiUrl: "https://staging.layerfi.com"
|
|
1758
1790
|
}
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1791
|
+
};
|
|
1792
|
+
var LayerProvider = ({
|
|
1793
|
+
appId,
|
|
1794
|
+
appSecret,
|
|
1795
|
+
businessId,
|
|
1796
|
+
children,
|
|
1797
|
+
businessAccessToken,
|
|
1798
|
+
environment = "production",
|
|
1799
|
+
theme,
|
|
1800
|
+
usePlaidSandbox,
|
|
1801
|
+
onError,
|
|
1802
|
+
eventCallbacks
|
|
1803
|
+
}) => {
|
|
1804
|
+
const defaultSWRConfig = {
|
|
1805
|
+
revalidateInterval: 0,
|
|
1806
|
+
revalidateOnFocus: false,
|
|
1807
|
+
revalidateOnReconnect: false,
|
|
1808
|
+
revalidateIfStale: false
|
|
1809
|
+
};
|
|
1810
|
+
errorHandler.setOnError(onError);
|
|
1811
|
+
const colors = buildColorsPalette(theme);
|
|
1812
|
+
const { url, scope, apiUrl } = LayerEnvironment[environment];
|
|
1813
|
+
const [state, dispatch] = (0, import_react13.useReducer)(reducer, {
|
|
1814
|
+
auth: {
|
|
1815
|
+
access_token: "",
|
|
1816
|
+
token_type: "",
|
|
1817
|
+
expires_in: 0,
|
|
1818
|
+
expires_at: new Date(2e3, 1, 1)
|
|
1819
|
+
},
|
|
1768
1820
|
businessId,
|
|
1821
|
+
business: void 0,
|
|
1822
|
+
categories: [],
|
|
1769
1823
|
apiUrl,
|
|
1824
|
+
theme,
|
|
1825
|
+
colors,
|
|
1770
1826
|
usePlaidSandbox,
|
|
1827
|
+
onboardingStep: void 0,
|
|
1828
|
+
environment,
|
|
1829
|
+
toasts: [],
|
|
1830
|
+
eventCallbacks: {}
|
|
1831
|
+
});
|
|
1832
|
+
const {
|
|
1771
1833
|
touch,
|
|
1772
|
-
read,
|
|
1773
1834
|
syncTimestamps,
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
const
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
}
|
|
1802
|
-
if (!isLoading && loadingStatus === "loading") {
|
|
1803
|
-
setLoadingStatus("complete");
|
|
1804
|
-
}
|
|
1805
|
-
}, [isLoading]);
|
|
1806
|
-
const fetchPlaidLinkToken = async () => {
|
|
1807
|
-
if (auth?.access_token) {
|
|
1808
|
-
const linkToken2 = (await Layer.getPlaidLinkToken(apiUrl, auth.access_token, {
|
|
1809
|
-
params: { businessId }
|
|
1810
|
-
})).data.link_token;
|
|
1811
|
-
setLinkMode("add");
|
|
1812
|
-
setLinkToken(linkToken2);
|
|
1813
|
-
}
|
|
1814
|
-
};
|
|
1815
|
-
const fetchPlaidUpdateModeLinkToken = async (plaidItemPlaidId) => {
|
|
1816
|
-
if (auth?.access_token) {
|
|
1817
|
-
const linkToken2 = (await Layer.getPlaidUpdateModeLinkToken(apiUrl, auth.access_token, {
|
|
1818
|
-
params: { businessId },
|
|
1819
|
-
body: { plaid_item_id: plaidItemPlaidId }
|
|
1820
|
-
})).data.link_token;
|
|
1821
|
-
setLinkMode("update");
|
|
1822
|
-
setLinkToken(linkToken2);
|
|
1823
|
-
}
|
|
1824
|
-
};
|
|
1825
|
-
const exchangePlaidPublicToken2 = async (publicToken, metadata) => {
|
|
1826
|
-
await Layer.exchangePlaidPublicToken(apiUrl, auth?.access_token, {
|
|
1827
|
-
params: { businessId },
|
|
1828
|
-
body: { public_token: publicToken, institution: metadata.institution }
|
|
1829
|
-
});
|
|
1830
|
-
refetchAccounts();
|
|
1831
|
-
};
|
|
1832
|
-
const { open: plaidLinkStart, ready: plaidLinkReady } = (0, import_react_plaid_link.usePlaidLink)({
|
|
1833
|
-
token: linkToken,
|
|
1834
|
-
// If in update mode, we don't need to exchange the public token for an access token.
|
|
1835
|
-
// The existing access token will automatically become valid again
|
|
1836
|
-
onSuccess: async (publicToken, metadata) => {
|
|
1837
|
-
if (linkMode == "add") {
|
|
1838
|
-
exchangePlaidPublicToken2(publicToken, metadata);
|
|
1839
|
-
} else {
|
|
1840
|
-
await updateConnectionStatus2();
|
|
1841
|
-
refetchAccounts();
|
|
1842
|
-
setLinkMode("add");
|
|
1843
|
-
touch("LINKED_ACCOUNTS" /* LINKED_ACCOUNTS */);
|
|
1844
|
-
}
|
|
1845
|
-
},
|
|
1846
|
-
onExit: () => setLinkMode("add"),
|
|
1847
|
-
env: USE_PLAID_SANDBOX ? "sandbox" : void 0
|
|
1848
|
-
});
|
|
1849
|
-
(0, import_react14.useEffect)(() => {
|
|
1850
|
-
if (plaidLinkReady) {
|
|
1851
|
-
plaidLinkStart();
|
|
1852
|
-
}
|
|
1853
|
-
}, [plaidLinkStart, plaidLinkReady]);
|
|
1854
|
-
const mockResponseData = {
|
|
1855
|
-
data: LINKED_ACCOUNTS_MOCK_DATA,
|
|
1856
|
-
meta: {},
|
|
1857
|
-
error: void 0
|
|
1858
|
-
};
|
|
1859
|
-
const addConnection = (source) => {
|
|
1860
|
-
if (source === "PLAID") {
|
|
1861
|
-
fetchPlaidLinkToken();
|
|
1862
|
-
} else {
|
|
1863
|
-
console.error(
|
|
1864
|
-
`Adding a connection with source ${source} not yet supported`
|
|
1865
|
-
);
|
|
1866
|
-
}
|
|
1867
|
-
};
|
|
1868
|
-
const repairConnection = async (source, connectionExternalId) => {
|
|
1869
|
-
if (source === "PLAID") {
|
|
1870
|
-
await fetchPlaidUpdateModeLinkToken(connectionExternalId);
|
|
1871
|
-
} else {
|
|
1872
|
-
console.error(
|
|
1873
|
-
`Repairing a connection with source ${source} not yet supported`
|
|
1874
|
-
);
|
|
1875
|
-
}
|
|
1876
|
-
};
|
|
1877
|
-
const removeConnection = async (source, connectionExternalId) => {
|
|
1878
|
-
if (source === "PLAID") {
|
|
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 }
|
|
1835
|
+
read,
|
|
1836
|
+
readTimestamps,
|
|
1837
|
+
hasBeenTouched,
|
|
1838
|
+
resetCaches
|
|
1839
|
+
} = useDataSync();
|
|
1840
|
+
const { data: auth } = appId !== void 0 && appSecret !== void 0 ? (0, import_swr2.default)(
|
|
1841
|
+
businessAccessToken === void 0 && appId !== void 0 && appSecret !== void 0 && (0, import_date_fns.isBefore)(state.auth.expires_at, /* @__PURE__ */ new Date()) && "authenticate",
|
|
1842
|
+
Layer.authenticate({
|
|
1843
|
+
appId,
|
|
1844
|
+
appSecret,
|
|
1845
|
+
authenticationUrl: url,
|
|
1846
|
+
scope
|
|
1847
|
+
}),
|
|
1848
|
+
defaultSWRConfig
|
|
1849
|
+
) : { data: void 0 };
|
|
1850
|
+
(0, import_react13.useEffect)(() => {
|
|
1851
|
+
if (businessAccessToken) {
|
|
1852
|
+
dispatch({
|
|
1853
|
+
type: "LayerContext.setAuth" /* setAuth */,
|
|
1854
|
+
payload: {
|
|
1855
|
+
auth: {
|
|
1856
|
+
access_token: businessAccessToken,
|
|
1857
|
+
token_type: "Bearer",
|
|
1858
|
+
expires_in: 3600,
|
|
1859
|
+
expires_at: (0, import_date_fns.add)(/* @__PURE__ */ new Date(), { seconds: 3600 })
|
|
1860
|
+
}
|
|
1861
|
+
}
|
|
1892
1862
|
});
|
|
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
|
|
1863
|
+
} else if (auth?.access_token) {
|
|
1864
|
+
dispatch({
|
|
1865
|
+
type: "LayerContext.setAuth" /* setAuth */,
|
|
1866
|
+
payload: {
|
|
1867
|
+
auth: {
|
|
1868
|
+
...auth,
|
|
1869
|
+
expires_at: (0, import_date_fns.add)(/* @__PURE__ */ new Date(), { seconds: auth.expires_in })
|
|
1870
|
+
}
|
|
1908
1871
|
}
|
|
1909
1872
|
});
|
|
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
1873
|
}
|
|
1917
|
-
};
|
|
1918
|
-
const
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1874
|
+
}, [businessAccessToken, auth?.access_token]);
|
|
1875
|
+
const { data: categoriesData } = (0, import_swr2.default)(
|
|
1876
|
+
businessId && state.auth?.access_token && `categories-${businessId}`,
|
|
1877
|
+
Layer.getCategories(apiUrl, state.auth?.access_token, {
|
|
1878
|
+
params: { businessId }
|
|
1879
|
+
}),
|
|
1880
|
+
{
|
|
1881
|
+
...defaultSWRConfig,
|
|
1882
|
+
onSuccess: (response) => {
|
|
1883
|
+
if (response?.data?.categories?.length) {
|
|
1884
|
+
dispatch({
|
|
1885
|
+
type: "LayerContext.setCategories" /* setCategories */,
|
|
1886
|
+
payload: { categories: response.data.categories || [] }
|
|
1887
|
+
});
|
|
1925
1888
|
}
|
|
1889
|
+
}
|
|
1890
|
+
}
|
|
1891
|
+
);
|
|
1892
|
+
(0, import_react13.useEffect)(() => {
|
|
1893
|
+
if (categoriesData?.data?.categories?.length) {
|
|
1894
|
+
dispatch({
|
|
1895
|
+
type: "LayerContext.setCategories" /* setCategories */,
|
|
1896
|
+
payload: { categories: categoriesData.data.categories || [] }
|
|
1926
1897
|
});
|
|
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
1898
|
}
|
|
1934
|
-
};
|
|
1935
|
-
const
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1899
|
+
}, [categoriesData]);
|
|
1900
|
+
const { data: businessData } = (0, import_swr2.default)(
|
|
1901
|
+
businessId && state?.auth?.access_token && `business-${businessId}`,
|
|
1902
|
+
Layer.getBusiness(apiUrl, state?.auth?.access_token, {
|
|
1903
|
+
params: { businessId }
|
|
1904
|
+
}),
|
|
1905
|
+
{
|
|
1906
|
+
...defaultSWRConfig,
|
|
1907
|
+
onSuccess: (response) => {
|
|
1908
|
+
if (response?.data) {
|
|
1909
|
+
dispatch({
|
|
1910
|
+
type: "LayerContext.setBusiness" /* setBusiness */,
|
|
1911
|
+
payload: { business: response.data || [] }
|
|
1912
|
+
});
|
|
1942
1913
|
}
|
|
1914
|
+
}
|
|
1915
|
+
}
|
|
1916
|
+
);
|
|
1917
|
+
(0, import_react13.useEffect)(() => {
|
|
1918
|
+
if (businessData?.data) {
|
|
1919
|
+
dispatch({
|
|
1920
|
+
type: "LayerContext.setBusiness" /* setBusiness */,
|
|
1921
|
+
payload: { business: businessData.data || [] }
|
|
1943
1922
|
});
|
|
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
1923
|
}
|
|
1924
|
+
}, [businessData]);
|
|
1925
|
+
const setTheme = (theme2) => {
|
|
1926
|
+
dispatch({
|
|
1927
|
+
type: "LayerContext.setTheme" /* setTheme */,
|
|
1928
|
+
payload: { theme: theme2 }
|
|
1929
|
+
});
|
|
1930
|
+
dispatch({
|
|
1931
|
+
type: "LayerContext.setColors" /* setColors */,
|
|
1932
|
+
payload: { colors: buildColorsPalette(theme2) }
|
|
1933
|
+
});
|
|
1951
1934
|
};
|
|
1952
|
-
const
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
params: { businessId }
|
|
1935
|
+
const setLightColor = (color) => {
|
|
1936
|
+
setTheme({
|
|
1937
|
+
...state.theme ?? {},
|
|
1938
|
+
colors: {
|
|
1939
|
+
...state.theme?.colors ?? {},
|
|
1940
|
+
light: color
|
|
1941
|
+
}
|
|
1960
1942
|
});
|
|
1961
1943
|
};
|
|
1962
|
-
const
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1944
|
+
const setDarkColor = (color) => {
|
|
1945
|
+
setTheme({
|
|
1946
|
+
...state.theme ?? {},
|
|
1947
|
+
colors: {
|
|
1948
|
+
...state.theme?.colors ?? {},
|
|
1949
|
+
dark: color
|
|
1950
|
+
}
|
|
1966
1951
|
});
|
|
1967
1952
|
};
|
|
1968
|
-
const
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1953
|
+
const setTextColor = (color) => {
|
|
1954
|
+
setTheme({
|
|
1955
|
+
...state.theme ?? {},
|
|
1956
|
+
colors: {
|
|
1957
|
+
...state.theme?.colors ?? {},
|
|
1958
|
+
text: color
|
|
1959
|
+
}
|
|
1972
1960
|
});
|
|
1973
|
-
await refetchAccounts();
|
|
1974
|
-
touch("LINKED_ACCOUNTS" /* LINKED_ACCOUNTS */);
|
|
1975
1961
|
};
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1962
|
+
const setToast = (toast) => {
|
|
1963
|
+
dispatch({ type: "LayerContext.setToast" /* setToast */, payload: { toast } });
|
|
1964
|
+
};
|
|
1965
|
+
const removeToast = (toast) => {
|
|
1966
|
+
dispatch({ type: "LayerContext.removeToast" /* removeToast */, payload: { toast } });
|
|
1967
|
+
};
|
|
1968
|
+
const setToastExit = (toast) => {
|
|
1969
|
+
dispatch({ type: "LayerContext.setToastExit" /* setToastExit */, payload: { toast } });
|
|
1970
|
+
};
|
|
1971
|
+
const addToast = (toast) => {
|
|
1972
|
+
const id = `${Date.now()}-${Math.random()}`;
|
|
1973
|
+
const newToast = { id, isExiting: false, ...toast };
|
|
1974
|
+
setToast(newToast);
|
|
1975
|
+
setTimeout(() => {
|
|
1976
|
+
removeToast(newToast);
|
|
1977
|
+
setTimeout(() => {
|
|
1978
|
+
setToastExit(newToast);
|
|
1979
|
+
}, 1e3);
|
|
1980
|
+
}, toast.duration || 2e3);
|
|
1981
|
+
};
|
|
1982
|
+
const setColors = (colors2) => setTheme({
|
|
1983
|
+
...state.theme ?? {},
|
|
1984
|
+
colors: colors2
|
|
1985
|
+
});
|
|
1986
|
+
const getColor = (shade) => {
|
|
1987
|
+
if (state.colors && shade in state.colors) {
|
|
1988
|
+
return state.colors[shade];
|
|
1984
1989
|
}
|
|
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
|
|
1990
|
+
return;
|
|
2002
1991
|
};
|
|
1992
|
+
const setOnboardingStep = (value) => dispatch({
|
|
1993
|
+
type: "LayerContext.setOnboardingStep" /* setOnboardingStep */,
|
|
1994
|
+
payload: { onboardingStep: value }
|
|
1995
|
+
});
|
|
1996
|
+
const drawerContextData = useDrawer();
|
|
1997
|
+
return /* @__PURE__ */ import_react13.default.createElement(import_swr2.SWRConfig, { value: defaultSWRConfig }, /* @__PURE__ */ import_react13.default.createElement(
|
|
1998
|
+
LayerContext.Provider,
|
|
1999
|
+
{
|
|
2000
|
+
value: {
|
|
2001
|
+
...state,
|
|
2002
|
+
setTheme,
|
|
2003
|
+
getColor,
|
|
2004
|
+
setLightColor,
|
|
2005
|
+
setDarkColor,
|
|
2006
|
+
setTextColor,
|
|
2007
|
+
setColors,
|
|
2008
|
+
setOnboardingStep,
|
|
2009
|
+
addToast,
|
|
2010
|
+
removeToast,
|
|
2011
|
+
onError: errorHandler.onError,
|
|
2012
|
+
touch,
|
|
2013
|
+
read,
|
|
2014
|
+
syncTimestamps,
|
|
2015
|
+
readTimestamps,
|
|
2016
|
+
expireDataCaches: resetCaches,
|
|
2017
|
+
hasBeenTouched,
|
|
2018
|
+
eventCallbacks
|
|
2019
|
+
}
|
|
2020
|
+
},
|
|
2021
|
+
/* @__PURE__ */ import_react13.default.createElement(BankTransactionsProvider, null, /* @__PURE__ */ import_react13.default.createElement(DrawerContext.Provider, { value: drawerContextData }, children, /* @__PURE__ */ import_react13.default.createElement(GlobalWidgets, null)))
|
|
2022
|
+
));
|
|
2003
2023
|
};
|
|
2004
2024
|
|
|
2025
|
+
// src/components/Onboarding/Onboarding.tsx
|
|
2026
|
+
var import_react39 = __toESM(require("react"));
|
|
2027
|
+
|
|
2028
|
+
// src/contexts/LinkedAccountsContext/LinkedAccountsContext.ts
|
|
2029
|
+
var import_react14 = require("react");
|
|
2030
|
+
var LinkedAccountsContext = (0, import_react14.createContext)({
|
|
2031
|
+
data: void 0,
|
|
2032
|
+
isLoading: false,
|
|
2033
|
+
loadingStatus: "initial",
|
|
2034
|
+
isValidating: false,
|
|
2035
|
+
error: void 0,
|
|
2036
|
+
updateConnectionStatus: () => {
|
|
2037
|
+
},
|
|
2038
|
+
addConnection: () => {
|
|
2039
|
+
},
|
|
2040
|
+
removeConnection: () => {
|
|
2041
|
+
},
|
|
2042
|
+
repairConnection: () => {
|
|
2043
|
+
},
|
|
2044
|
+
refetchAccounts: () => {
|
|
2045
|
+
},
|
|
2046
|
+
unlinkAccount: () => {
|
|
2047
|
+
},
|
|
2048
|
+
denyAccount: () => {
|
|
2049
|
+
},
|
|
2050
|
+
confirmAccount: () => {
|
|
2051
|
+
},
|
|
2052
|
+
breakConnection: () => {
|
|
2053
|
+
},
|
|
2054
|
+
syncAccounts: () => {
|
|
2055
|
+
}
|
|
2056
|
+
});
|
|
2057
|
+
|
|
2005
2058
|
// src/providers/LinkedAccountsProvider/LinkedAccountsProvider.tsx
|
|
2059
|
+
var import_react15 = __toESM(require("react"));
|
|
2006
2060
|
var LinkedAccountsProvider = ({
|
|
2007
2061
|
children
|
|
2008
2062
|
}) => {
|
|
@@ -2276,8 +2330,20 @@ var Sunrise = ({ size = 12, ...props }) => /* @__PURE__ */ React16.createElement
|
|
|
2276
2330
|
);
|
|
2277
2331
|
var Sunrise_default = Sunrise;
|
|
2278
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,
|
|
@@ -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,
|
|
@@ -6174,7 +6239,7 @@ var SplitTooltipDetails = ({
|
|
|
6174
6239
|
|
|
6175
6240
|
// src/components/BankTransactionRow/BankTransactionRow.tsx
|
|
6176
6241
|
var import_classnames33 = __toESM(require("classnames"));
|
|
6177
|
-
var
|
|
6242
|
+
var import_date_fns7 = require("date-fns");
|
|
6178
6243
|
var extractDescriptionForSplit = (category) => {
|
|
6179
6244
|
if (!category.entries) {
|
|
6180
6245
|
return "";
|
|
@@ -6209,9 +6274,9 @@ var BankTransactionRow = ({
|
|
|
6209
6274
|
const expandedRowRef = (0, import_react68.useRef)(null);
|
|
6210
6275
|
const [showRetry, setShowRetry] = (0, import_react68.useState)(false);
|
|
6211
6276
|
const {
|
|
6212
|
-
filters,
|
|
6213
6277
|
categorize: categorizeBankTransaction2,
|
|
6214
|
-
match: matchBankTransaction2
|
|
6278
|
+
match: matchBankTransaction2,
|
|
6279
|
+
shouldHideAfterCategorize
|
|
6215
6280
|
} = useBankTransactionsContext();
|
|
6216
6281
|
const [selectedCategory, setSelectedCategory] = (0, import_react68.useState)(
|
|
6217
6282
|
getDefaultSelectedCategory(bankTransaction)
|
|
@@ -6249,7 +6314,7 @@ var BankTransactionRow = ({
|
|
|
6249
6314
|
}
|
|
6250
6315
|
}, [bankTransaction.error]);
|
|
6251
6316
|
(0, import_react68.useEffect)(() => {
|
|
6252
|
-
if (editable && bankTransaction.recently_categorized) {
|
|
6317
|
+
if (editable && bankTransaction.recently_categorized && shouldHideAfterCategorize(bankTransaction)) {
|
|
6253
6318
|
setTimeout(() => {
|
|
6254
6319
|
removeTransaction(bankTransaction);
|
|
6255
6320
|
}, 300);
|
|
@@ -6282,7 +6347,7 @@ var BankTransactionRow = ({
|
|
|
6282
6347
|
const openClassName = open ? `${className}--expanded` : "";
|
|
6283
6348
|
const rowClassName = (0, import_classnames33.default)(
|
|
6284
6349
|
className,
|
|
6285
|
-
bankTransaction.recently_categorized && editable ? "Layer__bank-transaction-row--removing" : "",
|
|
6350
|
+
bankTransaction.recently_categorized && editable && shouldHideAfterCategorize(bankTransaction) ? "Layer__bank-transaction-row--removing" : "",
|
|
6286
6351
|
open ? openClassName : "",
|
|
6287
6352
|
initialLoad ? "initial-load" : "",
|
|
6288
6353
|
showComponent ? "show" : ""
|
|
@@ -6293,7 +6358,7 @@ var BankTransactionRow = ({
|
|
|
6293
6358
|
className: "Layer__table-cell Layer__bank-transaction-table__date-col",
|
|
6294
6359
|
...openRow
|
|
6295
6360
|
},
|
|
6296
|
-
/* @__PURE__ */ import_react68.default.createElement("span", { className: "Layer__table-cell-content" }, (0,
|
|
6361
|
+
/* @__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
6362
|
), /* @__PURE__ */ import_react68.default.createElement(
|
|
6298
6363
|
"td",
|
|
6299
6364
|
{
|
|
@@ -6382,8 +6447,8 @@ var BankTransactionRow = ({
|
|
|
6382
6447
|
bankTransaction,
|
|
6383
6448
|
dateFormat
|
|
6384
6449
|
}
|
|
6385
|
-
), /* @__PURE__ */ import_react68.default.createElement("span", { className: `${className}__category-text__text` }, `${(0,
|
|
6386
|
-
(0,
|
|
6450
|
+
), /* @__PURE__ */ import_react68.default.createElement("span", { className: `${className}__category-text__text` }, `${(0, import_date_fns7.format)(
|
|
6451
|
+
(0, import_date_fns7.parseISO)(bankTransaction.match.bank_transaction.date),
|
|
6387
6452
|
dateFormat
|
|
6388
6453
|
)}, ${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
6454
|
!categorized && !open && showRetry ? /* @__PURE__ */ import_react68.default.createElement(
|
|
@@ -6458,7 +6523,7 @@ var BankTransactionRow = ({
|
|
|
6458
6523
|
|
|
6459
6524
|
// src/components/BankTransactionList/Assignment.tsx
|
|
6460
6525
|
var import_react69 = __toESM(require("react"));
|
|
6461
|
-
var
|
|
6526
|
+
var import_date_fns8 = require("date-fns");
|
|
6462
6527
|
var Assignment = ({ bankTransaction }) => {
|
|
6463
6528
|
if (bankTransaction.match && bankTransaction.categorization_status === "MATCHED" /* MATCHED */) {
|
|
6464
6529
|
return /* @__PURE__ */ import_react69.default.createElement(import_react69.default.Fragment, null, /* @__PURE__ */ import_react69.default.createElement(
|
|
@@ -6469,8 +6534,8 @@ var Assignment = ({ bankTransaction }) => {
|
|
|
6469
6534
|
dateFormat: DATE_FORMAT,
|
|
6470
6535
|
text: "Matched"
|
|
6471
6536
|
}
|
|
6472
|
-
), /* @__PURE__ */ import_react69.default.createElement(Text, { className: "Layer__bank-transaction-list-item__category-text__text" }, `${(0,
|
|
6473
|
-
(0,
|
|
6537
|
+
), /* @__PURE__ */ import_react69.default.createElement(Text, { className: "Layer__bank-transaction-list-item__category-text__text" }, `${(0, import_date_fns8.format)(
|
|
6538
|
+
(0, import_date_fns8.parseISO)(bankTransaction.match.bank_transaction.date),
|
|
6474
6539
|
DATE_FORMAT
|
|
6475
6540
|
)}, ${bankTransaction.match.bank_transaction.description ?? bankTransaction.match?.details?.description}`));
|
|
6476
6541
|
}
|
|
@@ -6495,7 +6560,7 @@ var Assignment = ({ bankTransaction }) => {
|
|
|
6495
6560
|
|
|
6496
6561
|
// src/components/BankTransactionList/BankTransactionListItem.tsx
|
|
6497
6562
|
var import_classnames34 = __toESM(require("classnames"));
|
|
6498
|
-
var
|
|
6563
|
+
var import_date_fns9 = require("date-fns");
|
|
6499
6564
|
var BankTransactionListItem = ({
|
|
6500
6565
|
index = 0,
|
|
6501
6566
|
dateFormat,
|
|
@@ -6510,7 +6575,11 @@ var BankTransactionListItem = ({
|
|
|
6510
6575
|
}) => {
|
|
6511
6576
|
const expandedRowRef = (0, import_react70.useRef)(null);
|
|
6512
6577
|
const [showRetry, setShowRetry] = (0, import_react70.useState)(false);
|
|
6513
|
-
const {
|
|
6578
|
+
const {
|
|
6579
|
+
categorize: categorizeBankTransaction2,
|
|
6580
|
+
match: matchBankTransaction2,
|
|
6581
|
+
shouldHideAfterCategorize
|
|
6582
|
+
} = useBankTransactionsContext();
|
|
6514
6583
|
const [selectedCategory, setSelectedCategory] = (0, import_react70.useState)(
|
|
6515
6584
|
getDefaultSelectedCategory(bankTransaction)
|
|
6516
6585
|
);
|
|
@@ -6532,7 +6601,7 @@ var BankTransactionListItem = ({
|
|
|
6532
6601
|
}
|
|
6533
6602
|
}, [bankTransaction.error]);
|
|
6534
6603
|
(0, import_react70.useEffect)(() => {
|
|
6535
|
-
if (editable && bankTransaction.recently_categorized) {
|
|
6604
|
+
if (editable && bankTransaction.recently_categorized && shouldHideAfterCategorize(bankTransaction)) {
|
|
6536
6605
|
setTimeout(() => {
|
|
6537
6606
|
removeTransaction(bankTransaction);
|
|
6538
6607
|
}, 300);
|
|
@@ -6560,11 +6629,11 @@ var BankTransactionListItem = ({
|
|
|
6560
6629
|
const openClassName = open ? `${className}--expanded` : "";
|
|
6561
6630
|
const rowClassName = (0, import_classnames34.default)(
|
|
6562
6631
|
className,
|
|
6563
|
-
bankTransaction.recently_categorized && editable ? "Layer__bank-transaction-row--removing" : "",
|
|
6632
|
+
bankTransaction.recently_categorized && editable && shouldHideAfterCategorize(bankTransaction) ? "Layer__bank-transaction-row--removing" : "",
|
|
6564
6633
|
open ? openClassName : "",
|
|
6565
6634
|
showComponent ? "show" : ""
|
|
6566
6635
|
);
|
|
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,
|
|
6636
|
+
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
6637
|
"div",
|
|
6569
6638
|
{
|
|
6570
6639
|
onClick: toggleOpen,
|
|
@@ -7131,7 +7200,7 @@ var TransactionToOpenContext = (0, import_react78.createContext)({
|
|
|
7131
7200
|
|
|
7132
7201
|
// src/components/BankTransactionMobileList/BankTransactionMobileListItem.tsx
|
|
7133
7202
|
var import_classnames36 = __toESM(require("classnames"));
|
|
7134
|
-
var
|
|
7203
|
+
var import_date_fns10 = require("date-fns");
|
|
7135
7204
|
var DATE_FORMAT2 = "LLL d";
|
|
7136
7205
|
var getAssignedValue2 = (bankTransaction) => {
|
|
7137
7206
|
if (bankTransaction.categorization_status === "SPLIT" /* SPLIT */) {
|
|
@@ -7156,6 +7225,7 @@ var BankTransactionMobileListItem = ({
|
|
|
7156
7225
|
setTransactionIdToOpen,
|
|
7157
7226
|
clearTransactionIdToOpen
|
|
7158
7227
|
} = (0, import_react79.useContext)(TransactionToOpenContext);
|
|
7228
|
+
const { shouldHideAfterCategorize } = useBankTransactionsContext();
|
|
7159
7229
|
const formRowRef = useElementSize(
|
|
7160
7230
|
(_a, _b, { height: height2 }) => setHeight(height2)
|
|
7161
7231
|
);
|
|
@@ -7189,7 +7259,7 @@ var BankTransactionMobileListItem = ({
|
|
|
7189
7259
|
}, [transactionIdToOpen]);
|
|
7190
7260
|
(0, import_react79.useEffect)(() => {
|
|
7191
7261
|
if (!removeAnim && bankTransaction.recently_categorized) {
|
|
7192
|
-
if (editable) {
|
|
7262
|
+
if (editable && shouldHideAfterCategorize(bankTransaction)) {
|
|
7193
7263
|
setRemoveAnim(true);
|
|
7194
7264
|
openNext();
|
|
7195
7265
|
} else {
|
|
@@ -7222,7 +7292,7 @@ var BankTransactionMobileListItem = ({
|
|
|
7222
7292
|
}
|
|
7223
7293
|
}, []);
|
|
7224
7294
|
(0, import_react79.useEffect)(() => {
|
|
7225
|
-
if (editable && bankTransaction.recently_categorized) {
|
|
7295
|
+
if (editable && bankTransaction.recently_categorized && shouldHideAfterCategorize(bankTransaction)) {
|
|
7226
7296
|
setTimeout(() => {
|
|
7227
7297
|
removeTransaction(bankTransaction);
|
|
7228
7298
|
}, 300);
|
|
@@ -7253,7 +7323,7 @@ var BankTransactionMobileListItem = ({
|
|
|
7253
7323
|
},
|
|
7254
7324
|
isCredit(bankTransaction) ? "+$" : " $",
|
|
7255
7325
|
centsToDollars(bankTransaction.amount)
|
|
7256
|
-
), /* @__PURE__ */ import_react79.default.createElement("span", { className: `${className}__heading__date` }, (0,
|
|
7326
|
+
), /* @__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
7327
|
), categorizationEnabled(mode) ? /* @__PURE__ */ import_react79.default.createElement(
|
|
7258
7328
|
"div",
|
|
7259
7329
|
{
|
|
@@ -7776,11 +7846,11 @@ var DownloadCloud = ({ size = 18, ...props }) => /* @__PURE__ */ React103.create
|
|
|
7776
7846
|
var DownloadCloud_default = DownloadCloud;
|
|
7777
7847
|
|
|
7778
7848
|
// src/utils/business.ts
|
|
7779
|
-
var
|
|
7849
|
+
var import_date_fns11 = require("date-fns");
|
|
7780
7850
|
var getActivationDate = (business) => {
|
|
7781
7851
|
try {
|
|
7782
7852
|
if (business && business.activation_at) {
|
|
7783
|
-
return (0,
|
|
7853
|
+
return (0, import_date_fns11.parseISO)(business.activation_at);
|
|
7784
7854
|
}
|
|
7785
7855
|
return;
|
|
7786
7856
|
} catch (_err) {
|
|
@@ -7790,7 +7860,7 @@ var getActivationDate = (business) => {
|
|
|
7790
7860
|
var getEarliestDateToBrowse = (business) => {
|
|
7791
7861
|
const activationDate = getActivationDate(business);
|
|
7792
7862
|
if (activationDate) {
|
|
7793
|
-
return (0,
|
|
7863
|
+
return (0, import_date_fns11.startOfMonth)(activationDate);
|
|
7794
7864
|
}
|
|
7795
7865
|
return;
|
|
7796
7866
|
};
|
|
@@ -7802,7 +7872,7 @@ var isDateAllowedToBrowse = (date, business) => {
|
|
|
7802
7872
|
if (!activationDate) {
|
|
7803
7873
|
return true;
|
|
7804
7874
|
}
|
|
7805
|
-
return (0,
|
|
7875
|
+
return (0, import_date_fns11.differenceInCalendarMonths)((0, import_date_fns11.startOfMonth)(date), activationDate) >= 0;
|
|
7806
7876
|
};
|
|
7807
7877
|
|
|
7808
7878
|
// src/components/DatePicker/DatePicker.tsx
|
|
@@ -7811,7 +7881,7 @@ var import_react_datepicker = __toESM(require("react-datepicker"));
|
|
|
7811
7881
|
|
|
7812
7882
|
// src/components/DatePicker/DatePickerOptions.tsx
|
|
7813
7883
|
var import_react90 = __toESM(require("react"));
|
|
7814
|
-
var
|
|
7884
|
+
var import_date_fns12 = require("date-fns");
|
|
7815
7885
|
var DatePickerOptions = ({
|
|
7816
7886
|
options,
|
|
7817
7887
|
setSelectedDate
|
|
@@ -7826,8 +7896,8 @@ var DatePickerOptions = ({
|
|
|
7826
7896
|
key: option,
|
|
7827
7897
|
onClick: () => {
|
|
7828
7898
|
setSelectedDate([
|
|
7829
|
-
(0,
|
|
7830
|
-
(0,
|
|
7899
|
+
(0, import_date_fns12.startOfMonth)(/* @__PURE__ */ new Date()),
|
|
7900
|
+
(0, import_date_fns12.endOfMonth)(/* @__PURE__ */ new Date())
|
|
7831
7901
|
]);
|
|
7832
7902
|
}
|
|
7833
7903
|
},
|
|
@@ -7840,8 +7910,8 @@ var DatePickerOptions = ({
|
|
|
7840
7910
|
key: option,
|
|
7841
7911
|
onClick: () => {
|
|
7842
7912
|
setSelectedDate([
|
|
7843
|
-
(0,
|
|
7844
|
-
(0,
|
|
7913
|
+
(0, import_date_fns12.startOfMonth)((0, import_date_fns12.subMonths)(/* @__PURE__ */ new Date(), 1)),
|
|
7914
|
+
(0, import_date_fns12.endOfMonth)((0, import_date_fns12.subMonths)(/* @__PURE__ */ new Date(), 1))
|
|
7845
7915
|
]);
|
|
7846
7916
|
}
|
|
7847
7917
|
},
|
|
@@ -7854,8 +7924,8 @@ var DatePickerOptions = ({
|
|
|
7854
7924
|
key: option,
|
|
7855
7925
|
onClick: () => {
|
|
7856
7926
|
setSelectedDate([
|
|
7857
|
-
(0,
|
|
7858
|
-
(0,
|
|
7927
|
+
(0, import_date_fns12.startOfQuarter)(/* @__PURE__ */ new Date()),
|
|
7928
|
+
(0, import_date_fns12.endOfQuarter)(/* @__PURE__ */ new Date())
|
|
7859
7929
|
]);
|
|
7860
7930
|
}
|
|
7861
7931
|
},
|
|
@@ -7867,10 +7937,10 @@ var DatePickerOptions = ({
|
|
|
7867
7937
|
{
|
|
7868
7938
|
key: option,
|
|
7869
7939
|
onClick: () => {
|
|
7870
|
-
const lastQuarter = (0,
|
|
7940
|
+
const lastQuarter = (0, import_date_fns12.subQuarters)(/* @__PURE__ */ new Date(), 1);
|
|
7871
7941
|
setSelectedDate([
|
|
7872
|
-
(0,
|
|
7873
|
-
(0,
|
|
7942
|
+
(0, import_date_fns12.startOfQuarter)(lastQuarter),
|
|
7943
|
+
(0, import_date_fns12.endOfQuarter)(lastQuarter)
|
|
7874
7944
|
]);
|
|
7875
7945
|
}
|
|
7876
7946
|
},
|
|
@@ -7882,7 +7952,7 @@ var DatePickerOptions = ({
|
|
|
7882
7952
|
{
|
|
7883
7953
|
key: option,
|
|
7884
7954
|
onClick: () => {
|
|
7885
|
-
setSelectedDate([(0,
|
|
7955
|
+
setSelectedDate([(0, import_date_fns12.startOfYear)(/* @__PURE__ */ new Date()), (0, import_date_fns12.endOfYear)(/* @__PURE__ */ new Date())]);
|
|
7886
7956
|
}
|
|
7887
7957
|
},
|
|
7888
7958
|
"This year"
|
|
@@ -7893,8 +7963,8 @@ var DatePickerOptions = ({
|
|
|
7893
7963
|
{
|
|
7894
7964
|
key: option,
|
|
7895
7965
|
onClick: () => {
|
|
7896
|
-
const lastYear = (0,
|
|
7897
|
-
setSelectedDate([(0,
|
|
7966
|
+
const lastYear = (0, import_date_fns12.subYears)(/* @__PURE__ */ new Date(), 1);
|
|
7967
|
+
setSelectedDate([(0, import_date_fns12.startOfYear)(lastYear), (0, import_date_fns12.endOfYear)(lastYear)]);
|
|
7898
7968
|
}
|
|
7899
7969
|
},
|
|
7900
7970
|
"Last year"
|
|
@@ -8173,7 +8243,7 @@ var DatePicker = ({
|
|
|
8173
8243
|
|
|
8174
8244
|
// src/components/BankTransactions/BankTransactionsHeader.tsx
|
|
8175
8245
|
var import_classnames41 = __toESM(require("classnames"));
|
|
8176
|
-
var
|
|
8246
|
+
var import_date_fns13 = require("date-fns");
|
|
8177
8247
|
var DownloadButton = ({
|
|
8178
8248
|
downloadButtonTextOverride,
|
|
8179
8249
|
iconOnly
|
|
@@ -8279,8 +8349,8 @@ var BankTransactionsHeader = ({
|
|
|
8279
8349
|
onChange: (date) => {
|
|
8280
8350
|
if (!Array.isArray(date)) {
|
|
8281
8351
|
setDateRange({
|
|
8282
|
-
startDate: (0,
|
|
8283
|
-
endDate: (0,
|
|
8352
|
+
startDate: (0, import_date_fns13.startOfMonth)(date),
|
|
8353
|
+
endDate: (0, import_date_fns13.endOfMonth)(date)
|
|
8284
8354
|
});
|
|
8285
8355
|
}
|
|
8286
8356
|
},
|
|
@@ -8355,7 +8425,7 @@ var DataStates = ({
|
|
|
8355
8425
|
editable
|
|
8356
8426
|
}) => {
|
|
8357
8427
|
let title = editable ? "You are up to date with transactions!" : "You have no categorized transactions";
|
|
8358
|
-
let description = editable ? "All uncategorized
|
|
8428
|
+
let description = editable ? "All uncategorized transactions will be displayed here" : "All transactions will be displayed here once reviewed";
|
|
8359
8429
|
const showRefreshButton = bankTransactions?.length;
|
|
8360
8430
|
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
8431
|
DataState,
|
|
@@ -8380,10 +8450,9 @@ var DataStates = ({
|
|
|
8380
8450
|
};
|
|
8381
8451
|
|
|
8382
8452
|
// src/components/BankTransactions/BankTransactions.tsx
|
|
8383
|
-
var
|
|
8453
|
+
var import_date_fns14 = require("date-fns");
|
|
8384
8454
|
var COMPONENT_NAME2 = "bank-transactions";
|
|
8385
8455
|
var TEST_EMPTY_STATE = false;
|
|
8386
|
-
var POLL_INTERVAL = 1e3;
|
|
8387
8456
|
var categorizationEnabled = (mode) => {
|
|
8388
8457
|
if (mode === "bookkeeping-client") {
|
|
8389
8458
|
return false;
|
|
@@ -8412,8 +8481,8 @@ var BankTransactionsContent = ({
|
|
|
8412
8481
|
const [currentPage, setCurrentPage] = (0, import_react94.useState)(1);
|
|
8413
8482
|
const [initialLoad, setInitialLoad] = (0, import_react94.useState)(true);
|
|
8414
8483
|
const [dateRange, setDateRange] = (0, import_react94.useState)({
|
|
8415
|
-
startDate: (0,
|
|
8416
|
-
endDate: (0,
|
|
8484
|
+
startDate: (0, import_date_fns14.startOfMonth)(/* @__PURE__ */ new Date()),
|
|
8485
|
+
endDate: (0, import_date_fns14.endOfMonth)(/* @__PURE__ */ new Date())
|
|
8417
8486
|
});
|
|
8418
8487
|
const categorizeView = categorizeViewProp ?? categorizationEnabled(mode);
|
|
8419
8488
|
const {
|
|
@@ -8431,39 +8500,11 @@ var BankTransactionsContent = ({
|
|
|
8431
8500
|
fetchMore,
|
|
8432
8501
|
removeAfterCategorize
|
|
8433
8502
|
} = useBankTransactionsContext();
|
|
8434
|
-
const { data: linkedAccounts
|
|
8503
|
+
const { data: linkedAccounts } = useLinkedAccounts();
|
|
8435
8504
|
const isSyncing = (0, import_react94.useMemo)(
|
|
8436
8505
|
() => Boolean(linkedAccounts?.some((item) => item.is_syncing)),
|
|
8437
8506
|
[linkedAccounts]
|
|
8438
8507
|
);
|
|
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
8508
|
(0, import_react94.useEffect)(() => {
|
|
8468
8509
|
activate();
|
|
8469
8510
|
}, []);
|
|
@@ -8505,7 +8546,7 @@ var BankTransactionsContent = ({
|
|
|
8505
8546
|
const bankTransactions = TEST_EMPTY_STATE ? [] : (0, import_react94.useMemo)(() => {
|
|
8506
8547
|
if (monthlyView) {
|
|
8507
8548
|
return data?.filter(
|
|
8508
|
-
(x) => (0,
|
|
8549
|
+
(x) => (0, import_date_fns14.parseISO)(x.date) >= dateRange.startDate && (0, import_date_fns14.parseISO)(x.date) <= dateRange.endDate
|
|
8509
8550
|
);
|
|
8510
8551
|
}
|
|
8511
8552
|
const firstPageIndex = (currentPage - 1) * pageSize;
|
|
@@ -8790,14 +8831,14 @@ var applyShare = (items, total) => {
|
|
|
8790
8831
|
|
|
8791
8832
|
// src/hooks/useProfitAndLoss/useProfitAndLossLTM.tsx
|
|
8792
8833
|
var import_react97 = require("react");
|
|
8793
|
-
var
|
|
8834
|
+
var import_date_fns15 = require("date-fns");
|
|
8794
8835
|
var import_swr3 = __toESM(require("swr"));
|
|
8795
8836
|
var buildDates = ({ currentDate }) => {
|
|
8796
8837
|
return {
|
|
8797
|
-
startYear: (0,
|
|
8798
|
-
startMonth: (0,
|
|
8799
|
-
endYear: (0,
|
|
8800
|
-
endMonth: (0,
|
|
8838
|
+
startYear: (0, import_date_fns15.startOfMonth)(currentDate).getFullYear() - 1,
|
|
8839
|
+
startMonth: (0, import_date_fns15.startOfMonth)(currentDate).getMonth() + 1,
|
|
8840
|
+
endYear: (0, import_date_fns15.startOfMonth)(currentDate).getFullYear(),
|
|
8841
|
+
endMonth: (0, import_date_fns15.startOfMonth)(currentDate).getMonth() + 1
|
|
8801
8842
|
};
|
|
8802
8843
|
};
|
|
8803
8844
|
var buildMonthsArray = (startDate, endDate) => {
|
|
@@ -8811,7 +8852,7 @@ var buildMonthsArray = (startDate, endDate) => {
|
|
|
8811
8852
|
return dates;
|
|
8812
8853
|
};
|
|
8813
8854
|
var useProfitAndLossLTM = ({ currentDate, tagFilter, reportingBasis } = {
|
|
8814
|
-
currentDate: (0,
|
|
8855
|
+
currentDate: (0, import_date_fns15.startOfMonth)(Date.now())
|
|
8815
8856
|
}) => {
|
|
8816
8857
|
const {
|
|
8817
8858
|
businessId,
|
|
@@ -8854,7 +8895,7 @@ var useProfitAndLossLTM = ({ currentDate, tagFilter, reportingBasis } = {
|
|
|
8854
8895
|
);
|
|
8855
8896
|
(0, import_react97.useEffect)(() => {
|
|
8856
8897
|
const newData = data.slice();
|
|
8857
|
-
const newPeriod = buildMonthsArray((0,
|
|
8898
|
+
const newPeriod = buildMonthsArray((0, import_date_fns15.sub)(date, { years: 1 }), date);
|
|
8858
8899
|
if (newData && newPeriod) {
|
|
8859
8900
|
newPeriod.forEach((x) => {
|
|
8860
8901
|
if (!newData?.find(
|
|
@@ -8948,7 +8989,7 @@ var useProfitAndLossLTM = ({ currentDate, tagFilter, reportingBasis } = {
|
|
|
8948
8989
|
|
|
8949
8990
|
// src/hooks/useProfitAndLoss/useProfitAndLossQuery.tsx
|
|
8950
8991
|
var import_react98 = require("react");
|
|
8951
|
-
var
|
|
8992
|
+
var import_date_fns16 = require("date-fns");
|
|
8952
8993
|
var import_swr4 = __toESM(require("swr"));
|
|
8953
8994
|
var useProfitAndLossQuery = ({
|
|
8954
8995
|
startDate,
|
|
@@ -8956,8 +8997,8 @@ var useProfitAndLossQuery = ({
|
|
|
8956
8997
|
tagFilter,
|
|
8957
8998
|
reportingBasis
|
|
8958
8999
|
} = {
|
|
8959
|
-
startDate: (0,
|
|
8960
|
-
endDate: (0,
|
|
9000
|
+
startDate: (0, import_date_fns16.startOfMonth)(/* @__PURE__ */ new Date()),
|
|
9001
|
+
endDate: (0, import_date_fns16.endOfMonth)(/* @__PURE__ */ new Date())
|
|
8961
9002
|
}) => {
|
|
8962
9003
|
const { auth, businessId, apiUrl, syncTimestamps, read, hasBeenTouched } = useLayerContext();
|
|
8963
9004
|
const queryKey = businessId && startDate && endDate && auth?.access_token && `profit-and-loss-${businessId}-${startDate.valueOf()}-${endDate.valueOf()}-${tagFilter?.key}-${tagFilter?.values?.join(
|
|
@@ -8974,8 +9015,8 @@ var useProfitAndLossQuery = ({
|
|
|
8974
9015
|
Layer.getProfitAndLoss(apiUrl, auth?.access_token, {
|
|
8975
9016
|
params: {
|
|
8976
9017
|
businessId,
|
|
8977
|
-
startDate: (0,
|
|
8978
|
-
endDate: (0,
|
|
9018
|
+
startDate: (0, import_date_fns16.formatISO)(startDate.valueOf()),
|
|
9019
|
+
endDate: (0, import_date_fns16.formatISO)(endDate.valueOf()),
|
|
8979
9020
|
tagKey: tagFilter?.key,
|
|
8980
9021
|
tagValues: tagFilter?.values?.join(","),
|
|
8981
9022
|
reportingBasis
|
|
@@ -9007,21 +9048,21 @@ var useProfitAndLossQuery = ({
|
|
|
9007
9048
|
};
|
|
9008
9049
|
|
|
9009
9050
|
// src/hooks/useProfitAndLoss/useProfitAndLoss.tsx
|
|
9010
|
-
var
|
|
9051
|
+
var import_date_fns17 = require("date-fns");
|
|
9011
9052
|
var useProfitAndLoss = ({
|
|
9012
9053
|
startDate: initialStartDate,
|
|
9013
9054
|
endDate: initialEndDate,
|
|
9014
9055
|
tagFilter,
|
|
9015
9056
|
reportingBasis
|
|
9016
9057
|
} = {
|
|
9017
|
-
startDate: (0,
|
|
9018
|
-
endDate: (0,
|
|
9058
|
+
startDate: (0, import_date_fns17.startOfMonth)(/* @__PURE__ */ new Date()),
|
|
9059
|
+
endDate: (0, import_date_fns17.endOfMonth)(/* @__PURE__ */ new Date())
|
|
9019
9060
|
}) => {
|
|
9020
9061
|
const [startDate, setStartDate] = (0, import_react99.useState)(
|
|
9021
|
-
initialStartDate || (0,
|
|
9062
|
+
initialStartDate || (0, import_date_fns17.startOfMonth)(Date.now())
|
|
9022
9063
|
);
|
|
9023
9064
|
const [endDate, setEndDate] = (0, import_react99.useState)(
|
|
9024
|
-
initialEndDate || (0,
|
|
9065
|
+
initialEndDate || (0, import_date_fns17.endOfMonth)(Date.now())
|
|
9025
9066
|
);
|
|
9026
9067
|
const [filters, setFilters] = (0, import_react99.useState)({
|
|
9027
9068
|
expenses: void 0,
|
|
@@ -9035,7 +9076,7 @@ var useProfitAndLoss = ({
|
|
|
9035
9076
|
reportingBasis
|
|
9036
9077
|
});
|
|
9037
9078
|
const { data: summaryData } = useProfitAndLossLTM({
|
|
9038
|
-
currentDate: startDate ? startDate : (0,
|
|
9079
|
+
currentDate: startDate ? startDate : (0, import_date_fns17.startOfMonth)(/* @__PURE__ */ new Date())
|
|
9039
9080
|
});
|
|
9040
9081
|
const changeDateRange = ({
|
|
9041
9082
|
startDate: newStartDate,
|
|
@@ -9248,53 +9289,53 @@ var Indicator = ({
|
|
|
9248
9289
|
|
|
9249
9290
|
// src/components/ProfitAndLossChart/ProfitAndLossChart.tsx
|
|
9250
9291
|
var import_classnames42 = __toESM(require("classnames"));
|
|
9251
|
-
var
|
|
9292
|
+
var import_date_fns18 = require("date-fns");
|
|
9252
9293
|
var import_recharts = require("recharts");
|
|
9253
9294
|
var getChartWindow = ({
|
|
9254
9295
|
chartWindow,
|
|
9255
9296
|
currentYear,
|
|
9256
9297
|
currentMonth
|
|
9257
9298
|
}) => {
|
|
9258
|
-
const today = (0,
|
|
9259
|
-
const yearAgo = (0,
|
|
9260
|
-
const current = (0,
|
|
9261
|
-
if ((0,
|
|
9299
|
+
const today = (0, import_date_fns18.startOfMonth)(Date.now());
|
|
9300
|
+
const yearAgo = (0, import_date_fns18.sub)(today, { months: 11 });
|
|
9301
|
+
const current = (0, import_date_fns18.startOfMonth)(new Date(currentYear, currentMonth - 1, 1));
|
|
9302
|
+
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
9303
|
return chartWindow;
|
|
9263
9304
|
}
|
|
9264
|
-
if ((0,
|
|
9305
|
+
if ((0, import_date_fns18.differenceInMonths)((0, import_date_fns18.startOfMonth)(chartWindow.start), current) === 0) {
|
|
9265
9306
|
return {
|
|
9266
|
-
start: (0,
|
|
9267
|
-
end: (0,
|
|
9307
|
+
start: (0, import_date_fns18.startOfMonth)((0, import_date_fns18.sub)(current, { months: 1 })),
|
|
9308
|
+
end: (0, import_date_fns18.endOfMonth)((0, import_date_fns18.add)(current, { months: 11 }))
|
|
9268
9309
|
};
|
|
9269
9310
|
}
|
|
9270
|
-
if ((0,
|
|
9311
|
+
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
9312
|
return {
|
|
9272
|
-
start: (0,
|
|
9273
|
-
end: (0,
|
|
9313
|
+
start: (0, import_date_fns18.startOfMonth)((0, import_date_fns18.sub)(current, { months: 10 })),
|
|
9314
|
+
end: (0, import_date_fns18.endOfMonth)((0, import_date_fns18.add)(current, { months: 2 }))
|
|
9274
9315
|
};
|
|
9275
9316
|
}
|
|
9276
|
-
if ((0,
|
|
9317
|
+
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
9318
|
return {
|
|
9278
|
-
start: (0,
|
|
9279
|
-
end: (0,
|
|
9319
|
+
start: (0, import_date_fns18.startOfMonth)((0, import_date_fns18.sub)(current, { months: 11 })),
|
|
9320
|
+
end: (0, import_date_fns18.endOfMonth)((0, import_date_fns18.add)(current, { months: 1 }))
|
|
9280
9321
|
};
|
|
9281
9322
|
}
|
|
9282
9323
|
if (current >= yearAgo) {
|
|
9283
9324
|
return {
|
|
9284
|
-
start: (0,
|
|
9285
|
-
end: (0,
|
|
9325
|
+
start: (0, import_date_fns18.startOfMonth)(yearAgo),
|
|
9326
|
+
end: (0, import_date_fns18.endOfMonth)(today)
|
|
9286
9327
|
};
|
|
9287
9328
|
}
|
|
9288
9329
|
if (Number(current) > Number(chartWindow.end)) {
|
|
9289
9330
|
return {
|
|
9290
|
-
start: (0,
|
|
9291
|
-
end: (0,
|
|
9331
|
+
start: (0, import_date_fns18.startOfMonth)((0, import_date_fns18.sub)(current, { months: 12 })),
|
|
9332
|
+
end: (0, import_date_fns18.endOfMonth)(current)
|
|
9292
9333
|
};
|
|
9293
9334
|
}
|
|
9294
|
-
if ((0,
|
|
9335
|
+
if ((0, import_date_fns18.differenceInMonths)(current, (0, import_date_fns18.startOfMonth)(chartWindow.start)) < 0) {
|
|
9295
9336
|
return {
|
|
9296
|
-
start: (0,
|
|
9297
|
-
end: (0,
|
|
9337
|
+
start: (0, import_date_fns18.startOfMonth)(current),
|
|
9338
|
+
end: (0, import_date_fns18.endOfMonth)((0, import_date_fns18.add)(current, { months: 11 }))
|
|
9298
9339
|
};
|
|
9299
9340
|
}
|
|
9300
9341
|
return chartWindow;
|
|
@@ -9330,8 +9371,8 @@ var ProfitAndLossChart = ({
|
|
|
9330
9371
|
});
|
|
9331
9372
|
const [barAnimActive, setBarAnimActive] = (0, import_react101.useState)(true);
|
|
9332
9373
|
const [chartWindow, setChartWindow] = (0, import_react101.useState)({
|
|
9333
|
-
start: (0,
|
|
9334
|
-
end: (0,
|
|
9374
|
+
start: (0, import_date_fns18.startOfMonth)((0, import_date_fns18.sub)(Date.now(), { months: 11 })),
|
|
9375
|
+
end: (0, import_date_fns18.endOfMonth)(Date.now())
|
|
9335
9376
|
});
|
|
9336
9377
|
const selectionMonth = (0, import_react101.useMemo)(
|
|
9337
9378
|
() => ({
|
|
@@ -9346,25 +9387,25 @@ var ProfitAndLossChart = ({
|
|
|
9346
9387
|
}
|
|
9347
9388
|
}, [dateRange]);
|
|
9348
9389
|
const { data, loaded, pullData } = useProfitAndLossLTM({
|
|
9349
|
-
currentDate: (0,
|
|
9390
|
+
currentDate: (0, import_date_fns18.startOfMonth)(Date.now())
|
|
9350
9391
|
});
|
|
9351
9392
|
const loadingValue = (0, import_react101.useMemo)(() => getLoadingValue(data), [data]);
|
|
9352
9393
|
(0, import_react101.useEffect)(() => {
|
|
9353
9394
|
if (loaded === "complete" && data) {
|
|
9354
9395
|
const foundCurrent = data.find(
|
|
9355
|
-
(x) => Number((0,
|
|
9396
|
+
(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
9397
|
);
|
|
9357
9398
|
if (!foundCurrent) {
|
|
9358
|
-
const newDate = (0,
|
|
9399
|
+
const newDate = (0, import_date_fns18.startOfMonth)(localDateRange.startDate);
|
|
9359
9400
|
pullData(newDate);
|
|
9360
9401
|
return;
|
|
9361
9402
|
}
|
|
9362
9403
|
const foundBefore = data.find(
|
|
9363
|
-
(x) => Number((0,
|
|
9404
|
+
(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
9405
|
);
|
|
9365
9406
|
if (!foundBefore) {
|
|
9366
|
-
const newDate = (0,
|
|
9367
|
-
(0,
|
|
9407
|
+
const newDate = (0, import_date_fns18.startOfMonth)(
|
|
9408
|
+
(0, import_date_fns18.sub)(localDateRange.startDate, { months: 1 })
|
|
9368
9409
|
);
|
|
9369
9410
|
pullData(newDate);
|
|
9370
9411
|
}
|
|
@@ -9387,7 +9428,7 @@ var ProfitAndLossChart = ({
|
|
|
9387
9428
|
}, 2e3);
|
|
9388
9429
|
}
|
|
9389
9430
|
}, [loaded]);
|
|
9390
|
-
const getMonthName = (pnl) => pnl ? (0,
|
|
9431
|
+
const getMonthName = (pnl) => pnl ? (0, import_date_fns18.format)(
|
|
9391
9432
|
new Date(pnl.year, pnl.month - 1, 1),
|
|
9392
9433
|
compactView ? "LLLLL" : "LLL"
|
|
9393
9434
|
) : "";
|
|
@@ -9412,9 +9453,9 @@ var ProfitAndLossChart = ({
|
|
|
9412
9453
|
const loadingData = [];
|
|
9413
9454
|
const today = Date.now();
|
|
9414
9455
|
for (let i = 11; i >= 0; i--) {
|
|
9415
|
-
const currentDate = (0,
|
|
9456
|
+
const currentDate = (0, import_date_fns18.sub)(today, { months: i });
|
|
9416
9457
|
loadingData.push({
|
|
9417
|
-
name: (0,
|
|
9458
|
+
name: (0, import_date_fns18.format)(currentDate, compactView ? "LLLLL" : "LLL"),
|
|
9418
9459
|
revenue: 0,
|
|
9419
9460
|
revenueUncategorized: 0,
|
|
9420
9461
|
totalExpensesInverse: 0,
|
|
@@ -9445,18 +9486,18 @@ var ProfitAndLossChart = ({
|
|
|
9445
9486
|
}
|
|
9446
9487
|
return x;
|
|
9447
9488
|
})?.filter(
|
|
9448
|
-
(x) => (0,
|
|
9449
|
-
(0,
|
|
9489
|
+
(x) => (0, import_date_fns18.differenceInMonths)(
|
|
9490
|
+
(0, import_date_fns18.startOfMonth)(new Date(x.year, x.month - 1, 1)),
|
|
9450
9491
|
chartWindow.start
|
|
9451
|
-
) >= 0 && (0,
|
|
9452
|
-
(0,
|
|
9492
|
+
) >= 0 && (0, import_date_fns18.differenceInMonths)(
|
|
9493
|
+
(0, import_date_fns18.startOfMonth)(new Date(x.year, x.month - 1, 1)),
|
|
9453
9494
|
chartWindow.start
|
|
9454
|
-
) < 12 && (0,
|
|
9495
|
+
) < 12 && (0, import_date_fns18.differenceInMonths)(
|
|
9455
9496
|
chartWindow.end,
|
|
9456
|
-
(0,
|
|
9457
|
-
) >= 0 && (0,
|
|
9497
|
+
(0, import_date_fns18.startOfMonth)(new Date(x.year, x.month - 1, 1))
|
|
9498
|
+
) >= 0 && (0, import_date_fns18.differenceInMonths)(
|
|
9458
9499
|
chartWindow.end,
|
|
9459
|
-
(0,
|
|
9500
|
+
(0, import_date_fns18.startOfMonth)(new Date(x.year, x.month - 1, 1))
|
|
9460
9501
|
) <= 12
|
|
9461
9502
|
).map((x) => summarizePnL(x));
|
|
9462
9503
|
}, [selectionMonth, chartWindow, data, loaded, compactView]);
|
|
@@ -9470,7 +9511,7 @@ var ProfitAndLossChart = ({
|
|
|
9470
9511
|
if (isMonthAllowed) {
|
|
9471
9512
|
changeDateRange({
|
|
9472
9513
|
startDate: new Date(year, month - 1, 1),
|
|
9473
|
-
endDate: (0,
|
|
9514
|
+
endDate: (0, import_date_fns18.endOfMonth)(new Date(year, month - 1, 1))
|
|
9474
9515
|
});
|
|
9475
9516
|
}
|
|
9476
9517
|
}
|
|
@@ -9887,7 +9928,7 @@ var ProfitAndLossChart = ({
|
|
|
9887
9928
|
|
|
9888
9929
|
// src/components/ProfitAndLossDatePicker/ProfitAndLossDatePicker.tsx
|
|
9889
9930
|
var import_react102 = __toESM(require("react"));
|
|
9890
|
-
var
|
|
9931
|
+
var import_date_fns19 = require("date-fns");
|
|
9891
9932
|
var ProfitAndLossDatePicker = () => {
|
|
9892
9933
|
const { business } = useLayerContext();
|
|
9893
9934
|
const { changeDateRange, dateRange } = (0, import_react102.useContext)(ProfitAndLoss.Context);
|
|
@@ -9900,8 +9941,8 @@ var ProfitAndLossDatePicker = () => {
|
|
|
9900
9941
|
onChange: (date) => {
|
|
9901
9942
|
if (!Array.isArray(date)) {
|
|
9902
9943
|
changeDateRange({
|
|
9903
|
-
startDate: (0,
|
|
9904
|
-
endDate: (0,
|
|
9944
|
+
startDate: (0, import_date_fns19.startOfMonth)(date),
|
|
9945
|
+
endDate: (0, import_date_fns19.endOfMonth)(date)
|
|
9905
9946
|
});
|
|
9906
9947
|
}
|
|
9907
9948
|
},
|
|
@@ -10646,7 +10687,7 @@ var Filters = ({
|
|
|
10646
10687
|
};
|
|
10647
10688
|
|
|
10648
10689
|
// src/components/ProfitAndLossDetailedCharts/ProfitAndLossDetailedCharts.tsx
|
|
10649
|
-
var
|
|
10690
|
+
var import_date_fns20 = require("date-fns");
|
|
10650
10691
|
var ProfitAndLossDetailedCharts = ({
|
|
10651
10692
|
scope,
|
|
10652
10693
|
hideClose = false,
|
|
@@ -10671,7 +10712,7 @@ var ProfitAndLossDetailedCharts = ({
|
|
|
10671
10712
|
const data = theScope === "revenue" ? filteredDataRevenue : filteredDataExpenses;
|
|
10672
10713
|
const total = theScope === "revenue" ? filteredTotalRevenue : filteredTotalExpenses;
|
|
10673
10714
|
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,
|
|
10715
|
+
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
10716
|
Button,
|
|
10676
10717
|
{
|
|
10677
10718
|
rightIcon: /* @__PURE__ */ import_react106.default.createElement(X_default, null),
|
|
@@ -10679,7 +10720,7 @@ var ProfitAndLossDetailedCharts = ({
|
|
|
10679
10720
|
onClick: () => setSidebarScope(void 0),
|
|
10680
10721
|
variant: "secondary" /* secondary */
|
|
10681
10722
|
}
|
|
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,
|
|
10723
|
+
)), /* @__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
10724
|
DetailedChart,
|
|
10684
10725
|
{
|
|
10685
10726
|
filteredData: data,
|
|
@@ -11309,7 +11350,7 @@ var ProfitAndLossTableWithProvider = (props) => {
|
|
|
11309
11350
|
};
|
|
11310
11351
|
|
|
11311
11352
|
// src/components/ProfitAndLoss/ProfitAndLoss.tsx
|
|
11312
|
-
var
|
|
11353
|
+
var import_date_fns21 = require("date-fns");
|
|
11313
11354
|
var PNLContext = (0, import_react118.createContext)({
|
|
11314
11355
|
data: void 0,
|
|
11315
11356
|
filteredDataRevenue: [],
|
|
@@ -11320,8 +11361,8 @@ var PNLContext = (0, import_react118.createContext)({
|
|
|
11320
11361
|
isValidating: false,
|
|
11321
11362
|
error: void 0,
|
|
11322
11363
|
dateRange: {
|
|
11323
|
-
startDate: (0,
|
|
11324
|
-
endDate: (0,
|
|
11364
|
+
startDate: (0, import_date_fns21.startOfMonth)(/* @__PURE__ */ new Date()),
|
|
11365
|
+
endDate: (0, import_date_fns21.endOfMonth)(/* @__PURE__ */ new Date())
|
|
11325
11366
|
},
|
|
11326
11367
|
changeDateRange: () => {
|
|
11327
11368
|
},
|
|
@@ -11370,11 +11411,11 @@ var BalanceSheetContext = (0, import_react119.createContext)({
|
|
|
11370
11411
|
|
|
11371
11412
|
// src/hooks/useBalanceSheet/useBalanceSheet.tsx
|
|
11372
11413
|
var import_react120 = require("react");
|
|
11373
|
-
var
|
|
11414
|
+
var import_date_fns22 = require("date-fns");
|
|
11374
11415
|
var import_swr5 = __toESM(require("swr"));
|
|
11375
11416
|
var useBalanceSheet = (date = /* @__PURE__ */ new Date()) => {
|
|
11376
11417
|
const { auth, businessId, apiUrl, read, syncTimestamps, hasBeenTouched } = useLayerContext();
|
|
11377
|
-
const dateString = (0,
|
|
11418
|
+
const dateString = (0, import_date_fns22.format)((0, import_date_fns22.startOfDay)(date), "yyyy-MM-dd'T'HH:mm:ssXXX");
|
|
11378
11419
|
const queryKey = businessId && dateString && auth?.access_token && `balance-sheet-${businessId}-${dateString}`;
|
|
11379
11420
|
const { data, isLoading, isValidating, error, mutate } = (0, import_swr5.default)(
|
|
11380
11421
|
queryKey,
|
|
@@ -11583,7 +11624,7 @@ var BALANCE_SHEET_ROWS = [
|
|
|
11583
11624
|
];
|
|
11584
11625
|
|
|
11585
11626
|
// src/components/BalanceSheet/BalanceSheet.tsx
|
|
11586
|
-
var
|
|
11627
|
+
var import_date_fns23 = require("date-fns");
|
|
11587
11628
|
var COMPONENT_NAME3 = "balance-sheet";
|
|
11588
11629
|
var BalanceSheet = (props) => {
|
|
11589
11630
|
const balanceSheetContextData = useBalanceSheet(props.effectiveDate);
|
|
@@ -11601,13 +11642,13 @@ var BalanceSheetView = ({
|
|
|
11601
11642
|
asWidget = false,
|
|
11602
11643
|
stringOverrides
|
|
11603
11644
|
}) => {
|
|
11604
|
-
const [effectiveDate, setEffectiveDate] = (0, import_react127.useState)((0,
|
|
11645
|
+
const [effectiveDate, setEffectiveDate] = (0, import_react127.useState)((0, import_date_fns23.startOfDay)(/* @__PURE__ */ new Date()));
|
|
11605
11646
|
const { data, isLoading, refetch } = useBalanceSheet(effectiveDate);
|
|
11606
11647
|
(0, import_react127.useEffect)(() => {
|
|
11607
|
-
const d1 = effectiveDate && (0,
|
|
11608
|
-
const d2 = data?.effective_date && (0,
|
|
11609
|
-
(0,
|
|
11610
|
-
(0,
|
|
11648
|
+
const d1 = effectiveDate && (0, import_date_fns23.format)((0, import_date_fns23.startOfDay)(effectiveDate), "yyyy-MM-dd'T'HH:mm:ssXXX");
|
|
11649
|
+
const d2 = data?.effective_date && (0, import_date_fns23.format)(
|
|
11650
|
+
(0, import_date_fns23.startOfDay)(
|
|
11651
|
+
(0, import_date_fns23.parse)(data.effective_date, "yyyy-MM-dd'T'HH:mm:ssXXX", /* @__PURE__ */ new Date())
|
|
11611
11652
|
),
|
|
11612
11653
|
"yyyy-MM-dd'T'HH:mm:ssXXX"
|
|
11613
11654
|
);
|
|
@@ -11676,15 +11717,15 @@ var StatementOfCashFlowContext = (0, import_react128.createContext)({
|
|
|
11676
11717
|
|
|
11677
11718
|
// src/hooks/useStatementOfCashFlow/useStatementOfCashFlow.tsx
|
|
11678
11719
|
var import_react129 = require("react");
|
|
11679
|
-
var
|
|
11720
|
+
var import_date_fns24 = require("date-fns");
|
|
11680
11721
|
var import_swr6 = __toESM(require("swr"));
|
|
11681
11722
|
var useStatementOfCashFlow = (startDate = /* @__PURE__ */ new Date(), endDate = /* @__PURE__ */ new Date()) => {
|
|
11682
11723
|
const { auth, businessId, apiUrl, read, syncTimestamps, hasBeenTouched } = useLayerContext();
|
|
11683
|
-
const startDateString = (0,
|
|
11684
|
-
(0,
|
|
11724
|
+
const startDateString = (0, import_date_fns24.format)(
|
|
11725
|
+
(0, import_date_fns24.startOfDay)(startDate),
|
|
11685
11726
|
"yyyy-MM-dd'T'HH:mm:ssXXX"
|
|
11686
11727
|
);
|
|
11687
|
-
const endDateString = (0,
|
|
11728
|
+
const endDateString = (0, import_date_fns24.format)((0, import_date_fns24.startOfDay)(endDate), "yyyy-MM-dd'T'HH:mm:ssXXX");
|
|
11688
11729
|
const queryKey = businessId && startDateString && endDateString && auth?.access_token && `statement-of-cash-${businessId}-${startDateString}-${endDateString}`;
|
|
11689
11730
|
const { data, isLoading, isValidating, error, mutate } = (0, import_swr6.default)(
|
|
11690
11731
|
queryKey,
|
|
@@ -11813,7 +11854,7 @@ var STATEMENT_OF_CASH_FLOW_ROWS = [
|
|
|
11813
11854
|
];
|
|
11814
11855
|
|
|
11815
11856
|
// src/components/StatementOfCashFlow/StatementOfCashFlow.tsx
|
|
11816
|
-
var
|
|
11857
|
+
var import_date_fns25 = require("date-fns");
|
|
11817
11858
|
var COMPONENT_NAME4 = "statement-of-cash-flow";
|
|
11818
11859
|
var StatementOfCashFlow = ({ stringOverrides }) => {
|
|
11819
11860
|
const cashContextData = useStatementOfCashFlow();
|
|
@@ -11821,19 +11862,19 @@ var StatementOfCashFlow = ({ stringOverrides }) => {
|
|
|
11821
11862
|
};
|
|
11822
11863
|
var StatementOfCashFlowView = ({ stringOverrides }) => {
|
|
11823
11864
|
const [startDate, setStartDate] = (0, import_react131.useState)(
|
|
11824
|
-
(0,
|
|
11865
|
+
(0, import_date_fns25.startOfDay)((0, import_date_fns25.subWeeks)(/* @__PURE__ */ new Date(), 4))
|
|
11825
11866
|
);
|
|
11826
|
-
const [endDate, setEndDate] = (0, import_react131.useState)((0,
|
|
11867
|
+
const [endDate, setEndDate] = (0, import_react131.useState)((0, import_date_fns25.startOfDay)(/* @__PURE__ */ new Date()));
|
|
11827
11868
|
const { data, isLoading, refetch } = useStatementOfCashFlow(
|
|
11828
11869
|
startDate,
|
|
11829
11870
|
endDate
|
|
11830
11871
|
);
|
|
11831
11872
|
const handleDateChange = (dates) => {
|
|
11832
11873
|
if (dates[0]) {
|
|
11833
|
-
setStartDate((0,
|
|
11874
|
+
setStartDate((0, import_date_fns25.startOfDay)(dates[0]));
|
|
11834
11875
|
}
|
|
11835
11876
|
if (dates[1]) {
|
|
11836
|
-
setEndDate((0,
|
|
11877
|
+
setEndDate((0, import_date_fns25.startOfDay)(dates[1]));
|
|
11837
11878
|
}
|
|
11838
11879
|
if (dates[0] && dates[1]) {
|
|
11839
11880
|
refetch();
|
|
@@ -11869,7 +11910,7 @@ var import_react149 = __toESM(require("react"));
|
|
|
11869
11910
|
|
|
11870
11911
|
// src/contexts/ChartOfAccountsContext/ChartOfAccountsContext.tsx
|
|
11871
11912
|
var import_react132 = require("react");
|
|
11872
|
-
var
|
|
11913
|
+
var import_date_fns26 = require("date-fns");
|
|
11873
11914
|
var ChartOfAccountsContext = (0, import_react132.createContext)(
|
|
11874
11915
|
{
|
|
11875
11916
|
data: void 0,
|
|
@@ -11892,8 +11933,8 @@ var ChartOfAccountsContext = (0, import_react132.createContext)(
|
|
|
11892
11933
|
submitForm: () => {
|
|
11893
11934
|
},
|
|
11894
11935
|
dateRange: {
|
|
11895
|
-
startDate: (0,
|
|
11896
|
-
endDate: (0,
|
|
11936
|
+
startDate: (0, import_date_fns26.startOfMonth)(/* @__PURE__ */ new Date()),
|
|
11937
|
+
endDate: (0, import_date_fns26.endOfMonth)(/* @__PURE__ */ new Date())
|
|
11897
11938
|
},
|
|
11898
11939
|
changeDateRange: () => {
|
|
11899
11940
|
}
|
|
@@ -12128,7 +12169,7 @@ var LEDGER_ACCOUNT_SUBTYPES_FOR_TYPE = {
|
|
|
12128
12169
|
};
|
|
12129
12170
|
|
|
12130
12171
|
// src/hooks/useChartOfAccounts/useChartOfAccounts.tsx
|
|
12131
|
-
var
|
|
12172
|
+
var import_date_fns27 = require("date-fns");
|
|
12132
12173
|
var import_swr7 = __toESM(require("swr"));
|
|
12133
12174
|
var validate = (formData) => {
|
|
12134
12175
|
const errors = [];
|
|
@@ -12209,8 +12250,8 @@ var validateName = (formData) => {
|
|
|
12209
12250
|
var flattenAccounts = (accounts) => accounts.flatMap((a) => [a, flattenAccounts(a.sub_accounts || [])]).flat().filter((id) => id);
|
|
12210
12251
|
var useChartOfAccounts = ({ withDates, startDate: initialStartDate, endDate: initialEndDate } = {
|
|
12211
12252
|
withDates: false,
|
|
12212
|
-
startDate: (0,
|
|
12213
|
-
endDate: (0,
|
|
12253
|
+
startDate: (0, import_date_fns27.startOfMonth)(/* @__PURE__ */ new Date()),
|
|
12254
|
+
endDate: (0, import_date_fns27.endOfMonth)(/* @__PURE__ */ new Date())
|
|
12214
12255
|
}) => {
|
|
12215
12256
|
const {
|
|
12216
12257
|
auth,
|
|
@@ -12225,10 +12266,10 @@ var useChartOfAccounts = ({ withDates, startDate: initialStartDate, endDate: ini
|
|
|
12225
12266
|
const [sendingForm, setSendingForm] = (0, import_react134.useState)(false);
|
|
12226
12267
|
const [apiError, setApiError] = (0, import_react134.useState)(void 0);
|
|
12227
12268
|
const [startDate, setStartDate] = (0, import_react134.useState)(
|
|
12228
|
-
initialStartDate ?? (0,
|
|
12269
|
+
initialStartDate ?? (0, import_date_fns27.startOfMonth)(Date.now())
|
|
12229
12270
|
);
|
|
12230
12271
|
const [endDate, setEndDate] = (0, import_react134.useState)(
|
|
12231
|
-
initialEndDate ?? (0,
|
|
12272
|
+
initialEndDate ?? (0, import_date_fns27.endOfMonth)(Date.now())
|
|
12232
12273
|
);
|
|
12233
12274
|
const queryKey = businessId && auth?.access_token && `chart-of-accounts-${businessId}-${startDate?.valueOf()}-${endDate?.valueOf()}`;
|
|
12234
12275
|
const { data, isLoading, isValidating, error, mutate } = (0, import_swr7.default)(
|
|
@@ -12236,8 +12277,8 @@ var useChartOfAccounts = ({ withDates, startDate: initialStartDate, endDate: ini
|
|
|
12236
12277
|
Layer.getLedgerAccountBalances(apiUrl, auth?.access_token, {
|
|
12237
12278
|
params: {
|
|
12238
12279
|
businessId,
|
|
12239
|
-
startDate: withDates && startDate ? (0,
|
|
12240
|
-
endDate: withDates && endDate ? (0,
|
|
12280
|
+
startDate: withDates && startDate ? (0, import_date_fns27.formatISO)(startDate.valueOf()) : void 0,
|
|
12281
|
+
endDate: withDates && endDate ? (0, import_date_fns27.formatISO)(endDate.valueOf()) : void 0
|
|
12241
12282
|
}
|
|
12242
12283
|
})
|
|
12243
12284
|
);
|
|
@@ -12502,7 +12543,7 @@ var import_react141 = __toESM(require("react"));
|
|
|
12502
12543
|
|
|
12503
12544
|
// src/components/ChartOfAccountsDatePicker/ChartOfAccountsDatePicker.tsx
|
|
12504
12545
|
var import_react136 = __toESM(require("react"));
|
|
12505
|
-
var
|
|
12546
|
+
var import_date_fns28 = require("date-fns");
|
|
12506
12547
|
var ChartOfAccountsDatePicker = () => {
|
|
12507
12548
|
const { changeDateRange, dateRange } = (0, import_react136.useContext)(ChartOfAccountsContext);
|
|
12508
12549
|
return /* @__PURE__ */ import_react136.default.createElement(
|
|
@@ -12513,8 +12554,8 @@ var ChartOfAccountsDatePicker = () => {
|
|
|
12513
12554
|
onChange: (date) => {
|
|
12514
12555
|
if (!Array.isArray(date)) {
|
|
12515
12556
|
changeDateRange({
|
|
12516
|
-
startDate: (0,
|
|
12517
|
-
endDate: (0,
|
|
12557
|
+
startDate: (0, import_date_fns28.startOfMonth)(date),
|
|
12558
|
+
endDate: (0, import_date_fns28.endOfMonth)(date)
|
|
12518
12559
|
});
|
|
12519
12560
|
}
|
|
12520
12561
|
}
|
|
@@ -13064,7 +13105,7 @@ var Card = ({ children, className }) => {
|
|
|
13064
13105
|
|
|
13065
13106
|
// src/components/DateTime/DateTime.tsx
|
|
13066
13107
|
var import_react143 = __toESM(require("react"));
|
|
13067
|
-
var
|
|
13108
|
+
var import_date_fns29 = require("date-fns");
|
|
13068
13109
|
var DateTime = ({
|
|
13069
13110
|
value,
|
|
13070
13111
|
format: format7,
|
|
@@ -13074,10 +13115,10 @@ var DateTime = ({
|
|
|
13074
13115
|
onlyTime
|
|
13075
13116
|
}) => {
|
|
13076
13117
|
if (format7) {
|
|
13077
|
-
return /* @__PURE__ */ import_react143.default.createElement(Text, { className: "Layer__datetime" }, (0,
|
|
13118
|
+
return /* @__PURE__ */ import_react143.default.createElement(Text, { className: "Layer__datetime" }, (0, import_date_fns29.format)((0, import_date_fns29.parseISO)(value), format7));
|
|
13078
13119
|
}
|
|
13079
|
-
const date = (0,
|
|
13080
|
-
const time = (0,
|
|
13120
|
+
const date = (0, import_date_fns29.format)((0, import_date_fns29.parseISO)(value), dateFormat ?? DATE_FORMAT);
|
|
13121
|
+
const time = (0, import_date_fns29.format)((0, import_date_fns29.parseISO)(value), timeFormat ?? TIME_FORMAT);
|
|
13081
13122
|
return /* @__PURE__ */ import_react143.default.createElement(Text, { className: "Layer__datetime" }, !onlyTime && /* @__PURE__ */ import_react143.default.createElement(
|
|
13082
13123
|
Text,
|
|
13083
13124
|
{
|
|
@@ -13242,7 +13283,7 @@ var LedgerAccountEntryDetails = ({ stringOverrides }) => {
|
|
|
13242
13283
|
// src/components/LedgerAccount/LedgerAccountRow.tsx
|
|
13243
13284
|
var import_react147 = __toESM(require("react"));
|
|
13244
13285
|
var import_classnames55 = __toESM(require("classnames"));
|
|
13245
|
-
var
|
|
13286
|
+
var import_date_fns30 = require("date-fns");
|
|
13246
13287
|
var LedgerAccountRow = ({
|
|
13247
13288
|
row,
|
|
13248
13289
|
index,
|
|
@@ -13281,7 +13322,7 @@ var LedgerAccountRow = ({
|
|
|
13281
13322
|
}
|
|
13282
13323
|
}
|
|
13283
13324
|
},
|
|
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,
|
|
13325
|
+
/* @__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
13326
|
Text,
|
|
13286
13327
|
{
|
|
13287
13328
|
weight: "normal" /* normal */,
|
|
@@ -13314,7 +13355,7 @@ var LedgerAccountRow = ({
|
|
|
13314
13355
|
}
|
|
13315
13356
|
}
|
|
13316
13357
|
},
|
|
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,
|
|
13358
|
+
/* @__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
13359
|
Text,
|
|
13319
13360
|
{
|
|
13320
13361
|
weight: "normal" /* normal */,
|
|
@@ -13343,7 +13384,7 @@ var LedgerAccountRow = ({
|
|
|
13343
13384
|
}
|
|
13344
13385
|
}
|
|
13345
13386
|
},
|
|
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,
|
|
13387
|
+
/* @__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
13388
|
/* @__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
13389
|
/* @__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
13390
|
/* @__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 +13894,7 @@ var import_react157 = __toESM(require("react"));
|
|
|
13853
13894
|
// src/components/JournalRow/JournalRow.tsx
|
|
13854
13895
|
var import_react152 = __toESM(require("react"));
|
|
13855
13896
|
var import_classnames57 = __toESM(require("classnames"));
|
|
13856
|
-
var
|
|
13897
|
+
var import_date_fns31 = require("date-fns");
|
|
13857
13898
|
var INDENTATION2 = 24;
|
|
13858
13899
|
var EXPANDED_STYLE3 = {
|
|
13859
13900
|
height: "100%",
|
|
@@ -13966,7 +14007,7 @@ var JournalRow = ({
|
|
|
13966
14007
|
)
|
|
13967
14008
|
))),
|
|
13968
14009
|
/* @__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,
|
|
14010
|
+
/* @__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
14011
|
/* @__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
14012
|
/* @__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
14013
|
/* @__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 +14904,7 @@ var TasksList = ({ pageSize = 10 }) => {
|
|
|
14863
14904
|
// src/components/TasksPending/TasksPending.tsx
|
|
14864
14905
|
var import_react164 = __toESM(require("react"));
|
|
14865
14906
|
var import_classnames59 = __toESM(require("classnames"));
|
|
14866
|
-
var
|
|
14907
|
+
var import_date_fns32 = require("date-fns");
|
|
14867
14908
|
var import_recharts4 = require("recharts");
|
|
14868
14909
|
var TasksPending = () => {
|
|
14869
14910
|
const { data } = (0, import_react164.useContext)(TasksContext);
|
|
@@ -14881,7 +14922,7 @@ var TasksPending = () => {
|
|
|
14881
14922
|
const taskStatusClassName = (0, import_classnames59.default)(
|
|
14882
14923
|
completedTasks && completedTasks > 0 ? "Layer__tasks-pending-bar__status--done" : "Layer__tasks-pending-bar__status--pending"
|
|
14883
14924
|
);
|
|
14884
|
-
return /* @__PURE__ */ import_react164.default.createElement("div", { className: "Layer__tasks-pending" }, /* @__PURE__ */ import_react164.default.createElement(Text, { size: "lg" /* lg */ }, (0,
|
|
14925
|
+
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
14926
|
import_recharts4.Pie,
|
|
14886
14927
|
{
|
|
14887
14928
|
data: chartData,
|
|
@@ -15208,7 +15249,7 @@ var NotificationCard = ({
|
|
|
15208
15249
|
};
|
|
15209
15250
|
|
|
15210
15251
|
// src/components/TransactionToReviewCard/TransactionToReviewCard.tsx
|
|
15211
|
-
var
|
|
15252
|
+
var import_date_fns33 = require("date-fns");
|
|
15212
15253
|
var TransactionToReviewCard = ({
|
|
15213
15254
|
onClick,
|
|
15214
15255
|
usePnlDateRange
|
|
@@ -15217,7 +15258,7 @@ var TransactionToReviewCard = ({
|
|
|
15217
15258
|
const dateRange = usePnlDateRange ? contextDateRange : void 0;
|
|
15218
15259
|
const [toReview, setToReview] = (0, import_react171.useState)(0);
|
|
15219
15260
|
const { data, loaded, error, refetch } = useProfitAndLossLTM({
|
|
15220
|
-
currentDate: dateRange ? dateRange.startDate : (0,
|
|
15261
|
+
currentDate: dateRange ? dateRange.startDate : (0, import_date_fns33.startOfMonth)(/* @__PURE__ */ new Date())
|
|
15221
15262
|
});
|
|
15222
15263
|
(0, import_react171.useEffect)(() => {
|
|
15223
15264
|
checkTransactionsToReview();
|
|
@@ -15228,7 +15269,7 @@ var TransactionToReviewCard = ({
|
|
|
15228
15269
|
const checkTransactionsToReview = () => {
|
|
15229
15270
|
if (data && dateRange) {
|
|
15230
15271
|
const monthTx = data.filter(
|
|
15231
|
-
(x) => x.month - 1 === (0,
|
|
15272
|
+
(x) => x.month - 1 === (0, import_date_fns33.getMonth)(dateRange.startDate) && x.year === (0, import_date_fns33.getYear)(dateRange.startDate)
|
|
15232
15273
|
);
|
|
15233
15274
|
if (monthTx.length > 0) {
|
|
15234
15275
|
setToReview(monthTx[0].uncategorized_transactions);
|
|
@@ -15677,6 +15718,7 @@ var Components = ({
|
|
|
15677
15718
|
StatementOfCashFlow,
|
|
15678
15719
|
Tasks,
|
|
15679
15720
|
useBankTransactionsContext,
|
|
15721
|
+
useDataSync,
|
|
15680
15722
|
useLayerContext
|
|
15681
15723
|
});
|
|
15682
15724
|
//# sourceMappingURL=index.js.map
|