@layerfi/components 0.1.37 → 0.1.38

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 CHANGED
@@ -397,9 +397,9 @@ function useSizeClass() {
397
397
  const [width] = useWindowSize();
398
398
  const sizeClass = useMemo(() => {
399
399
  switch (true) {
400
- case width < BREAKPOINTS.MOBILE:
400
+ case width <= BREAKPOINTS.MOBILE:
401
401
  return "mobile";
402
- case width < BREAKPOINTS.TABLET:
402
+ case width <= BREAKPOINTS.TABLET:
403
403
  return "tablet";
404
404
  default:
405
405
  return "desktop";
@@ -551,8 +551,25 @@ var DEPENDENCIES = {
551
551
  ["STATEMENT_OF_CASH_FLOWS" /* STATEMENT_OF_CASH_FLOWS */]: ALL_TOUCHABLE
552
552
  };
553
553
  var useDataSync = () => {
554
- const [syncTimestamps, setSyncTimestamps] = useState2({});
555
- const [readTimestamps, setReadTimestamps] = useState2({});
554
+ const initialTimestamp = Date.now();
555
+ const [syncTimestamps, setSyncTimestamps] = useState2({
556
+ ["BALANCE_SHEET" /* BALANCE_SHEET */]: initialTimestamp,
557
+ ["CHART_OF_ACCOUNTS" /* CHART_OF_ACCOUNTS */]: initialTimestamp,
558
+ ["JOURNAL" /* JOURNAL */]: initialTimestamp,
559
+ ["LEDGER_ACCOUNTS" /* LEDGER_ACCOUNTS */]: initialTimestamp,
560
+ ["LINKED_ACCOUNTS" /* LINKED_ACCOUNTS */]: initialTimestamp,
561
+ ["PROFIT_AND_LOSS" /* PROFIT_AND_LOSS */]: initialTimestamp,
562
+ ["STATEMENT_OF_CASH_FLOWS" /* STATEMENT_OF_CASH_FLOWS */]: initialTimestamp
563
+ });
564
+ const [readTimestamps, setReadTimestamps] = useState2({
565
+ ["BALANCE_SHEET" /* BALANCE_SHEET */]: initialTimestamp,
566
+ ["CHART_OF_ACCOUNTS" /* CHART_OF_ACCOUNTS */]: initialTimestamp,
567
+ ["JOURNAL" /* JOURNAL */]: initialTimestamp,
568
+ ["LEDGER_ACCOUNTS" /* LEDGER_ACCOUNTS */]: initialTimestamp,
569
+ ["LINKED_ACCOUNTS" /* LINKED_ACCOUNTS */]: initialTimestamp,
570
+ ["PROFIT_AND_LOSS" /* PROFIT_AND_LOSS */]: initialTimestamp,
571
+ ["STATEMENT_OF_CASH_FLOWS" /* STATEMENT_OF_CASH_FLOWS */]: initialTimestamp
572
+ });
556
573
  const touch = (model) => {
557
574
  setSyncTimestamps({
558
575
  ...syncTimestamps,
@@ -7544,7 +7561,7 @@ var isDateAllowedToBrowse = (date, business) => {
7544
7561
  };
7545
7562
 
7546
7563
  // src/components/DatePicker/DatePicker.tsx
7547
- import React100, { useEffect as useEffect18, useState as useState23 } from "react";
7564
+ import React100, { useEffect as useEffect18, useRef as useRef13, useState as useState23 } from "react";
7548
7565
  import ReactDatePicker from "react-datepicker";
7549
7566
  import "react-datepicker/dist/react-datepicker.css";
7550
7567
 
@@ -7694,7 +7711,7 @@ var DatePicker = ({
7694
7711
  selected,
7695
7712
  onChange,
7696
7713
  mode = "dayPicker",
7697
- dateFormat = mode === "monthPicker" || mode === "monthRangePicker" ? "MMMM, yyyy" : mode === "timePicker" ? "h:mm aa" : "MMMM d, yyyy",
7714
+ dateFormat = mode === "monthPicker" || mode === "monthRangePicker" ? "MMM, yyyy" : mode === "timePicker" ? "h:mm aa" : "MMM d, yyyy",
7698
7715
  timeIntervals = 15,
7699
7716
  timeCaption,
7700
7717
  placeholderText,
@@ -7703,11 +7720,15 @@ var DatePicker = ({
7703
7720
  calendarClassName,
7704
7721
  popperClassName,
7705
7722
  minDate,
7723
+ maxDate = /* @__PURE__ */ new Date(),
7706
7724
  currentDateOption = true,
7725
+ navigateArrows = mode === "monthPicker",
7707
7726
  ...props
7708
7727
  }) => {
7728
+ const pickerRef = useRef13(null);
7709
7729
  const [updatePickerDate, setPickerDate] = useState23(false);
7710
7730
  const [selectedDates, setSelectedDates] = useState23(selected);
7731
+ const { isDesktop } = useSizeClass();
7711
7732
  const [startDate, setStartDate] = useState23(
7712
7733
  getDefaultRangeDate("start", mode, selected) ?? /* @__PURE__ */ new Date()
7713
7734
  );
@@ -7747,7 +7768,8 @@ var DatePicker = ({
7747
7768
  }, [startDate, endDate]);
7748
7769
  const wrapperClassNames = classNames37(
7749
7770
  "Layer__datepicker__wrapper",
7750
- mode === "timePicker" && "Layer__datepicker__time__wrapper"
7771
+ mode === "timePicker" && "Layer__datepicker__time__wrapper",
7772
+ navigateArrows && "Layer__datepicker__wrapper--arrows"
7751
7773
  );
7752
7774
  const datePickerWrapperClassNames = classNames37(
7753
7775
  "Layer__datepicker",
@@ -7760,6 +7782,7 @@ var DatePicker = ({
7760
7782
  );
7761
7783
  const popperClassNames = classNames37(
7762
7784
  "Layer__datepicker__popper",
7785
+ mode === "timePicker" && "Layer__datepicker__time__popper",
7763
7786
  popperClassName
7764
7787
  );
7765
7788
  const handleDateChange = (date) => {
@@ -7790,9 +7813,35 @@ var DatePicker = ({
7790
7813
  );
7791
7814
  }
7792
7815
  };
7816
+ const isTodayOrAfter = Boolean(
7817
+ selectedDates instanceof Date && selectedDates >= /* @__PURE__ */ new Date()
7818
+ );
7819
+ const isBeforeMinDate = Boolean(
7820
+ minDate && selectedDates instanceof Date && selectedDates <= minDate
7821
+ );
7822
+ const changeDate = (value) => {
7823
+ if (mode === "dayPicker") {
7824
+ setSelectedDates(
7825
+ new Date(
7826
+ selectedDates.setDate(
7827
+ selectedDates.getDate() + value
7828
+ )
7829
+ )
7830
+ );
7831
+ } else if (mode === "monthPicker") {
7832
+ setSelectedDates(
7833
+ new Date(
7834
+ selectedDates.setMonth(
7835
+ selectedDates.getMonth() + value
7836
+ )
7837
+ )
7838
+ );
7839
+ }
7840
+ };
7793
7841
  return /* @__PURE__ */ React100.createElement("div", { className: wrapperClassNames }, /* @__PURE__ */ React100.createElement(
7794
7842
  ReactDatePicker,
7795
7843
  {
7844
+ ref: pickerRef,
7796
7845
  wrapperClassName: datePickerWrapperClassNames,
7797
7846
  startDate: isRangeMode(mode) ? startDate : void 0,
7798
7847
  endDate: isRangeMode(mode) ? endDate : void 0,
@@ -7808,10 +7857,33 @@ var DatePicker = ({
7808
7857
  renderDayContents: (day) => /* @__PURE__ */ React100.createElement("span", { className: "Layer__datepicker__day-contents" }, day),
7809
7858
  timeIntervals,
7810
7859
  timeCaption,
7860
+ timeFormat: "h mm aa",
7811
7861
  showTimeSelect: mode === "timePicker",
7812
7862
  showTimeSelectOnly: mode === "timePicker",
7813
7863
  minDate,
7814
- maxDate: /* @__PURE__ */ new Date(),
7864
+ maxDate,
7865
+ withPortal: !isDesktop,
7866
+ onCalendarOpen: () => {
7867
+ if (!isDesktop) {
7868
+ setTimeout(() => {
7869
+ document.getElementById("Layer__datepicker__portal")?.classList.remove("Layer__datepicker__portal--closed");
7870
+ document.getElementById("Layer__datepicker__portal")?.classList.add("Layer__datepicker__portal--opened");
7871
+ }, 10);
7872
+ }
7873
+ },
7874
+ onCalendarClose: () => {
7875
+ if (!isDesktop) {
7876
+ document.getElementById("Layer__datepicker__portal")?.classList.add("Layer__datepicker__portal--closed");
7877
+ document.getElementById("Layer__datepicker__portal")?.classList.remove("Layer__datepicker__portal--opened");
7878
+ }
7879
+ },
7880
+ portalId: "Layer__datepicker__portal",
7881
+ onFocus: (e) => e.target.readOnly = true,
7882
+ onInputClick: () => {
7883
+ if (pickerRef.current && !isDesktop) {
7884
+ pickerRef.current.setOpen(!pickerRef.current.isCalendarOpen);
7885
+ }
7886
+ },
7815
7887
  ...props
7816
7888
  },
7817
7889
  mode === "dayRangePicker" && /* @__PURE__ */ React100.createElement(
@@ -7821,7 +7893,39 @@ var DatePicker = ({
7821
7893
  setSelectedDate: setSelectedDates
7822
7894
  }
7823
7895
  )
7824
- ), currentDateOption && (mode === "dayPicker" || mode === "monthPicker") && /* @__PURE__ */ React100.createElement(
7896
+ ), navigateArrows && !isDesktop && /* @__PURE__ */ React100.createElement(React100.Fragment, null, /* @__PURE__ */ React100.createElement(
7897
+ Button,
7898
+ {
7899
+ "aria-label": "Previous Date",
7900
+ className: classNames37(
7901
+ "Layer__datepicker__prev-button",
7902
+ isBeforeMinDate && "Layer__datepicker__button--disabled"
7903
+ ),
7904
+ onClick: () => changeDate(-1),
7905
+ variant: "secondary" /* secondary */,
7906
+ disabled: isBeforeMinDate
7907
+ },
7908
+ /* @__PURE__ */ React100.createElement(ChevronLeft_default, { className: "Layer__datepicker__button-icon", size: 16 })
7909
+ ), /* @__PURE__ */ React100.createElement(
7910
+ Button,
7911
+ {
7912
+ "aria-label": "Next Date",
7913
+ variant: "secondary" /* secondary */,
7914
+ className: classNames37(
7915
+ "Layer__datepicker__next-button",
7916
+ isTodayOrAfter ? "Layer__datepicker__button--disabled" : void 0
7917
+ ),
7918
+ onClick: () => changeDate(1),
7919
+ disabled: isTodayOrAfter
7920
+ },
7921
+ /* @__PURE__ */ React100.createElement(
7922
+ ChevronRight_default,
7923
+ {
7924
+ className: "Layer__datepicker__button-icon",
7925
+ size: 16
7926
+ }
7927
+ )
7928
+ )), currentDateOption && (mode === "dayPicker" || mode === "monthPicker") && /* @__PURE__ */ React100.createElement(
7825
7929
  Button,
7826
7930
  {
7827
7931
  className: "Layer__datepicker__current-button",
@@ -8293,7 +8397,7 @@ var BankTransactionsContent = ({
8293
8397
  setDateRange: (v) => setDateRange(v)
8294
8398
  }
8295
8399
  ),
8296
- !listView && /* @__PURE__ */ React106.createElement(
8400
+ !listView && /* @__PURE__ */ React106.createElement("div", { className: "Layer__bank-transactions__table-wrapper" }, /* @__PURE__ */ React106.createElement(
8297
8401
  BankTransactionsTable,
8298
8402
  {
8299
8403
  categorizeView,
@@ -8306,7 +8410,7 @@ var BankTransactionsContent = ({
8306
8410
  showDescriptions,
8307
8411
  showReceiptUploads
8308
8412
  }
8309
- ),
8413
+ )),
8310
8414
  isLoading && !bankTransactions ? /* @__PURE__ */ React106.createElement("div", { className: "Layer__bank-transactions__loader-container" }, /* @__PURE__ */ React106.createElement(Loader2, null)) : null,
8311
8415
  !isLoading && listView && mobileComponent !== "mobileList" ? /* @__PURE__ */ React106.createElement(
8312
8416
  BankTransactionList,
@@ -8358,7 +8462,7 @@ var BankTransactionsContent = ({
8358
8462
  import React107 from "react";
8359
8463
 
8360
8464
  // src/hooks/useQuickbooks/useQuickbooks.ts
8361
- import { useEffect as useEffect21, useRef as useRef13, useState as useState27 } from "react";
8465
+ import { useEffect as useEffect21, useRef as useRef14, useState as useState27 } from "react";
8362
8466
  var DEBUG2 = true;
8363
8467
  var useQuickbooks = () => {
8364
8468
  const { auth, businessId, apiUrl } = useLayerContext();
@@ -8366,7 +8470,7 @@ var useQuickbooks = () => {
8366
8470
  const [quickbooksIsLinked, setQuickbooksIsLinked] = useState27(
8367
8471
  null
8368
8472
  );
8369
- const syncStatusIntervalRef = useRef13(null);
8473
+ const syncStatusIntervalRef = useRef14(null);
8370
8474
  useEffect21(() => {
8371
8475
  if (isSyncingFromQuickbooks && syncStatusIntervalRef.current === null) {
8372
8476
  const interval = setInterval(() => fetchIsSyncingFromQuickbooks(), 2e3);
@@ -8792,6 +8896,7 @@ var useProfitAndLossLTM = ({ currentDate, tagFilter, reportingBasis } = {
8792
8896
  totalExpenses: 0,
8793
8897
  uncategorizedInflows: 0,
8794
8898
  uncategorizedOutflows: 0,
8899
+ uncategorized_transactions: 0,
8795
8900
  isLoading: true
8796
8901
  });
8797
8902
  }
@@ -8842,12 +8947,16 @@ var useProfitAndLossLTM = ({ currentDate, tagFilter, reportingBasis } = {
8842
8947
  mutate();
8843
8948
  }
8844
8949
  }, [syncTimestamps]);
8950
+ const refetch = () => {
8951
+ mutate();
8952
+ };
8845
8953
  return {
8846
8954
  data,
8847
8955
  isLoading,
8848
8956
  loaded,
8849
8957
  error,
8850
- pullData
8958
+ pullData,
8959
+ refetch
8851
8960
  };
8852
8961
  };
8853
8962
 
@@ -11041,7 +11150,7 @@ var TableRow = ({
11041
11150
  };
11042
11151
 
11043
11152
  // src/components/Table/Table.tsx
11044
- import React131, { useEffect as useEffect28, useRef as useRef14 } from "react";
11153
+ import React131, { useEffect as useEffect28, useRef as useRef15 } from "react";
11045
11154
  import classNames47 from "classnames";
11046
11155
  var Table = ({
11047
11156
  componentName,
@@ -11049,8 +11158,8 @@ var Table = ({
11049
11158
  borderCollapse = "separate",
11050
11159
  bottomSpacing = true
11051
11160
  }) => {
11052
- const tableRef = useRef14(null);
11053
- const prevChildrenRef = useRef14([]);
11161
+ const tableRef = useRef15(null);
11162
+ const prevChildrenRef = useRef15([]);
11054
11163
  useEffect28(() => {
11055
11164
  if (tableRef.current) {
11056
11165
  const tbody = tableRef.current.querySelector("tbody");
@@ -14737,7 +14846,7 @@ var BookkeepingOverview = ({
14737
14846
  import React175, { useState as useState55 } from "react";
14738
14847
 
14739
14848
  // src/components/TransactionToReviewCard/TransactionToReviewCard.tsx
14740
- import React174, { useContext as useContext37, useEffect as useEffect43, useMemo as useMemo20 } from "react";
14849
+ import React174, { useContext as useContext37, useEffect as useEffect43, useState as useState54 } from "react";
14741
14850
 
14742
14851
  // src/components/BadgeLoader/BadgeLoader.tsx
14743
14852
  import React172 from "react";
@@ -14764,27 +14873,33 @@ var NotificationCard = ({
14764
14873
  };
14765
14874
 
14766
14875
  // src/components/TransactionToReviewCard/TransactionToReviewCard.tsx
14876
+ import { getMonth, getYear, startOfMonth as startOfMonth14 } from "date-fns";
14767
14877
  var TransactionToReviewCard = ({
14768
14878
  onClick,
14769
14879
  usePnlDateRange
14770
14880
  }) => {
14771
- const {
14772
- data,
14773
- isLoading,
14774
- loadingStatus,
14775
- error,
14776
- refetch,
14777
- activate: activateBankTransactions
14778
- } = useBankTransactionsContext();
14779
14881
  const { dateRange: contextDateRange } = useContext37(ProfitAndLoss.Context);
14780
14882
  const dateRange = usePnlDateRange ? contextDateRange : void 0;
14883
+ const [toReview, setToReview] = useState54(0);
14884
+ const { data, loaded, error, refetch } = useProfitAndLossLTM({
14885
+ currentDate: dateRange ? dateRange.startDate : startOfMonth14(/* @__PURE__ */ new Date())
14886
+ });
14781
14887
  useEffect43(() => {
14782
- activateBankTransactions();
14888
+ checkTransactionsToReview();
14783
14889
  }, []);
14784
- const toReview = useMemo20(
14785
- () => countTransactionsToReview({ transactions: data, dateRange }),
14786
- [data, isLoading, dateRange]
14787
- );
14890
+ useEffect43(() => {
14891
+ checkTransactionsToReview();
14892
+ }, [dateRange, loaded]);
14893
+ const checkTransactionsToReview = () => {
14894
+ if (data && dateRange) {
14895
+ const monthTx = data.filter(
14896
+ (x) => x.month - 1 === getMonth(dateRange.startDate) && x.year === getYear(dateRange.startDate)
14897
+ );
14898
+ if (monthTx.length > 0) {
14899
+ setToReview(monthTx[0].uncategorized_transactions);
14900
+ }
14901
+ }
14902
+ };
14788
14903
  return /* @__PURE__ */ React174.createElement(
14789
14904
  NotificationCard,
14790
14905
  {
@@ -14792,8 +14907,8 @@ var TransactionToReviewCard = ({
14792
14907
  onClick: () => onClick && onClick()
14793
14908
  },
14794
14909
  /* @__PURE__ */ React174.createElement(Text, { size: "sm" /* sm */ }, "Transactions to review"),
14795
- loadingStatus === "initial" || loadingStatus === "loading" ? /* @__PURE__ */ React174.createElement(BadgeLoader, null) : null,
14796
- loadingStatus === "complete" && error ? /* @__PURE__ */ React174.createElement(
14910
+ loaded === "initial" || loaded === "loading" ? /* @__PURE__ */ React174.createElement(BadgeLoader, null) : null,
14911
+ loaded === "complete" && error ? /* @__PURE__ */ React174.createElement(
14797
14912
  Badge,
14798
14913
  {
14799
14914
  variant: "error" /* ERROR */,
@@ -14803,7 +14918,7 @@ var TransactionToReviewCard = ({
14803
14918
  },
14804
14919
  "Refresh"
14805
14920
  ) : null,
14806
- loadingStatus === "complete" && !error && toReview > 0 ? /* @__PURE__ */ React174.createElement(
14921
+ loaded === "complete" && !error && toReview > 0 ? /* @__PURE__ */ React174.createElement(
14807
14922
  Badge,
14808
14923
  {
14809
14924
  variant: "warning" /* WARNING */,
@@ -14813,7 +14928,7 @@ var TransactionToReviewCard = ({
14813
14928
  toReview,
14814
14929
  " pending"
14815
14930
  ) : null,
14816
- loadingStatus === "complete" && !error && toReview === 0 ? /* @__PURE__ */ React174.createElement(
14931
+ loaded === "complete" && !error && toReview === 0 ? /* @__PURE__ */ React174.createElement(
14817
14932
  Badge,
14818
14933
  {
14819
14934
  variant: "success" /* SUCCESS */,
@@ -14950,7 +15065,7 @@ var GeneralLedgerView = ({
14950
15065
  };
14951
15066
 
14952
15067
  // src/views/Reports/Reports.tsx
14953
- import React178, { useContext as useContext38, useRef as useRef15, useState as useState57 } from "react";
15068
+ import React178, { useContext as useContext38, useRef as useRef16, useState as useState57 } from "react";
14954
15069
  var DownloadButton2 = () => {
14955
15070
  const { dateRange } = useContext38(ProfitAndLoss.Context);
14956
15071
  const { auth, businessId, apiUrl } = useLayerContext();
@@ -15000,7 +15115,7 @@ var DownloadButton2 = () => {
15000
15115
  );
15001
15116
  };
15002
15117
  var Reports = ({ title = "Reports" }) => {
15003
- const containerRef = useRef15(null);
15118
+ const containerRef = useRef16(null);
15004
15119
  const [activeTab, setActiveTab] = useState57("profitAndLoss");
15005
15120
  return /* @__PURE__ */ React178.createElement(View, { title }, /* @__PURE__ */ React178.createElement("div", { className: "Layer__component Layer__header__actions" }, /* @__PURE__ */ React178.createElement(
15006
15121
  Toggle,
@@ -15040,10 +15155,10 @@ var ReportsPanel = ({ containerRef, openReport }) => {
15040
15155
  };
15041
15156
 
15042
15157
  // src/components/ProfitAndLossView/ProfitAndLossView.tsx
15043
- import React179, { useContext as useContext39, useRef as useRef16 } from "react";
15158
+ import React179, { useContext as useContext39, useRef as useRef17 } from "react";
15044
15159
  var COMPONENT_NAME7 = "profit-and-loss";
15045
15160
  var ProfitAndLossView = (props) => {
15046
- const containerRef = useRef16(null);
15161
+ const containerRef = useRef17(null);
15047
15162
  return /* @__PURE__ */ React179.createElement(Container, { name: COMPONENT_NAME7, ref: containerRef }, /* @__PURE__ */ React179.createElement(ProfitAndLoss, null, /* @__PURE__ */ React179.createElement(ProfitAndLossPanel, { containerRef, ...props })));
15048
15163
  };
15049
15164
  var ProfitAndLossPanel = ({