@layerfi/components 0.1.12 → 0.1.14

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
@@ -780,7 +780,6 @@ var debounce = (fnc, timeout = 300) => {
780
780
  }, timeout);
781
781
  };
782
782
  };
783
- var convertToStableName = (name) => name.replace(/[`~!@#$%^&*()_|+\-=?;:'",.<>\{\}\[\]\\\/]/gi, "").replace(/\W+/g, " ").split(/ |\B(?=[A-Z])/).map((word) => word.toLowerCase()).join("_");
784
783
 
785
784
  // src/components/BankTransactionListItem/BankTransactionListItem.tsx
786
785
  import React48, { useEffect as useEffect6, useRef as useRef11, useState as useState9 } from "react";
@@ -2210,6 +2209,7 @@ import React37 from "react";
2210
2209
  import ReactSelect, {
2211
2210
  components as components2
2212
2211
  } from "react-select";
2212
+ import classNames14 from "classnames";
2213
2213
  var DropdownIndicator2 = (props) => {
2214
2214
  return /* @__PURE__ */ React37.createElement(components2.DropdownIndicator, { ...props }, /* @__PURE__ */ React37.createElement(ChevronDownFill_default, null));
2215
2215
  };
@@ -2221,13 +2221,20 @@ var Select2 = ({
2221
2221
  value,
2222
2222
  onChange,
2223
2223
  disabled,
2224
- placeholder
2224
+ placeholder,
2225
+ isInvalid,
2226
+ errorMessage
2225
2227
  }) => {
2226
- return /* @__PURE__ */ React37.createElement(
2228
+ const baseClassName = classNames14(
2229
+ "Layer__select",
2230
+ isInvalid ? "Layer__select--error" : "",
2231
+ className
2232
+ );
2233
+ return /* @__PURE__ */ React37.createElement(Tooltip, { disabled: !isInvalid || !errorMessage }, /* @__PURE__ */ React37.createElement(TooltipTrigger, { className: "Layer__input-tooltip" }, /* @__PURE__ */ React37.createElement(
2227
2234
  ReactSelect,
2228
2235
  {
2229
2236
  name,
2230
- className: `Layer__select ${className ?? ""}`,
2237
+ className: baseClassName,
2231
2238
  classNamePrefix,
2232
2239
  placeholder: placeholder ?? "Select...",
2233
2240
  options,
@@ -2238,7 +2245,7 @@ var Select2 = ({
2238
2245
  components: { DropdownIndicator: DropdownIndicator2 },
2239
2246
  isDisabled: disabled
2240
2247
  }
2241
- );
2248
+ )), /* @__PURE__ */ React37.createElement(TooltipContent, { className: "Layer__tooltip" }, errorMessage));
2242
2249
  };
2243
2250
 
2244
2251
  // src/components/MatchForm/MatchForm.tsx
@@ -2268,7 +2275,7 @@ var MatchBadge = ({
2268
2275
  };
2269
2276
 
2270
2277
  // src/components/MatchForm/MatchForm.tsx
2271
- import classNames14 from "classnames";
2278
+ import classNames15 from "classnames";
2272
2279
  import { parseISO as parseISO4, format as formatTime3 } from "date-fns";
2273
2280
  var MatchForm = ({
2274
2281
  classNamePrefix,
@@ -2287,7 +2294,7 @@ var MatchForm = ({
2287
2294
  "div",
2288
2295
  {
2289
2296
  key: idx,
2290
- className: classNames14(
2297
+ className: classNames15(
2291
2298
  `${classNamePrefix}__match-row`,
2292
2299
  match.id === selectedMatchId ? `${classNamePrefix}__match-row--selected` : ""
2293
2300
  ),
@@ -2346,12 +2353,12 @@ var MatchForm = ({
2346
2353
 
2347
2354
  // src/components/Textarea/Textarea.tsx
2348
2355
  import React40 from "react";
2349
- import classNames15 from "classnames";
2356
+ import classNames16 from "classnames";
2350
2357
  var Textarea = ({
2351
2358
  className,
2352
2359
  ...props
2353
2360
  }) => {
2354
- const baseClassName = classNames15("Layer__textarea", className);
2361
+ const baseClassName = classNames16("Layer__textarea", className);
2355
2362
  return /* @__PURE__ */ React40.createElement("textarea", { ...props, className: baseClassName });
2356
2363
  };
2357
2364
 
@@ -2360,7 +2367,7 @@ import React41, {
2360
2367
  useEffect as useEffect2,
2361
2368
  useState as useState5
2362
2369
  } from "react";
2363
- import classNames16 from "classnames";
2370
+ import classNames17 from "classnames";
2364
2371
  var Toggle = ({
2365
2372
  name,
2366
2373
  options,
@@ -2377,7 +2384,7 @@ var Toggle = ({
2377
2384
  }
2378
2385
  });
2379
2386
  const selectedValue = selected || options[0].value;
2380
- const baseClassName = classNames16(
2387
+ const baseClassName = classNames17(
2381
2388
  "Layer__toggle",
2382
2389
  `Layer__toggle--${size}`,
2383
2390
  initialized ? "Layer__toggle--initialized" : ""
@@ -2628,7 +2635,7 @@ var Notification = ({
2628
2635
  };
2629
2636
 
2630
2637
  // src/components/ExpandedBankTransactionRow/ExpandedBankTransactionRow.tsx
2631
- import classNames17 from "classnames";
2638
+ import classNames18 from "classnames";
2632
2639
  var hasMatch = (bankTransaction) => {
2633
2640
  return Boolean(
2634
2641
  bankTransaction?.suggested_matches && bankTransaction?.suggested_matches?.length > 0 || bankTransaction?.match
@@ -2881,7 +2888,7 @@ var ExpandedBankTransactionRow = forwardRef2(
2881
2888
  /* @__PURE__ */ React44.createElement("div", { className: `${className}__content-panels` }, /* @__PURE__ */ React44.createElement(
2882
2889
  "div",
2883
2890
  {
2884
- className: classNames17(
2891
+ className: classNames18(
2885
2892
  `${className}__match`,
2886
2893
  `${className}__content-panel`,
2887
2894
  purpose === "match" /* match */ ? `${className}__content-panel--active` : ""
@@ -2903,7 +2910,7 @@ var ExpandedBankTransactionRow = forwardRef2(
2903
2910
  ), /* @__PURE__ */ React44.createElement(
2904
2911
  "div",
2905
2912
  {
2906
- className: classNames17(
2913
+ className: classNames18(
2907
2914
  `${className}__splits`,
2908
2915
  `${className}__content-panel`,
2909
2916
  purpose === "categorize" /* categorize */ ? `${className}__content-panel--active` : ""
@@ -3042,7 +3049,7 @@ var SplitTooltipDetails = ({
3042
3049
  };
3043
3050
 
3044
3051
  // src/components/BankTransactionRow/BankTransactionRow.tsx
3045
- import classNames18 from "classnames";
3052
+ import classNames19 from "classnames";
3046
3053
  import { parseISO as parseISO5, format as formatTime4 } from "date-fns";
3047
3054
  var isCredit = ({ direction }) => direction === "CREDIT" /* CREDIT */;
3048
3055
  var extractDescriptionForSplit = (category) => {
@@ -3141,7 +3148,7 @@ var BankTransactionRow = ({
3141
3148
  }
3142
3149
  const className = "Layer__bank-transaction-row";
3143
3150
  const openClassName = open ? `${className}--expanded` : "";
3144
- const rowClassName = classNames18(
3151
+ const rowClassName = classNames19(
3145
3152
  className,
3146
3153
  bankTransaction.recently_categorized && editable ? "Layer__bank-transaction-row--removing" : "",
3147
3154
  open ? openClassName : "",
@@ -3215,7 +3222,7 @@ var BankTransactionRow = ({
3215
3222
  /* @__PURE__ */ React46.createElement(
3216
3223
  "td",
3217
3224
  {
3218
- className: classNames18(
3225
+ className: classNames19(
3219
3226
  "Layer__table-cell",
3220
3227
  "Layer__table-cell__category-col",
3221
3228
  `${className}__actions-cell`,
@@ -3370,7 +3377,7 @@ var Assignment = ({ bankTransaction }) => {
3370
3377
  };
3371
3378
 
3372
3379
  // src/components/BankTransactionListItem/BankTransactionListItem.tsx
3373
- import classNames19 from "classnames";
3380
+ import classNames20 from "classnames";
3374
3381
  import { parseISO as parseISO7, format as formatTime6 } from "date-fns";
3375
3382
  var isCredit2 = ({ direction }) => direction === "CREDIT" /* CREDIT */;
3376
3383
  var BankTransactionListItem = ({
@@ -3429,7 +3436,7 @@ var BankTransactionListItem = ({
3429
3436
  }
3430
3437
  const className = "Layer__bank-transaction-list-item";
3431
3438
  const openClassName = open ? `${className}--expanded` : "";
3432
- const rowClassName = classNames19(
3439
+ const rowClassName = classNames20(
3433
3440
  className,
3434
3441
  bankTransaction.recently_categorized ? "Layer__bank-transaction-row--removing" : "",
3435
3442
  open ? openClassName : "",
@@ -3736,10 +3743,10 @@ var hslToHex = (hsl) => {
3736
3743
  };
3737
3744
 
3738
3745
  // src/components/Container/Container.tsx
3739
- import classNames20 from "classnames";
3746
+ import classNames21 from "classnames";
3740
3747
  var Container = forwardRef3(
3741
3748
  ({ name, className, children, asWidget, elevated = false }, ref) => {
3742
- const baseClassName = classNames20(
3749
+ const baseClassName = classNames21(
3743
3750
  "Layer__component Layer__component-container",
3744
3751
  `Layer__${name}`,
3745
3752
  elevated && "Layer__component--elevated",
@@ -3754,10 +3761,10 @@ var Container = forwardRef3(
3754
3761
 
3755
3762
  // src/components/Container/Header.tsx
3756
3763
  import React50, { forwardRef as forwardRef4 } from "react";
3757
- import classNames21 from "classnames";
3764
+ import classNames22 from "classnames";
3758
3765
  var Header = forwardRef4(
3759
3766
  ({ className, children, style }, ref) => {
3760
- const baseClassName = classNames21("Layer__component-header", className);
3767
+ const baseClassName = classNames22("Layer__component-header", className);
3761
3768
  return /* @__PURE__ */ React50.createElement("header", { ref, className: baseClassName, style }, children);
3762
3769
  }
3763
3770
  );
@@ -4308,7 +4315,7 @@ var useLinkedAccounts = () => {
4308
4315
  const exchangePublicToken = async (publicToken, metadata) => {
4309
4316
  await Layer.exchangePlaidPublicToken(apiUrl, auth?.access_token, {
4310
4317
  params: { businessId },
4311
- body: { public_token: publicToken, institution_id: metadata.institution }
4318
+ body: { public_token: publicToken, institution: metadata.institution }
4312
4319
  });
4313
4320
  refetchAccounts();
4314
4321
  };
@@ -4467,7 +4474,7 @@ var MoreVertical_default = MoreVertical;
4467
4474
 
4468
4475
  // src/components/HoverMenu/HoverMenu.tsx
4469
4476
  import React60, { useEffect as useEffect9, useRef as useRef12, useState as useState12 } from "react";
4470
- import classNames22 from "classnames";
4477
+ import classNames23 from "classnames";
4471
4478
  var HoverMenu = ({
4472
4479
  children,
4473
4480
  config,
@@ -4476,7 +4483,7 @@ var HoverMenu = ({
4476
4483
  }) => {
4477
4484
  const [openMenu, setOpenMenu] = useState12(false);
4478
4485
  const hoverMenuRef = useRef12(null);
4479
- const hoverMenuClassName = classNames22(
4486
+ const hoverMenuClassName = classNames23(
4480
4487
  "Layer__hover-menu",
4481
4488
  openMenu && "Layer__hover-menu--open"
4482
4489
  );
@@ -4839,13 +4846,13 @@ var InstitutionIcon = ({ size = 18, ...props }) => /* @__PURE__ */ React62.creat
4839
4846
  var InstitutionIcon_default = InstitutionIcon;
4840
4847
 
4841
4848
  // src/components/LinkedAccountThumb/LinkedAccountThumb.tsx
4842
- import classNames23 from "classnames";
4849
+ import classNames24 from "classnames";
4843
4850
  var AccountNumber = ({ accountNumber }) => /* @__PURE__ */ React63.createElement("div", { className: "account-number" }, /* @__PURE__ */ React63.createElement(Text, { size: "sm" }, "\u2022\u2022\u2022 ", accountNumber));
4844
4851
  var LinkedAccountThumb = ({
4845
4852
  account,
4846
4853
  asWidget
4847
4854
  }) => {
4848
- const linkedAccountThumbClassName = classNames23(
4855
+ const linkedAccountThumbClassName = classNames24(
4849
4856
  "Layer__linked-account-thumb",
4850
4857
  asWidget && "--as-widget"
4851
4858
  );
@@ -4890,7 +4897,7 @@ var LinkedAccountThumb = ({
4890
4897
  };
4891
4898
 
4892
4899
  // src/components/LinkedAccounts/LinkedAccounts.tsx
4893
- import classNames24 from "classnames";
4900
+ import classNames25 from "classnames";
4894
4901
  var COMPONENT_NAME2 = "linked-accounts";
4895
4902
  var LinkedAccounts = ({ asWidget, elevated }) => {
4896
4903
  const {
@@ -4907,7 +4914,7 @@ var LinkedAccounts = ({ asWidget, elevated }) => {
4907
4914
  { name: "Renew link", action: renewLinkAccount },
4908
4915
  { name: "Unlink", action: unlinkAccount }
4909
4916
  ];
4910
- const linkedAccountsNewAccountClassName = classNames24(
4917
+ const linkedAccountsNewAccountClassName = classNames25(
4911
4918
  "Layer__linked-accounts__new-account",
4912
4919
  asWidget && "--as-widget"
4913
4920
  );
@@ -5008,12 +5015,12 @@ var applyShare = (items, total) => {
5008
5015
  });
5009
5016
  };
5010
5017
 
5011
- // src/hooks/useProfitAndLoss/useProfitAndLoss.tsx
5018
+ // src/hooks/useProfitAndLoss/useProfitAndLossQuery.tsx
5012
5019
  import { startOfMonth, endOfMonth, formatISO } from "date-fns";
5013
5020
  import useSWR5 from "swr";
5014
- var useProfitAndLoss = ({
5015
- startDate: initialStartDate,
5016
- endDate: initialEndDate,
5021
+ var useProfitAndLossQuery = ({
5022
+ startDate,
5023
+ endDate,
5017
5024
  tagFilter,
5018
5025
  reportingBasis
5019
5026
  } = {
@@ -5021,17 +5028,6 @@ var useProfitAndLoss = ({
5021
5028
  endDate: endOfMonth(/* @__PURE__ */ new Date())
5022
5029
  }) => {
5023
5030
  const { auth, businessId, apiUrl } = useLayerContext();
5024
- const [startDate, setStartDate] = useState13(
5025
- initialStartDate || startOfMonth(Date.now())
5026
- );
5027
- const [endDate, setEndDate] = useState13(
5028
- initialEndDate || endOfMonth(Date.now())
5029
- );
5030
- const [filters, setFilters] = useState13({
5031
- expenses: void 0,
5032
- revenue: void 0
5033
- });
5034
- const [sidebarScope, setSidebarScope] = useState13(void 0);
5035
5031
  const {
5036
5032
  data: rawData,
5037
5033
  isLoading,
@@ -5045,15 +5041,83 @@ var useProfitAndLoss = ({
5045
5041
  Layer.getProfitAndLoss(apiUrl, auth?.access_token, {
5046
5042
  params: {
5047
5043
  businessId,
5048
- startDate: formatISO(startDate),
5049
- endDate: formatISO(endDate),
5044
+ startDate: formatISO(startDate.valueOf()),
5045
+ endDate: formatISO(endDate.valueOf()),
5050
5046
  tagKey: tagFilter?.key,
5051
5047
  tagValues: tagFilter?.values?.join(","),
5052
5048
  reportingBasis
5053
5049
  }
5054
5050
  })
5055
5051
  );
5056
- const { data, error } = rawData || {};
5052
+ const refetch = () => {
5053
+ mutate();
5054
+ };
5055
+ return {
5056
+ startDate,
5057
+ endDate,
5058
+ data: rawData?.data,
5059
+ isLoading,
5060
+ isValidating,
5061
+ error: rawError,
5062
+ refetch
5063
+ };
5064
+ };
5065
+
5066
+ // src/hooks/useProfitAndLoss/useProfitAndLoss.tsx
5067
+ import { startOfMonth as startOfMonth2, endOfMonth as endOfMonth2 } from "date-fns";
5068
+ var useProfitAndLoss = ({
5069
+ startDate: initialStartDate,
5070
+ endDate: initialEndDate,
5071
+ tagFilter,
5072
+ reportingBasis,
5073
+ fetchMultipleMonths = false
5074
+ } = {
5075
+ startDate: startOfMonth2(/* @__PURE__ */ new Date()),
5076
+ endDate: endOfMonth2(/* @__PURE__ */ new Date())
5077
+ }) => {
5078
+ const [startDate, setStartDate] = useState13(
5079
+ initialStartDate || startOfMonth2(Date.now())
5080
+ );
5081
+ const [endDate, setEndDate] = useState13(
5082
+ initialEndDate || endOfMonth2(Date.now())
5083
+ );
5084
+ const [filters, setFilters] = useState13({
5085
+ expenses: void 0,
5086
+ revenue: void 0
5087
+ });
5088
+ const [sidebarScope, setSidebarScope] = useState13(void 0);
5089
+ const { data, isLoading, isValidating, error, refetch } = useProfitAndLossQuery({
5090
+ startDate,
5091
+ endDate,
5092
+ tagFilter,
5093
+ reportingBasis
5094
+ });
5095
+ const changeDateRange = ({
5096
+ startDate: newStartDate,
5097
+ endDate: newEndDate
5098
+ }) => {
5099
+ newStartDate && setStartDate(newStartDate);
5100
+ newEndDate && setEndDate(newEndDate);
5101
+ };
5102
+ const sortBy = (scope, field, direction) => {
5103
+ setFilters({
5104
+ ...filters,
5105
+ [scope]: {
5106
+ ...filters[scope],
5107
+ sortBy: field,
5108
+ sortDirection: direction ?? filters[scope]?.sortDirection === "desc" ? "asc" : "desc"
5109
+ }
5110
+ });
5111
+ };
5112
+ const setFilterTypes = (scope, types) => {
5113
+ setFilters({
5114
+ ...filters,
5115
+ [scope]: {
5116
+ ...filters[scope],
5117
+ types
5118
+ }
5119
+ });
5120
+ };
5057
5121
  const { filteredDataRevenue, filteredTotalRevenue } = useMemo3(() => {
5058
5122
  if (!data) {
5059
5123
  return { filteredDataRevenue: [], filteredTotalRevenue: void 0 };
@@ -5128,35 +5192,6 @@ var useProfitAndLoss = ({
5128
5192
  const withShare = applyShare(sorted, total);
5129
5193
  return { filteredDataExpenses: withShare, filteredTotalExpenses: total };
5130
5194
  }, [data, startDate, filters, sidebarScope]);
5131
- const changeDateRange = ({
5132
- startDate: newStartDate,
5133
- endDate: newEndDate
5134
- }) => {
5135
- newStartDate && setStartDate(newStartDate);
5136
- newEndDate && setEndDate(newEndDate);
5137
- };
5138
- const refetch = () => {
5139
- mutate();
5140
- };
5141
- const sortBy = (scope, field, direction) => {
5142
- setFilters({
5143
- ...filters,
5144
- [scope]: {
5145
- ...filters[scope],
5146
- sortBy: field,
5147
- sortDirection: direction ?? filters[scope]?.sortDirection === "desc" ? "asc" : "desc"
5148
- }
5149
- });
5150
- };
5151
- const setFilterTypes = (scope, types) => {
5152
- setFilters({
5153
- ...filters,
5154
- [scope]: {
5155
- ...filters[scope],
5156
- types
5157
- }
5158
- });
5159
- };
5160
5195
  return {
5161
5196
  data,
5162
5197
  filteredDataRevenue,
@@ -5165,7 +5200,7 @@ var useProfitAndLoss = ({
5165
5200
  filteredTotalExpenses,
5166
5201
  isLoading,
5167
5202
  isValidating,
5168
- error: error || rawError,
5203
+ error,
5169
5204
  dateRange: { startDate, endDate },
5170
5205
  refetch,
5171
5206
  changeDateRange,
@@ -5178,7 +5213,350 @@ var useProfitAndLoss = ({
5178
5213
  };
5179
5214
 
5180
5215
  // src/components/ProfitAndLossChart/ProfitAndLossChart.tsx
5181
- import React66, { useContext as useContext2, useMemo as useMemo4, useState as useState14 } from "react";
5216
+ import React66, { useContext as useContext2, useEffect as useEffect12, useMemo as useMemo5, useState as useState16 } from "react";
5217
+
5218
+ // src/hooks/useProfitAndLoss/useProfitAndLossLTM.tsx
5219
+ import { useEffect as useEffect10, useMemo as useMemo4, useState as useState14 } from "react";
5220
+ import { startOfMonth as startOfMonth3, endOfMonth as endOfMonth3, sub } from "date-fns";
5221
+ var buildDates = ({ currentDate }) => {
5222
+ const list = [];
5223
+ for (let i = 11; i > 0; i--) {
5224
+ const startDateWithOffset = startOfMonth3(sub(currentDate, { months: i }));
5225
+ const endDateWithOffset = endOfMonth3(sub(currentDate, { months: i }));
5226
+ list.push({
5227
+ startDate: startDateWithOffset,
5228
+ endDate: endDateWithOffset
5229
+ });
5230
+ }
5231
+ list.push({
5232
+ startDate: startOfMonth3(currentDate),
5233
+ endDate: endOfMonth3(currentDate)
5234
+ });
5235
+ return list;
5236
+ };
5237
+ var useProfitAndLossLTM = ({ currentDate, tagFilter, reportingBasis } = {
5238
+ currentDate: /* @__PURE__ */ new Date()
5239
+ }) => {
5240
+ const { businessId } = useLayerContext();
5241
+ const [loaded, setLoaded] = useState14("initial");
5242
+ const dates = useMemo4(() => {
5243
+ return buildDates({ currentDate });
5244
+ }, [currentDate, businessId, tagFilter, reportingBasis]);
5245
+ const {
5246
+ data: data0,
5247
+ isLoading: isLoading0,
5248
+ error: error0,
5249
+ startDate: startDate0,
5250
+ endDate: endDate0
5251
+ } = useProfitAndLossQuery({
5252
+ startDate: dates[0].startDate,
5253
+ endDate: dates[0].endDate,
5254
+ tagFilter,
5255
+ reportingBasis
5256
+ });
5257
+ const {
5258
+ data: data1,
5259
+ isLoading: isLoading1,
5260
+ error: error1,
5261
+ startDate: startDate1,
5262
+ endDate: endDate1
5263
+ } = useProfitAndLossQuery({
5264
+ startDate: dates[1].startDate,
5265
+ endDate: dates[1].endDate,
5266
+ tagFilter,
5267
+ reportingBasis
5268
+ });
5269
+ const {
5270
+ data: data2,
5271
+ isLoading: isLoading2,
5272
+ error: error2,
5273
+ startDate: startDate2,
5274
+ endDate: endDate2
5275
+ } = useProfitAndLossQuery({
5276
+ startDate: dates[2].startDate,
5277
+ endDate: dates[2].endDate,
5278
+ tagFilter,
5279
+ reportingBasis
5280
+ });
5281
+ const {
5282
+ data: data3,
5283
+ isLoading: isLoading3,
5284
+ error: error3,
5285
+ startDate: startDate3,
5286
+ endDate: endDate3
5287
+ } = useProfitAndLossQuery({
5288
+ startDate: dates[3].startDate,
5289
+ endDate: dates[3].endDate,
5290
+ tagFilter,
5291
+ reportingBasis
5292
+ });
5293
+ const {
5294
+ data: data4,
5295
+ isLoading: isLoading4,
5296
+ error: error4,
5297
+ startDate: startDate4,
5298
+ endDate: endDate4
5299
+ } = useProfitAndLossQuery({
5300
+ startDate: dates[4].startDate,
5301
+ endDate: dates[4].endDate,
5302
+ tagFilter,
5303
+ reportingBasis
5304
+ });
5305
+ const {
5306
+ data: data5,
5307
+ isLoading: isLoading5,
5308
+ error: error5,
5309
+ startDate: startDate5,
5310
+ endDate: endDate5
5311
+ } = useProfitAndLossQuery({
5312
+ startDate: dates[5].startDate,
5313
+ endDate: dates[5].endDate,
5314
+ tagFilter,
5315
+ reportingBasis
5316
+ });
5317
+ const {
5318
+ data: data6,
5319
+ isLoading: isLoading6,
5320
+ error: error6,
5321
+ startDate: startDate6,
5322
+ endDate: endDate6
5323
+ } = useProfitAndLossQuery({
5324
+ startDate: dates[6].startDate,
5325
+ endDate: dates[6].endDate,
5326
+ tagFilter,
5327
+ reportingBasis
5328
+ });
5329
+ const {
5330
+ data: data7,
5331
+ isLoading: isLoading7,
5332
+ error: error7,
5333
+ startDate: startDate7,
5334
+ endDate: endDate7
5335
+ } = useProfitAndLossQuery({
5336
+ startDate: dates[7].startDate,
5337
+ endDate: dates[7].endDate,
5338
+ tagFilter,
5339
+ reportingBasis
5340
+ });
5341
+ const {
5342
+ data: data8,
5343
+ isLoading: isLoading8,
5344
+ error: error8,
5345
+ startDate: startDate8,
5346
+ endDate: endDate8
5347
+ } = useProfitAndLossQuery({
5348
+ startDate: dates[8].startDate,
5349
+ endDate: dates[8].endDate,
5350
+ tagFilter,
5351
+ reportingBasis
5352
+ });
5353
+ const {
5354
+ data: data9,
5355
+ isLoading: isLoading9,
5356
+ error: error9,
5357
+ startDate: startDate9,
5358
+ endDate: endDate9
5359
+ } = useProfitAndLossQuery({
5360
+ startDate: dates[9].startDate,
5361
+ endDate: dates[9].endDate,
5362
+ tagFilter,
5363
+ reportingBasis
5364
+ });
5365
+ const {
5366
+ data: data10,
5367
+ isLoading: isLoading10,
5368
+ error: error10,
5369
+ startDate: startDate10,
5370
+ endDate: endDate10
5371
+ } = useProfitAndLossQuery({
5372
+ startDate: dates[10].startDate,
5373
+ endDate: dates[10].endDate,
5374
+ tagFilter,
5375
+ reportingBasis
5376
+ });
5377
+ const {
5378
+ data: data11,
5379
+ isLoading: isLoading11,
5380
+ error: error11,
5381
+ startDate: startDate11,
5382
+ endDate: endDate11
5383
+ } = useProfitAndLossQuery({
5384
+ startDate: dates[11].startDate,
5385
+ endDate: dates[11].endDate,
5386
+ tagFilter,
5387
+ reportingBasis
5388
+ });
5389
+ const { data, isLoading, error } = useMemo4(() => {
5390
+ return {
5391
+ data: [
5392
+ {
5393
+ data: data0,
5394
+ isLoading: isLoading0,
5395
+ error: error0,
5396
+ startDate: startDate0,
5397
+ endDate: endDate0
5398
+ },
5399
+ {
5400
+ data: data1,
5401
+ isLoading: isLoading1,
5402
+ error: error1,
5403
+ startDate: startDate1,
5404
+ endDate: endDate1
5405
+ },
5406
+ {
5407
+ data: data2,
5408
+ isLoading: isLoading2,
5409
+ error: error2,
5410
+ startDate: startDate2,
5411
+ endDate: endDate2
5412
+ },
5413
+ {
5414
+ data: data3,
5415
+ isLoading: isLoading3,
5416
+ error: error3,
5417
+ startDate: startDate3,
5418
+ endDate: endDate3
5419
+ },
5420
+ {
5421
+ data: data4,
5422
+ isLoading: isLoading4,
5423
+ error: error4,
5424
+ startDate: startDate4,
5425
+ endDate: endDate4
5426
+ },
5427
+ {
5428
+ data: data5,
5429
+ isLoading: isLoading5,
5430
+ error: error5,
5431
+ startDate: startDate5,
5432
+ endDate: endDate5
5433
+ },
5434
+ {
5435
+ data: data6,
5436
+ isLoading: isLoading6,
5437
+ error: error6,
5438
+ startDate: startDate6,
5439
+ endDate: endDate6
5440
+ },
5441
+ {
5442
+ data: data7,
5443
+ isLoading: isLoading7,
5444
+ error: error7,
5445
+ startDate: startDate7,
5446
+ endDate: endDate7
5447
+ },
5448
+ {
5449
+ data: data8,
5450
+ isLoading: isLoading8,
5451
+ error: error8,
5452
+ startDate: startDate8,
5453
+ endDate: endDate8
5454
+ },
5455
+ {
5456
+ data: data9,
5457
+ isLoading: isLoading9,
5458
+ error: error9,
5459
+ startDate: startDate9,
5460
+ endDate: endDate9
5461
+ },
5462
+ {
5463
+ data: data10,
5464
+ isLoading: isLoading10,
5465
+ error: error10,
5466
+ startDate: startDate10,
5467
+ endDate: endDate10
5468
+ },
5469
+ {
5470
+ data: data11,
5471
+ isLoading: isLoading11,
5472
+ error: error11,
5473
+ startDate: startDate11,
5474
+ endDate: endDate11
5475
+ }
5476
+ ],
5477
+ error: [
5478
+ error0,
5479
+ error1,
5480
+ error2,
5481
+ error3,
5482
+ error4,
5483
+ error5,
5484
+ error6,
5485
+ error7,
5486
+ error8,
5487
+ error9,
5488
+ error10,
5489
+ error11
5490
+ ].find((x) => !!x),
5491
+ isLoading: [
5492
+ isLoading0,
5493
+ isLoading1,
5494
+ isLoading2,
5495
+ isLoading3,
5496
+ isLoading4,
5497
+ isLoading5,
5498
+ isLoading6,
5499
+ isLoading7,
5500
+ isLoading8,
5501
+ isLoading9,
5502
+ isLoading10,
5503
+ isLoading11
5504
+ ].find((x) => !!x)
5505
+ };
5506
+ }, [
5507
+ data0,
5508
+ data1,
5509
+ data2,
5510
+ data3,
5511
+ data4,
5512
+ data5,
5513
+ data6,
5514
+ data7,
5515
+ data8,
5516
+ data9,
5517
+ data10,
5518
+ data11,
5519
+ isLoading0,
5520
+ isLoading1,
5521
+ isLoading2,
5522
+ isLoading3,
5523
+ isLoading4,
5524
+ isLoading5,
5525
+ isLoading6,
5526
+ isLoading7,
5527
+ isLoading8,
5528
+ isLoading9,
5529
+ isLoading10,
5530
+ isLoading11,
5531
+ error0,
5532
+ error1,
5533
+ error2,
5534
+ error3,
5535
+ error4,
5536
+ error5,
5537
+ error6,
5538
+ error7,
5539
+ error8,
5540
+ error9,
5541
+ error10,
5542
+ error11
5543
+ ]);
5544
+ useEffect10(() => {
5545
+ if (isLoading && loaded === "initial") {
5546
+ setLoaded("loading");
5547
+ return;
5548
+ }
5549
+ if (!isLoading && data && !data.find((x) => !x.data && !x.error)) {
5550
+ setLoaded("complete");
5551
+ }
5552
+ }, [data, isLoading]);
5553
+ return {
5554
+ data,
5555
+ isLoading,
5556
+ loaded,
5557
+ error
5558
+ };
5559
+ };
5182
5560
 
5183
5561
  // src/utils/format.ts
5184
5562
  var capitalizeFirstLetter = (text) => text.charAt(0).toUpperCase() + text.slice(1);
@@ -5219,46 +5597,69 @@ var humanizeEnum = (text) => {
5219
5597
  };
5220
5598
 
5221
5599
  // src/components/ProfitAndLossChart/Indicator.tsx
5222
- import React65, { useEffect as useEffect10 } from "react";
5600
+ import React65, { useEffect as useEffect11, useState as useState15 } from "react";
5223
5601
  var emptyViewBox = { x: 0, y: 0, width: 0, height: 0 };
5224
5602
  var Indicator = ({
5225
- viewBox = {},
5226
5603
  className,
5227
5604
  animateFrom,
5228
- setAnimateFrom
5605
+ setAnimateFrom,
5606
+ customCursorSize,
5607
+ setCustomCursorSize,
5608
+ viewBox = {}
5229
5609
  }) => {
5230
5610
  if (!className?.match(/selected/)) {
5231
5611
  return null;
5232
5612
  }
5613
+ const [opacityIndicator, setOpacityIndicator] = useState15(0);
5233
5614
  const { x: animateTo = 0, width = 0 } = "x" in viewBox ? viewBox : emptyViewBox;
5234
5615
  const margin = width > 12 ? 4 : 1;
5235
5616
  const boxWidth = width * 2 + margin;
5236
5617
  const multiplier = width > 12 ? 1.2 : 1;
5237
5618
  const xOffset = (boxWidth * multiplier - boxWidth) / 2;
5238
- const borderRadius = width > 16 ? 8 : width / 2;
5239
- useEffect10(() => {
5619
+ const borderRadius = 6;
5620
+ const rectWidth = `${boxWidth * multiplier}px`;
5621
+ const rectHeight = "calc(100% - 38px)";
5622
+ useEffect11(() => {
5623
+ if (Math.abs(animateTo - animateFrom) < 30) {
5624
+ setOpacityIndicator(0);
5625
+ }
5240
5626
  setAnimateFrom(animateTo);
5627
+ setTimeout(() => {
5628
+ setOpacityIndicator(1);
5629
+ }, 200);
5241
5630
  }, [animateTo]);
5631
+ const rectRef = (ref) => {
5632
+ if (ref) {
5633
+ const refRectWidth = ref.getBoundingClientRect().width;
5634
+ const refRectHeight = ref.getBoundingClientRect().height;
5635
+ if (customCursorSize.width !== refRectWidth || customCursorSize.height !== refRectHeight) {
5636
+ setCustomCursorSize(refRectWidth, refRectHeight, actualX - xOffset);
5637
+ }
5638
+ }
5639
+ };
5242
5640
  const actualX = animateFrom === -1 ? animateTo : animateFrom;
5243
5641
  return /* @__PURE__ */ React65.createElement(
5244
5642
  "rect",
5245
5643
  {
5644
+ ref: rectRef,
5246
5645
  className: "Layer__profit-and-loss-chart__selection-indicator",
5247
5646
  rx: borderRadius,
5248
5647
  ry: borderRadius,
5249
5648
  style: {
5250
- width: `${boxWidth * multiplier}px`,
5649
+ width: rectWidth,
5251
5650
  // @ts-expect-error -- y is fine but x apparently isn't!
5252
5651
  x: actualX - xOffset,
5253
- y: 22,
5254
- height: "calc(100% - 38px)"
5652
+ y: 1,
5653
+ height: rectHeight,
5654
+ opacity: opacityIndicator
5255
5655
  }
5256
5656
  }
5257
5657
  );
5258
5658
  };
5259
5659
 
5260
5660
  // src/components/ProfitAndLossChart/ProfitAndLossChart.tsx
5261
- import { endOfMonth as endOfMonth2, format as format4, parseISO as parseISO8, startOfMonth as startOfMonth2, sub } from "date-fns";
5661
+ import classNames26 from "classnames";
5662
+ import { format as format4, parseISO as parseISO8, startOfMonth as startOfMonth4 } from "date-fns";
5262
5663
  import {
5263
5664
  BarChart,
5264
5665
  XAxis,
@@ -5276,82 +5677,24 @@ var barSize = 20;
5276
5677
  var ProfitAndLossChart = () => {
5277
5678
  const { getColor } = useLayerContext();
5278
5679
  const { changeDateRange, dateRange } = useContext2(ProfitAndLoss.Context);
5279
- const thisMonth = startOfMonth2(Date.now());
5680
+ const [customCursorSize, setCustomCursorSize] = useState16({
5681
+ width: 0,
5682
+ height: 0,
5683
+ x: 0
5684
+ });
5685
+ const [barAnimActive, setBarAnimActive] = useState16(true);
5280
5686
  const startSelectionMonth = dateRange.startDate.getMonth();
5281
5687
  const endSelectionMonth = dateRange.endDate.getMonth();
5282
- const monthData = [];
5283
- monthData.push(
5284
- useProfitAndLoss({
5285
- startDate: startOfMonth2(sub(thisMonth, { months: 11 })),
5286
- endDate: endOfMonth2(sub(thisMonth, { months: 11 }))
5287
- })?.data
5288
- );
5289
- monthData.push(
5290
- useProfitAndLoss({
5291
- startDate: startOfMonth2(sub(thisMonth, { months: 10 })),
5292
- endDate: endOfMonth2(sub(thisMonth, { months: 10 }))
5293
- })?.data
5294
- );
5295
- monthData.push(
5296
- useProfitAndLoss({
5297
- startDate: startOfMonth2(sub(thisMonth, { months: 9 })),
5298
- endDate: endOfMonth2(sub(thisMonth, { months: 9 }))
5299
- })?.data
5300
- );
5301
- monthData.push(
5302
- useProfitAndLoss({
5303
- startDate: startOfMonth2(sub(thisMonth, { months: 8 })),
5304
- endDate: endOfMonth2(sub(thisMonth, { months: 8 }))
5305
- })?.data
5306
- );
5307
- monthData.push(
5308
- useProfitAndLoss({
5309
- startDate: startOfMonth2(sub(thisMonth, { months: 7 })),
5310
- endDate: endOfMonth2(sub(thisMonth, { months: 7 }))
5311
- })?.data
5312
- );
5313
- monthData.push(
5314
- useProfitAndLoss({
5315
- startDate: startOfMonth2(sub(thisMonth, { months: 6 })),
5316
- endDate: endOfMonth2(sub(thisMonth, { months: 6 }))
5317
- })?.data
5318
- );
5319
- monthData.push(
5320
- useProfitAndLoss({
5321
- startDate: startOfMonth2(sub(thisMonth, { months: 5 })),
5322
- endDate: endOfMonth2(sub(thisMonth, { months: 5 }))
5323
- })?.data
5324
- );
5325
- monthData.push(
5326
- useProfitAndLoss({
5327
- startDate: startOfMonth2(sub(thisMonth, { months: 4 })),
5328
- endDate: endOfMonth2(sub(thisMonth, { months: 4 }))
5329
- })?.data
5330
- );
5331
- monthData.push(
5332
- useProfitAndLoss({
5333
- startDate: startOfMonth2(sub(thisMonth, { months: 3 })),
5334
- endDate: endOfMonth2(sub(thisMonth, { months: 3 }))
5335
- })?.data
5336
- );
5337
- monthData.push(
5338
- useProfitAndLoss({
5339
- startDate: startOfMonth2(sub(thisMonth, { months: 2 })),
5340
- endDate: endOfMonth2(sub(thisMonth, { months: 2 }))
5341
- })?.data
5342
- );
5343
- monthData.push(
5344
- useProfitAndLoss({
5345
- startDate: startOfMonth2(sub(thisMonth, { months: 1 })),
5346
- endDate: endOfMonth2(sub(thisMonth, { months: 1 }))
5347
- })?.data
5348
- );
5349
- monthData.push(
5350
- useProfitAndLoss({
5351
- startDate: thisMonth,
5352
- endDate: endOfMonth2(thisMonth)
5353
- })?.data
5354
- );
5688
+ const { data, loaded } = useProfitAndLossLTM({
5689
+ currentDate: startOfMonth4(Date.now())
5690
+ });
5691
+ useEffect12(() => {
5692
+ if (loaded === "complete") {
5693
+ setTimeout(() => {
5694
+ setBarAnimActive(false);
5695
+ }, 1e3);
5696
+ }
5697
+ }, [loaded]);
5355
5698
  const getMonthName = (pnl) => pnl ? format4(parseISO8(pnl.start_date), "LLL") : "";
5356
5699
  const summarizePnL = (pnl) => ({
5357
5700
  name: getMonthName(pnl),
@@ -5361,56 +5704,68 @@ var ProfitAndLossChart = () => {
5361
5704
  selected: !!pnl && parseISO8(pnl.start_date).getMonth() >= startSelectionMonth && parseISO8(pnl.end_date).getMonth() <= endSelectionMonth
5362
5705
  });
5363
5706
  const onClick = ({ activeTooltipIndex }) => {
5364
- const selection = monthData[activeTooltipIndex || -1];
5365
- if (selection) {
5366
- const { start_date: startDate, end_date: endDate } = selection;
5707
+ const selection = data[activeTooltipIndex || -1];
5708
+ if (selection && selection.data) {
5709
+ const { start_date, end_date } = selection.data;
5367
5710
  changeDateRange({
5368
- startDate: parseISO8(startDate),
5369
- endDate: parseISO8(endDate)
5711
+ startDate: parseISO8(start_date),
5712
+ endDate: parseISO8(end_date)
5370
5713
  });
5371
5714
  }
5372
5715
  };
5373
- const CustomTooltip = ({
5374
- active,
5375
- payload,
5376
- label
5377
- }) => {
5716
+ const CustomTooltip = ({ active, payload }) => {
5378
5717
  if (active && payload && payload.length) {
5379
5718
  const netProfit = payload[0].payload.netProfit ?? 0;
5380
5719
  const netProfitClass = netProfit > 0 ? "positive" : netProfit < 0 ? "negative" : "";
5381
- return /* @__PURE__ */ React66.createElement("div", { className: "Layer__chart__tooltip" }, /* @__PURE__ */ React66.createElement("ul", { className: "Layer__chart__tooltip-list" }, /* @__PURE__ */ React66.createElement("li", null, /* @__PURE__ */ React66.createElement("label", { className: "Layer__chart__tooltip-label" }, capitalizeFirstLetter(payload[0].name ?? "")), /* @__PURE__ */ React66.createElement("span", { className: "Layer__chart__tooltip-value" }, "$", centsToDollars(Math.abs(payload[0].value ?? 0)))), /* @__PURE__ */ React66.createElement("li", null, /* @__PURE__ */ React66.createElement("label", { className: "Layer__chart__tooltip-label" }, capitalizeFirstLetter(payload[1].name ?? "")), /* @__PURE__ */ React66.createElement("span", { className: "Layer__chart__tooltip-value" }, "$", centsToDollars(Math.abs(payload[1].value ?? 0)))), /* @__PURE__ */ React66.createElement("li", null, /* @__PURE__ */ React66.createElement("label", { className: "Layer__chart__tooltip-label" }, "Net Profit"), /* @__PURE__ */ React66.createElement("span", { className: `Layer__chart__tooltip-value ${netProfitClass}` }, "$", centsToDollars(netProfit)))));
5720
+ return /* @__PURE__ */ React66.createElement("div", { className: "Layer__chart__tooltip" }, loaded !== "complete" ? /* @__PURE__ */ React66.createElement(Text, null, "Loading...") : /* @__PURE__ */ React66.createElement("ul", { className: "Layer__chart__tooltip-list" }, /* @__PURE__ */ React66.createElement("li", null, /* @__PURE__ */ React66.createElement("label", { className: "Layer__chart__tooltip-label" }, capitalizeFirstLetter(payload[0].name ?? "")), /* @__PURE__ */ React66.createElement("span", { className: "Layer__chart__tooltip-value" }, "$", centsToDollars(Math.abs(payload[0].value ?? 0)))), /* @__PURE__ */ React66.createElement("li", null, /* @__PURE__ */ React66.createElement("label", { className: "Layer__chart__tooltip-label" }, capitalizeFirstLetter(payload[1].name ?? "")), /* @__PURE__ */ React66.createElement("span", { className: "Layer__chart__tooltip-value" }, "$", centsToDollars(Math.abs(payload[1].value ?? 0)))), /* @__PURE__ */ React66.createElement("li", null, /* @__PURE__ */ React66.createElement("label", { className: "Layer__chart__tooltip-label" }, "Net Profit"), /* @__PURE__ */ React66.createElement(
5721
+ "span",
5722
+ {
5723
+ className: `Layer__chart__tooltip-value ${netProfitClass}`
5724
+ },
5725
+ "$",
5726
+ centsToDollars(netProfit)
5727
+ ))));
5382
5728
  }
5383
5729
  return null;
5384
5730
  };
5385
5731
  const CustomizedCursor = (props) => {
5386
- const { x, width, height } = props;
5732
+ const { x, y } = props;
5733
+ const { width, height } = customCursorSize;
5734
+ const offsetX = width * 0.1;
5387
5735
  return /* @__PURE__ */ React66.createElement(
5388
5736
  Rectangle,
5389
5737
  {
5390
- fill: getColor(900)?.hex ?? "#333",
5738
+ fill: "#F7F8FA",
5391
5739
  stroke: "none",
5392
- x: x + width / 2 - 11,
5393
- y: height + 44,
5394
- radius: 2,
5395
- width: 22,
5396
- height: 2,
5740
+ x: x + offsetX,
5741
+ y,
5742
+ width,
5743
+ height,
5744
+ radius: 6,
5397
5745
  className: "Layer__chart__tooltip-cursor"
5398
5746
  }
5399
5747
  );
5400
5748
  };
5401
- const data = useMemo4(
5402
- () => monthData.map(summarizePnL),
5403
- [
5404
- startSelectionMonth,
5405
- endSelectionMonth,
5406
- ...monthData.map((m) => m?.net_profit)
5407
- ]
5408
- );
5409
- const [animateFrom, setAnimateFrom] = useState14(-1);
5749
+ const theData = useMemo5(() => {
5750
+ if (loaded !== "complete") {
5751
+ return data?.map((x) => ({
5752
+ name: format4(x.startDate, "LLL"),
5753
+ revenue: 1,
5754
+ expenses: 1,
5755
+ netProfit: 0,
5756
+ selected: false
5757
+ }));
5758
+ }
5759
+ return data?.map((x) => summarizePnL(x.data));
5760
+ }, [startSelectionMonth, endSelectionMonth, loaded]);
5761
+ const [animateFrom, setAnimateFrom] = useState16(-1);
5410
5762
  return /* @__PURE__ */ React66.createElement(
5411
5763
  ResponsiveContainer,
5412
5764
  {
5413
- className: "Layer__chart-container",
5765
+ className: classNames26(
5766
+ "Layer__chart-container",
5767
+ loaded !== "complete" && "Layer__chart-container--loading"
5768
+ ),
5414
5769
  width: "100%",
5415
5770
  height: "100%",
5416
5771
  minHeight: 200
@@ -5419,7 +5774,7 @@ var ProfitAndLossChart = () => {
5419
5774
  BarChart,
5420
5775
  {
5421
5776
  margin: { left: 12, right: 12, bottom: 12 },
5422
- data,
5777
+ data: theData,
5423
5778
  onClick,
5424
5779
  barGap,
5425
5780
  className: "Layer__profit-and-loss-chart"
@@ -5445,9 +5800,9 @@ var ProfitAndLossChart = () => {
5445
5800
  /* @__PURE__ */ React66.createElement(
5446
5801
  Legend,
5447
5802
  {
5448
- verticalAlign: "top",
5803
+ verticalAlign: "bottom",
5449
5804
  align: "left",
5450
- wrapperStyle: { top: -24 },
5805
+ wrapperStyle: { bottom: 0 },
5451
5806
  payload: [
5452
5807
  {
5453
5808
  value: "Revenue",
@@ -5468,7 +5823,7 @@ var ProfitAndLossChart = () => {
5468
5823
  {
5469
5824
  dataKey: "revenue",
5470
5825
  barSize,
5471
- isAnimationActive: false,
5826
+ isAnimationActive: barAnimActive,
5472
5827
  radius: [2, 2, 0, 0],
5473
5828
  className: "Layer__profit-and-loss-chart__bar--income"
5474
5829
  },
@@ -5478,30 +5833,34 @@ var ProfitAndLossChart = () => {
5478
5833
  content: /* @__PURE__ */ React66.createElement(
5479
5834
  Indicator,
5480
5835
  {
5836
+ setCustomCursorSize: (width, height, x) => setCustomCursorSize({ width, height, x }),
5837
+ customCursorSize,
5481
5838
  animateFrom,
5482
5839
  setAnimateFrom
5483
5840
  }
5484
5841
  )
5485
5842
  }
5486
5843
  ),
5487
- data.map((entry) => /* @__PURE__ */ React66.createElement(
5488
- Cell,
5489
- {
5490
- key: entry.name,
5491
- className: entry.selected ? "Layer__profit-and-loss-chart__cell--selected" : ""
5492
- }
5493
- ))
5844
+ theData?.map((entry) => {
5845
+ return /* @__PURE__ */ React66.createElement(
5846
+ Cell,
5847
+ {
5848
+ key: entry.name,
5849
+ className: entry.selected ? "Layer__profit-and-loss-chart__cell--selected" : ""
5850
+ }
5851
+ );
5852
+ })
5494
5853
  ),
5495
5854
  /* @__PURE__ */ React66.createElement(
5496
5855
  Bar,
5497
5856
  {
5498
5857
  dataKey: "expenses",
5499
5858
  barSize,
5500
- isAnimationActive: false,
5859
+ isAnimationActive: barAnimActive,
5501
5860
  radius: [2, 2, 0, 0],
5502
5861
  className: "Layer__profit-and-loss-chart__bar--expenses"
5503
5862
  },
5504
- data.map((entry) => /* @__PURE__ */ React66.createElement(
5863
+ theData.map((entry) => /* @__PURE__ */ React66.createElement(
5505
5864
  Cell,
5506
5865
  {
5507
5866
  key: entry.name,
@@ -5514,19 +5873,19 @@ var ProfitAndLossChart = () => {
5514
5873
  };
5515
5874
 
5516
5875
  // src/components/ProfitAndLossDatePicker/ProfitAndLossDatePicker.tsx
5517
- import React67, { useContext as useContext3, useState as useState15, useEffect as useEffect11 } from "react";
5518
- import { add, endOfMonth as endOfMonth3, format as format5, startOfMonth as startOfMonth3 } from "date-fns";
5876
+ import React67, { useContext as useContext3, useState as useState17, useEffect as useEffect13 } from "react";
5877
+ import { add, endOfMonth as endOfMonth4, format as format5, startOfMonth as startOfMonth5 } from "date-fns";
5519
5878
  var ProfitAndLossDatePicker = () => {
5520
5879
  const { changeDateRange, dateRange } = useContext3(ProfitAndLoss.Context);
5521
- const [isAnimating, setIsAnimating] = useState15(false);
5522
- const [localDate, setLocalDate] = useState15(dateRange.startDate);
5523
- const [nextOpacity, setNextOpacity] = useState15(0);
5524
- const [currentOpacity, setCurrentOpacity] = useState15(1);
5525
- const [transformStyle, setTransformStyle] = useState15({
5880
+ const [isAnimating, setIsAnimating] = useState17(false);
5881
+ const [localDate, setLocalDate] = useState17(dateRange.startDate);
5882
+ const [nextOpacity, setNextOpacity] = useState17(0);
5883
+ const [currentOpacity, setCurrentOpacity] = useState17(1);
5884
+ const [transformStyle, setTransformStyle] = useState17({
5526
5885
  transform: "translateX(33%)",
5527
5886
  transition: "ease"
5528
5887
  });
5529
- useEffect11(() => {
5888
+ useEffect13(() => {
5530
5889
  if (dateRange.startDate !== localDate && !isAnimating) {
5531
5890
  setLocalDate(dateRange.startDate);
5532
5891
  setTransformStyle({ transform: "translateX(33%)", transition: "none" });
@@ -5542,8 +5901,8 @@ var ProfitAndLossDatePicker = () => {
5542
5901
  setCurrentOpacity(0);
5543
5902
  }
5544
5903
  changeDateRange({
5545
- startDate: startOfMonth3(newDate),
5546
- endDate: endOfMonth3(newDate)
5904
+ startDate: startOfMonth5(newDate),
5905
+ endDate: endOfMonth4(newDate)
5547
5906
  });
5548
5907
  const translateXValue = monthsToAdd > 0 ? "0%" : "66%";
5549
5908
  setTransformStyle({
@@ -5564,64 +5923,64 @@ var ProfitAndLossDatePicker = () => {
5564
5923
  const currentLabel = format5(localDate, "LLLL, y");
5565
5924
  const prevLabel = format5(add(localDate, { months: -1 }), "LLLL, y");
5566
5925
  const nextLabel = format5(add(localDate, { months: 1 }), "LLLL, y");
5567
- return /* @__PURE__ */ React67.createElement(
5926
+ return /* @__PURE__ */ React67.createElement("div", { className: "Layer__profit-and-loss-date-picker" }, /* @__PURE__ */ React67.createElement(
5568
5927
  "div",
5569
5928
  {
5570
- className: "Layer__profit-and-loss-date-picker"
5929
+ className: "Layer__profit-and-loss-date-picker__labels-container",
5930
+ style: transformStyle
5571
5931
  },
5572
- /* @__PURE__ */ React67.createElement("div", { className: "Layer__profit-and-loss-date-picker__labels-container", style: transformStyle }, /* @__PURE__ */ React67.createElement("span", { className: "Layer__profit-and-loss-date-picker__label" }, prevLabel), /* @__PURE__ */ React67.createElement(
5932
+ /* @__PURE__ */ React67.createElement("span", { className: "Layer__profit-and-loss-date-picker__label" }, prevLabel),
5933
+ /* @__PURE__ */ React67.createElement(
5573
5934
  "span",
5574
5935
  {
5575
5936
  className: "Layer__profit-and-loss-date-picker__label",
5576
5937
  style: { opacity: currentOpacity }
5577
5938
  },
5578
5939
  currentLabel
5579
- ), /* @__PURE__ */ React67.createElement(
5940
+ ),
5941
+ /* @__PURE__ */ React67.createElement(
5580
5942
  "span",
5581
5943
  {
5582
5944
  className: "Layer__profit-and-loss-date-picker__label",
5583
5945
  style: { opacity: nextOpacity }
5584
5946
  },
5585
5947
  nextLabel
5586
- )),
5948
+ )
5949
+ ), /* @__PURE__ */ React67.createElement(
5950
+ "button",
5951
+ {
5952
+ "aria-label": "View Previous Month",
5953
+ className: "Layer__profit-and-loss-date-picker__button",
5954
+ onClick: () => change(-1),
5955
+ disabled: isAnimating
5956
+ },
5587
5957
  /* @__PURE__ */ React67.createElement(
5588
- "button",
5958
+ ChevronLeft_default,
5589
5959
  {
5590
- "aria-label": "View Previous Month",
5591
- className: "Layer__profit-and-loss-date-picker__button",
5592
- onClick: () => change(-1),
5593
- disabled: isAnimating
5594
- },
5595
- /* @__PURE__ */ React67.createElement(
5596
- ChevronLeft_default,
5597
- {
5598
- className: "Layer__profit-and-loss-date-picker__button-icon",
5599
- size: 16
5600
- }
5601
- )
5602
- ),
5960
+ className: "Layer__profit-and-loss-date-picker__button-icon",
5961
+ size: 16
5962
+ }
5963
+ )
5964
+ ), /* @__PURE__ */ React67.createElement(
5965
+ "button",
5966
+ {
5967
+ "aria-label": "View Next Month",
5968
+ className: "Layer__profit-and-loss-date-picker__button",
5969
+ onClick: () => change(1),
5970
+ disabled: isAnimating
5971
+ },
5603
5972
  /* @__PURE__ */ React67.createElement(
5604
- "button",
5973
+ ChevronRight_default,
5605
5974
  {
5606
- "aria-label": "View Next Month",
5607
- className: "Layer__profit-and-loss-date-picker__button",
5608
- onClick: () => change(1),
5609
- disabled: isAnimating
5610
- },
5611
- /* @__PURE__ */ React67.createElement(
5612
- ChevronRight_default,
5613
- {
5614
- className: "Layer__profit-and-loss-date-picker__button-icon",
5615
- size: 16
5616
- }
5617
- )
5618
- ),
5619
- /* @__PURE__ */ React67.createElement("div", { className: "Layer__profit-and-loss-date-picker__effect-blur" })
5620
- );
5975
+ className: "Layer__profit-and-loss-date-picker__button-icon",
5976
+ size: 16
5977
+ }
5978
+ )
5979
+ ), /* @__PURE__ */ React67.createElement("div", { className: "Layer__profit-and-loss-date-picker__effect-blur" }));
5621
5980
  };
5622
5981
 
5623
5982
  // src/components/ProfitAndLossDetailedCharts/ProfitAndLossDetailedCharts.tsx
5624
- import React73, { useContext as useContext4, useState as useState16 } from "react";
5983
+ import React73, { useContext as useContext4, useState as useState18 } from "react";
5625
5984
 
5626
5985
  // src/icons/X.tsx
5627
5986
  import * as React68 from "react";
@@ -5657,7 +6016,7 @@ var X = ({ size = 18, ...props }) => /* @__PURE__ */ React68.createElement(
5657
6016
  var X_default = X;
5658
6017
 
5659
6018
  // src/components/ProfitAndLossDetailedCharts/DetailedChart.tsx
5660
- import React69, { useMemo as useMemo5 } from "react";
6019
+ import React69, { useMemo as useMemo6 } from "react";
5661
6020
 
5662
6021
  // src/config/charts.ts
5663
6022
  var INACTIVE_OPACITY_LEVELS = [
@@ -5763,7 +6122,7 @@ var DetailedChart = ({
5763
6122
  date,
5764
6123
  isLoading
5765
6124
  }) => {
5766
- const chartData = useMemo5(() => {
6125
+ const chartData = useMemo6(() => {
5767
6126
  if (!filteredData) {
5768
6127
  return [];
5769
6128
  }
@@ -6034,7 +6393,7 @@ var SortArrows = ({ size = 13, ...props }) => /* @__PURE__ */ React70.createElem
6034
6393
  width: size,
6035
6394
  height: size
6036
6395
  },
6037
- /* @__PURE__ */ React70.createElement("g", { "clip-path": "url(#clip0_1758_75388)" }, /* @__PURE__ */ React70.createElement(
6396
+ /* @__PURE__ */ React70.createElement("g", { clipPath: "url(#clip0_1758_75388)" }, /* @__PURE__ */ React70.createElement(
6038
6397
  "path",
6039
6398
  {
6040
6399
  d: "M1.33325 8.5L3.99992 11.1667L6.66659 8.5",
@@ -6084,7 +6443,7 @@ var SortArrows = ({ size = 13, ...props }) => /* @__PURE__ */ React70.createElem
6084
6443
  var SortArrows_default = SortArrows;
6085
6444
 
6086
6445
  // src/components/ProfitAndLossDetailedCharts/DetailedTable.tsx
6087
- import classNames25 from "classnames";
6446
+ import classNames27 from "classnames";
6088
6447
  var DetailedTable = ({
6089
6448
  filteredData,
6090
6449
  sidebarScope,
@@ -6094,7 +6453,7 @@ var DetailedTable = ({
6094
6453
  setHoveredItem
6095
6454
  }) => {
6096
6455
  const buildColClass = (column) => {
6097
- return classNames25(
6456
+ return classNames27(
6098
6457
  "Layer__sortable-col",
6099
6458
  sidebarScope && filters[sidebarScope]?.sortBy === column ? `sort--${(sidebarScope && filters[sidebarScope]?.sortDirection) ?? "desc"}` : ""
6100
6459
  );
@@ -6129,7 +6488,7 @@ var DetailedTable = ({
6129
6488
  "tr",
6130
6489
  {
6131
6490
  key: `pl-side-table-item-${idx}`,
6132
- className: classNames25(
6491
+ className: classNames27(
6133
6492
  "Layer__profit-and-loss-detailed-table__row",
6134
6493
  hoveredItem && hoveredItem === item.display_name ? "active" : ""
6135
6494
  ),
@@ -6214,7 +6573,7 @@ var ProfitAndLossDetailedCharts = ({
6214
6573
  const theScope = scope ? scope : sidebarScope;
6215
6574
  const data = theScope === "revenue" ? filteredDataRevenue : filteredDataExpenses;
6216
6575
  const total = theScope === "revenue" ? filteredTotalRevenue : filteredTotalExpenses;
6217
- const [hoveredItem, setHoveredItem] = useState16();
6576
+ const [hoveredItem, setHoveredItem] = useState18();
6218
6577
  return /* @__PURE__ */ React73.createElement("div", { className: "Layer__profit-and-loss-detailed-charts" }, /* @__PURE__ */ React73.createElement("header", { className: "Layer__profit-and-loss-detailed-charts__header" }, /* @__PURE__ */ React73.createElement("div", { className: "Layer__profit-and-loss-detailed-charts__head" }, /* @__PURE__ */ React73.createElement(Text, { size: "lg" /* lg */, weight: "bold" /* bold */, className: "title" }, humanizeTitle(theScope)), /* @__PURE__ */ React73.createElement(Text, { size: "sm" /* sm */, className: "date" }, format6(dateRange.startDate, "LLLL, y")), showDatePicker && /* @__PURE__ */ React73.createElement(ProfitAndLossDatePicker, null)), !hideClose && /* @__PURE__ */ React73.createElement(
6219
6578
  Button,
6220
6579
  {
@@ -6256,17 +6615,17 @@ var ProfitAndLossDetailedCharts = ({
6256
6615
  };
6257
6616
 
6258
6617
  // src/components/ProfitAndLossSummaries/ProfitAndLossSummaries.tsx
6259
- import React76, { useContext as useContext5, useMemo as useMemo6 } from "react";
6618
+ import React76, { useContext as useContext5, useMemo as useMemo7 } from "react";
6260
6619
 
6261
6620
  // src/components/SkeletonLoader/SkeletonLoader.tsx
6262
6621
  import React74 from "react";
6263
- import classNames26 from "classnames";
6622
+ import classNames28 from "classnames";
6264
6623
  var SkeletonLoader = ({
6265
6624
  height,
6266
6625
  width,
6267
6626
  className
6268
6627
  }) => {
6269
- const baseClassName = classNames26(
6628
+ const baseClassName = classNames28(
6270
6629
  "Layer__skeleton-loader Layer__anim--skeleton-loading",
6271
6630
  className
6272
6631
  );
@@ -6310,7 +6669,7 @@ var MiniChart = ({ data }) => {
6310
6669
  };
6311
6670
 
6312
6671
  // src/components/ProfitAndLossSummaries/ProfitAndLossSummaries.tsx
6313
- import classNames27 from "classnames";
6672
+ import classNames29 from "classnames";
6314
6673
  var CHART_PLACEHOLDER = [
6315
6674
  {
6316
6675
  name: "placeholder",
@@ -6348,13 +6707,14 @@ var ProfitAndLossSummaries = ({
6348
6707
  setSidebarScope,
6349
6708
  sidebarScope
6350
6709
  } = useContext5(ProfitAndLoss.Context);
6351
- const expensesChartData = useMemo6(() => {
6352
- return buildMiniChartData("expenses", storedData);
6710
+ const dataItem = Array.isArray(storedData) ? storedData[storedData.length - 1] : storedData;
6711
+ const expensesChartData = useMemo7(() => {
6712
+ return buildMiniChartData("expenses", dataItem);
6353
6713
  }, [storedData]);
6354
- const revenueChartData = useMemo6(() => {
6355
- return buildMiniChartData("revenue", storedData);
6714
+ const revenueChartData = useMemo7(() => {
6715
+ return buildMiniChartData("revenue", dataItem);
6356
6716
  }, [storedData]);
6357
- const data = storedData ? storedData : { income: { value: NaN }, net_profit: NaN };
6717
+ const data = dataItem ? dataItem : { income: { value: NaN }, net_profit: NaN };
6358
6718
  const incomeDirectionClass = (data.income.value ?? NaN) < 0 ? "Layer__profit-and-loss-summaries__amount--negative" : "Layer__profit-and-loss-summaries__amount--positive";
6359
6719
  const expensesDirectionClass = (data?.income?.value ?? NaN) - data.net_profit < 0 ? "Layer__profit-and-loss-summaries__amount--negative" : "Layer__profit-and-loss-summaries__amount--positive";
6360
6720
  const netProfitDirectionClass = data.net_profit < 0 ? "Layer__profit-and-loss-summaries__amount--negative" : "Layer__profit-and-loss-summaries__amount--positive";
@@ -6366,7 +6726,7 @@ var ProfitAndLossSummaries = ({
6366
6726
  /* @__PURE__ */ React76.createElement(
6367
6727
  "div",
6368
6728
  {
6369
- className: classNames27(
6729
+ className: classNames29(
6370
6730
  "Layer__profit-and-loss-summaries__summary",
6371
6731
  actionable && "Layer__actionable",
6372
6732
  "Layer__profit-and-loss-summaries__summary--income",
@@ -6388,7 +6748,7 @@ var ProfitAndLossSummaries = ({
6388
6748
  /* @__PURE__ */ React76.createElement(
6389
6749
  "div",
6390
6750
  {
6391
- className: classNames27(
6751
+ className: classNames29(
6392
6752
  "Layer__profit-and-loss-summaries__summary",
6393
6753
  actionable && "Layer__actionable",
6394
6754
  "Layer__profit-and-loss-summaries__summary--expenses",
@@ -6412,7 +6772,7 @@ var ProfitAndLossSummaries = ({
6412
6772
  /* @__PURE__ */ React76.createElement(
6413
6773
  "div",
6414
6774
  {
6415
- className: classNames27(
6775
+ className: classNames29(
6416
6776
  "Layer__profit-and-loss-summaries__summary net-profit Layer__profit-and-loss-summaries__summary--net-profit",
6417
6777
  actionable && "Layer__actionable"
6418
6778
  )
@@ -6432,7 +6792,7 @@ var ProfitAndLossSummaries = ({
6432
6792
  import React79, { useContext as useContext6 } from "react";
6433
6793
 
6434
6794
  // src/components/ProfitAndLossRow/ProfitAndLossRow.tsx
6435
- import React78, { useState as useState17 } from "react";
6795
+ import React78, { useState as useState19 } from "react";
6436
6796
 
6437
6797
  // src/icons/PieChart.tsx
6438
6798
  import * as React77 from "react";
@@ -6481,7 +6841,7 @@ var ProfitAndLossRow = ({
6481
6841
  return null;
6482
6842
  }
6483
6843
  const { value, display_name, line_items } = lineItem;
6484
- const [expanded, setExpanded] = useState17(true);
6844
+ const [expanded, setExpanded] = useState19(true);
6485
6845
  const amount = value ?? 0;
6486
6846
  const amountString = centsToDollars(Math.abs(amount));
6487
6847
  const labelClasses = [
@@ -6603,19 +6963,20 @@ var empty_profit_and_loss_report_default = {
6603
6963
  };
6604
6964
 
6605
6965
  // src/components/ProfitAndLossTable/ProfitAndLossTable.tsx
6606
- import classNames28 from "classnames";
6966
+ import classNames30 from "classnames";
6607
6967
  var ProfitAndLossTable = ({ lockExpanded, asContainer }) => {
6608
6968
  const {
6609
6969
  data: actualData,
6610
6970
  isLoading,
6611
6971
  setSidebarScope
6612
6972
  } = useContext6(ProfitAndLoss.Context);
6613
- const data = !actualData || isLoading ? empty_profit_and_loss_report_default : actualData;
6973
+ const currentData = Array.isArray(actualData) ? actualData[actualData.length - 1] : actualData;
6974
+ const data = !currentData || isLoading ? empty_profit_and_loss_report_default : currentData;
6614
6975
  if (isLoading || actualData === void 0) {
6615
6976
  return /* @__PURE__ */ React79.createElement(
6616
6977
  "div",
6617
6978
  {
6618
- className: classNames28(
6979
+ className: classNames30(
6619
6980
  "Layer__profit-and-loss-table__loader-container",
6620
6981
  asContainer && "Layer__component-container"
6621
6982
  )
@@ -6626,7 +6987,7 @@ var ProfitAndLossTable = ({ lockExpanded, asContainer }) => {
6626
6987
  return /* @__PURE__ */ React79.createElement(React79.Fragment, null, /* @__PURE__ */ React79.createElement(
6627
6988
  "div",
6628
6989
  {
6629
- className: classNames28(
6990
+ className: classNames30(
6630
6991
  "Layer__profit-and-loss-table Layer__profit-and-loss-table--main",
6631
6992
  asContainer && "Layer__component-container"
6632
6993
  )
@@ -6729,7 +7090,7 @@ var ProfitAndLossTable = ({ lockExpanded, asContainer }) => {
6729
7090
  };
6730
7091
 
6731
7092
  // src/components/ProfitAndLoss/ProfitAndLoss.tsx
6732
- import { endOfMonth as endOfMonth4, startOfMonth as startOfMonth4 } from "date-fns";
7093
+ import { endOfMonth as endOfMonth5, startOfMonth as startOfMonth6 } from "date-fns";
6733
7094
  var PNLContext = createContext2({
6734
7095
  data: void 0,
6735
7096
  filteredDataRevenue: [],
@@ -6740,8 +7101,8 @@ var PNLContext = createContext2({
6740
7101
  isValidating: false,
6741
7102
  error: void 0,
6742
7103
  dateRange: {
6743
- startDate: startOfMonth4(/* @__PURE__ */ new Date()),
6744
- endDate: endOfMonth4(/* @__PURE__ */ new Date())
7104
+ startDate: startOfMonth6(/* @__PURE__ */ new Date()),
7105
+ endDate: endOfMonth5(/* @__PURE__ */ new Date())
6745
7106
  },
6746
7107
  changeDateRange: () => {
6747
7108
  },
@@ -6779,8 +7140,8 @@ ProfitAndLoss.DetailedCharts = ProfitAndLossDetailedCharts;
6779
7140
  import React82, { useContext as useContext7, useRef as useRef14 } from "react";
6780
7141
 
6781
7142
  // src/components/Panel/Panel.tsx
6782
- import React81, { useEffect as useEffect12, useState as useState18 } from "react";
6783
- import classNames29 from "classnames";
7143
+ import React81, { useEffect as useEffect14, useState as useState20 } from "react";
7144
+ import classNames31 from "classnames";
6784
7145
  var Panel = ({
6785
7146
  children,
6786
7147
  className,
@@ -6789,8 +7150,8 @@ var Panel = ({
6789
7150
  sidebarIsOpen,
6790
7151
  parentRef
6791
7152
  }) => {
6792
- const [sidebarHeight, setSidebarHeight] = useState18(0);
6793
- useEffect12(() => {
7153
+ const [sidebarHeight, setSidebarHeight] = useState20(0);
7154
+ useEffect14(() => {
6794
7155
  if (parentRef?.current?.offsetHeight) {
6795
7156
  setSidebarHeight(parentRef?.current?.offsetHeight - 1);
6796
7157
  }
@@ -6798,7 +7159,7 @@ var Panel = ({
6798
7159
  return /* @__PURE__ */ React81.createElement(
6799
7160
  "div",
6800
7161
  {
6801
- className: classNames29(
7162
+ className: classNames31(
6802
7163
  "Layer__panel",
6803
7164
  className,
6804
7165
  sidebarIsOpen && "Layer__panel--open"
@@ -6876,10 +7237,213 @@ var Components = ({
6876
7237
  };
6877
7238
 
6878
7239
  // src/components/ChartOfAccounts/ChartOfAccounts.tsx
6879
- import React96, { createContext as createContext3, useContext as useContext14, useState as useState24 } from "react";
7240
+ import React96, { createContext as createContext3, useContext as useContext14, useState as useState26 } from "react";
7241
+
7242
+ // src/hooks/useChartOfAccounts/useChartOfAccounts.tsx
7243
+ import { useState as useState21 } from "react";
7244
+
7245
+ // src/components/ChartOfAccountsForm/constants.ts
7246
+ var LEDGER_ACCOUNT_TYPES = [
7247
+ {
7248
+ value: "ASSET",
7249
+ label: "Assets"
7250
+ },
7251
+ {
7252
+ value: "LIABILITY",
7253
+ label: "Liabilities"
7254
+ },
7255
+ {
7256
+ value: "EQUITY",
7257
+ label: "Equities"
7258
+ },
7259
+ {
7260
+ value: "REVENUE",
7261
+ label: "Revenue"
7262
+ },
7263
+ {
7264
+ value: "EXPENSE",
7265
+ label: "Expenses"
7266
+ }
7267
+ ];
7268
+ var DEFAULT_ACCOUNT_TYPE_DIRECTION = {
7269
+ ASSET: "DEBIT" /* DEBIT */,
7270
+ LIABILITY: "CREDIT" /* CREDIT */,
7271
+ EQUITY: "CREDIT" /* CREDIT */,
7272
+ REVENUE: "CREDIT" /* CREDIT */,
7273
+ EXPENSE: "DEBIT" /* DEBIT */
7274
+ };
7275
+ var NORMALITY_OPTIONS = [
7276
+ {
7277
+ value: "DEBIT" /* DEBIT */,
7278
+ label: "Debit"
7279
+ },
7280
+ {
7281
+ value: "CREDIT" /* CREDIT */,
7282
+ label: "Credit"
7283
+ }
7284
+ ];
7285
+ var ASSET_LEDGER_ACCOUNT_SUBTYPES = [
7286
+ {
7287
+ value: "BANK_ACCOUNTS",
7288
+ label: "Bank Accounts"
7289
+ },
7290
+ {
7291
+ value: "ACCOUNTS_RECEIVABLE",
7292
+ label: "Accounts Receivable"
7293
+ },
7294
+ {
7295
+ value: "INVENTORY",
7296
+ label: "Inventory"
7297
+ },
7298
+ {
7299
+ value: "PAYMENT_PROCESSOR_CLEARING_ACCOUNT",
7300
+ label: "Payment Processor Clearing Accounts"
7301
+ },
7302
+ {
7303
+ value: "FIXED_ASSET",
7304
+ label: "Fixed Assets"
7305
+ },
7306
+ {
7307
+ value: "CASH",
7308
+ label: "Cash"
7309
+ },
7310
+ {
7311
+ value: "UNDEPOSITED_FUNDS",
7312
+ label: "Undeposited Funds"
7313
+ }
7314
+ ];
7315
+ var LIABILITY_LEDGER_ACCOUNT_SUBTYPES = [
7316
+ {
7317
+ value: "LIABILITY",
7318
+ label: "Liabilities"
7319
+ },
7320
+ {
7321
+ value: "ACCOUNTS_PAYABLE",
7322
+ label: "Accounts Payable"
7323
+ },
7324
+ {
7325
+ value: "CREDIT_CARD",
7326
+ label: "Credit Cards"
7327
+ },
7328
+ {
7329
+ value: "SHAREHOLDER_LOAN",
7330
+ label: "Shareholder Loans"
7331
+ },
7332
+ {
7333
+ value: "PAYROLL_LIABILITY",
7334
+ label: "Payroll Liabilities"
7335
+ },
7336
+ {
7337
+ value: "SALES_TAXES_PAYABLE",
7338
+ label: "Sales Taxes Payable"
7339
+ },
7340
+ {
7341
+ value: "LINE_OF_CREDIT",
7342
+ label: "Lines of Credit"
7343
+ },
7344
+ {
7345
+ value: "NOTES_PAYABLE",
7346
+ label: "Notes Payable"
7347
+ },
7348
+ {
7349
+ value: "TIPS",
7350
+ label: "Tips"
7351
+ },
7352
+ {
7353
+ value: "UNEARNED_REVENUE",
7354
+ label: "Unearned Revenue"
7355
+ },
7356
+ {
7357
+ value: "UNDEPOSITED_OUTFLOWS",
7358
+ label: "Undeposited Outflows"
7359
+ }
7360
+ ];
7361
+ var EQUITY_LEDGER_ACCOUNT_SUBTYPES = [
7362
+ {
7363
+ value: "CONTRIBUTIONS",
7364
+ label: "Contributions"
7365
+ },
7366
+ {
7367
+ value: "DISTRIBUTIONS",
7368
+ label: "Distributions"
7369
+ },
7370
+ {
7371
+ value: "COMMON_STOCK",
7372
+ label: "Common Stock"
7373
+ },
7374
+ {
7375
+ value: "ADDITIONAL_PAID_IN_CAPITAL",
7376
+ label: "Additional Paid In Capital"
7377
+ },
7378
+ {
7379
+ value: "RETAINED_EARNINGS",
7380
+ label: "Retained Earnings"
7381
+ },
7382
+ {
7383
+ value: "ACCUMULATED_ADJUSTMENTS",
7384
+ label: "Accumulated Adjustments"
7385
+ },
7386
+ {
7387
+ value: "OPENING_BALANCE_EQUITY",
7388
+ label: "Opening Balance Equity"
7389
+ }
7390
+ ];
7391
+ var REVENUE_LEDGER_ACCOUNT_SUBTYPES = [
7392
+ {
7393
+ value: "SALES",
7394
+ label: "Sales"
7395
+ },
7396
+ {
7397
+ value: "UNCATEGORIZED_REVENUE",
7398
+ label: "Uncategorized Revenue"
7399
+ },
7400
+ {
7401
+ value: "RETURNS_ALLOWANCES",
7402
+ label: "Returns & Allowances"
7403
+ }
7404
+ ];
7405
+ var EXPENSE_LEDGER_ACCOUNT_SUBTYPES = [
7406
+ {
7407
+ value: "COGS",
7408
+ label: "COGS"
7409
+ },
7410
+ {
7411
+ value: "OPERATING_EXPENSES",
7412
+ label: "Operating Expenses"
7413
+ },
7414
+ {
7415
+ value: "PAYROLL",
7416
+ label: "Payroll"
7417
+ },
7418
+ {
7419
+ value: "TAXES_LICENSES",
7420
+ label: "Taxes & Licenses"
7421
+ },
7422
+ {
7423
+ value: "BAD_DEBT",
7424
+ label: "Bad Debt"
7425
+ },
7426
+ {
7427
+ value: "CHARITABLE_CONTRIBUTIONS",
7428
+ label: "Charitable Contributions"
7429
+ }
7430
+ ];
7431
+ var LEDGER_ACCOUNT_SUBTYPES = [
7432
+ ...ASSET_LEDGER_ACCOUNT_SUBTYPES,
7433
+ ...LIABILITY_LEDGER_ACCOUNT_SUBTYPES,
7434
+ ...EQUITY_LEDGER_ACCOUNT_SUBTYPES,
7435
+ ...REVENUE_LEDGER_ACCOUNT_SUBTYPES,
7436
+ ...EXPENSE_LEDGER_ACCOUNT_SUBTYPES
7437
+ ];
7438
+ var LEDGER_ACCOUNT_SUBTYPES_FOR_TYPE = {
7439
+ ASSET: ASSET_LEDGER_ACCOUNT_SUBTYPES,
7440
+ LIABILITY: LIABILITY_LEDGER_ACCOUNT_SUBTYPES,
7441
+ EQUITY: EQUITY_LEDGER_ACCOUNT_SUBTYPES,
7442
+ REVENUE: REVENUE_LEDGER_ACCOUNT_SUBTYPES,
7443
+ EXPENSE: EXPENSE_LEDGER_ACCOUNT_SUBTYPES
7444
+ };
6880
7445
 
6881
7446
  // src/hooks/useChartOfAccounts/useChartOfAccounts.tsx
6882
- import { useState as useState19 } from "react";
6883
7447
  import useSWR6 from "swr";
6884
7448
  var validate = (formData) => {
6885
7449
  const errors = [];
@@ -6887,6 +7451,14 @@ var validate = (formData) => {
6887
7451
  if (nameError) {
6888
7452
  errors.push(nameError);
6889
7453
  }
7454
+ const normalityError = validateNormality(formData);
7455
+ if (normalityError) {
7456
+ errors.push(normalityError);
7457
+ }
7458
+ const typeError = validateType(formData);
7459
+ if (typeError) {
7460
+ errors.push(typeError);
7461
+ }
6890
7462
  return errors;
6891
7463
  };
6892
7464
  var revalidateField = (fieldName, formData) => {
@@ -6898,10 +7470,48 @@ var revalidateField = (fieldName, formData) => {
6898
7470
  }
6899
7471
  return (formData?.errors || []).filter((x) => x.field !== fieldName);
6900
7472
  }
7473
+ case "normality": {
7474
+ const normalityError = validateNormality(formData);
7475
+ if (normalityError) {
7476
+ return (formData?.errors || []).filter((x) => x.field !== fieldName).concat([normalityError]);
7477
+ }
7478
+ return (formData?.errors || []).filter((x) => x.field !== fieldName);
7479
+ }
7480
+ case "type": {
7481
+ const typeError = validateType(formData);
7482
+ if (typeError) {
7483
+ return (formData?.errors || []).filter((x) => x.field !== fieldName).concat([typeError]);
7484
+ }
7485
+ return (formData?.errors || []).filter((x) => x.field !== fieldName);
7486
+ }
6901
7487
  default:
6902
7488
  return formData?.errors;
6903
7489
  }
6904
7490
  };
7491
+ var validateType = (formData) => {
7492
+ if (!formData?.data.type?.value) {
7493
+ return {
7494
+ field: "type",
7495
+ message: "Must be selected"
7496
+ };
7497
+ }
7498
+ return;
7499
+ };
7500
+ var validateNormality = (formData) => {
7501
+ const stringValueNormality = formData?.data.normality?.value?.toString();
7502
+ if (stringValueNormality === void 0) {
7503
+ return {
7504
+ field: "normality",
7505
+ message: "Must be selected"
7506
+ };
7507
+ } else if (!["DEBIT", "CREDIT"].includes(stringValueNormality)) {
7508
+ return {
7509
+ field: "normality",
7510
+ message: "Must be selected"
7511
+ };
7512
+ }
7513
+ return;
7514
+ };
6905
7515
  var validateName = (formData) => {
6906
7516
  if (!formData?.data.name?.trim()) {
6907
7517
  return {
@@ -6914,9 +7524,9 @@ var validateName = (formData) => {
6914
7524
  var flattenAccounts = (accounts) => accounts.flatMap((a) => [a, flattenAccounts(a.sub_accounts || [])]).flat().filter((id) => id);
6915
7525
  var useChartOfAccounts = () => {
6916
7526
  const { auth, businessId, apiUrl } = useLayerContext();
6917
- const [form, setForm] = useState19();
6918
- const [sendingForm, setSendingForm] = useState19(false);
6919
- const [apiError, setApiError] = useState19(void 0);
7527
+ const [form, setForm] = useState21();
7528
+ const [sendingForm, setSendingForm] = useState21(false);
7529
+ const [apiError, setApiError] = useState21(void 0);
6920
7530
  const { data, isLoading, isValidating, error, mutate } = useSWR6(
6921
7531
  businessId && auth?.access_token && `chart-of-accounts-${businessId}`,
6922
7532
  Layer.getLedgerAccountBalances(apiUrl, auth?.access_token, {
@@ -6942,14 +7552,8 @@ var useChartOfAccounts = () => {
6942
7552
  const update = async (accountData, accountId) => {
6943
7553
  setSendingForm(true);
6944
7554
  setApiError(void 0);
6945
- const stable_name = convertToStableName(accountData.name);
6946
7555
  const newAccountData = {
6947
- ...accountData,
6948
- stable_name,
6949
- pnl_category: "INCOME",
6950
- //this field will be deprecated soon, but is still required
6951
- always_show_in_pnl: false
6952
- //this field will be deprecated soon, but is still required
7556
+ ...accountData
6953
7557
  };
6954
7558
  try {
6955
7559
  await Layer.updateAccount(apiUrl, auth?.access_token, {
@@ -6978,13 +7582,14 @@ var useChartOfAccounts = () => {
6978
7582
  }
6979
7583
  const data2 = {
6980
7584
  name: form.data.name ?? "",
6981
- normality: form.data.subType?.value,
7585
+ stable_name: form.data.stable_name,
6982
7586
  parent_id: form.data.parent ? {
6983
7587
  type: "AccountId",
6984
7588
  id: form.data.parent.value
6985
7589
  } : void 0,
6986
7590
  account_type: form.data.type.value.toString(),
6987
- account_subtype: form.data.subType?.value.toString()
7591
+ account_subtype: form.data.subType?.value.toString(),
7592
+ normality: form.data.normality?.value
6988
7593
  };
6989
7594
  if (form.action === "new") {
6990
7595
  create(data2);
@@ -7001,10 +7606,8 @@ var useChartOfAccounts = () => {
7001
7606
  data: {
7002
7607
  parent: void 0,
7003
7608
  name: void 0,
7004
- type: {
7005
- value: "ASSETS",
7006
- label: "Assets"
7007
- },
7609
+ type: void 0,
7610
+ normality: void 0,
7008
7611
  subType: void 0
7009
7612
  }
7010
7613
  });
@@ -7025,12 +7628,19 @@ var useChartOfAccounts = () => {
7025
7628
  value: parent.id,
7026
7629
  label: parent.name
7027
7630
  } : void 0,
7631
+ stable_name: found.stable_name,
7028
7632
  name: found.name,
7029
7633
  type: {
7030
- value: "ASSETS",
7031
- label: "Assets"
7634
+ value: found.account_type.value,
7635
+ label: found.account_type.display_name
7032
7636
  },
7033
- subType: void 0
7637
+ subType: found.account_subtype ? {
7638
+ value: found.account_subtype?.value,
7639
+ label: found.account_subtype?.display_name
7640
+ } : void 0,
7641
+ normality: NORMALITY_OPTIONS.find(
7642
+ (normalityOption) => normalityOption.value == found.normality
7643
+ )
7034
7644
  }
7035
7645
  });
7036
7646
  };
@@ -7039,13 +7649,41 @@ var useChartOfAccounts = () => {
7039
7649
  if (!form) {
7040
7650
  return;
7041
7651
  }
7042
- const newFormData = {
7652
+ let newFormData = {
7043
7653
  ...form,
7044
7654
  data: {
7045
7655
  ...form.data,
7046
7656
  [fieldName]: value
7047
7657
  }
7048
7658
  };
7659
+ if (fieldName === "parent") {
7660
+ const allAccounts = flattenAccounts(data?.data?.accounts || []);
7661
+ const foundParent = allAccounts?.find(
7662
+ (x) => x.id === value.value
7663
+ );
7664
+ if (foundParent) {
7665
+ newFormData = {
7666
+ ...newFormData,
7667
+ data: {
7668
+ ...newFormData.data,
7669
+ /* Inherit the parent's type */
7670
+ type: {
7671
+ value: foundParent.account_type.value,
7672
+ label: foundParent.account_type.display_name
7673
+ },
7674
+ /* If the parent has a subtype, inherit it */
7675
+ subType: foundParent.account_subtype ? {
7676
+ value: foundParent.account_subtype?.value,
7677
+ label: foundParent.account_subtype?.display_name
7678
+ } : void 0,
7679
+ /* Inherit the parent's normality */
7680
+ normality: NORMALITY_OPTIONS.find(
7681
+ (normalityOption) => normalityOption.value == foundParent.normality
7682
+ )
7683
+ }
7684
+ };
7685
+ }
7686
+ }
7049
7687
  const errors = revalidateField(fieldName, newFormData);
7050
7688
  setForm({
7051
7689
  ...newFormData,
@@ -7072,12 +7710,12 @@ var useChartOfAccounts = () => {
7072
7710
  };
7073
7711
 
7074
7712
  // src/hooks/useLedgerAccounts/useLedgerAccounts.tsx
7075
- import { useState as useState20 } from "react";
7713
+ import { useState as useState22 } from "react";
7076
7714
  import useSWR7 from "swr";
7077
7715
  var useLedgerAccounts = () => {
7078
7716
  const { auth, businessId, apiUrl } = useLayerContext();
7079
- const [accountId, setAccountId] = useState20();
7080
- const [selectedEntryId, setSelectedEntryId] = useState20();
7717
+ const [accountId, setAccountId] = useState22();
7718
+ const [selectedEntryId, setSelectedEntryId] = useState22();
7081
7719
  const { data, isLoading, isValidating, error, mutate } = useSWR7(
7082
7720
  businessId && accountId && auth?.access_token && `ledger-accounts-lines-${businessId}-${accountId}`,
7083
7721
  Layer.getLedgerAccountsLines(apiUrl, auth?.access_token, {
@@ -7123,7 +7761,7 @@ var useLedgerAccounts = () => {
7123
7761
  import React88, { useContext as useContext10 } from "react";
7124
7762
 
7125
7763
  // src/components/ChartOfAccountsRow/ChartOfAccountsRow.tsx
7126
- import React84, { useContext as useContext8, useEffect as useEffect13, useState as useState21 } from "react";
7764
+ import React84, { useContext as useContext8, useEffect as useEffect15, useState as useState23 } from "react";
7127
7765
 
7128
7766
  // src/icons/Edit2.tsx
7129
7767
  import * as React83 from "react";
@@ -7150,7 +7788,7 @@ var Edit2 = ({ size = 18, ...props }) => /* @__PURE__ */ React83.createElement(
7150
7788
  var Edit2_default = Edit2;
7151
7789
 
7152
7790
  // src/components/ChartOfAccountsRow/ChartOfAccountsRow.tsx
7153
- import classNames30 from "classnames";
7791
+ import classNames32 from "classnames";
7154
7792
  var INDENTATION = 24;
7155
7793
  var MOBILE_INDENTATION = 12;
7156
7794
  var EXPANDED_STYLE = {
@@ -7184,7 +7822,7 @@ var ChartOfAccountsRow = ({
7184
7822
  const { form, editAccount } = useContext8(ChartOfAccountsContext);
7185
7823
  const { setAccountId } = useContext8(LedgerAccountsContext);
7186
7824
  const baseStyle = view === "desktop" ? EXPANDED_STYLE : EXPANDED_MOBILE_STYLE;
7187
- const [isOpen, setIsOpen] = useState21(defaultOpen);
7825
+ const [isOpen, setIsOpen] = useState23(defaultOpen);
7188
7826
  const style = expanded ? {
7189
7827
  ...baseStyle,
7190
7828
  transitionDelay: `${15 * index}ms`
@@ -7192,14 +7830,14 @@ var ChartOfAccountsRow = ({
7192
7830
  ...COLLAPSED_STYLE,
7193
7831
  transitionDelay: `${acountsLength - 15 * index}ms`
7194
7832
  };
7195
- const [showComponent, setShowComponent] = useState21(false);
7196
- useEffect13(() => {
7833
+ const [showComponent, setShowComponent] = useState23(false);
7834
+ useEffect15(() => {
7197
7835
  const timeoutId = setTimeout(() => {
7198
7836
  setShowComponent(true);
7199
7837
  }, cumulativeIndex * 50);
7200
7838
  return () => clearTimeout(timeoutId);
7201
7839
  }, []);
7202
- const baseClass = classNames30(
7840
+ const baseClass = classNames32(
7203
7841
  "Layer__table-row",
7204
7842
  isOpen ? "Layer__table-row--expanded" : "Layer__table-row--collapsed",
7205
7843
  !expanded && "Layer__table-row--hidden",
@@ -7207,11 +7845,11 @@ var ChartOfAccountsRow = ({
7207
7845
  form?.accountId === account.id && "Layer__table-row--active",
7208
7846
  !showComponent && "Layer__table-row--anim-starting-state"
7209
7847
  );
7210
- const desktopRowClass = classNames30(
7848
+ const desktopRowClass = classNames32(
7211
7849
  baseClass,
7212
7850
  "Layer__chart-of-accounts__row---desktop"
7213
7851
  );
7214
- const mobileRowClass = classNames30(
7852
+ const mobileRowClass = classNames32(
7215
7853
  baseClass,
7216
7854
  "Layer__chart-of-accounts__row---mobile"
7217
7855
  );
@@ -7369,23 +8007,11 @@ var ChartOfAccountsRow = ({
7369
8007
  import React87 from "react";
7370
8008
 
7371
8009
  // src/components/ChartOfAccountsForm/ChartOfAccountsForm.tsx
7372
- import React86, { useContext as useContext9, useMemo as useMemo8 } from "react";
7373
-
7374
- // src/components/ChartOfAccountsForm/constants.ts
7375
- var SUB_TYPE_OPTIONS = [
7376
- {
7377
- value: "DEBIT" /* DEBIT */,
7378
- label: "Debit"
7379
- },
7380
- {
7381
- value: "CREDIT" /* CREDIT */,
7382
- label: "Credit"
7383
- }
7384
- ];
8010
+ import React86, { useContext as useContext9, useMemo as useMemo9 } from "react";
7385
8011
 
7386
8012
  // src/components/ChartOfAccountsForm/useParentOptions.ts
7387
- import { useMemo as useMemo7 } from "react";
7388
- var useParentOptions = (data) => useMemo7(
8013
+ import { useMemo as useMemo8 } from "react";
8014
+ var useParentOptions = (data) => useMemo8(
7389
8015
  () => flattenAccounts(data?.accounts || []).sort((a, b) => a?.name && b?.name ? a.name.localeCompare(b.name) : 0).map((x) => {
7390
8016
  return {
7391
8017
  label: x.name,
@@ -7407,7 +8033,7 @@ var ChartOfAccountsForm = () => {
7407
8033
  apiError
7408
8034
  } = useContext9(ChartOfAccountsContext);
7409
8035
  const parentOptions = useParentOptions(data);
7410
- const entry = useMemo8(() => {
8036
+ const entry = useMemo9(() => {
7411
8037
  if (form?.action === "edit" && form.accountId) {
7412
8038
  return flattenAccounts(data?.accounts || []).find(
7413
8039
  (x) => x.id === form.accountId
@@ -7486,19 +8112,33 @@ var ChartOfAccountsForm = () => {
7486
8112
  )), /* @__PURE__ */ React86.createElement(InputGroup, { name: "type", label: "Type", inline: true }, /* @__PURE__ */ React86.createElement(
7487
8113
  Select2,
7488
8114
  {
7489
- options: [],
7490
- disabled: true,
8115
+ options: LEDGER_ACCOUNT_TYPES,
7491
8116
  value: form?.data.type,
7492
- onChange: (sel) => changeFormData("type", sel)
8117
+ onChange: (sel) => changeFormData("type", sel),
8118
+ isInvalid: Boolean(form?.errors?.find((x) => x.field === "type")),
8119
+ errorMessage: form?.errors?.find((x) => x.field === "type")?.message,
8120
+ disabled: sendingForm || form.action === "edit" || form.data.parent !== void 0
7493
8121
  }
7494
8122
  )), /* @__PURE__ */ React86.createElement(InputGroup, { name: "subType", label: "Sub-Type", inline: true }, /* @__PURE__ */ React86.createElement(
7495
8123
  Select2,
7496
8124
  {
7497
- options: SUB_TYPE_OPTIONS,
8125
+ options: form?.data.type?.value !== void 0 ? LEDGER_ACCOUNT_SUBTYPES_FOR_TYPE[form?.data.type?.value] : LEDGER_ACCOUNT_SUBTYPES,
7498
8126
  value: form?.data.subType,
7499
8127
  onChange: (sel) => changeFormData("subType", sel),
7500
8128
  disabled: sendingForm
7501
8129
  }
8130
+ )), /* @__PURE__ */ React86.createElement(InputGroup, { name: "normality", label: "Normality", inline: true }, /* @__PURE__ */ React86.createElement(
8131
+ Select2,
8132
+ {
8133
+ options: NORMALITY_OPTIONS,
8134
+ value: form?.data.normality,
8135
+ isInvalid: Boolean(
8136
+ form?.errors?.find((x) => x.field === "normality")
8137
+ ),
8138
+ errorMessage: form?.errors?.find((x) => x.field === "normality")?.message,
8139
+ onChange: (sel) => changeFormData("normality", sel),
8140
+ disabled: sendingForm
8141
+ }
7502
8142
  )))
7503
8143
  );
7504
8144
  };
@@ -7580,19 +8220,19 @@ var ChartOfAccountsTable = ({
7580
8220
  // src/components/LedgerAccount/LedgerAccountIndex.tsx
7581
8221
  import React95, {
7582
8222
  useContext as useContext13,
7583
- useEffect as useEffect15,
7584
- useMemo as useMemo10,
7585
- useState as useState23
8223
+ useEffect as useEffect17,
8224
+ useMemo as useMemo11,
8225
+ useState as useState25
7586
8226
  } from "react";
7587
8227
 
7588
8228
  // src/components/LedgerAccountEntryDetails/LedgerAccountEntryDetails.tsx
7589
- import React93, { useContext as useContext11, useMemo as useMemo9 } from "react";
8229
+ import React93, { useContext as useContext11, useMemo as useMemo10 } from "react";
7590
8230
 
7591
8231
  // src/components/Card/Card.tsx
7592
8232
  import React89 from "react";
7593
- import classNames31 from "classnames";
8233
+ import classNames33 from "classnames";
7594
8234
  var Card = ({ children, className }) => {
7595
- return /* @__PURE__ */ React89.createElement("div", { className: classNames31("Layer__card", className) }, children);
8235
+ return /* @__PURE__ */ React89.createElement("div", { className: classNames33("Layer__card", className) }, children);
7596
8236
  };
7597
8237
 
7598
8238
  // src/components/DateTime/DateTime.tsx
@@ -7634,14 +8274,14 @@ var DateTime = ({
7634
8274
 
7635
8275
  // src/components/DetailsList/DetailsList.tsx
7636
8276
  import React91 from "react";
7637
- import classNames32 from "classnames";
8277
+ import classNames34 from "classnames";
7638
8278
  var DetailsList = ({
7639
8279
  title,
7640
8280
  children,
7641
8281
  className,
7642
8282
  actions
7643
8283
  }) => {
7644
- return /* @__PURE__ */ React91.createElement("div", { className: classNames32("Layer__details-list", className) }, title && /* @__PURE__ */ React91.createElement(Header, null, /* @__PURE__ */ React91.createElement(Heading, { size: "secondary" /* secondary */ }, title), actions && /* @__PURE__ */ React91.createElement("div", { className: "Layer__details-list__actions" }, actions)), /* @__PURE__ */ React91.createElement("ul", { className: "Layer__details-list__list" }, children));
8284
+ return /* @__PURE__ */ React91.createElement("div", { className: classNames34("Layer__details-list", className) }, title && /* @__PURE__ */ React91.createElement(Header, null, /* @__PURE__ */ React91.createElement(Heading, { size: "secondary" /* secondary */ }, title), actions && /* @__PURE__ */ React91.createElement("div", { className: "Layer__details-list__actions" }, actions)), /* @__PURE__ */ React91.createElement("ul", { className: "Layer__details-list__list" }, children));
7645
8285
  };
7646
8286
 
7647
8287
  // src/components/DetailsList/DetailsListItem.tsx
@@ -7697,7 +8337,7 @@ var SourceDetailView = ({ source }) => {
7697
8337
  };
7698
8338
  var LedgerAccountEntryDetails = () => {
7699
8339
  const { entryData, isLoadingEntry, closeSelectedEntry, errorEntry } = useContext11(LedgerAccountsContext);
7700
- const { totalDebit, totalCredit } = useMemo9(() => {
8340
+ const { totalDebit, totalCredit } = useMemo10(() => {
7701
8341
  let totalDebit2 = 0;
7702
8342
  let totalCredit2 = 0;
7703
8343
  entryData?.line_items?.forEach((item) => {
@@ -7722,7 +8362,7 @@ var LedgerAccountEntryDetails = () => {
7722
8362
  }
7723
8363
  )
7724
8364
  },
7725
- /* @__PURE__ */ React93.createElement(DetailsListItem, { label: "Source", isLoading: isLoadingEntry }, /* @__PURE__ */ React93.createElement(Badge, null, entryData?.source?.type)),
8365
+ /* @__PURE__ */ React93.createElement(DetailsListItem, { label: "Source", isLoading: isLoadingEntry }, /* @__PURE__ */ React93.createElement(Badge, null, entryData?.source?.entity_name)),
7726
8366
  entryData?.source?.display_description && /* @__PURE__ */ React93.createElement(SourceDetailView, { source: entryData?.source })
7727
8367
  ), /* @__PURE__ */ React93.createElement(
7728
8368
  DetailsList,
@@ -7738,8 +8378,8 @@ var LedgerAccountEntryDetails = () => {
7738
8378
  };
7739
8379
 
7740
8380
  // src/components/LedgerAccount/LedgerAccountRow.tsx
7741
- import React94, { useContext as useContext12, useEffect as useEffect14, useState as useState22 } from "react";
7742
- import classNames33 from "classnames";
8381
+ import React94, { useContext as useContext12, useEffect as useEffect16, useState as useState24 } from "react";
8382
+ import classNames35 from "classnames";
7743
8383
  import { parseISO as parseISO10, format as formatTime8 } from "date-fns";
7744
8384
  var LedgerAccountRow = ({
7745
8385
  row,
@@ -7748,8 +8388,8 @@ var LedgerAccountRow = ({
7748
8388
  view
7749
8389
  }) => {
7750
8390
  const { selectedEntryId, setSelectedEntryId, closeSelectedEntry } = useContext12(LedgerAccountsContext);
7751
- const [showComponent, setShowComponent] = useState22(false);
7752
- useEffect14(() => {
8391
+ const [showComponent, setShowComponent] = useState24(false);
8392
+ useEffect16(() => {
7753
8393
  if (initialLoad) {
7754
8394
  const timeoutId = setTimeout(() => {
7755
8395
  setShowComponent(true);
@@ -7763,7 +8403,7 @@ var LedgerAccountRow = ({
7763
8403
  return /* @__PURE__ */ React94.createElement(
7764
8404
  "tr",
7765
8405
  {
7766
- className: classNames33(
8406
+ className: classNames35(
7767
8407
  "Layer__table-row",
7768
8408
  row.entry_id === selectedEntryId && "Layer__table-row--active",
7769
8409
  initialLoad && "initial-load",
@@ -7796,7 +8436,7 @@ var LedgerAccountRow = ({
7796
8436
  return /* @__PURE__ */ React94.createElement(
7797
8437
  "tr",
7798
8438
  {
7799
- className: classNames33(
8439
+ className: classNames35(
7800
8440
  "Layer__table-row",
7801
8441
  row.entry_id === selectedEntryId && "Layer__table-row--active",
7802
8442
  initialLoad && "initial-load",
@@ -7825,7 +8465,7 @@ var LedgerAccountRow = ({
7825
8465
  return /* @__PURE__ */ React94.createElement(
7826
8466
  "tr",
7827
8467
  {
7828
- className: classNames33(
8468
+ className: classNames35(
7829
8469
  "Layer__table-row",
7830
8470
  row.entry_id === selectedEntryId && "Layer__table-row--active",
7831
8471
  initialLoad && "initial-load",
@@ -7851,14 +8491,14 @@ var LedgerAccountRow = ({
7851
8491
  };
7852
8492
 
7853
8493
  // src/components/LedgerAccount/LedgerAccountIndex.tsx
7854
- import classNames34 from "classnames";
8494
+ import classNames36 from "classnames";
7855
8495
  var LedgerAccount = ({
7856
8496
  containerRef,
7857
8497
  pageSize = 15,
7858
8498
  view
7859
8499
  }) => {
7860
- const [currentPage, setCurrentPage] = useState23(1);
7861
- const [initialLoad, setInitialLoad] = useState23(true);
8500
+ const [currentPage, setCurrentPage] = useState25(1);
8501
+ const [initialLoad, setInitialLoad] = useState25(true);
7862
8502
  const { data: accountData } = useContext13(ChartOfAccountsContext);
7863
8503
  const {
7864
8504
  data: rawData,
@@ -7871,7 +8511,7 @@ var LedgerAccount = ({
7871
8511
  closeSelectedEntry,
7872
8512
  refetch
7873
8513
  } = useContext13(LedgerAccountsContext);
7874
- useEffect15(() => {
8514
+ useEffect17(() => {
7875
8515
  if (!isLoading) {
7876
8516
  const timeoutLoad = setTimeout(() => {
7877
8517
  setInitialLoad(false);
@@ -7879,16 +8519,16 @@ var LedgerAccount = ({
7879
8519
  return () => clearTimeout(timeoutLoad);
7880
8520
  }
7881
8521
  }, [isLoading]);
7882
- const baseClassName = classNames34(
8522
+ const baseClassName = classNames36(
7883
8523
  "Layer__ledger-account__index",
7884
8524
  accountId && "open"
7885
8525
  );
7886
- const entry = useMemo10(() => {
8526
+ const entry = useMemo11(() => {
7887
8527
  return flattenAccounts(accountData?.accounts || []).find(
7888
8528
  (x) => x.id === accountId
7889
8529
  );
7890
8530
  }, [accountId]);
7891
- const data = useMemo10(() => {
8531
+ const data = useMemo11(() => {
7892
8532
  const firstPageIndex = (currentPage - 1) * pageSize;
7893
8533
  const lastPageIndex = firstPageIndex + pageSize;
7894
8534
  return rawData?.sort((a, b) => Date.parse(b.date) - Date.parse(a.date))?.slice(firstPageIndex, lastPageIndex);
@@ -8025,7 +8665,7 @@ var ChartOfAccounts = (props) => {
8025
8665
  };
8026
8666
  var ChartOfAccountsContent = ({ asWidget }) => {
8027
8667
  const { accountId } = useContext14(LedgerAccountsContext);
8028
- const [view, setView] = useState24("desktop");
8668
+ const [view, setView] = useState26("desktop");
8029
8669
  const containerRef = useElementSize((_a, _b, { width }) => {
8030
8670
  if (width) {
8031
8671
  if (width >= BREAKPOINTS.TABLET && view !== "desktop") {
@@ -8041,7 +8681,7 @@ var ChartOfAccountsContent = ({ asWidget }) => {
8041
8681
  };
8042
8682
 
8043
8683
  // src/providers/LayerProvider/LayerProvider.tsx
8044
- import React97, { useReducer, useEffect as useEffect16 } from "react";
8684
+ import React97, { useReducer, useEffect as useEffect18 } from "react";
8045
8685
  import { add as add2, isBefore } from "date-fns";
8046
8686
  import useSWR8, { SWRConfig } from "swr";
8047
8687
  var reducer = (state, action) => {
@@ -8106,7 +8746,7 @@ var LayerProvider = ({
8106
8746
  }),
8107
8747
  defaultSWRConfig
8108
8748
  ) : { data: void 0 };
8109
- useEffect16(() => {
8749
+ useEffect18(() => {
8110
8750
  if (businessAccessToken) {
8111
8751
  dispatch({
8112
8752
  type: "LayerContext.setAuth" /* setAuth */,