@layerfi/components 0.1.106-alpha → 0.1.106

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.
@@ -5603,7 +5603,7 @@ var import_react12 = require("react");
5603
5603
  var import_react10 = require("react");
5604
5604
 
5605
5605
  // package.json
5606
- var version = "0.1.106-alpha";
5606
+ var version = "0.1.106";
5607
5607
 
5608
5608
  // src/models/APIError.ts
5609
5609
  var APIError = class _APIError extends Error {
@@ -7118,48 +7118,28 @@ var _RANGE_PICKER_MODES = [
7118
7118
  var isDateRangePickerMode = (mode) => {
7119
7119
  return _RANGE_PICKER_MODES.includes(mode);
7120
7120
  };
7121
- function startOfNextDay(date) {
7122
- return (0, import_date_fns3.startOfDay)((0, import_date_fns3.addDays)(date, 1));
7123
- }
7124
7121
  function clampToPresentOrPast(date, cutoff = (0, import_date_fns3.endOfDay)(/* @__PURE__ */ new Date())) {
7125
7122
  return (0, import_date_fns3.min)([date, cutoff]);
7126
7123
  }
7127
- function withShiftedEnd(fn) {
7128
- return ({ currentStart, currentEnd, newEnd }) => {
7129
- const shiftedCurrentEnd = startOfNextDay(currentEnd);
7130
- const shiftedNewEnd = clampToPresentOrPast(startOfNextDay(newEnd), startOfNextDay(/* @__PURE__ */ new Date()));
7131
- return fn({ currentStart, shiftedCurrentEnd, shiftedNewEnd });
7132
- };
7133
- }
7134
7124
  var RANGE_MODE_LOOKUP = {
7125
+ dayPicker: {
7126
+ getStart: ({ start }) => (0, import_date_fns3.startOfMonth)(start),
7127
+ getEnd: ({ end }) => clampToPresentOrPast((0, import_date_fns3.endOfDay)(end))
7128
+ },
7135
7129
  dayRangePicker: {
7136
7130
  getStart: ({ start }) => start,
7137
- getShiftedStart: withShiftedEnd(({ currentStart, shiftedCurrentEnd, shiftedNewEnd }) => {
7138
- const fullDayCount = (0, import_date_fns3.differenceInDays)(shiftedCurrentEnd, currentStart);
7139
- return (0, import_date_fns3.subDays)(shiftedNewEnd, fullDayCount);
7140
- }),
7141
7131
  getEnd: ({ end }) => clampToPresentOrPast((0, import_date_fns3.endOfDay)(end))
7142
7132
  },
7143
7133
  monthPicker: {
7144
7134
  getStart: ({ start }) => (0, import_date_fns3.startOfMonth)(start),
7145
- getShiftedStart: withShiftedEnd(({ shiftedNewEnd }) => {
7146
- return (0, import_date_fns3.subMonths)(shiftedNewEnd, 1);
7147
- }),
7148
7135
  getEnd: ({ end }) => clampToPresentOrPast((0, import_date_fns3.endOfMonth)(end))
7149
7136
  },
7150
7137
  monthRangePicker: {
7151
7138
  getStart: ({ start }) => (0, import_date_fns3.startOfMonth)(start),
7152
- getShiftedStart: withShiftedEnd(({ currentStart, shiftedCurrentEnd, shiftedNewEnd }) => {
7153
- const fullMonthCount = (0, import_date_fns3.differenceInMonths)(shiftedCurrentEnd, currentStart);
7154
- return (0, import_date_fns3.subMonths)(shiftedNewEnd, fullMonthCount);
7155
- }),
7156
7139
  getEnd: ({ end }) => clampToPresentOrPast((0, import_date_fns3.endOfMonth)(end))
7157
7140
  },
7158
7141
  yearPicker: {
7159
7142
  getStart: ({ start }) => (0, import_date_fns3.startOfYear)(start),
7160
- getShiftedStart: withShiftedEnd(({ shiftedNewEnd }) => {
7161
- return (0, import_date_fns3.subYears)(shiftedNewEnd, 1);
7162
- }),
7163
7143
  getEnd: ({ end }) => clampToPresentOrPast((0, import_date_fns3.endOfYear)(end))
7164
7144
  }
7165
7145
  };
@@ -7175,6 +7155,12 @@ function withCorrectedRange(fn) {
7175
7155
  function buildStore() {
7176
7156
  const now = /* @__PURE__ */ new Date();
7177
7157
  return (0, import_zustand.createStore)((set2) => {
7158
+ const setDate = ({ date }) => {
7159
+ set2({
7160
+ start: RANGE_MODE_LOOKUP.dayPicker.getStart({ start: date }),
7161
+ end: RANGE_MODE_LOOKUP.dayPicker.getEnd({ end: date })
7162
+ });
7163
+ };
7178
7164
  const setDateRange = withCorrectedRange(({ start, end }) => {
7179
7165
  set2({
7180
7166
  start: RANGE_MODE_LOOKUP.dayRangePicker.getStart({ start }),
@@ -7202,9 +7188,12 @@ function buildStore() {
7202
7188
  const setRangeWithExplicitDisplayMode = ({
7203
7189
  start,
7204
7190
  end,
7205
- rangeDisplayMode
7191
+ displayMode
7206
7192
  }) => {
7207
- switch (rangeDisplayMode) {
7193
+ switch (displayMode) {
7194
+ case "dayPicker":
7195
+ setDate({ date: end });
7196
+ break;
7208
7197
  case "dayRangePicker":
7209
7198
  setDateRange({ start, end });
7210
7199
  break;
@@ -7219,8 +7208,8 @@ function buildStore() {
7219
7208
  break;
7220
7209
  default:
7221
7210
  safeAssertUnreachable({
7222
- value: rangeDisplayMode,
7223
- message: "Invalid `rangeDisplayMode`"
7211
+ value: displayMode,
7212
+ message: "Invalid `displayMode`"
7224
7213
  });
7225
7214
  }
7226
7215
  };
@@ -7228,22 +7217,7 @@ function buildStore() {
7228
7217
  start: (0, import_date_fns3.startOfMonth)(now),
7229
7218
  end: clampToPresentOrPast((0, import_date_fns3.endOfMonth)(now)),
7230
7219
  actions: {
7231
- setDate: ({ date }) => {
7232
- set2(({
7233
- start: currentStart,
7234
- end: currentEnd
7235
- }) => {
7236
- const newEnd = RANGE_MODE_LOOKUP.dayRangePicker.getEnd({ end: date });
7237
- return {
7238
- start: RANGE_MODE_LOOKUP.dayRangePicker.getShiftedStart({
7239
- currentStart,
7240
- currentEnd,
7241
- newEnd
7242
- }),
7243
- end: newEnd
7244
- };
7245
- });
7246
- },
7220
+ setDate,
7247
7221
  setRangeWithExplicitDisplayMode,
7248
7222
  setDateRange,
7249
7223
  setMonth,
@@ -12307,8 +12281,7 @@ var LinkedAccountsContent = ({
12307
12281
  asWidget,
12308
12282
  showLedgerBalance,
12309
12283
  showUnlinkItem,
12310
- showBreakConnection,
12311
- showAddAccount
12284
+ showBreakConnection
12312
12285
  }) => {
12313
12286
  const { data, addConnection } = (0, import_react48.useContext)(LinkedAccountsContext);
12314
12287
  const linkedAccountsNewAccountClassName = (0, import_classnames25.default)(
@@ -12331,7 +12304,7 @@ var LinkedAccountsContent = ({
12331
12304
  },
12332
12305
  index
12333
12306
  )),
12334
- showAddAccount && /* @__PURE__ */ (0, import_jsx_runtime78.jsx)(
12307
+ /* @__PURE__ */ (0, import_jsx_runtime78.jsx)(
12335
12308
  "div",
12336
12309
  {
12337
12310
  role: "button",
@@ -12892,6 +12865,25 @@ var highlightNextArrow = ({
12892
12865
  }
12893
12866
  return false;
12894
12867
  };
12868
+ var getDateFormat = (mode) => {
12869
+ switch (mode) {
12870
+ case "dayPicker":
12871
+ case "dayRangePicker":
12872
+ return "MMM d, yyyy";
12873
+ case "monthPicker":
12874
+ case "monthRangePicker":
12875
+ return "MMM yyyy";
12876
+ case "yearPicker":
12877
+ return "yyyy";
12878
+ case "timePicker":
12879
+ return "h:mm aa";
12880
+ default:
12881
+ unsafeAssertUnreachable({
12882
+ value: mode,
12883
+ message: "Invalid datepicker mode"
12884
+ });
12885
+ }
12886
+ };
12895
12887
  var DatePicker = (_a) => {
12896
12888
  var _b = _a, {
12897
12889
  selected,
@@ -12899,7 +12891,7 @@ var DatePicker = (_a) => {
12899
12891
  disabled,
12900
12892
  displayMode = "dayPicker",
12901
12893
  allowedModes,
12902
- dateFormat = displayMode === "monthPicker" || displayMode === "monthRangePicker" ? "MMM, yyyy" : displayMode === "timePicker" ? "h:mm aa" : "MMM d, yyyy",
12894
+ dateFormat = getDateFormat(displayMode),
12903
12895
  timeIntervals = 15,
12904
12896
  timeCaption,
12905
12897
  placeholderText: _placeholderText,
@@ -13623,11 +13615,10 @@ var LinkedAccounts = (props) => {
13623
13615
  };
13624
13616
  var LinkedAccountsComponent = ({
13625
13617
  asWidget,
13626
- elevated,
13618
+ elevated = false,
13627
13619
  showLedgerBalance = true,
13628
13620
  showUnlinkItem = false,
13629
13621
  showBreakConnection = false,
13630
- showAddAccount = true,
13631
13622
  stringOverrides
13632
13623
  }) => {
13633
13624
  const {
@@ -13662,8 +13653,7 @@ var LinkedAccountsComponent = ({
13662
13653
  asWidget,
13663
13654
  showLedgerBalance,
13664
13655
  showUnlinkItem,
13665
- showBreakConnection,
13666
- showAddAccount
13656
+ showBreakConnection
13667
13657
  }
13668
13658
  ) : null,
13669
13659
  /* @__PURE__ */ (0, import_jsx_runtime93.jsx)(OpeningBalanceModal, {})
@@ -16455,6 +16445,7 @@ function buildCustomPlaceholder({ placeholder }) {
16455
16445
  } = _b, restProps = __objRest(_b, [
16456
16446
  "children"
16457
16447
  ]);
16448
+ if (!placeholder) return null;
16458
16449
  return /* @__PURE__ */ (0, import_jsx_runtime118.jsx)(
16459
16450
  import_react_select4.components.Placeholder,
16460
16451
  __spreadProps(__spreadValues({}, restProps), {
@@ -21562,7 +21553,7 @@ var HEADER_HEIGHT = 41;
21562
21553
  var CONTAINER_HEIGHT = ROW_HEIGHT * MAX_NUM_ROWS + HEADER_HEIGHT - 1;
21563
21554
  var CSS_PREFIX = "Layer__csv-upload__validate-csv-table";
21564
21555
  function ValidateCsvTable({ data, headers, formatters: formatters2, className }) {
21565
- const columns2 = (0, import_react107.useMemo)(
21556
+ const columns = (0, import_react107.useMemo)(
21566
21557
  () => {
21567
21558
  const columnDefs = [{
21568
21559
  id: "row",
@@ -21616,7 +21607,7 @@ function ValidateCsvTable({ data, headers, formatters: formatters2, className })
21616
21607
  }), []);
21617
21608
  const table = (0, import_react_table.useReactTable)({
21618
21609
  data,
21619
- columns: columns2,
21610
+ columns,
21620
21611
  state,
21621
21612
  getCoreRowModel: (0, import_react_table.getCoreRowModel)(),
21622
21613
  getSortedRowModel: (0, import_react_table.getSortedRowModel)()
@@ -22875,12 +22866,11 @@ var Integrations = (props) => {
22875
22866
  return /* @__PURE__ */ (0, import_jsx_runtime190.jsx)(QuickbooksContextProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime190.jsx)(IntegrationsComponent, __spreadValues({}, props)) });
22876
22867
  };
22877
22868
  var IntegrationsComponent = ({
22878
- elevated,
22879
22869
  stringOverrides
22880
22870
  }) => {
22881
22871
  const { quickbooksConnectionStatus } = (0, import_react123.useContext)(QuickbooksContext);
22882
22872
  const isLoading = quickbooksConnectionStatus === void 0;
22883
- return /* @__PURE__ */ (0, import_jsx_runtime190.jsxs)(Container, { name: COMPONENT_NAME3, elevated, children: [
22873
+ return /* @__PURE__ */ (0, import_jsx_runtime190.jsxs)(Container, { name: COMPONENT_NAME3, children: [
22884
22874
  /* @__PURE__ */ (0, import_jsx_runtime190.jsxs)(Header, { className: "Layer__linked-accounts__header", children: [
22885
22875
  /* @__PURE__ */ (0, import_jsx_runtime190.jsx)(
22886
22876
  Heading,
@@ -23212,6 +23202,7 @@ var defaultModeByReport = {
23212
23202
  };
23213
23203
  var ReportsModeStoreContext = (0, import_react127.createContext)(
23214
23204
  (0, import_zustand3.createStore)(() => ({
23205
+ resetPnLModeToDefaultOnMount: true,
23215
23206
  modeByReport: {},
23216
23207
  actions: {
23217
23208
  setModeForReport: () => {
@@ -23219,6 +23210,10 @@ var ReportsModeStoreContext = (0, import_react127.createContext)(
23219
23210
  }
23220
23211
  }))
23221
23212
  );
23213
+ function useReportModeStore() {
23214
+ const store = (0, import_react127.useContext)(ReportsModeStoreContext);
23215
+ return (0, import_zustand3.useStore)(store);
23216
+ }
23222
23217
  function useReportMode(report) {
23223
23218
  const store = (0, import_react127.useContext)(ReportsModeStoreContext);
23224
23219
  return (0, import_zustand3.useStore)(store, (state) => state.modeByReport[report]);
@@ -23234,11 +23229,13 @@ function useReportModeWithFallback(report, fallback) {
23234
23229
  }
23235
23230
  function ReportsModeStoreProvider({
23236
23231
  children,
23237
- initialModes
23232
+ initialModes,
23233
+ resetPnLModeToDefaultOnMount = true
23238
23234
  }) {
23239
23235
  const [store] = (0, import_react127.useState)(
23240
23236
  () => (0, import_zustand3.createStore)((set2) => ({
23241
23237
  modeByReport: __spreadValues(__spreadValues({}, defaultModeByReport), initialModes),
23238
+ resetPnLModeToDefaultOnMount,
23242
23239
  actions: {
23243
23240
  setModeForReport: (report, mode) => set2((state) => ({
23244
23241
  modeByReport: __spreadProps(__spreadValues({}, state.modeByReport), {
@@ -24633,21 +24630,11 @@ function useGlobalDateRangePicker({ displayMode, setDisplayMode }) {
24633
24630
  setDisplayMode(newMode);
24634
24631
  }
24635
24632
  }, [setDisplayMode]);
24636
- const { dateFormat, dateOrDateRange } = (0, import_react132.useMemo)(() => {
24633
+ const dateOrDateRange = (0, import_react132.useMemo)(() => {
24637
24634
  if (displayMode === "monthPicker") {
24638
- return {
24639
- dateOrDateRange: start,
24640
- dateFormat: void 0
24641
- };
24635
+ return start;
24642
24636
  }
24643
- return {
24644
- /*
24645
- * This intentionally needs to be cast to a mutable array. The `DatePicker`
24646
- * component should accept a readonly array, but that refactor is out of scope.
24647
- */
24648
- dateOrDateRange: [start, end],
24649
- dateFormat: "MMM d"
24650
- };
24637
+ return [start, end];
24651
24638
  }, [
24652
24639
  start,
24653
24640
  end,
@@ -24656,10 +24643,9 @@ function useGlobalDateRangePicker({ displayMode, setDisplayMode }) {
24656
24643
  const onChangeDateOrDateRange = (0, import_react132.useCallback)((dates) => {
24657
24644
  var _a;
24658
24645
  const dateProps = dates instanceof Date ? { start: dates, end: dates } : { start: dates[0], end: (_a = dates[1]) != null ? _a : dates[0] };
24659
- setRangeWithExplicitDisplayMode(__spreadProps(__spreadValues({}, dateProps), { rangeDisplayMode: displayMode }));
24646
+ setRangeWithExplicitDisplayMode(__spreadProps(__spreadValues({}, dateProps), { displayMode }));
24660
24647
  }, [displayMode, setRangeWithExplicitDisplayMode]);
24661
24648
  return {
24662
- dateFormat,
24663
24649
  rangeDisplayMode: displayMode,
24664
24650
  onChangeMode,
24665
24651
  dateOrDateRange,
@@ -24677,24 +24663,24 @@ var ProfitAndLossDatePicker = ({
24677
24663
  const isMounted = (0, import_react133.useRef)(false);
24678
24664
  const { business } = useLayerContext();
24679
24665
  const displayMode = useReportModeWithFallback("ProfitAndLoss" /* ProfitAndLoss */, "monthPicker");
24666
+ const { resetPnLModeToDefaultOnMount } = useReportModeStore();
24680
24667
  const { setModeForReport } = useReportModeActions();
24681
24668
  const setDisplayMode = (0, import_react133.useCallback)((mode) => {
24682
24669
  setModeForReport("ProfitAndLoss" /* ProfitAndLoss */, mode);
24683
24670
  }, [setModeForReport]);
24684
24671
  (0, import_react133.useEffect)(() => {
24685
24672
  const initialDatePickerMode = getInitialDateRangePickerMode({ allowedDatePickerModes, defaultDatePickerMode });
24686
- if (!isMounted.current && displayMode !== initialDatePickerMode) {
24673
+ if (!isMounted.current && resetPnLModeToDefaultOnMount && displayMode !== initialDatePickerMode) {
24687
24674
  setDisplayMode(initialDatePickerMode);
24688
24675
  }
24689
24676
  isMounted.current = true;
24690
- }, [allowedDatePickerModes, defaultDatePickerMode, displayMode, setDisplayMode]);
24677
+ }, [resetPnLModeToDefaultOnMount, allowedDatePickerModes, defaultDatePickerMode, displayMode, setDisplayMode]);
24691
24678
  const cleanedAllowedModes = getAllowedDateRangePickerModes({ allowedDatePickerModes, defaultDatePickerMode });
24692
24679
  const {
24693
24680
  rangeDisplayMode,
24694
24681
  onChangeMode,
24695
24682
  dateOrDateRange,
24696
- onChangeDateOrDateRange,
24697
- dateFormat
24683
+ onChangeDateOrDateRange
24698
24684
  } = useGlobalDateRangePicker({ displayMode, setDisplayMode });
24699
24685
  const minDate = getEarliestDateToBrowse(business);
24700
24686
  return /* @__PURE__ */ (0, import_jsx_runtime198.jsx)(
@@ -24708,7 +24694,6 @@ var ProfitAndLossDatePicker = ({
24708
24694
  slots: {
24709
24695
  ModeSelector: DatePickerModeSelector
24710
24696
  },
24711
- dateFormat,
24712
24697
  customDateRanges,
24713
24698
  minDate
24714
24699
  }
@@ -27450,7 +27435,6 @@ function StatementOfCashFlowDatePicker({
27450
27435
  setModeForReport("StatementOfCashFlows" /* StatementOfCashFlows */, mode);
27451
27436
  }, [setModeForReport]);
27452
27437
  const {
27453
- dateFormat,
27454
27438
  rangeDisplayMode,
27455
27439
  onChangeMode,
27456
27440
  dateOrDateRange,
@@ -27469,7 +27453,6 @@ function StatementOfCashFlowDatePicker({
27469
27453
  slots: {
27470
27454
  ModeSelector: DatePickerModeSelector
27471
27455
  },
27472
- dateFormat,
27473
27456
  customDateRanges,
27474
27457
  minDate
27475
27458
  }
@@ -29510,7 +29493,7 @@ var DetailsListItem = ({
29510
29493
  }) => {
29511
29494
  return /* @__PURE__ */ (0, import_jsx_runtime250.jsxs)("li", { className: "Layer__details-list-item", children: [
29512
29495
  /* @__PURE__ */ (0, import_jsx_runtime250.jsx)("label", { className: "Layer__details-list-item__label", children: label }),
29513
- /* @__PURE__ */ (0, import_jsx_runtime250.jsx)("span", { className: "Layer__details-list-item__value", children: isLoading ? /* @__PURE__ */ (0, import_jsx_runtime250.jsx)(SkeletonLoader, {}) : renderValue(children) })
29496
+ /* @__PURE__ */ (0, import_jsx_runtime250.jsx)("div", { className: "Layer__details-list-item__value", children: isLoading ? /* @__PURE__ */ (0, import_jsx_runtime250.jsx)(SkeletonLoader, {}) : renderValue(children) })
29514
29497
  ] });
29515
29498
  };
29516
29499
 
@@ -30630,7 +30613,10 @@ var JournalEntryDetails = () => {
30630
30613
  /* @__PURE__ */ (0, import_jsx_runtime255.jsxs)(
30631
30614
  DetailsList,
30632
30615
  {
30633
- title: `Journal Entry ${entry ? entryNumber(entry) : ""}`,
30616
+ title: /* @__PURE__ */ (0, import_jsx_runtime255.jsxs)(VStack, { children: [
30617
+ /* @__PURE__ */ (0, import_jsx_runtime255.jsx)(Span, { children: "Journal Entry" }),
30618
+ entry && /* @__PURE__ */ (0, import_jsx_runtime255.jsx)(Span, { variant: "subtle", size: "xs", children: `Journal ID #${entryNumber(entry)}` })
30619
+ ] }),
30634
30620
  className: "Layer__border-top",
30635
30621
  children: [
30636
30622
  /* @__PURE__ */ (0, import_jsx_runtime255.jsx)(DetailsListItem, { label: "Entry type", isLoading: isLoadingEntry, children: humanizeEnum((_c = entry == null ? void 0 : entry.entry_type) != null ? _c : "") }),
@@ -34444,7 +34430,6 @@ var BookkeepingOverview = ({
34444
34430
  {
34445
34431
  name: "bookkeeping-overview-profit-and-loss",
34446
34432
  asWidget: true,
34447
- elevated: true,
34448
34433
  style: {
34449
34434
  position: "relative",
34450
34435
  zIndex: 2
@@ -34582,7 +34567,6 @@ var AccountingOverview = ({
34582
34567
  {
34583
34568
  name: "accounting-overview-profit-and-loss",
34584
34569
  asWidget: true,
34585
- elevated: true,
34586
34570
  children: [
34587
34571
  /* @__PURE__ */ (0, import_jsx_runtime302.jsx)(
34588
34572
  ProfitAndLoss.Header,
@@ -34669,7 +34653,7 @@ var BankTransactionsWithLinkedAccounts = ({
34669
34653
  title,
34670
34654
  // deprecated
34671
34655
  showTitle = true,
34672
- elevatedLinkedAccounts = true,
34656
+ elevatedLinkedAccounts = false,
34673
34657
  mode,
34674
34658
  showBreakConnection = false,
34675
34659
  showCustomerVendor = false,
@@ -34680,7 +34664,6 @@ var BankTransactionsWithLinkedAccounts = ({
34680
34664
  showTooltips = false,
34681
34665
  showUnlinkItem = false,
34682
34666
  showUploadOptions = false,
34683
- showAddAccount = true,
34684
34667
  mobileComponent,
34685
34668
  stringOverrides
34686
34669
  }) => {
@@ -34697,7 +34680,6 @@ var BankTransactionsWithLinkedAccounts = ({
34697
34680
  showLedgerBalance,
34698
34681
  showUnlinkItem,
34699
34682
  showBreakConnection,
34700
- showAddAccount,
34701
34683
  stringOverrides: stringOverrides == null ? void 0 : stringOverrides.linkedAccounts
34702
34684
  }
34703
34685
  ),
@@ -37052,7 +37034,7 @@ var Reports = ({
37052
37034
  onChange: (opt) => setActiveTab(opt.target.value)
37053
37035
  }
37054
37036
  ) }),
37055
- /* @__PURE__ */ (0, import_jsx_runtime325.jsx)(Container, { name: "reports", ref: containerRef, children: /* @__PURE__ */ (0, import_jsx_runtime325.jsx)(ReportsModeStoreProvider, { initialModes, children: /* @__PURE__ */ (0, import_jsx_runtime325.jsx)(ProfitAndLoss, { asContainer: false, comparisonConfig, withReportsModeProvider: false, children: /* @__PURE__ */ (0, import_jsx_runtime325.jsx)(
37037
+ /* @__PURE__ */ (0, import_jsx_runtime325.jsx)(Container, { name: "reports", ref: containerRef, children: /* @__PURE__ */ (0, import_jsx_runtime325.jsx)(ReportsModeStoreProvider, { initialModes, resetPnLModeToDefaultOnMount: false, children: /* @__PURE__ */ (0, import_jsx_runtime325.jsx)(ProfitAndLoss, { asContainer: false, comparisonConfig, withReportsModeProvider: false, children: /* @__PURE__ */ (0, import_jsx_runtime325.jsx)(
37056
37038
  ReportsPanel,
37057
37039
  {
37058
37040
  openReport: activeTab,
@@ -37188,31 +37170,387 @@ var Components = ({
37188
37170
  ] });
37189
37171
  };
37190
37172
 
37191
- // src/components/Invoices/InvoicesTable.tsx
37192
- var import_react224 = require("react");
37173
+ // src/components/Invoices/Invoices.tsx
37174
+ var import_react238 = require("react");
37193
37175
 
37194
- // src/features/invoices/api/useListInvoices.tsx
37195
- var import_infinite7 = __toESM(require("swr/infinite"));
37176
+ // src/components/Invoices/InvoiceDetail/InvoiceDetail.tsx
37177
+ var import_react232 = require("react");
37178
+
37179
+ // src/components/BaseDetailView/BaseDetailView.tsx
37180
+ var import_jsx_runtime327 = require("react/jsx-runtime");
37181
+ var BaseDetailView = ({ name, onGoBack, slots, children }) => {
37182
+ const { Header: Header6 } = slots;
37183
+ return /* @__PURE__ */ (0, import_jsx_runtime327.jsxs)(Container, { name, className: "Layer__BaseDetailView", children: [
37184
+ /* @__PURE__ */ (0, import_jsx_runtime327.jsxs)(HStack, { align: "center", gap: "md", className: "Layer__BaseDetailView__Header", children: [
37185
+ /* @__PURE__ */ (0, import_jsx_runtime327.jsx)(Button2, { variant: "outlined", icon: true, onPress: onGoBack, children: /* @__PURE__ */ (0, import_jsx_runtime327.jsx)(BackArrow_default, {}) }),
37186
+ /* @__PURE__ */ (0, import_jsx_runtime327.jsx)(Header6, {})
37187
+ ] }),
37188
+ children
37189
+ ] });
37190
+ };
37191
+
37192
+ // src/components/Invoices/InvoiceForm/useInvoiceForm.ts
37193
+ var import_react230 = require("react");
37194
+ var import_react_form7 = require("@tanstack/react-form");
37195
+
37196
+ // src/features/forms/hooks/useForm.tsx
37197
+ var import_react_form6 = require("@tanstack/react-form");
37198
+
37199
+ // src/components/ui/Form/Form.tsx
37196
37200
  var import_react220 = require("react");
37197
- var import_lodash6 = __toESM(require_lodash());
37198
- var import_effect11 = require("effect");
37201
+ var import_react_aria_components14 = require("react-aria-components");
37202
+ var import_classnames88 = __toESM(require("classnames"));
37203
+ var import_jsx_runtime328 = require("react/jsx-runtime");
37204
+ var FORM_CLASS_NAME = "Layer__UI__Form";
37205
+ var Form = (0, import_react220.forwardRef)(
37206
+ function Form2(_a, ref) {
37207
+ var _b = _a, { children, className } = _b, restProps = __objRest(_b, ["children", "className"]);
37208
+ return /* @__PURE__ */ (0, import_jsx_runtime328.jsx)(import_react_aria_components14.Form, __spreadProps(__spreadValues({}, restProps), { className: (0, import_classnames88.default)(FORM_CLASS_NAME, className), ref, children }));
37209
+ }
37210
+ );
37211
+ var TEXT_FIELD_CLASS_NAME = "Layer__UI__TextField";
37212
+ var TextField = (0, import_react220.forwardRef)(
37213
+ function TextField2(_a, ref) {
37214
+ var _b = _a, { children, inline, textarea, className } = _b, restProps = __objRest(_b, ["children", "inline", "textarea", "className"]);
37215
+ const dataProperties = toDataProperties({ inline, textarea });
37216
+ return /* @__PURE__ */ (0, import_jsx_runtime328.jsx)(import_react_aria_components14.TextField, __spreadProps(__spreadValues(__spreadValues({}, restProps), dataProperties), { className: (0, import_classnames88.default)(TEXT_FIELD_CLASS_NAME, className), ref, children: withRenderProp(children, (node) => node) }));
37217
+ }
37218
+ );
37219
+ var FIELD_ERROR_CLASS_NAME = "Layer__UI__FieldError";
37220
+ var FieldError = (0, import_react220.forwardRef)(
37221
+ function FieldError2({ children }, ref) {
37222
+ return /* @__PURE__ */ (0, import_jsx_runtime328.jsx)(import_react_aria_components14.FieldError, { className: FIELD_ERROR_CLASS_NAME, ref, children: withRenderProp(children, (node) => node) });
37223
+ }
37224
+ );
37199
37225
 
37200
- // src/types/utility/pagination.ts
37226
+ // src/features/forms/components/BaseFormTextField.tsx
37227
+ var import_jsx_runtime329 = require("react/jsx-runtime");
37228
+ function BaseFormTextField({
37229
+ label,
37230
+ className,
37231
+ inline = false,
37232
+ showLabel = true,
37233
+ showFieldError = true,
37234
+ isTextArea = false,
37235
+ children
37236
+ }) {
37237
+ const field = useFieldContext();
37238
+ const { name, state } = field;
37239
+ const { meta } = state;
37240
+ const { errors, isValid: isValid2 } = meta;
37241
+ const errorMessage = errors.length !== 0 ? errors[0] : void 0;
37242
+ const shouldShowErrorMessage = showFieldError && errorMessage;
37243
+ const additionalAriaProps = !showLabel && { "aria-label": label };
37244
+ return /* @__PURE__ */ (0, import_jsx_runtime329.jsxs)(TextField, __spreadProps(__spreadValues({ name, isInvalid: !isValid2, inline, className, textarea: isTextArea }, additionalAriaProps), { children: [
37245
+ showLabel && /* @__PURE__ */ (0, import_jsx_runtime329.jsx)(Label, __spreadProps(__spreadValues({ size: "sm", htmlFor: name }, !inline && { pbe: "3xs" }), { children: label })),
37246
+ children,
37247
+ shouldShowErrorMessage && /* @__PURE__ */ (0, import_jsx_runtime329.jsx)(FieldError, { children: errorMessage })
37248
+ ] }));
37249
+ }
37250
+
37251
+ // src/features/forms/components/FormBigDecimalField.tsx
37252
+ var import_react223 = require("react");
37253
+
37254
+ // src/components/ui/Input/InputGroup.tsx
37255
+ var import_react221 = require("react");
37256
+ var import_react_aria_components15 = require("react-aria-components");
37257
+ var import_jsx_runtime330 = require("react/jsx-runtime");
37258
+ var INPUT_GROUP_CLASS_NAME = "Layer__InputGroup";
37259
+ var InputGroup2 = (0, import_react221.forwardRef)(
37260
+ function InputGroup3(_a, ref) {
37261
+ var _b = _a, { actionCount } = _b, restProps = __objRest(_b, ["actionCount"]);
37262
+ const dataProperties = toDataProperties({ "action-count": actionCount });
37263
+ return /* @__PURE__ */ (0, import_jsx_runtime330.jsx)(
37264
+ import_react_aria_components15.Group,
37265
+ __spreadProps(__spreadValues(__spreadValues({}, restProps), dataProperties), {
37266
+ className: INPUT_GROUP_CLASS_NAME,
37267
+ ref
37268
+ })
37269
+ );
37270
+ }
37271
+ );
37272
+
37273
+ // src/features/forms/components/FormBigDecimalField.tsx
37274
+ var import_effect10 = require("effect");
37275
+
37276
+ // src/components/ui/Input/Input.tsx
37277
+ var import_react222 = require("react");
37278
+ var import_react_aria_components16 = require("react-aria-components");
37279
+ var import_jsx_runtime331 = require("react/jsx-runtime");
37280
+ var INPUT_CLASS_NAME = "Layer__UI__Input";
37281
+ var Input2 = (0, import_react222.forwardRef)(
37282
+ function Input3(_a, ref) {
37283
+ var _b = _a, { inset, placement } = _b, restProps = __objRest(_b, ["inset", "placement"]);
37284
+ const dataProperties = toDataProperties({ inset, placement });
37285
+ return /* @__PURE__ */ (0, import_jsx_runtime331.jsx)(
37286
+ import_react_aria_components16.Input,
37287
+ __spreadProps(__spreadValues(__spreadValues({}, restProps), dataProperties), {
37288
+ className: INPUT_CLASS_NAME,
37289
+ ref
37290
+ })
37291
+ );
37292
+ }
37293
+ );
37294
+
37295
+ // src/utils/bigDecimalUtils.ts
37201
37296
  var import_effect9 = require("effect");
37202
- var PaginatedResponseMetaSchema = import_effect9.Schema.Struct({
37203
- cursor: import_effect9.Schema.NullOr(import_effect9.Schema.String),
37204
- hasMore: (0, import_effect9.pipe)(
37205
- import_effect9.Schema.propertySignature(import_effect9.Schema.Boolean),
37206
- import_effect9.Schema.fromKey("has_more")
37207
- ),
37208
- totalCount: (0, import_effect9.pipe)(
37209
- import_effect9.Schema.propertySignature(import_effect9.Schema.UndefinedOr(import_effect9.Schema.Number)),
37210
- import_effect9.Schema.fromKey("total_count")
37211
- )
37297
+ var BIG_DECIMAL_ZERO = import_effect9.BigDecimal.fromBigInt(BigInt(0));
37298
+ var BIG_DECIMAL_ONE = import_effect9.BigDecimal.fromBigInt(BigInt(1));
37299
+ var BIG_DECIMAL_ONE_HUNDRED = import_effect9.BigDecimal.fromBigInt(BigInt(100));
37300
+ var DECIMAL_CHARS_REGEX = /^[\d.,-]+$/;
37301
+ var NON_NEGATIVE_DECIMAL_CHARS_REGEX = /^[\d.,]+$/;
37302
+ var convertBigDecimalToCents = (amount) => {
37303
+ const scaled = import_effect9.BigDecimal.multiply(amount, BIG_DECIMAL_ONE_HUNDRED);
37304
+ const rounded = import_effect9.BigDecimal.round(scaled, { scale: 0 });
37305
+ return Number(rounded.value);
37306
+ };
37307
+ var convertCentsToBigDecimal = (cents) => {
37308
+ const decimalCents = import_effect9.BigDecimal.fromBigInt(BigInt(cents));
37309
+ return import_effect9.BigDecimal.unsafeDivide(decimalCents, BIG_DECIMAL_ONE_HUNDRED);
37310
+ };
37311
+ function formatBigDecimalToString(value, maxDecimalPlaces = 10) {
37312
+ const normalizedBigDecimal = import_effect9.BigDecimal.normalize(value);
37313
+ const formatter2 = new Intl.NumberFormat(
37314
+ "en-US",
37315
+ {
37316
+ minimumFractionDigits: 0,
37317
+ maximumFractionDigits: maxDecimalPlaces
37318
+ }
37319
+ );
37320
+ let decimalAsNumber = 0;
37321
+ try {
37322
+ decimalAsNumber = import_effect9.BigDecimal.unsafeToNumber(normalizedBigDecimal);
37323
+ } catch (e) {
37324
+ }
37325
+ return formatter2.format(decimalAsNumber);
37326
+ }
37327
+
37328
+ // src/features/forms/components/FormBigDecimalField.tsx
37329
+ var import_jsx_runtime332 = require("react/jsx-runtime");
37330
+ var DEFAULT_MAX_INPUT_LENGTH = 10;
37331
+ function FormBigDecimalField(_a) {
37332
+ var _b = _a, {
37333
+ maxInputLength = DEFAULT_MAX_INPUT_LENGTH,
37334
+ allowNegative = false
37335
+ } = _b, restProps = __objRest(_b, [
37336
+ "maxInputLength",
37337
+ "allowNegative"
37338
+ ]);
37339
+ const field = useFieldContext();
37340
+ const { name, state, handleChange, handleBlur } = field;
37341
+ const { value } = state;
37342
+ const [inputValue, setInputValue] = (0, import_react223.useState)(formatBigDecimalToString(value, maxInputLength));
37343
+ const onInputChange = (0, import_react223.useCallback)((e) => {
37344
+ setInputValue(e.target.value);
37345
+ }, []);
37346
+ const onInputBlur = (0, import_react223.useCallback)(() => {
37347
+ const cleaned = inputValue.replace(/,/g, "");
37348
+ const maybeDecimal = import_effect10.BigDecimal.fromString(cleaned);
37349
+ const decimal = import_effect10.Option.match(maybeDecimal, {
37350
+ onNone: () => BIG_DECIMAL_ZERO,
37351
+ onSome: (amount) => amount
37352
+ });
37353
+ const normalizedDecimal = import_effect10.BigDecimal.normalize(decimal);
37354
+ handleChange(normalizedDecimal);
37355
+ handleBlur();
37356
+ setInputValue(formatBigDecimalToString(normalizedDecimal, maxInputLength));
37357
+ }, [inputValue, handleBlur, handleChange, maxInputLength]);
37358
+ const allowedChars = (0, import_react223.useMemo)(
37359
+ () => allowNegative ? DECIMAL_CHARS_REGEX : NON_NEGATIVE_DECIMAL_CHARS_REGEX,
37360
+ [allowNegative]
37361
+ );
37362
+ const onBeforeInput = (0, import_react223.useCallback)((e) => {
37363
+ if (e.data && !allowedChars.test(e.data)) {
37364
+ e.preventDefault();
37365
+ }
37366
+ }, [allowedChars]);
37367
+ const onPaste = (0, import_react223.useCallback)((e) => {
37368
+ const pastedText = e.clipboardData.getData("text");
37369
+ if (!allowedChars.test(pastedText)) {
37370
+ e.preventDefault();
37371
+ }
37372
+ }, [allowedChars]);
37373
+ (0, import_react223.useEffect)(() => {
37374
+ setInputValue(formatBigDecimalToString(value, maxInputLength));
37375
+ }, [value, maxInputLength]);
37376
+ return /* @__PURE__ */ (0, import_jsx_runtime332.jsx)(BaseFormTextField, __spreadProps(__spreadValues({}, restProps), { inputMode: "decimal", children: /* @__PURE__ */ (0, import_jsx_runtime332.jsx)(InputGroup2, { children: /* @__PURE__ */ (0, import_jsx_runtime332.jsx)(
37377
+ Input2,
37378
+ {
37379
+ inset: true,
37380
+ id: name,
37381
+ name,
37382
+ value: inputValue,
37383
+ onChange: onInputChange,
37384
+ onBlur: onInputBlur,
37385
+ maxLength: maxInputLength,
37386
+ onBeforeInput,
37387
+ onPaste
37388
+ }
37389
+ ) }) }));
37390
+ }
37391
+
37392
+ // src/features/forms/components/FormCheckboxField.tsx
37393
+ var import_react224 = require("react");
37394
+ var import_classnames89 = __toESM(require("classnames"));
37395
+ var import_jsx_runtime333 = require("react/jsx-runtime");
37396
+ var FORM_CHECKBOX_FIELD_CLASSNAME = "Layer__FormCheckboxField";
37397
+ function FormCheckboxField({
37398
+ label,
37399
+ className,
37400
+ inline = false,
37401
+ showLabel = true,
37402
+ showErrorInTooltip = true
37403
+ }) {
37404
+ const field = useFieldContext();
37405
+ const { name, state, handleChange, handleBlur } = field;
37406
+ const { meta, value } = state;
37407
+ const { errors, isValid: isValid2 } = meta;
37408
+ const errorMessage = errors.length !== 0 ? errors[0] : void 0;
37409
+ const tooltipProps = showErrorInTooltip ? { tooltip: errorMessage } : {};
37410
+ const additionalAriaProps = !showLabel && { "aria-label": label };
37411
+ const checkboxClassNames = (0, import_classnames89.default)(
37412
+ FORM_CHECKBOX_FIELD_CLASSNAME,
37413
+ inline && `${FORM_CHECKBOX_FIELD_CLASSNAME}--inline`,
37414
+ className
37415
+ );
37416
+ const onChange = (0, import_react224.useCallback)((isSelected) => {
37417
+ handleChange(isSelected);
37418
+ }, [handleChange]);
37419
+ return /* @__PURE__ */ (0, import_jsx_runtime333.jsx)(
37420
+ CheckboxWithTooltip,
37421
+ __spreadProps(__spreadValues(__spreadValues(__spreadValues({
37422
+ className: checkboxClassNames,
37423
+ isSelected: value,
37424
+ isInvalid: !isValid2,
37425
+ onChange,
37426
+ onBlur: handleBlur,
37427
+ name,
37428
+ value: name,
37429
+ size: "lg"
37430
+ }, tooltipProps), additionalAriaProps), !isValid2 && { variant: "error" }), {
37431
+ children: showLabel && /* @__PURE__ */ (0, import_jsx_runtime333.jsx)(Label, { slot: "label", size: "sm", htmlFor: name, children: label })
37432
+ })
37433
+ );
37434
+ }
37435
+
37436
+ // src/features/forms/components/FormCurrencyField.tsx
37437
+ var import_react225 = require("react");
37438
+ var import_react_currency_input_field2 = __toESM(require("react-currency-input-field"));
37439
+ var import_effect11 = require("effect");
37440
+ var import_jsx_runtime334 = require("react/jsx-runtime");
37441
+ var ZERO_CENTS_INPUT_VALUE = "0.00";
37442
+ var getCurrencyInputValueFromCents = (cents) => !Number.isNaN(cents) ? centsToDollarsWithoutCommas(cents) : ZERO_CENTS_INPUT_VALUE;
37443
+ function FormCurrencyField(props) {
37444
+ const field = useFieldContext();
37445
+ const { label } = props;
37446
+ const { name, state, handleChange, handleBlur } = field;
37447
+ const { value } = state;
37448
+ const [inputValue, setInputValue] = (0, import_react225.useState)(getCurrencyInputValueFromCents(value));
37449
+ const onInputChange = (0, import_react225.useCallback)((newValue) => {
37450
+ setInputValue(newValue != null ? newValue : ZERO_CENTS_INPUT_VALUE);
37451
+ }, []);
37452
+ const onInputBlur = (0, import_react225.useCallback)(() => {
37453
+ const maybeAmount = import_effect11.BigDecimal.fromString(inputValue);
37454
+ const cents = import_effect11.Option.match(maybeAmount, {
37455
+ onNone: () => 0,
37456
+ onSome: (amount) => convertBigDecimalToCents(amount)
37457
+ });
37458
+ handleChange(cents);
37459
+ handleBlur();
37460
+ setInputValue(getCurrencyInputValueFromCents(cents));
37461
+ }, [inputValue, handleChange, handleBlur]);
37462
+ (0, import_react225.useEffect)(() => {
37463
+ setInputValue(getCurrencyInputValueFromCents(value));
37464
+ }, [value]);
37465
+ return /* @__PURE__ */ (0, import_jsx_runtime334.jsx)(BaseFormTextField, __spreadProps(__spreadValues({}, props), { children: /* @__PURE__ */ (0, import_jsx_runtime334.jsx)(InputGroup2, { children: /* @__PURE__ */ (0, import_jsx_runtime334.jsx)(
37466
+ import_react_currency_input_field2.default,
37467
+ {
37468
+ name,
37469
+ intlConfig: {
37470
+ locale: "en-US",
37471
+ currency: "USD"
37472
+ },
37473
+ prefix: "$",
37474
+ decimalScale: 2,
37475
+ decimalsLimit: 2,
37476
+ disableAbbreviations: true,
37477
+ value: inputValue,
37478
+ onValueChange: onInputChange,
37479
+ onBlur: onInputBlur,
37480
+ className: "Layer__UI__Input",
37481
+ "data-inset": "true",
37482
+ "aria-label": label
37483
+ }
37484
+ ) }) }));
37485
+ }
37486
+
37487
+ // src/features/forms/components/FormTextAreaField.tsx
37488
+ var import_react227 = require("react");
37489
+
37490
+ // src/components/ui/Input/TextArea.tsx
37491
+ var import_react226 = require("react");
37492
+ var import_react_aria_components17 = require("react-aria-components");
37493
+ var import_jsx_runtime335 = require("react/jsx-runtime");
37494
+ var TEXTAREA_CLASS_NAME = "Layer__UI__TextArea";
37495
+ var TextArea = (0, import_react226.forwardRef)(
37496
+ function TextArea2(_a, ref) {
37497
+ var _b = _a, { resize = "none" } = _b, restProps = __objRest(_b, ["resize"]);
37498
+ const dataProperties = toDataProperties({ resize });
37499
+ return /* @__PURE__ */ (0, import_jsx_runtime335.jsx)(
37500
+ import_react_aria_components17.TextArea,
37501
+ __spreadProps(__spreadValues(__spreadValues({}, restProps), dataProperties), {
37502
+ className: TEXTAREA_CLASS_NAME,
37503
+ ref
37504
+ })
37505
+ );
37506
+ }
37507
+ );
37508
+
37509
+ // src/features/forms/components/FormTextAreaField.tsx
37510
+ var import_jsx_runtime336 = require("react/jsx-runtime");
37511
+ function FormTextAreaField(props) {
37512
+ const field = useFieldContext();
37513
+ const { name, state, handleChange, handleBlur } = field;
37514
+ const { value } = state;
37515
+ const onChange = (0, import_react227.useCallback)((e) => {
37516
+ handleChange(e.target.value);
37517
+ }, [handleChange]);
37518
+ return /* @__PURE__ */ (0, import_jsx_runtime336.jsx)(BaseFormTextField, __spreadProps(__spreadValues({}, props), { isTextArea: true, children: /* @__PURE__ */ (0, import_jsx_runtime336.jsx)(TextArea, { id: name, name, value, onChange, onBlur: handleBlur }) }));
37519
+ }
37520
+
37521
+ // src/features/forms/components/FormTextField.tsx
37522
+ var import_react228 = require("react");
37523
+ var import_jsx_runtime337 = require("react/jsx-runtime");
37524
+ function FormTextField(props) {
37525
+ const field = useFieldContext();
37526
+ const { name, state, handleChange, handleBlur } = field;
37527
+ const { value } = state;
37528
+ const onChange = (0, import_react228.useCallback)((e) => {
37529
+ handleChange(e.target.value);
37530
+ }, [handleChange]);
37531
+ return /* @__PURE__ */ (0, import_jsx_runtime337.jsx)(BaseFormTextField, __spreadProps(__spreadValues({}, props), { children: /* @__PURE__ */ (0, import_jsx_runtime337.jsx)(InputGroup2, { children: /* @__PURE__ */ (0, import_jsx_runtime337.jsx)(Input2, { inset: true, id: name, name, value, onChange, onBlur: handleBlur }) }) }));
37532
+ }
37533
+
37534
+ // src/features/forms/hooks/useForm.tsx
37535
+ var { fieldContext, useFieldContext, formContext, useFormContext } = (0, import_react_form6.createFormHookContexts)();
37536
+ var { useAppForm, withForm } = (0, import_react_form6.createFormHook)({
37537
+ fieldComponents: {
37538
+ BaseFormTextField,
37539
+ FormBigDecimalField,
37540
+ FormCheckboxField,
37541
+ FormCurrencyField,
37542
+ FormTextAreaField,
37543
+ FormTextField
37544
+ },
37545
+ formComponents: {
37546
+ // TODO: define a submit button component
37547
+ },
37548
+ fieldContext,
37549
+ formContext
37212
37550
  });
37213
37551
 
37214
37552
  // src/features/invoices/invoiceSchemas.ts
37215
- var import_effect10 = require("effect");
37553
+ var import_effect12 = require("effect");
37216
37554
  var InvoiceStatus = /* @__PURE__ */ ((InvoiceStatus3) => {
37217
37555
  InvoiceStatus3["Voided"] = "VOIDED";
37218
37556
  InvoiceStatus3["Paid"] = "PAID";
@@ -37222,10 +37560,10 @@ var InvoiceStatus = /* @__PURE__ */ ((InvoiceStatus3) => {
37222
37560
  InvoiceStatus3["Sent"] = "SENT";
37223
37561
  return InvoiceStatus3;
37224
37562
  })(InvoiceStatus || {});
37225
- var InvoiceStatusSchema = import_effect10.Schema.Enums(InvoiceStatus);
37226
- var TransformedInvoiceStatusSchema = import_effect10.Schema.transform(
37227
- import_effect10.Schema.NonEmptyTrimmedString,
37228
- import_effect10.Schema.typeSchema(InvoiceStatusSchema),
37563
+ var InvoiceStatusSchema = import_effect12.Schema.Enums(InvoiceStatus);
37564
+ var TransformedInvoiceStatusSchema = import_effect12.Schema.transform(
37565
+ import_effect12.Schema.NonEmptyTrimmedString,
37566
+ import_effect12.Schema.typeSchema(InvoiceStatusSchema),
37229
37567
  {
37230
37568
  decode: (input) => {
37231
37569
  if (Object.values(InvoiceStatusSchema.enums).includes(input)) {
@@ -37236,163 +37574,688 @@ var TransformedInvoiceStatusSchema = import_effect10.Schema.transform(
37236
37574
  encode: (input) => input
37237
37575
  }
37238
37576
  );
37239
- var InvoiceLineItemSchema = import_effect10.Schema.Struct({
37240
- id: import_effect10.Schema.UUID,
37241
- externalId: (0, import_effect10.pipe)(
37242
- import_effect10.Schema.propertySignature(import_effect10.Schema.NullOr(import_effect10.Schema.String)),
37243
- import_effect10.Schema.fromKey("external_id")
37577
+ var InvoiceLineItemSchema = import_effect12.Schema.Struct({
37578
+ id: import_effect12.Schema.UUID,
37579
+ externalId: (0, import_effect12.pipe)(
37580
+ import_effect12.Schema.propertySignature(import_effect12.Schema.NullOr(import_effect12.Schema.String)),
37581
+ import_effect12.Schema.fromKey("external_id")
37244
37582
  ),
37245
- invoiceId: (0, import_effect10.pipe)(
37246
- import_effect10.Schema.propertySignature(import_effect10.Schema.UUID),
37247
- import_effect10.Schema.fromKey("invoice_id")
37583
+ invoiceId: (0, import_effect12.pipe)(
37584
+ import_effect12.Schema.propertySignature(import_effect12.Schema.UUID),
37585
+ import_effect12.Schema.fromKey("invoice_id")
37248
37586
  ),
37249
- description: import_effect10.Schema.NullOr(import_effect10.Schema.String),
37250
- product: import_effect10.Schema.NullOr(import_effect10.Schema.String),
37251
- unitPrice: (0, import_effect10.pipe)(
37252
- import_effect10.Schema.propertySignature(import_effect10.Schema.Number),
37253
- import_effect10.Schema.fromKey("unit_price")
37587
+ description: import_effect12.Schema.NullOr(import_effect12.Schema.String),
37588
+ product: import_effect12.Schema.NullOr(import_effect12.Schema.String),
37589
+ unitPrice: (0, import_effect12.pipe)(
37590
+ import_effect12.Schema.propertySignature(import_effect12.Schema.Number),
37591
+ import_effect12.Schema.fromKey("unit_price")
37254
37592
  ),
37255
- quantity: import_effect10.Schema.BigDecimal,
37256
- subtotal: import_effect10.Schema.Number,
37257
- discountAmount: (0, import_effect10.pipe)(
37258
- import_effect10.Schema.propertySignature(import_effect10.Schema.Number),
37259
- import_effect10.Schema.fromKey("discount_amount")
37593
+ quantity: import_effect12.Schema.BigDecimal,
37594
+ subtotal: import_effect12.Schema.Number,
37595
+ discountAmount: (0, import_effect12.pipe)(
37596
+ import_effect12.Schema.propertySignature(import_effect12.Schema.Number),
37597
+ import_effect12.Schema.fromKey("discount_amount")
37260
37598
  ),
37261
- salesTaxTotal: (0, import_effect10.pipe)(
37262
- import_effect10.Schema.propertySignature(import_effect10.Schema.Number),
37263
- import_effect10.Schema.fromKey("sales_taxes_total")
37599
+ salesTaxTotal: (0, import_effect12.pipe)(
37600
+ import_effect12.Schema.propertySignature(import_effect12.Schema.Number),
37601
+ import_effect12.Schema.fromKey("sales_taxes_total")
37264
37602
  ),
37265
- totalAmount: (0, import_effect10.pipe)(
37266
- import_effect10.Schema.propertySignature(import_effect10.Schema.Number),
37267
- import_effect10.Schema.fromKey("total_amount")
37603
+ totalAmount: (0, import_effect12.pipe)(
37604
+ import_effect12.Schema.propertySignature(import_effect12.Schema.Number),
37605
+ import_effect12.Schema.fromKey("total_amount")
37268
37606
  ),
37269
- memo: import_effect10.Schema.NullOr(import_effect10.Schema.String)
37607
+ memo: import_effect12.Schema.NullOr(import_effect12.Schema.String)
37270
37608
  });
37271
- var InvoiceSchema = import_effect10.Schema.Struct({
37272
- id: import_effect10.Schema.UUID,
37273
- businessId: (0, import_effect10.pipe)(
37274
- import_effect10.Schema.propertySignature(import_effect10.Schema.UUID),
37275
- import_effect10.Schema.fromKey("business_id")
37609
+ var InvoiceSchema = import_effect12.Schema.Struct({
37610
+ id: import_effect12.Schema.UUID,
37611
+ businessId: (0, import_effect12.pipe)(
37612
+ import_effect12.Schema.propertySignature(import_effect12.Schema.UUID),
37613
+ import_effect12.Schema.fromKey("business_id")
37276
37614
  ),
37277
- externalId: (0, import_effect10.pipe)(
37278
- import_effect10.Schema.propertySignature(import_effect10.Schema.NullOr(import_effect10.Schema.String)),
37279
- import_effect10.Schema.fromKey("external_id")
37615
+ externalId: (0, import_effect12.pipe)(
37616
+ import_effect12.Schema.propertySignature(import_effect12.Schema.NullOr(import_effect12.Schema.String)),
37617
+ import_effect12.Schema.fromKey("external_id")
37280
37618
  ),
37281
37619
  status: TransformedInvoiceStatusSchema,
37282
- sentAt: (0, import_effect10.pipe)(
37283
- import_effect10.Schema.propertySignature(import_effect10.Schema.NullOr(import_effect10.Schema.Date)),
37284
- import_effect10.Schema.fromKey("sent_at")
37620
+ sentAt: (0, import_effect12.pipe)(
37621
+ import_effect12.Schema.propertySignature(import_effect12.Schema.NullOr(import_effect12.Schema.Date)),
37622
+ import_effect12.Schema.fromKey("sent_at")
37285
37623
  ),
37286
- dueAt: (0, import_effect10.pipe)(
37287
- import_effect10.Schema.propertySignature(import_effect10.Schema.NullOr(import_effect10.Schema.Date)),
37288
- import_effect10.Schema.fromKey("due_at")
37624
+ dueAt: (0, import_effect12.pipe)(
37625
+ import_effect12.Schema.propertySignature(import_effect12.Schema.NullOr(import_effect12.Schema.Date)),
37626
+ import_effect12.Schema.fromKey("due_at")
37289
37627
  ),
37290
- paidAt: (0, import_effect10.pipe)(
37291
- import_effect10.Schema.propertySignature(import_effect10.Schema.NullOr(import_effect10.Schema.Date)),
37292
- import_effect10.Schema.fromKey("paid_at")
37628
+ paidAt: (0, import_effect12.pipe)(
37629
+ import_effect12.Schema.propertySignature(import_effect12.Schema.NullOr(import_effect12.Schema.Date)),
37630
+ import_effect12.Schema.fromKey("paid_at")
37293
37631
  ),
37294
- voidedAt: (0, import_effect10.pipe)(
37295
- import_effect10.Schema.propertySignature(import_effect10.Schema.NullOr(import_effect10.Schema.Date)),
37296
- import_effect10.Schema.fromKey("voided_at")
37632
+ voidedAt: (0, import_effect12.pipe)(
37633
+ import_effect12.Schema.propertySignature(import_effect12.Schema.NullOr(import_effect12.Schema.Date)),
37634
+ import_effect12.Schema.fromKey("voided_at")
37297
37635
  ),
37298
- invoiceNumber: (0, import_effect10.pipe)(
37299
- import_effect10.Schema.propertySignature(import_effect10.Schema.NullOr(import_effect10.Schema.String)),
37300
- import_effect10.Schema.fromKey("invoice_number")
37636
+ invoiceNumber: (0, import_effect12.pipe)(
37637
+ import_effect12.Schema.propertySignature(import_effect12.Schema.NullOr(import_effect12.Schema.String)),
37638
+ import_effect12.Schema.fromKey("invoice_number")
37301
37639
  ),
37302
- recipientName: (0, import_effect10.pipe)(
37303
- import_effect10.Schema.propertySignature(import_effect10.Schema.NullOr(import_effect10.Schema.String)),
37304
- import_effect10.Schema.fromKey("recipient_name")
37640
+ recipientName: (0, import_effect12.pipe)(
37641
+ import_effect12.Schema.propertySignature(import_effect12.Schema.NullOr(import_effect12.Schema.String)),
37642
+ import_effect12.Schema.fromKey("recipient_name")
37305
37643
  ),
37306
- customer: import_effect10.Schema.NullOr(CustomerSchema),
37307
- lineItems: (0, import_effect10.pipe)(
37308
- import_effect10.Schema.propertySignature(import_effect10.Schema.Array(InvoiceLineItemSchema)),
37309
- import_effect10.Schema.fromKey("line_items")
37644
+ customer: import_effect12.Schema.NullOr(CustomerSchema),
37645
+ lineItems: (0, import_effect12.pipe)(
37646
+ import_effect12.Schema.propertySignature(import_effect12.Schema.Array(InvoiceLineItemSchema)),
37647
+ import_effect12.Schema.fromKey("line_items")
37310
37648
  ),
37311
- subtotal: import_effect10.Schema.Number,
37312
- additionalDiscount: (0, import_effect10.pipe)(
37313
- import_effect10.Schema.propertySignature(import_effect10.Schema.Number),
37314
- import_effect10.Schema.fromKey("additional_discount")
37649
+ subtotal: import_effect12.Schema.Number,
37650
+ additionalDiscount: (0, import_effect12.pipe)(
37651
+ import_effect12.Schema.propertySignature(import_effect12.Schema.Number),
37652
+ import_effect12.Schema.fromKey("additional_discount")
37315
37653
  ),
37316
- additionalSalesTaxesTotal: (0, import_effect10.pipe)(
37317
- import_effect10.Schema.propertySignature(import_effect10.Schema.Number),
37318
- import_effect10.Schema.fromKey("additional_sales_taxes_total")
37654
+ additionalSalesTaxesTotal: (0, import_effect12.pipe)(
37655
+ import_effect12.Schema.propertySignature(import_effect12.Schema.Number),
37656
+ import_effect12.Schema.fromKey("additional_sales_taxes_total")
37319
37657
  ),
37320
- totalAmount: (0, import_effect10.pipe)(
37321
- import_effect10.Schema.propertySignature(import_effect10.Schema.Number),
37322
- import_effect10.Schema.fromKey("total_amount")
37658
+ totalAmount: (0, import_effect12.pipe)(
37659
+ import_effect12.Schema.propertySignature(import_effect12.Schema.Number),
37660
+ import_effect12.Schema.fromKey("total_amount")
37323
37661
  ),
37324
- outstandingBalance: (0, import_effect10.pipe)(
37325
- import_effect10.Schema.propertySignature(import_effect10.Schema.Number),
37326
- import_effect10.Schema.fromKey("outstanding_balance")
37662
+ outstandingBalance: (0, import_effect12.pipe)(
37663
+ import_effect12.Schema.propertySignature(import_effect12.Schema.Number),
37664
+ import_effect12.Schema.fromKey("outstanding_balance")
37327
37665
  ),
37328
- importedAt: (0, import_effect10.pipe)(
37329
- import_effect10.Schema.propertySignature(import_effect10.Schema.Date),
37330
- import_effect10.Schema.fromKey("imported_at")
37666
+ importedAt: (0, import_effect12.pipe)(
37667
+ import_effect12.Schema.propertySignature(import_effect12.Schema.Date),
37668
+ import_effect12.Schema.fromKey("imported_at")
37331
37669
  ),
37332
- updatedAt: (0, import_effect10.pipe)(
37333
- import_effect10.Schema.propertySignature(import_effect10.Schema.NullOr(import_effect10.Schema.Date)),
37334
- import_effect10.Schema.fromKey("updated_at")
37670
+ updatedAt: (0, import_effect12.pipe)(
37671
+ import_effect12.Schema.propertySignature(import_effect12.Schema.NullOr(import_effect12.Schema.Date)),
37672
+ import_effect12.Schema.fromKey("updated_at")
37335
37673
  ),
37336
- memo: import_effect10.Schema.NullOr(import_effect10.Schema.String)
37674
+ memo: import_effect12.Schema.NullOr(import_effect12.Schema.String)
37337
37675
  });
37338
- var UpsertInvoiceTaxLineItemSchema = import_effect10.Schema.Struct({
37339
- amount: import_effect10.Schema.NumberFromString.pipe(import_effect10.Schema.int())
37676
+ var UpsertInvoiceTaxLineItemSchema = import_effect12.Schema.Struct({
37677
+ amount: import_effect12.Schema.Number
37340
37678
  });
37341
- var UpsertInvoiceLineItemSchema = import_effect10.Schema.Struct({
37342
- description: (0, import_effect10.pipe)(
37343
- import_effect10.Schema.propertySignature(import_effect10.Schema.UndefinedOr(import_effect10.Schema.String)),
37344
- import_effect10.Schema.fromKey("description")
37345
- ),
37346
- product: (0, import_effect10.pipe)(
37347
- import_effect10.Schema.propertySignature(import_effect10.Schema.String),
37348
- import_effect10.Schema.fromKey("product")
37679
+ var UpsertInvoiceLineItemSchema = import_effect12.Schema.Struct({
37680
+ description: import_effect12.Schema.String,
37681
+ product: import_effect12.Schema.String,
37682
+ unitPrice: (0, import_effect12.pipe)(
37683
+ import_effect12.Schema.propertySignature(import_effect12.Schema.Number),
37684
+ import_effect12.Schema.fromKey("unit_price")
37349
37685
  ),
37350
- unitPrice: (0, import_effect10.pipe)(
37351
- import_effect10.Schema.propertySignature(import_effect10.Schema.NumberFromString.pipe(import_effect10.Schema.int())),
37352
- import_effect10.Schema.fromKey("unit_price")
37353
- ),
37354
- quantity: (0, import_effect10.pipe)(
37355
- import_effect10.Schema.propertySignature(import_effect10.Schema.BigDecimal),
37356
- import_effect10.Schema.fromKey("quantity")
37357
- )
37686
+ quantity: import_effect12.Schema.BigDecimal
37358
37687
  });
37359
- var UpsertInvoiceSchema = import_effect10.Schema.Struct({
37360
- sentAt: (0, import_effect10.pipe)(
37361
- import_effect10.Schema.propertySignature(import_effect10.Schema.Date),
37362
- import_effect10.Schema.fromKey("sent_at")
37688
+ var UpsertInvoiceSchema = import_effect12.Schema.Struct({
37689
+ sentAt: (0, import_effect12.pipe)(
37690
+ import_effect12.Schema.propertySignature(import_effect12.Schema.Date),
37691
+ import_effect12.Schema.fromKey("sent_at")
37363
37692
  ),
37364
- dueAt: (0, import_effect10.pipe)(
37365
- import_effect10.Schema.propertySignature(import_effect10.Schema.Date),
37366
- import_effect10.Schema.fromKey("due_at")
37693
+ dueAt: (0, import_effect12.pipe)(
37694
+ import_effect12.Schema.propertySignature(import_effect12.Schema.Date),
37695
+ import_effect12.Schema.fromKey("due_at")
37367
37696
  ),
37368
- invoiceNumber: (0, import_effect10.pipe)(
37369
- import_effect10.Schema.propertySignature(import_effect10.Schema.UndefinedOr(import_effect10.Schema.String)),
37370
- import_effect10.Schema.fromKey("invoice_number")
37697
+ invoiceNumber: (0, import_effect12.pipe)(
37698
+ import_effect12.Schema.propertySignature(import_effect12.Schema.UndefinedOr(import_effect12.Schema.String)),
37699
+ import_effect12.Schema.fromKey("invoice_number")
37371
37700
  ),
37372
- customerId: (0, import_effect10.pipe)(
37373
- import_effect10.Schema.propertySignature(import_effect10.Schema.UUID),
37374
- import_effect10.Schema.fromKey("customer_id")
37701
+ customerId: (0, import_effect12.pipe)(
37702
+ import_effect12.Schema.propertySignature(import_effect12.Schema.UUID),
37703
+ import_effect12.Schema.fromKey("customer_id")
37375
37704
  ),
37376
- memo: import_effect10.Schema.NullOr(import_effect10.Schema.String),
37377
- lineItems: (0, import_effect10.pipe)(
37378
- import_effect10.Schema.propertySignature(import_effect10.Schema.Array(UpsertInvoiceLineItemSchema)),
37379
- import_effect10.Schema.fromKey("line_items")
37705
+ memo: import_effect12.Schema.NullOr(import_effect12.Schema.String),
37706
+ lineItems: (0, import_effect12.pipe)(
37707
+ import_effect12.Schema.propertySignature(import_effect12.Schema.Array(UpsertInvoiceLineItemSchema)),
37708
+ import_effect12.Schema.fromKey("line_items")
37380
37709
  ),
37381
- additionalDiscount: (0, import_effect10.pipe)(
37382
- import_effect10.Schema.propertySignature(import_effect10.Schema.UndefinedOr(import_effect10.Schema.NumberFromString.pipe(import_effect10.Schema.int()))),
37383
- import_effect10.Schema.fromKey("additional_discount")
37710
+ additionalDiscount: (0, import_effect12.pipe)(
37711
+ import_effect12.Schema.propertySignature(import_effect12.Schema.UndefinedOr(import_effect12.Schema.Number)),
37712
+ import_effect12.Schema.fromKey("additional_discount")
37384
37713
  ),
37385
- additionalSalesTaxes: (0, import_effect10.pipe)(
37386
- import_effect10.Schema.propertySignature(import_effect10.Schema.UndefinedOr(import_effect10.Schema.Array(UpsertInvoiceTaxLineItemSchema))),
37387
- import_effect10.Schema.fromKey("additional_sales_taxes")
37714
+ additionalSalesTaxes: (0, import_effect12.pipe)(
37715
+ import_effect12.Schema.propertySignature(import_effect12.Schema.UndefinedOr(import_effect12.Schema.Array(UpsertInvoiceTaxLineItemSchema))),
37716
+ import_effect12.Schema.fromKey("additional_sales_taxes")
37717
+ )
37718
+ });
37719
+
37720
+ // src/features/invoices/api/useUpsertInvoice.tsx
37721
+ var import_react229 = require("react");
37722
+ var import_mutation26 = __toESM(require("swr/mutation"));
37723
+ var import_effect13 = require("effect");
37724
+ var UPSERT_INVOICES_TAG_KEY = "#upsert-invoice";
37725
+ var createInvoice = post(({ businessId }) => `/v1/businesses/${businessId}/invoices`);
37726
+ var updateInvoice = put(({ businessId, invoiceId }) => `/v1/businesses/${businessId}/invoices/${invoiceId}`);
37727
+ function buildKey39({
37728
+ access_token: accessToken,
37729
+ apiUrl,
37730
+ businessId,
37731
+ invoiceId = void 0
37732
+ }) {
37733
+ if (accessToken && apiUrl) {
37734
+ return {
37735
+ accessToken,
37736
+ apiUrl,
37737
+ businessId,
37738
+ invoiceId,
37739
+ tags: [UPSERT_INVOICES_TAG_KEY]
37740
+ };
37741
+ }
37742
+ }
37743
+ var UpsertInvoiceReturnSchema = import_effect13.Schema.Struct({
37744
+ data: InvoiceSchema
37745
+ });
37746
+ var UpsertInvoiceSWRResponse = class {
37747
+ constructor(swrResponse) {
37748
+ __publicField(this, "swrResponse");
37749
+ this.swrResponse = swrResponse;
37750
+ }
37751
+ get data() {
37752
+ return this.swrResponse.data;
37753
+ }
37754
+ get trigger() {
37755
+ return this.swrResponse.trigger;
37756
+ }
37757
+ get isMutating() {
37758
+ return this.swrResponse.isMutating;
37759
+ }
37760
+ get isError() {
37761
+ return this.swrResponse.error !== void 0;
37762
+ }
37763
+ };
37764
+ var CreateParamsSchema = import_effect13.Schema.Struct({
37765
+ businessId: import_effect13.Schema.String
37766
+ });
37767
+ var UpdateParamsSchema = import_effect13.Schema.Struct({
37768
+ businessId: import_effect13.Schema.String,
37769
+ invoiceId: import_effect13.Schema.String
37770
+ });
37771
+ var isParamsValidForMode = (mode, params) => {
37772
+ if (mode === "Update" /* Update */) {
37773
+ return import_effect13.Effect.runSync(import_effect13.Effect.either(import_effect13.Schema.decodeUnknown(UpdateParamsSchema)(params)))._tag === "Right";
37774
+ }
37775
+ if (mode === "Create" /* Create */) {
37776
+ return import_effect13.Effect.runSync(import_effect13.Effect.either(import_effect13.Schema.decodeUnknown(CreateParamsSchema)(params)))._tag === "Right";
37777
+ }
37778
+ return false;
37779
+ };
37780
+ function getRequestFn(mode, params) {
37781
+ if (mode === "Update" /* Update */) {
37782
+ if (!isParamsValidForMode("Update" /* Update */, params)) {
37783
+ throw new Error("Invalid params for upsert mode");
37784
+ }
37785
+ return ({ apiUrl, accessToken, body }) => updateInvoice(apiUrl, accessToken, { params, body });
37786
+ } else {
37787
+ if (!isParamsValidForMode("Create" /* Create */, params)) {
37788
+ throw new Error("Invalid params for create mode");
37789
+ }
37790
+ return ({ apiUrl, accessToken, body }) => createInvoice(apiUrl, accessToken, { params, body });
37791
+ }
37792
+ }
37793
+ var useUpsertInvoice = (props) => {
37794
+ const { data } = useAuth();
37795
+ const { businessId } = useLayerContext();
37796
+ const { mode } = props;
37797
+ const invoiceId = mode === "Update" /* Update */ ? props.invoiceId : void 0;
37798
+ const rawMutationResponse = (0, import_mutation26.default)(
37799
+ () => buildKey39(__spreadProps(__spreadValues({}, data), {
37800
+ businessId,
37801
+ invoiceId
37802
+ })),
37803
+ ({ accessToken, apiUrl, businessId: businessId2, invoiceId: invoiceId2 }, { arg: body }) => {
37804
+ const request2 = getRequestFn(mode, { businessId: businessId2, invoiceId: invoiceId2 });
37805
+ return request2({
37806
+ apiUrl,
37807
+ accessToken,
37808
+ body
37809
+ }).then(import_effect13.Schema.decodeUnknownPromise(UpsertInvoiceReturnSchema));
37810
+ },
37811
+ {
37812
+ revalidate: false
37813
+ }
37814
+ );
37815
+ const mutationResponse = new UpsertInvoiceSWRResponse(rawMutationResponse);
37816
+ const originalTrigger = mutationResponse.trigger;
37817
+ const stableProxiedTrigger = (0, import_react229.useCallback)(
37818
+ (...triggerParameters) => __async(null, null, function* () {
37819
+ const triggerResult = yield originalTrigger(...triggerParameters);
37820
+ return triggerResult;
37821
+ }),
37822
+ [originalTrigger]
37823
+ );
37824
+ return new Proxy(mutationResponse, {
37825
+ get(target, prop) {
37826
+ if (prop === "trigger") {
37827
+ return stableProxiedTrigger;
37828
+ }
37829
+ return Reflect.get(target, prop);
37830
+ }
37831
+ });
37832
+ };
37833
+
37834
+ // src/components/Invoices/InvoiceForm/useInvoiceForm.ts
37835
+ var import_effect14 = require("effect");
37836
+ var EMPTY_LINE_ITEM = {
37837
+ product: "",
37838
+ description: "",
37839
+ unitPrice: 0,
37840
+ quantity: BIG_DECIMAL_ONE,
37841
+ amount: 0,
37842
+ isTaxable: false
37843
+ };
37844
+ var DEFAULT_FORM_VALUES = {
37845
+ invoiceNumber: "",
37846
+ customer: null,
37847
+ email: "",
37848
+ address: "",
37849
+ lineItems: [EMPTY_LINE_ITEM]
37850
+ };
37851
+ var getInvoiceLineItemAmount = (lineItem) => {
37852
+ const { unitPrice, quantity } = lineItem;
37853
+ return convertBigDecimalToCents(import_effect14.BigDecimal.multiply(quantity, convertCentsToBigDecimal(unitPrice)));
37854
+ };
37855
+ var getAugmentedInvoiceFormLineItem = (lineItem) => {
37856
+ return __spreadProps(__spreadValues({}, lineItem), {
37857
+ amount: getInvoiceLineItemAmount(lineItem),
37858
+ isTaxable: lineItem.salesTaxTotal > 0
37859
+ });
37860
+ };
37861
+ var getInvoiceFormDefaultValues = (invoice) => {
37862
+ var _a, _b;
37863
+ return {
37864
+ invoiceNumber: invoice.invoiceNumber,
37865
+ customer: invoice.customer,
37866
+ email: (_a = invoice.customer) == null ? void 0 : _a.email,
37867
+ address: (_b = invoice.customer) == null ? void 0 : _b.addressString,
37868
+ lineItems: invoice.lineItems.map(getAugmentedInvoiceFormLineItem)
37869
+ };
37870
+ };
37871
+ var useInvoiceForm = (props) => {
37872
+ const [submitError, setSubmitError] = (0, import_react230.useState)(void 0);
37873
+ const { onSuccess, mode } = props;
37874
+ const upsertInvoiceProps = mode === "Update" /* Update */ ? { mode, invoiceId: props.invoice.id } : { mode };
37875
+ const { trigger: upsertInvoice } = useUpsertInvoice(upsertInvoiceProps);
37876
+ const defaultValues = mode === "Update" /* Update */ ? getInvoiceFormDefaultValues(props.invoice) : DEFAULT_FORM_VALUES;
37877
+ const form = useAppForm({
37878
+ defaultValues,
37879
+ onSubmit: (_0) => __async(null, [_0], function* ({ value }) {
37880
+ var _a;
37881
+ try {
37882
+ const payload = __spreadProps(__spreadValues({}, value), {
37883
+ customerId: (_a = value == null ? void 0 : value.customer) == null ? void 0 : _a.id
37884
+ });
37885
+ const invoiceParams = import_effect14.Schema.validateSync(UpsertInvoiceSchema)(payload);
37886
+ const { data: invoice } = yield upsertInvoice(invoiceParams);
37887
+ setSubmitError(void 0);
37888
+ onSuccess == null ? void 0 : onSuccess(invoice);
37889
+ } catch (e) {
37890
+ setSubmitError("Something went wrong. Please try again.");
37891
+ }
37892
+ })
37893
+ });
37894
+ const isFormValid = (0, import_react_form7.useStore)(form.store, (state) => state.isValid);
37895
+ return { form, submitError, isFormValid };
37896
+ };
37897
+
37898
+ // src/components/Invoices/InvoiceForm/InvoiceForm.tsx
37899
+ var import_lucide_react16 = require("lucide-react");
37900
+ var import_effect15 = require("effect");
37901
+
37902
+ // src/features/customers/components/CustomerSelector.tsx
37903
+ var import_react231 = require("react");
37904
+ var import_classnames90 = __toESM(require("classnames"));
37905
+ var import_jsx_runtime338 = require("react/jsx-runtime");
37906
+ function getCustomerName(customer) {
37907
+ var _a, _b, _c;
37908
+ return (_c = (_b = (_a = customer.individualName) != null ? _a : customer.companyName) != null ? _b : customer.externalId) != null ? _c : "Unknown Customer";
37909
+ }
37910
+ var CustomerAsOption = class {
37911
+ constructor(customer) {
37912
+ __publicField(this, "internalCustomer");
37913
+ this.internalCustomer = customer;
37914
+ }
37915
+ get original() {
37916
+ return this.internalCustomer;
37917
+ }
37918
+ get label() {
37919
+ return getCustomerName(this.internalCustomer);
37920
+ }
37921
+ get id() {
37922
+ return this.internalCustomer.id;
37923
+ }
37924
+ get value() {
37925
+ return this.internalCustomer.id;
37926
+ }
37927
+ };
37928
+ function CustomerSelector({
37929
+ selectedCustomer,
37930
+ onSelectedCustomerChange,
37931
+ placeholder,
37932
+ isReadOnly,
37933
+ inline,
37934
+ className
37935
+ }) {
37936
+ const combinedClassName = (0, import_classnames90.default)(
37937
+ "Layer__CustomerSelector",
37938
+ inline && "Layer__CustomerSelector--inline",
37939
+ className
37940
+ );
37941
+ const { searchQuery, handleInputChange } = useDebouncedSearchInput({
37942
+ initialInputState: () => ""
37943
+ });
37944
+ const effectiveSearchQuery = searchQuery === "" ? void 0 : searchQuery;
37945
+ const { data, isLoading, isError } = useListCustomers({ query: effectiveSearchQuery });
37946
+ const options = (0, import_react231.useMemo)(
37947
+ () => (data == null ? void 0 : data.flatMap(({ data: data2 }) => data2).map((customer) => new CustomerAsOption(customer))) || [],
37948
+ [data]
37949
+ );
37950
+ const selectedCustomerId = selectedCustomer == null ? void 0 : selectedCustomer.id;
37951
+ const handleSelectionChange = (0, import_react231.useCallback)(
37952
+ (selectedOption) => {
37953
+ if (selectedOption === null) {
37954
+ handleInputChange("");
37955
+ if (selectedCustomerId) {
37956
+ onSelectedCustomerChange(null);
37957
+ }
37958
+ return;
37959
+ }
37960
+ const selectedCustomer2 = options.find(({ id }) => id === selectedOption.value);
37961
+ if (selectedCustomer2) {
37962
+ const selectedCustomerWithType = selectedCustomer2.original;
37963
+ if (selectedCustomer2.id !== selectedCustomerId) {
37964
+ onSelectedCustomerChange(selectedCustomerWithType);
37965
+ }
37966
+ handleInputChange("");
37967
+ return;
37968
+ }
37969
+ },
37970
+ [options, handleInputChange, selectedCustomerId, onSelectedCustomerChange]
37971
+ );
37972
+ const selectedCustomerForComboBox = (0, import_react231.useMemo)(
37973
+ () => {
37974
+ if (selectedCustomer === null) {
37975
+ return null;
37976
+ }
37977
+ return {
37978
+ label: getCustomerName(selectedCustomer),
37979
+ value: selectedCustomer.id
37980
+ };
37981
+ },
37982
+ [selectedCustomer]
37983
+ );
37984
+ const EmptyMessage = (0, import_react231.useMemo)(
37985
+ () => /* @__PURE__ */ (0, import_jsx_runtime338.jsx)(P, { variant: "subtle", children: "No matching customer" }),
37986
+ []
37987
+ );
37988
+ const ErrorMessage = (0, import_react231.useMemo)(
37989
+ () => /* @__PURE__ */ (0, import_jsx_runtime338.jsx)(
37990
+ P,
37991
+ {
37992
+ size: "xs",
37993
+ status: "error",
37994
+ children: "An error occurred while loading customers."
37995
+ }
37996
+ ),
37997
+ []
37998
+ );
37999
+ const inputId = (0, import_react231.useId)();
38000
+ const isFiltered = effectiveSearchQuery !== void 0;
38001
+ const noCustomersExist = !isLoading && !isFiltered && data !== void 0 && data.every(({ data: data2 }) => data2.length === 0);
38002
+ const shouldHideComponent = noCustomersExist || isReadOnly && selectedCustomer === null;
38003
+ if (shouldHideComponent) {
38004
+ return null;
38005
+ }
38006
+ const isLoadingWithoutFallback = isLoading && !data;
38007
+ const shouldDisableComboBox = isLoadingWithoutFallback || isError;
38008
+ return /* @__PURE__ */ (0, import_jsx_runtime338.jsxs)(VStack, { className: combinedClassName, children: [
38009
+ /* @__PURE__ */ (0, import_jsx_runtime338.jsx)(Label, { htmlFor: inputId, size: "sm", children: "Customer" }),
38010
+ /* @__PURE__ */ (0, import_jsx_runtime338.jsx)(
38011
+ ComboBox,
38012
+ {
38013
+ selectedValue: selectedCustomerForComboBox,
38014
+ onSelectedValueChange: handleSelectionChange,
38015
+ options,
38016
+ onInputValueChange: handleInputChange,
38017
+ inputId,
38018
+ placeholder,
38019
+ slots: { EmptyMessage, ErrorMessage },
38020
+ isDisabled: isReadOnly || shouldDisableComboBox,
38021
+ isError,
38022
+ isLoading: isLoadingWithoutFallback
38023
+ }
38024
+ )
38025
+ ] });
38026
+ }
38027
+
38028
+ // src/components/Invoices/InvoiceForm/InvoiceForm.tsx
38029
+ var import_jsx_runtime339 = require("react/jsx-runtime");
38030
+ var INVOICE_FORM_CSS_PREFIX = "Layer__InvoiceForm";
38031
+ var INVOICE_FORM_FIELD_CSS_PREFIX = `${INVOICE_FORM_CSS_PREFIX}__Field`;
38032
+ var InvoiceForm = (props) => {
38033
+ const { onSuccess, mode } = props;
38034
+ const { form } = useInvoiceForm(
38035
+ __spreadValues({ onSuccess }, mode === "Update" /* Update */ ? { mode, invoice: props.invoice } : { mode })
38036
+ );
38037
+ return /* @__PURE__ */ (0, import_jsx_runtime339.jsxs)(Form, { className: INVOICE_FORM_CSS_PREFIX, children: [
38038
+ /* @__PURE__ */ (0, import_jsx_runtime339.jsxs)(VStack, { className: `${INVOICE_FORM_CSS_PREFIX}__Metadata`, gap: "xs", children: [
38039
+ /* @__PURE__ */ (0, import_jsx_runtime339.jsx)(
38040
+ form.Field,
38041
+ {
38042
+ name: "customer",
38043
+ listeners: {
38044
+ onChange: ({ value: customer }) => {
38045
+ form.setFieldValue("email", customer == null ? void 0 : customer.email);
38046
+ form.setFieldValue("address", customer == null ? void 0 : customer.addressString);
38047
+ }
38048
+ },
38049
+ children: (field) => /* @__PURE__ */ (0, import_jsx_runtime339.jsx)(
38050
+ CustomerSelector,
38051
+ {
38052
+ className: `${INVOICE_FORM_FIELD_CSS_PREFIX}__Customer`,
38053
+ selectedCustomer: field.state.value,
38054
+ onSelectedCustomerChange: field.handleChange,
38055
+ inline: true
38056
+ }
38057
+ )
38058
+ }
38059
+ ),
38060
+ /* @__PURE__ */ (0, import_jsx_runtime339.jsx)(form.AppField, { name: "email", children: (field) => /* @__PURE__ */ (0, import_jsx_runtime339.jsx)(field.FormTextField, { label: "Email", inline: true, className: `${INVOICE_FORM_FIELD_CSS_PREFIX}__Email` }) }),
38061
+ /* @__PURE__ */ (0, import_jsx_runtime339.jsx)(form.AppField, { name: "address", children: (field) => /* @__PURE__ */ (0, import_jsx_runtime339.jsx)(field.FormTextAreaField, { label: "Billing address", inline: true, className: `${INVOICE_FORM_FIELD_CSS_PREFIX}__Address` }) })
38062
+ ] }),
38063
+ /* @__PURE__ */ (0, import_jsx_runtime339.jsx)(VStack, { className: `${INVOICE_FORM_CSS_PREFIX}__LineItems`, gap: "xs", children: /* @__PURE__ */ (0, import_jsx_runtime339.jsx)(form.AppField, { name: "lineItems", mode: "array", children: (field) => /* @__PURE__ */ (0, import_jsx_runtime339.jsxs)(VStack, { gap: "xs", align: "baseline", children: [
38064
+ field.state.value.map((_, index) => /* @__PURE__ */ (0, import_jsx_runtime339.jsxs)(HStack, { gap: "xs", align: "end", className: `${INVOICE_FORM_CSS_PREFIX}__LineItem`, children: [
38065
+ /* @__PURE__ */ (0, import_jsx_runtime339.jsx)(form.AppField, { name: `lineItems[${index}].product`, children: (innerField) => /* @__PURE__ */ (0, import_jsx_runtime339.jsx)(innerField.FormTextField, { label: "Product", showLabel: index === 0 }) }),
38066
+ /* @__PURE__ */ (0, import_jsx_runtime339.jsx)(form.AppField, { name: `lineItems[${index}].description`, children: (innerField) => /* @__PURE__ */ (0, import_jsx_runtime339.jsx)(innerField.FormTextField, { label: "Description", showLabel: index === 0 }) }),
38067
+ /* @__PURE__ */ (0, import_jsx_runtime339.jsx)(
38068
+ form.AppField,
38069
+ {
38070
+ name: `lineItems[${index}].quantity`,
38071
+ listeners: {
38072
+ onBlur: ({ value: quantity }) => {
38073
+ const unitPrice = form.getFieldValue(`lineItems[${index}].unitPrice`);
38074
+ const nextAmount = import_effect15.BigDecimal.multiply(convertCentsToBigDecimal(unitPrice), quantity);
38075
+ form.setFieldValue(`lineItems[${index}].amount`, convertBigDecimalToCents(nextAmount));
38076
+ }
38077
+ },
38078
+ children: (innerField) => /* @__PURE__ */ (0, import_jsx_runtime339.jsx)(innerField.FormBigDecimalField, { label: "Quantity", showLabel: index === 0 })
38079
+ }
38080
+ ),
38081
+ /* @__PURE__ */ (0, import_jsx_runtime339.jsx)(
38082
+ form.AppField,
38083
+ {
38084
+ name: `lineItems[${index}].unitPrice`,
38085
+ listeners: {
38086
+ onBlur: ({ value: unitPrice }) => {
38087
+ const quantity = form.getFieldValue(`lineItems[${index}].quantity`);
38088
+ const nextAmount = import_effect15.BigDecimal.multiply(convertCentsToBigDecimal(unitPrice), quantity);
38089
+ form.setFieldValue(`lineItems[${index}].amount`, convertBigDecimalToCents(nextAmount));
38090
+ }
38091
+ },
38092
+ children: (innerField) => /* @__PURE__ */ (0, import_jsx_runtime339.jsx)(innerField.FormCurrencyField, { label: "Rate", showLabel: index === 0 })
38093
+ }
38094
+ ),
38095
+ /* @__PURE__ */ (0, import_jsx_runtime339.jsx)(
38096
+ form.AppField,
38097
+ {
38098
+ name: `lineItems[${index}].amount`,
38099
+ listeners: {
38100
+ onBlur: ({ value: amount }) => {
38101
+ const quantity = form.getFieldValue(`lineItems[${index}].quantity`);
38102
+ let nextUnitPrice = BIG_DECIMAL_ZERO;
38103
+ try {
38104
+ nextUnitPrice = import_effect15.BigDecimal.unsafeDivide(convertCentsToBigDecimal(amount), quantity);
38105
+ } catch (e) {
38106
+ }
38107
+ form.setFieldValue(`lineItems[${index}].unitPrice`, convertBigDecimalToCents(nextUnitPrice));
38108
+ }
38109
+ },
38110
+ children: (innerField) => /* @__PURE__ */ (0, import_jsx_runtime339.jsx)(innerField.FormCurrencyField, { label: "Amount", showLabel: index === 0 })
38111
+ }
38112
+ ),
38113
+ /* @__PURE__ */ (0, import_jsx_runtime339.jsx)(form.AppField, { name: `lineItems[${index}].isTaxable`, children: (innerField) => /* @__PURE__ */ (0, import_jsx_runtime339.jsx)(innerField.FormCheckboxField, { label: "Tax", showLabel: index === 0 }) }),
38114
+ /* @__PURE__ */ (0, import_jsx_runtime339.jsx)(Button2, { variant: "outlined", icon: true, "aria-label": "Delete line item", onClick: () => field.removeValue(index), children: /* @__PURE__ */ (0, import_jsx_runtime339.jsx)(import_lucide_react16.Trash, { size: 16 }) })
38115
+ ] }, `lineItems[${index}]`)),
38116
+ /* @__PURE__ */ (0, import_jsx_runtime339.jsxs)(Button2, { variant: "outlined", onClick: () => field.pushValue(EMPTY_LINE_ITEM), children: [
38117
+ "Add line item",
38118
+ /* @__PURE__ */ (0, import_jsx_runtime339.jsx)(import_lucide_react16.Plus, { size: 16 })
38119
+ ] })
38120
+ ] }) }) })
38121
+ ] });
38122
+ };
38123
+
38124
+ // src/components/DataPoint/DataPoint.tsx
38125
+ var import_jsx_runtime340 = require("react/jsx-runtime");
38126
+ var DataPoint = ({ label, children }) => {
38127
+ return /* @__PURE__ */ (0, import_jsx_runtime340.jsxs)(VStack, { gap: "3xs", children: [
38128
+ /* @__PURE__ */ (0, import_jsx_runtime340.jsx)(Span, { variant: "subtle", size: "xs", children: label }),
38129
+ children
38130
+ ] });
38131
+ };
38132
+
38133
+ // src/components/Invoices/InvoiceStatusCell/InvoiceStatusCell.tsx
38134
+ var import_pluralize6 = __toESM(require("pluralize"));
38135
+ var import_jsx_runtime341 = require("react/jsx-runtime");
38136
+ var getDueStatusConfig = (invoice, { inline }) => {
38137
+ const badgeSize = inline ? "xs" /* EXTRA_SMALL */ : "small" /* SMALL */;
38138
+ const iconSize = inline ? 10 : 12;
38139
+ switch (invoice.status) {
38140
+ case "WRITTEN_OFF" /* WrittenOff */: {
38141
+ return { text: "Written Off" };
38142
+ }
38143
+ case "PARTIALLY_WRITTEN_OFF" /* PartiallyWrittenOff */: {
38144
+ return { text: "Partially Written Off" };
38145
+ }
38146
+ case "PAID" /* Paid */: {
38147
+ return {
38148
+ text: "Paid",
38149
+ badge: /* @__PURE__ */ (0, import_jsx_runtime341.jsx)(Badge, { variant: "success" /* SUCCESS */, size: badgeSize, icon: /* @__PURE__ */ (0, import_jsx_runtime341.jsx)(CheckCircle_default, { size: iconSize }), iconOnly: true })
38150
+ };
38151
+ }
38152
+ case "VOIDED" /* Voided */: {
38153
+ return { text: "Voided" };
38154
+ }
38155
+ case "SENT" /* Sent */:
38156
+ case "PARTIALLY_PAID" /* PartiallyPaid */: {
38157
+ if (invoice.dueAt === null) {
38158
+ return {
38159
+ text: invoice.status === "PARTIALLY_PAID" /* PartiallyPaid */ ? "Partially Paid" : "Sent"
38160
+ };
38161
+ }
38162
+ const dueDifference = getDueDifference(invoice.dueAt);
38163
+ if (dueDifference === 0) {
38164
+ return {
38165
+ text: "Due Today"
38166
+ };
38167
+ }
38168
+ if (dueDifference < 0) {
38169
+ return {
38170
+ text: "Overdue",
38171
+ subText: `Due ${(0, import_pluralize6.default)("day", Math.abs(dueDifference), true)} ago`,
38172
+ badge: /* @__PURE__ */ (0, import_jsx_runtime341.jsx)(Badge, { variant: "warning" /* WARNING */, size: badgeSize, icon: /* @__PURE__ */ (0, import_jsx_runtime341.jsx)(AlertCircle_default, { size: iconSize }), iconOnly: true })
38173
+ };
38174
+ }
38175
+ return {
38176
+ text: "Sent",
38177
+ subText: `Due in ${(0, import_pluralize6.default)("day", Math.abs(dueDifference), true)}`
38178
+ };
38179
+ }
38180
+ default: {
38181
+ unsafeAssertUnreachable({
38182
+ value: invoice.status,
38183
+ message: "Unexpected invoice status"
38184
+ });
38185
+ }
38186
+ }
38187
+ };
38188
+ var InvoiceStatusCell = ({ invoice, inline = false }) => {
38189
+ const dueStatus = getDueStatusConfig(invoice, { inline });
38190
+ const Stack3 = inline ? HStack : VStack;
38191
+ const subText = inline && dueStatus.subText ? `(${dueStatus.subText})` : dueStatus.subText;
38192
+ return /* @__PURE__ */ (0, import_jsx_runtime341.jsxs)(HStack, { gap: "xs", align: "center", children: [
38193
+ dueStatus.badge,
38194
+ /* @__PURE__ */ (0, import_jsx_runtime341.jsxs)(Stack3, __spreadProps(__spreadValues({}, inline && { gap: "3xs", align: "center" }), { children: [
38195
+ /* @__PURE__ */ (0, import_jsx_runtime341.jsx)(Span, { children: dueStatus.text }),
38196
+ subText && /* @__PURE__ */ (0, import_jsx_runtime341.jsx)(Span, { variant: "subtle", size: "sm", children: subText })
38197
+ ] }))
38198
+ ] });
38199
+ };
38200
+
38201
+ // src/components/Invoices/InvoiceDetail/InvoiceDetail.tsx
38202
+ var import_jsx_runtime342 = require("react/jsx-runtime");
38203
+ var InvoiceDetail = (props) => {
38204
+ const _a = props, { onSuccess: _onSuccess, onGoBack } = _a, restProps = __objRest(_a, ["onSuccess", "onGoBack"]);
38205
+ const Header6 = (0, import_react232.useCallback)(() => {
38206
+ return /* @__PURE__ */ (0, import_jsx_runtime342.jsx)(InvoiceDetailHeader, __spreadValues({}, restProps));
38207
+ }, [restProps]);
38208
+ return /* @__PURE__ */ (0, import_jsx_runtime342.jsxs)(BaseDetailView, { slots: { Header: Header6 }, name: "Invoice Detail View", onGoBack, children: [
38209
+ restProps.mode === "Update" /* Update */ && /* @__PURE__ */ (0, import_jsx_runtime342.jsx)(InvoiceDetailSubHeader, { invoice: restProps.invoice }),
38210
+ /* @__PURE__ */ (0, import_jsx_runtime342.jsx)(InvoiceForm, __spreadValues({}, props))
38211
+ ] });
38212
+ };
38213
+ var InvoiceDetailHeader = (props) => {
38214
+ const { mode } = props;
38215
+ if (mode === "Create" /* Create */) {
38216
+ return /* @__PURE__ */ (0, import_jsx_runtime342.jsx)(Heading2, { children: "Create Invoice" });
38217
+ }
38218
+ const invoice = props.invoice;
38219
+ const { invoiceNumber } = invoice;
38220
+ return /* @__PURE__ */ (0, import_jsx_runtime342.jsx)(Heading2, { children: invoiceNumber ? `Invoice ${invoiceNumber}` : "View Invoice" });
38221
+ };
38222
+ var InvoiceDetailSubHeader = ({ invoice }) => {
38223
+ const { outstandingBalance, totalAmount } = invoice;
38224
+ return /* @__PURE__ */ (0, import_jsx_runtime342.jsx)(HStack, { className: "Layer__InvoiceDetail__SubHeader", children: /* @__PURE__ */ (0, import_jsx_runtime342.jsxs)(HStack, { gap: "5xl", children: [
38225
+ /* @__PURE__ */ (0, import_jsx_runtime342.jsx)(DataPoint, { label: "Balance due", children: /* @__PURE__ */ (0, import_jsx_runtime342.jsx)(Span, { children: convertCentsToCurrency(outstandingBalance) }) }),
38226
+ /* @__PURE__ */ (0, import_jsx_runtime342.jsx)(DataPoint, { label: "Open balance", children: /* @__PURE__ */ (0, import_jsx_runtime342.jsx)(Span, { children: convertCentsToCurrency(totalAmount) }) }),
38227
+ /* @__PURE__ */ (0, import_jsx_runtime342.jsx)(DataPoint, { label: "Status", children: /* @__PURE__ */ (0, import_jsx_runtime342.jsx)(InvoiceStatusCell, { invoice, inline: true }) })
38228
+ ] }) });
38229
+ };
38230
+
38231
+ // src/components/Invoices/InvoicesTable/InvoicesTable.tsx
38232
+ var import_react237 = require("react");
38233
+
38234
+ // src/features/invoices/api/useListInvoices.tsx
38235
+ var import_infinite7 = __toESM(require("swr/infinite"));
38236
+ var import_react233 = require("react");
38237
+ var import_lodash6 = __toESM(require_lodash());
38238
+ var import_effect17 = require("effect");
38239
+
38240
+ // src/types/utility/pagination.ts
38241
+ var import_effect16 = require("effect");
38242
+ var PaginatedResponseMetaSchema = import_effect16.Schema.Struct({
38243
+ cursor: import_effect16.Schema.NullOr(import_effect16.Schema.String),
38244
+ hasMore: (0, import_effect16.pipe)(
38245
+ import_effect16.Schema.propertySignature(import_effect16.Schema.Boolean),
38246
+ import_effect16.Schema.fromKey("has_more")
38247
+ ),
38248
+ totalCount: (0, import_effect16.pipe)(
38249
+ import_effect16.Schema.propertySignature(import_effect16.Schema.UndefinedOr(import_effect16.Schema.Number)),
38250
+ import_effect16.Schema.fromKey("total_count")
37388
38251
  )
37389
38252
  });
37390
38253
 
37391
38254
  // src/features/invoices/api/useListInvoices.tsx
37392
38255
  var LIST_INVOICES_TAG_KEY = "#list-invoices";
37393
- var ListInvoicesReturnSchema = import_effect11.Schema.Struct({
37394
- data: import_effect11.Schema.Array(InvoiceSchema),
37395
- meta: import_effect11.Schema.Struct({
38256
+ var ListInvoicesReturnSchema = import_effect17.Schema.Struct({
38257
+ data: import_effect17.Schema.Array(InvoiceSchema),
38258
+ meta: import_effect17.Schema.Struct({
37396
38259
  pagination: PaginatedResponseMetaSchema
37397
38260
  })
37398
38261
  });
@@ -37520,7 +38383,7 @@ function useListInvoices({
37520
38383
  showTotalCount: showTotalCount2
37521
38384
  }
37522
38385
  }
37523
- )().then(import_effect11.Schema.decodeUnknownPromise(ListInvoicesReturnSchema)),
38386
+ )().then(import_effect17.Schema.decodeUnknownPromise(ListInvoicesReturnSchema)),
37524
38387
  {
37525
38388
  keepPreviousData: true,
37526
38389
  revalidateFirstPage: false,
@@ -37534,20 +38397,20 @@ function useListInvoices({
37534
38397
  var import_react_table2 = require("@tanstack/react-table");
37535
38398
 
37536
38399
  // src/components/DataTable/DataTable.tsx
37537
- var import_react222 = require("react");
38400
+ var import_react235 = require("react");
37538
38401
 
37539
38402
  // src/components/ui/Table/Table.tsx
37540
- var import_react221 = require("react");
37541
- var import_react_aria_components14 = require("react-aria-components");
37542
- var import_classnames88 = __toESM(require("classnames"));
37543
- var import_jsx_runtime327 = require("react/jsx-runtime");
38403
+ var import_react234 = require("react");
38404
+ var import_react_aria_components18 = require("react-aria-components");
38405
+ var import_classnames91 = __toESM(require("classnames"));
38406
+ var import_jsx_runtime343 = require("react/jsx-runtime");
37544
38407
  var CSS_PREFIX2 = "Layer__UI__Table";
37545
- var getClassName = (component, additionalClassNames) => (0, import_classnames88.default)(`${CSS_PREFIX2}-${component}`, additionalClassNames);
37546
- var Table2 = (0, import_react221.forwardRef)(
38408
+ var getClassName = (component, additionalClassNames) => (0, import_classnames91.default)(`${CSS_PREFIX2}-${component}`, additionalClassNames);
38409
+ var Table2 = (0, import_react234.forwardRef)(
37547
38410
  (_a, ref) => {
37548
38411
  var _b = _a, { children, className } = _b, restProps = __objRest(_b, ["children", "className"]);
37549
- return /* @__PURE__ */ (0, import_jsx_runtime327.jsx)(
37550
- import_react_aria_components14.Table,
38412
+ return /* @__PURE__ */ (0, import_jsx_runtime343.jsx)(
38413
+ import_react_aria_components18.Table,
37551
38414
  __spreadProps(__spreadValues({
37552
38415
  className: getClassName("Table" /* Table */, className)
37553
38416
  }, restProps), {
@@ -37560,8 +38423,8 @@ var Table2 = (0, import_react221.forwardRef)(
37560
38423
  Table2.displayName = "Table" /* Table */;
37561
38424
  var TableHeaderInner = (_a, ref) => {
37562
38425
  var _b = _a, { children, className } = _b, restProps = __objRest(_b, ["children", "className"]);
37563
- return /* @__PURE__ */ (0, import_jsx_runtime327.jsx)(
37564
- import_react_aria_components14.TableHeader,
38426
+ return /* @__PURE__ */ (0, import_jsx_runtime343.jsx)(
38427
+ import_react_aria_components18.TableHeader,
37565
38428
  __spreadProps(__spreadValues({
37566
38429
  className: getClassName("TableHeader" /* TableHeader */, className)
37567
38430
  }, restProps), {
@@ -37570,12 +38433,12 @@ var TableHeaderInner = (_a, ref) => {
37570
38433
  })
37571
38434
  );
37572
38435
  };
37573
- var TableHeader = (0, import_react221.forwardRef)(TableHeaderInner);
38436
+ var TableHeader = (0, import_react234.forwardRef)(TableHeaderInner);
37574
38437
  TableHeader.displayName = "TableHeader" /* TableHeader */;
37575
38438
  var TableBodyInner = (_a, ref) => {
37576
38439
  var _b = _a, { children, className } = _b, restProps = __objRest(_b, ["children", "className"]);
37577
- return /* @__PURE__ */ (0, import_jsx_runtime327.jsx)(
37578
- import_react_aria_components14.TableBody,
38440
+ return /* @__PURE__ */ (0, import_jsx_runtime343.jsx)(
38441
+ import_react_aria_components18.TableBody,
37579
38442
  __spreadProps(__spreadValues({
37580
38443
  className: getClassName("TableBody" /* TableBody */, className)
37581
38444
  }, restProps), {
@@ -37584,12 +38447,12 @@ var TableBodyInner = (_a, ref) => {
37584
38447
  })
37585
38448
  );
37586
38449
  };
37587
- var TableBody2 = (0, import_react221.forwardRef)(TableBodyInner);
38450
+ var TableBody2 = (0, import_react234.forwardRef)(TableBodyInner);
37588
38451
  TableBody2.displayName = "TableBody" /* TableBody */;
37589
38452
  var RowInner = (_a, ref) => {
37590
38453
  var _b = _a, { children, className } = _b, restProps = __objRest(_b, ["children", "className"]);
37591
- return /* @__PURE__ */ (0, import_jsx_runtime327.jsx)(
37592
- import_react_aria_components14.Row,
38454
+ return /* @__PURE__ */ (0, import_jsx_runtime343.jsx)(
38455
+ import_react_aria_components18.Row,
37593
38456
  __spreadProps(__spreadValues({
37594
38457
  className: getClassName("Row" /* Row */, className)
37595
38458
  }, restProps), {
@@ -37598,14 +38461,14 @@ var RowInner = (_a, ref) => {
37598
38461
  })
37599
38462
  );
37600
38463
  };
37601
- var Row2 = (0, import_react221.forwardRef)(RowInner);
38464
+ var Row2 = (0, import_react234.forwardRef)(RowInner);
37602
38465
  Row2.displayName = "Row" /* Row */;
37603
- var Column = (0, import_react221.forwardRef)(
38466
+ var Column = (0, import_react234.forwardRef)(
37604
38467
  (_a, ref) => {
37605
38468
  var _b = _a, { children, className, textAlign = "left" } = _b, restProps = __objRest(_b, ["children", "className", "textAlign"]);
37606
38469
  const dataProperties = toDataProperties({ "text-align": textAlign });
37607
- return /* @__PURE__ */ (0, import_jsx_runtime327.jsx)(
37608
- import_react_aria_components14.Column,
38470
+ return /* @__PURE__ */ (0, import_jsx_runtime343.jsx)(
38471
+ import_react_aria_components18.Column,
37609
38472
  __spreadProps(__spreadValues(__spreadValues({
37610
38473
  className: getClassName("Column" /* Column */, className)
37611
38474
  }, restProps), dataProperties), {
@@ -37616,11 +38479,11 @@ var Column = (0, import_react221.forwardRef)(
37616
38479
  }
37617
38480
  );
37618
38481
  Column.displayName = "Column" /* Column */;
37619
- var Cell5 = (0, import_react221.forwardRef)(
38482
+ var Cell5 = (0, import_react234.forwardRef)(
37620
38483
  (_a, ref) => {
37621
38484
  var _b = _a, { children, className } = _b, restProps = __objRest(_b, ["children", "className"]);
37622
- return /* @__PURE__ */ (0, import_jsx_runtime327.jsx)(
37623
- import_react_aria_components14.Cell,
38485
+ return /* @__PURE__ */ (0, import_jsx_runtime343.jsx)(
38486
+ import_react_aria_components18.Cell,
37624
38487
  __spreadProps(__spreadValues({
37625
38488
  className: getClassName("Cell" /* Cell */, className)
37626
38489
  }, restProps), {
@@ -37633,7 +38496,7 @@ var Cell5 = (0, import_react221.forwardRef)(
37633
38496
  Cell5.displayName = "Cell" /* Cell */;
37634
38497
 
37635
38498
  // src/components/DataTable/DataTable.tsx
37636
- var import_jsx_runtime328 = require("react/jsx-runtime");
38499
+ var import_jsx_runtime344 = require("react/jsx-runtime");
37637
38500
  var DataTable = ({
37638
38501
  columnConfig,
37639
38502
  data,
@@ -37643,19 +38506,20 @@ var DataTable = ({
37643
38506
  ariaLabel,
37644
38507
  slots
37645
38508
  }) => {
37646
- const columns2 = Object.values(columnConfig);
38509
+ const columns = Object.values(columnConfig);
37647
38510
  const { EmptyState, ErrorState } = slots;
37648
- const renderTableBody = (0, import_react222.useMemo)(() => {
38511
+ const isEmptyTable = (data == null ? void 0 : data.length) === 0;
38512
+ const renderTableBody = (0, import_react235.useMemo)(() => {
37649
38513
  if (isError) {
37650
- return /* @__PURE__ */ (0, import_jsx_runtime328.jsx)(Row2, { children: /* @__PURE__ */ (0, import_jsx_runtime328.jsx)(Cell5, { colSpan: columns2.length, children: /* @__PURE__ */ (0, import_jsx_runtime328.jsx)(ErrorState, {}) }) });
38514
+ return /* @__PURE__ */ (0, import_jsx_runtime344.jsx)(Row2, { children: /* @__PURE__ */ (0, import_jsx_runtime344.jsx)(Cell5, { colSpan: columns.length, children: /* @__PURE__ */ (0, import_jsx_runtime344.jsx)(ErrorState, {}) }) });
37651
38515
  }
37652
38516
  if (isLoading) {
37653
- return /* @__PURE__ */ (0, import_jsx_runtime328.jsx)(Row2, { children: /* @__PURE__ */ (0, import_jsx_runtime328.jsx)(Cell5, { colSpan: columns2.length, children: /* @__PURE__ */ (0, import_jsx_runtime328.jsx)(Loader2, {}) }) });
38517
+ return /* @__PURE__ */ (0, import_jsx_runtime344.jsx)(Row2, { children: /* @__PURE__ */ (0, import_jsx_runtime344.jsx)(Cell5, { colSpan: columns.length, children: /* @__PURE__ */ (0, import_jsx_runtime344.jsx)(Loader2, {}) }) });
37654
38518
  }
37655
- if ((data == null ? void 0 : data.length) === 0) {
37656
- return /* @__PURE__ */ (0, import_jsx_runtime328.jsx)(Row2, { children: /* @__PURE__ */ (0, import_jsx_runtime328.jsx)(Cell5, { colSpan: columns2.length, children: /* @__PURE__ */ (0, import_jsx_runtime328.jsx)(EmptyState, {}) }) });
38519
+ if (isEmptyTable) {
38520
+ return /* @__PURE__ */ (0, import_jsx_runtime344.jsx)(Row2, { children: /* @__PURE__ */ (0, import_jsx_runtime344.jsx)(Cell5, { colSpan: columns.length, children: /* @__PURE__ */ (0, import_jsx_runtime344.jsx)(EmptyState, {}) }) });
37657
38521
  }
37658
- const RowRenderer = (row) => /* @__PURE__ */ (0, import_jsx_runtime328.jsx)(Row2, { children: columns2.map((col) => /* @__PURE__ */ (0, import_jsx_runtime328.jsx)(
38522
+ const RowRenderer = (row) => /* @__PURE__ */ (0, import_jsx_runtime344.jsx)(Row2, { children: columns.map((col) => /* @__PURE__ */ (0, import_jsx_runtime344.jsx)(
37659
38523
  Cell5,
37660
38524
  {
37661
38525
  className: `Layer__UI__Table-Cell__${componentName}--${col.id}`,
@@ -37665,16 +38529,16 @@ var DataTable = ({
37665
38529
  )) }, row.id);
37666
38530
  RowRenderer.displayName = "Row";
37667
38531
  return RowRenderer;
37668
- }, [isLoading, data, columns2, EmptyState, componentName]);
37669
- return /* @__PURE__ */ (0, import_jsx_runtime328.jsxs)(Table2, { "aria-label": ariaLabel, className: `Layer__UI__Table__${componentName}`, children: [
37670
- /* @__PURE__ */ (0, import_jsx_runtime328.jsx)(TableHeader, { columns: columns2, children: ({ id, header, isRowHeader }) => /* @__PURE__ */ (0, import_jsx_runtime328.jsx)(Column, { isRowHeader, className: `Layer__UI__Table-Column__${componentName}--${id}`, children: header }, id) }),
37671
- /* @__PURE__ */ (0, import_jsx_runtime328.jsx)(TableBody2, { items: data, children: renderTableBody })
38532
+ }, [isError, isLoading, isEmptyTable, columns, ErrorState, EmptyState, componentName]);
38533
+ return /* @__PURE__ */ (0, import_jsx_runtime344.jsxs)(Table2, { "aria-label": ariaLabel, className: `Layer__UI__Table__${componentName}`, children: [
38534
+ /* @__PURE__ */ (0, import_jsx_runtime344.jsx)(TableHeader, { columns, children: ({ id, header, isRowHeader }) => /* @__PURE__ */ (0, import_jsx_runtime344.jsx)(Column, { isRowHeader, className: `Layer__UI__Table-Column__${componentName}--${id}`, children: header }, id) }),
38535
+ /* @__PURE__ */ (0, import_jsx_runtime344.jsx)(TableBody2, { items: data, children: renderTableBody })
37672
38536
  ] });
37673
38537
  };
37674
38538
 
37675
38539
  // src/components/DataTable/PaginatedTable.tsx
37676
- var import_react223 = require("react");
37677
- var import_jsx_runtime329 = require("react/jsx-runtime");
38540
+ var import_react236 = require("react");
38541
+ var import_jsx_runtime345 = require("react/jsx-runtime");
37678
38542
  var EMPTY_ARRAY = [];
37679
38543
  function PaginatedTable({
37680
38544
  data,
@@ -37687,10 +38551,10 @@ function PaginatedTable({
37687
38551
  slots
37688
38552
  }) {
37689
38553
  const { pageSize = 20, hasMore, fetchMore } = paginationProps;
37690
- const [pagination, setPagination] = (0, import_react223.useState)({ pageIndex: 0, pageSize });
38554
+ const [pagination, setPagination] = (0, import_react236.useState)({ pageIndex: 0, pageSize });
37691
38555
  const columnHelper = (0, import_react_table2.createColumnHelper)();
37692
- const columns2 = Object.values(columnConfig);
37693
- const columnDefs = columns2.map((col) => {
38556
+ const columns = Object.values(columnConfig);
38557
+ const columnDefs = columns.map((col) => {
37694
38558
  return columnHelper.display({
37695
38559
  id: col.id,
37696
38560
  header: () => col.header,
@@ -37707,12 +38571,12 @@ function PaginatedTable({
37707
38571
  autoResetPageIndex: false
37708
38572
  });
37709
38573
  const { rows } = table.getRowModel();
37710
- const rowData = (0, import_react223.useMemo)(() => rows.map((r) => r.original), [rows]);
37711
- const onPageChange = (0, import_react223.useCallback)((page) => {
38574
+ const rowData = (0, import_react236.useMemo)(() => rows.map((r) => r.original), [rows]);
38575
+ const onPageChange = (0, import_react236.useCallback)((page) => {
37712
38576
  table.setPageIndex(page - 1);
37713
38577
  }, [table]);
37714
- return /* @__PURE__ */ (0, import_jsx_runtime329.jsxs)(VStack, { children: [
37715
- /* @__PURE__ */ (0, import_jsx_runtime329.jsx)(
38578
+ return /* @__PURE__ */ (0, import_jsx_runtime345.jsxs)(VStack, { children: [
38579
+ /* @__PURE__ */ (0, import_jsx_runtime345.jsx)(
37716
38580
  DataTable,
37717
38581
  {
37718
38582
  ariaLabel,
@@ -37724,7 +38588,7 @@ function PaginatedTable({
37724
38588
  slots
37725
38589
  }
37726
38590
  ),
37727
- !isError && !isLoading && /* @__PURE__ */ (0, import_jsx_runtime329.jsx)(
38591
+ !isError && !isLoading && /* @__PURE__ */ (0, import_jsx_runtime345.jsx)(
37728
38592
  Pagination,
37729
38593
  {
37730
38594
  currentPage: table.getState().pagination.pageIndex + 1,
@@ -37738,14 +38602,11 @@ function PaginatedTable({
37738
38602
  ] });
37739
38603
  }
37740
38604
 
37741
- // src/components/Invoices/InvoicesTable.tsx
37742
- var import_pluralize6 = __toESM(require("pluralize"));
37743
-
37744
38605
  // src/icons/ChevronRightFill.tsx
37745
- var import_jsx_runtime330 = require("react/jsx-runtime");
38606
+ var import_jsx_runtime346 = require("react/jsx-runtime");
37746
38607
  var ChevronRightFill = (_a) => {
37747
38608
  var _b = _a, { size = 18 } = _b, props = __objRest(_b, ["size"]);
37748
- return /* @__PURE__ */ (0, import_jsx_runtime330.jsxs)(
38609
+ return /* @__PURE__ */ (0, import_jsx_runtime346.jsxs)(
37749
38610
  "svg",
37750
38611
  __spreadProps(__spreadValues({
37751
38612
  xmlns: "http://www.w3.org/2000/svg",
@@ -37755,8 +38616,8 @@ var ChevronRightFill = (_a) => {
37755
38616
  width: size,
37756
38617
  height: size,
37757
38618
  children: [
37758
- /* @__PURE__ */ (0, import_jsx_runtime330.jsx)("path", { d: "M6.75 4.5L11.25 9L6.75 13.5", fill: "currentColor" }),
37759
- /* @__PURE__ */ (0, import_jsx_runtime330.jsx)(
38619
+ /* @__PURE__ */ (0, import_jsx_runtime346.jsx)("path", { d: "M6.75 4.5L11.25 9L6.75 13.5", fill: "currentColor" }),
38620
+ /* @__PURE__ */ (0, import_jsx_runtime346.jsx)(
37760
38621
  "path",
37761
38622
  {
37762
38623
  d: "M6.75 4.5L11.25 9L6.75 13.5Z",
@@ -37771,38 +38632,38 @@ var ChevronRightFill = (_a) => {
37771
38632
  };
37772
38633
  var ChevronRightFill_default = ChevronRightFill;
37773
38634
 
37774
- // src/components/Invoices/InvoicesTable.tsx
37775
- var import_lucide_react16 = require("lucide-react");
38635
+ // src/components/Invoices/InvoicesTable/InvoicesTable.tsx
38636
+ var import_lucide_react17 = require("lucide-react");
37776
38637
 
37777
38638
  // src/components/DataTable/DataTableHeader.tsx
37778
- var import_jsx_runtime331 = require("react/jsx-runtime");
38639
+ var import_jsx_runtime347 = require("react/jsx-runtime");
37779
38640
  var DataTableHeader = ({ name, count, slotProps = {}, slots = {} }) => {
37780
38641
  const { showCount, totalCount } = count != null ? count : {};
37781
38642
  const { Filters: Filters2, HeaderActions, HeaderFilters } = slots;
37782
- return /* @__PURE__ */ (0, import_jsx_runtime331.jsxs)(VStack, { children: [
37783
- /* @__PURE__ */ (0, import_jsx_runtime331.jsxs)(HStack, { justify: "space-between", align: "center", className: "Layer__DataTableHeader__Header", children: [
37784
- /* @__PURE__ */ (0, import_jsx_runtime331.jsxs)(HStack, { pis: "md", align: "center", gap: "xl", children: [
37785
- /* @__PURE__ */ (0, import_jsx_runtime331.jsxs)(HStack, { align: "center", gap: "sm", children: [
37786
- /* @__PURE__ */ (0, import_jsx_runtime331.jsx)(Span, { weight: "bold", size: "lg", children: name }),
37787
- showCount && (totalCount ? /* @__PURE__ */ (0, import_jsx_runtime331.jsx)(Badge, { variant: "default" /* DEFAULT */, size: "medium" /* MEDIUM */, children: totalCount }) : /* @__PURE__ */ (0, import_jsx_runtime331.jsx)(BadgeLoader, {}))
38643
+ return /* @__PURE__ */ (0, import_jsx_runtime347.jsxs)(VStack, { children: [
38644
+ /* @__PURE__ */ (0, import_jsx_runtime347.jsxs)(HStack, { justify: "space-between", align: "center", className: "Layer__DataTableHeader__Header", children: [
38645
+ /* @__PURE__ */ (0, import_jsx_runtime347.jsxs)(HStack, { pis: "md", align: "center", gap: "xl", children: [
38646
+ /* @__PURE__ */ (0, import_jsx_runtime347.jsxs)(HStack, { align: "center", gap: "sm", children: [
38647
+ /* @__PURE__ */ (0, import_jsx_runtime347.jsx)(Span, { weight: "bold", size: "lg", children: name }),
38648
+ showCount && (totalCount ? /* @__PURE__ */ (0, import_jsx_runtime347.jsx)(Badge, { variant: "default" /* DEFAULT */, size: "medium" /* MEDIUM */, children: totalCount }) : /* @__PURE__ */ (0, import_jsx_runtime347.jsx)(BadgeLoader, {}))
37788
38649
  ] }),
37789
- HeaderFilters && /* @__PURE__ */ (0, import_jsx_runtime331.jsx)(HeaderFilters, {})
38650
+ HeaderFilters && /* @__PURE__ */ (0, import_jsx_runtime347.jsx)(HeaderFilters, {})
37790
38651
  ] }),
37791
- /* @__PURE__ */ (0, import_jsx_runtime331.jsxs)(HStack, { pie: "md", align: "center", gap: "3xs", children: [
37792
- slotProps.SearchField && /* @__PURE__ */ (0, import_jsx_runtime331.jsx)(SearchField, __spreadValues({}, slotProps.SearchField)),
37793
- HeaderActions && /* @__PURE__ */ (0, import_jsx_runtime331.jsx)(HeaderActions, {})
38652
+ /* @__PURE__ */ (0, import_jsx_runtime347.jsxs)(HStack, { pie: "md", align: "center", gap: "3xs", children: [
38653
+ slotProps.SearchField && /* @__PURE__ */ (0, import_jsx_runtime347.jsx)(SearchField, __spreadValues({}, slotProps.SearchField)),
38654
+ HeaderActions && /* @__PURE__ */ (0, import_jsx_runtime347.jsx)(HeaderActions, {})
37794
38655
  ] })
37795
38656
  ] }),
37796
- Filters2 && /* @__PURE__ */ (0, import_jsx_runtime331.jsxs)(HStack, { pis: "md", pie: "md", justify: "space-between", align: "center", className: "Layer__DataTableHeader__Filters", children: [
37797
- /* @__PURE__ */ (0, import_jsx_runtime331.jsx)(Filters2, {}),
37798
- slotProps.ClearFiltersButton && /* @__PURE__ */ (0, import_jsx_runtime331.jsx)(Button2, __spreadProps(__spreadValues({ variant: "outlined" }, slotProps.ClearFiltersButton), { children: "Clear All Filters" }))
38657
+ Filters2 && /* @__PURE__ */ (0, import_jsx_runtime347.jsxs)(HStack, { pis: "md", pie: "md", justify: "space-between", align: "center", className: "Layer__DataTableHeader__Filters", children: [
38658
+ /* @__PURE__ */ (0, import_jsx_runtime347.jsx)(Filters2, {}),
38659
+ slotProps.ClearFiltersButton && /* @__PURE__ */ (0, import_jsx_runtime347.jsx)(Button2, __spreadProps(__spreadValues({ variant: "outlined" }, slotProps.ClearFiltersButton), { children: "Clear All Filters" }))
37799
38660
  ] })
37800
38661
  ] });
37801
38662
  };
37802
38663
 
37803
- // src/components/Invoices/InvoicesTable.tsx
38664
+ // src/components/Invoices/InvoicesTable/InvoicesTable.tsx
37804
38665
  var import_date_fns51 = require("date-fns");
37805
- var import_jsx_runtime332 = require("react/jsx-runtime");
38666
+ var import_jsx_runtime348 = require("react/jsx-runtime");
37806
38667
  var COMPONENT_NAME10 = "InvoicesTable";
37807
38668
  var InvoiceStatusOptionConfig = {
37808
38669
  ["All" /* All */]: { label: "All", value: "All" /* All */ },
@@ -37823,12 +38684,12 @@ var AmountCell = ({ invoice }) => {
37823
38684
  case "WRITTEN_OFF" /* WrittenOff */:
37824
38685
  case "VOIDED" /* Voided */:
37825
38686
  case "SENT" /* Sent */: {
37826
- return /* @__PURE__ */ (0, import_jsx_runtime332.jsx)(VStack, { children: /* @__PURE__ */ (0, import_jsx_runtime332.jsx)(Span, { align: "right", children: totalAmount }) });
38687
+ return /* @__PURE__ */ (0, import_jsx_runtime348.jsx)(VStack, { children: /* @__PURE__ */ (0, import_jsx_runtime348.jsx)(Span, { align: "right", children: totalAmount }) });
37827
38688
  }
37828
38689
  case "PARTIALLY_PAID" /* PartiallyPaid */: {
37829
- return /* @__PURE__ */ (0, import_jsx_runtime332.jsxs)(VStack, { children: [
37830
- /* @__PURE__ */ (0, import_jsx_runtime332.jsx)(Span, { align: "right", children: totalAmount }),
37831
- /* @__PURE__ */ (0, import_jsx_runtime332.jsxs)(Span, { align: "right", variant: "subtle", size: "sm", children: [
38690
+ return /* @__PURE__ */ (0, import_jsx_runtime348.jsxs)(VStack, { children: [
38691
+ /* @__PURE__ */ (0, import_jsx_runtime348.jsx)(Span, { align: "right", children: totalAmount }),
38692
+ /* @__PURE__ */ (0, import_jsx_runtime348.jsxs)(Span, { align: "right", variant: "subtle", size: "sm", children: [
37832
38693
  outstandingBalance,
37833
38694
  " ",
37834
38695
  "outstanding"
@@ -37843,71 +38704,11 @@ var AmountCell = ({ invoice }) => {
37843
38704
  }
37844
38705
  }
37845
38706
  };
37846
- var getDueStatusConfig = (invoice) => {
37847
- switch (invoice.status) {
37848
- case "WRITTEN_OFF" /* WrittenOff */: {
37849
- return { text: "Written Off" };
37850
- }
37851
- case "PARTIALLY_WRITTEN_OFF" /* PartiallyWrittenOff */: {
37852
- return { text: "Partially Written Off" };
37853
- }
37854
- case "PAID" /* Paid */: {
37855
- return {
37856
- text: "Paid",
37857
- badge: /* @__PURE__ */ (0, import_jsx_runtime332.jsx)(Badge, { variant: "success" /* SUCCESS */, size: "small" /* SMALL */, icon: /* @__PURE__ */ (0, import_jsx_runtime332.jsx)(CheckCircle_default, { size: 12 }), iconOnly: true })
37858
- };
37859
- }
37860
- case "VOIDED" /* Voided */: {
37861
- return { text: "Voided" };
37862
- }
37863
- case "SENT" /* Sent */:
37864
- case "PARTIALLY_PAID" /* PartiallyPaid */: {
37865
- if (invoice.dueAt === null) {
37866
- return {
37867
- text: invoice.status === "PARTIALLY_PAID" /* PartiallyPaid */ ? "Partially Paid" : "Sent"
37868
- };
37869
- }
37870
- const dueDifference = getDueDifference(invoice.dueAt);
37871
- if (dueDifference === 0) {
37872
- return {
37873
- text: "Due Today"
37874
- };
37875
- }
37876
- if (dueDifference < 0) {
37877
- return {
37878
- text: "Overdue",
37879
- subText: `Due ${(0, import_pluralize6.default)("day", Math.abs(dueDifference), true)} ago`,
37880
- badge: /* @__PURE__ */ (0, import_jsx_runtime332.jsx)(Badge, { variant: "warning" /* WARNING */, size: "small" /* SMALL */, icon: /* @__PURE__ */ (0, import_jsx_runtime332.jsx)(AlertCircle_default, { size: 12 }), iconOnly: true })
37881
- };
37882
- }
37883
- return {
37884
- text: "Sent",
37885
- subText: `Due in ${(0, import_pluralize6.default)("day", Math.abs(dueDifference), true)}`
37886
- };
37887
- }
37888
- default: {
37889
- unsafeAssertUnreachable({
37890
- value: invoice.status,
37891
- message: "Unexpected invoice status"
37892
- });
37893
- }
37894
- }
37895
- };
37896
- var StatusCell = ({ invoice }) => {
37897
- const dueStatus = getDueStatusConfig(invoice);
37898
- return /* @__PURE__ */ (0, import_jsx_runtime332.jsxs)(HStack, { gap: "xs", align: "center", children: [
37899
- dueStatus.badge,
37900
- /* @__PURE__ */ (0, import_jsx_runtime332.jsxs)(VStack, { children: [
37901
- /* @__PURE__ */ (0, import_jsx_runtime332.jsx)(Span, { children: dueStatus.text }),
37902
- /* @__PURE__ */ (0, import_jsx_runtime332.jsx)(Span, { variant: "subtle", size: "sm", children: dueStatus.subText })
37903
- ] })
37904
- ] });
37905
- };
37906
- var getCustomerName = (invoice) => {
38707
+ var getCustomerName2 = (invoice) => {
37907
38708
  const { recipientName, customer } = invoice;
37908
38709
  return recipientName || (customer == null ? void 0 : customer.individualName) || (customer == null ? void 0 : customer.companyName);
37909
38710
  };
37910
- var columns = {
38711
+ var getColumnConfig = (onSelectInvoice) => ({
37911
38712
  ["SentAt" /* SentAt */]: {
37912
38713
  id: "SentAt" /* SentAt */,
37913
38714
  header: "Sent Date",
@@ -37922,35 +38723,35 @@ var columns = {
37922
38723
  ["Customer" /* Customer */]: {
37923
38724
  id: "Customer" /* Customer */,
37924
38725
  header: "Customer",
37925
- cell: (row) => getCustomerName(row)
38726
+ cell: (row) => getCustomerName2(row)
37926
38727
  },
37927
38728
  ["Total" /* Total */]: {
37928
38729
  id: "Total" /* Total */,
37929
38730
  header: "Amount",
37930
- cell: (row) => /* @__PURE__ */ (0, import_jsx_runtime332.jsx)(AmountCell, { invoice: row })
38731
+ cell: (row) => /* @__PURE__ */ (0, import_jsx_runtime348.jsx)(AmountCell, { invoice: row })
37931
38732
  },
37932
38733
  ["Status" /* Status */]: {
37933
38734
  id: "Status" /* Status */,
37934
38735
  header: "Status",
37935
- cell: (row) => /* @__PURE__ */ (0, import_jsx_runtime332.jsx)(StatusCell, { invoice: row })
38736
+ cell: (row) => /* @__PURE__ */ (0, import_jsx_runtime348.jsx)(InvoiceStatusCell, { invoice: row })
37936
38737
  },
37937
38738
  ["Expand" /* Expand */]: {
37938
38739
  id: "Expand" /* Expand */,
37939
- cell: (_row) => /* @__PURE__ */ (0, import_jsx_runtime332.jsx)(Button2, { inset: true, icon: true, "aria-label": "View invoice", variant: "ghost", children: /* @__PURE__ */ (0, import_jsx_runtime332.jsx)(ChevronRightFill_default, {}) })
38740
+ cell: (row) => /* @__PURE__ */ (0, import_jsx_runtime348.jsx)(Button2, { inset: true, icon: true, onPress: () => onSelectInvoice(row), "aria-label": "View invoice", variant: "ghost", children: /* @__PURE__ */ (0, import_jsx_runtime348.jsx)(ChevronRightFill_default, {}) })
37940
38741
  }
37941
- };
37942
- var unpaidStatuses = ["SENT" /* Sent */, "PARTIALLY_PAID" /* PartiallyPaid */];
38742
+ });
38743
+ var UNPAID_STATUSES2 = ["SENT" /* Sent */, "PARTIALLY_PAID" /* PartiallyPaid */];
37943
38744
  var getListInvoiceParams = ({ statusFilter }) => {
37944
38745
  if (!statusFilter) return {};
37945
38746
  switch (statusFilter) {
37946
38747
  case "All" /* All */:
37947
38748
  return {};
37948
38749
  case "Unpaid" /* Unpaid */:
37949
- return { status: unpaidStatuses };
38750
+ return { status: UNPAID_STATUSES2 };
37950
38751
  case "Overdue" /* Overdue */:
37951
- return { status: unpaidStatuses, dueAtEnd: (0, import_date_fns51.endOfYesterday)() };
38752
+ return { status: UNPAID_STATUSES2, dueAtEnd: (0, import_date_fns51.endOfYesterday)() };
37952
38753
  case "Sent" /* Sent */:
37953
- return { status: unpaidStatuses, dueAtStart: (0, import_date_fns51.startOfToday)() };
38754
+ return { status: UNPAID_STATUSES2, dueAtStart: (0, import_date_fns51.startOfToday)() };
37954
38755
  case "Paid" /* Paid */:
37955
38756
  return { status: ["PAID" /* Paid */, "PARTIALLY_WRITTEN_OFF" /* PartiallyWrittenOff */] };
37956
38757
  case "Written Off" /* WrittenOff */:
@@ -37964,9 +38765,9 @@ var getListInvoiceParams = ({ statusFilter }) => {
37964
38765
  });
37965
38766
  }
37966
38767
  };
37967
- var InvoicesTable = () => {
37968
- const [selectedInvoiceStatusOption, setSelectedInvoiceStatusOption] = (0, import_react224.useState)(ALL_OPTION);
37969
- const listInvoiceParams = (0, import_react224.useMemo)(
38768
+ var InvoicesTable = ({ onCreateInvoice, onSelectInvoice }) => {
38769
+ const [selectedInvoiceStatusOption, setSelectedInvoiceStatusOption] = (0, import_react237.useState)(ALL_OPTION);
38770
+ const listInvoiceParams = (0, import_react237.useMemo)(
37970
38771
  () => getListInvoiceParams({ statusFilter: selectedInvoiceStatusOption == null ? void 0 : selectedInvoiceStatusOption.value }),
37971
38772
  [selectedInvoiceStatusOption == null ? void 0 : selectedInvoiceStatusOption.value]
37972
38773
  );
@@ -37974,25 +38775,25 @@ var InvoicesTable = () => {
37974
38775
  const invoices = data == null ? void 0 : data.flatMap(({ data: data2 }) => data2);
37975
38776
  const paginationMeta = data == null ? void 0 : data[data.length - 1].meta.pagination;
37976
38777
  const hasMore = paginationMeta == null ? void 0 : paginationMeta.hasMore;
37977
- const fetchMore = (0, import_react224.useCallback)(() => {
38778
+ const fetchMore = (0, import_react237.useCallback)(() => {
37978
38779
  if (hasMore) {
37979
38780
  void setSize(size + 1);
37980
38781
  }
37981
38782
  }, [hasMore, setSize, size]);
37982
- const paginationProps = (0, import_react224.useMemo)(() => {
38783
+ const paginationProps = (0, import_react237.useMemo)(() => {
37983
38784
  return {
37984
38785
  pageSize: 10,
37985
38786
  hasMore,
37986
38787
  fetchMore
37987
38788
  };
37988
38789
  }, [fetchMore, hasMore]);
37989
- const options = (0, import_react224.useMemo)(() => Object.values(InvoiceStatusOptionConfig), []);
37990
- const SelectedValue = (0, import_react224.useMemo)(() => {
38790
+ const options = (0, import_react237.useMemo)(() => Object.values(InvoiceStatusOptionConfig), []);
38791
+ const SelectedValue = (0, import_react237.useMemo)(() => {
37991
38792
  const label = selectedInvoiceStatusOption == null ? void 0 : selectedInvoiceStatusOption.label;
37992
38793
  return label ? `Status: ${label}` : "Status";
37993
38794
  }, [selectedInvoiceStatusOption == null ? void 0 : selectedInvoiceStatusOption.label]);
37994
- const StatusFilter = (0, import_react224.useCallback)(
37995
- () => /* @__PURE__ */ (0, import_jsx_runtime332.jsx)(
38795
+ const StatusFilter = (0, import_react237.useCallback)(
38796
+ () => /* @__PURE__ */ (0, import_jsx_runtime348.jsx)(
37996
38797
  ComboBox,
37997
38798
  {
37998
38799
  className: "Layer__InvoicesTable__StatusFilter",
@@ -38008,27 +38809,27 @@ var InvoicesTable = () => {
38008
38809
  ),
38009
38810
  [SelectedValue, options, selectedInvoiceStatusOption]
38010
38811
  );
38011
- const CreateInvoiceButton = (0, import_react224.useCallback)(
38012
- () => /* @__PURE__ */ (0, import_jsx_runtime332.jsxs)(Button2, { children: [
38812
+ const CreateInvoiceButton = (0, import_react237.useCallback)(
38813
+ () => /* @__PURE__ */ (0, import_jsx_runtime348.jsxs)(Button2, { onPress: onCreateInvoice, children: [
38013
38814
  "Create Invoice",
38014
- /* @__PURE__ */ (0, import_jsx_runtime332.jsx)(import_lucide_react16.Plus, { size: 16 })
38815
+ /* @__PURE__ */ (0, import_jsx_runtime348.jsx)(import_lucide_react17.Plus, { size: 16 })
38015
38816
  ] }),
38016
- []
38817
+ [onCreateInvoice]
38017
38818
  );
38018
- const InvoicesTableEmptyState = (0, import_react224.useCallback)(() => {
38819
+ const InvoicesTableEmptyState = (0, import_react237.useCallback)(() => {
38019
38820
  const isFiltered = selectedInvoiceStatusOption && selectedInvoiceStatusOption !== ALL_OPTION;
38020
- return /* @__PURE__ */ (0, import_jsx_runtime332.jsx)(
38821
+ return /* @__PURE__ */ (0, import_jsx_runtime348.jsx)(
38021
38822
  DataState,
38022
38823
  {
38023
38824
  status: "allDone" /* allDone */,
38024
38825
  title: isFiltered ? "No results found" : "No invoices yet",
38025
38826
  description: isFiltered ? "We couldn\u2019t find any invoices with the current filters. Try changing or clearing them to see more results." : "Add your first invoice to start tracking what your customers owe you.",
38026
- icon: isFiltered ? /* @__PURE__ */ (0, import_jsx_runtime332.jsx)(import_lucide_react16.Search, {}) : /* @__PURE__ */ (0, import_jsx_runtime332.jsx)(import_lucide_react16.HandCoins, {}),
38827
+ icon: isFiltered ? /* @__PURE__ */ (0, import_jsx_runtime348.jsx)(import_lucide_react17.Search, {}) : /* @__PURE__ */ (0, import_jsx_runtime348.jsx)(import_lucide_react17.HandCoins, {}),
38027
38828
  spacing: true
38028
38829
  }
38029
38830
  );
38030
38831
  }, [selectedInvoiceStatusOption]);
38031
- const InvoicesTableErrorState = (0, import_react224.useCallback)(() => /* @__PURE__ */ (0, import_jsx_runtime332.jsx)(
38832
+ const InvoicesTableErrorState = (0, import_react237.useCallback)(() => /* @__PURE__ */ (0, import_jsx_runtime348.jsx)(
38032
38833
  DataState,
38033
38834
  {
38034
38835
  status: "failed" /* failed */,
@@ -38040,8 +38841,9 @@ var InvoicesTable = () => {
38040
38841
  spacing: true
38041
38842
  }
38042
38843
  ), [refetch]);
38043
- return /* @__PURE__ */ (0, import_jsx_runtime332.jsxs)(Container, { name: "InvoicesTable", children: [
38044
- /* @__PURE__ */ (0, import_jsx_runtime332.jsx)(
38844
+ const columnConfig = (0, import_react237.useMemo)(() => getColumnConfig(onSelectInvoice), [onSelectInvoice]);
38845
+ return /* @__PURE__ */ (0, import_jsx_runtime348.jsxs)(Container, { name: "InvoicesTable", children: [
38846
+ /* @__PURE__ */ (0, import_jsx_runtime348.jsx)(
38045
38847
  DataTableHeader,
38046
38848
  {
38047
38849
  name: "Invoices",
@@ -38051,14 +38853,14 @@ var InvoicesTable = () => {
38051
38853
  }
38052
38854
  }
38053
38855
  ),
38054
- /* @__PURE__ */ (0, import_jsx_runtime332.jsx)(
38856
+ /* @__PURE__ */ (0, import_jsx_runtime348.jsx)(
38055
38857
  PaginatedTable,
38056
38858
  {
38057
38859
  ariaLabel: "Invoices",
38058
38860
  data: invoices,
38059
38861
  isLoading: data === void 0 || isLoading,
38060
38862
  isError,
38061
- columnConfig: columns,
38863
+ columnConfig,
38062
38864
  paginationProps,
38063
38865
  componentName: COMPONENT_NAME10,
38064
38866
  slots: {
@@ -38071,28 +38873,38 @@ var InvoicesTable = () => {
38071
38873
  };
38072
38874
 
38073
38875
  // src/components/Invoices/Invoices.tsx
38074
- var import_jsx_runtime333 = require("react/jsx-runtime");
38876
+ var import_jsx_runtime349 = require("react/jsx-runtime");
38075
38877
  var unstable_Invoices = ({
38076
38878
  showTitle = true,
38077
38879
  stringOverrides
38078
38880
  }) => {
38079
- return /* @__PURE__ */ (0, import_jsx_runtime333.jsx)(
38881
+ const [invoiceFormMode, setInvoiceFormMode] = (0, import_react238.useState)(null);
38882
+ const goBackToInvoicesTable = (0, import_react238.useCallback)(() => {
38883
+ setInvoiceFormMode(null);
38884
+ }, []);
38885
+ const onCreateInvoice = (0, import_react238.useCallback)(() => {
38886
+ setInvoiceFormMode({ mode: "Create" /* Create */ });
38887
+ }, []);
38888
+ const onSelectInvoice = (0, import_react238.useCallback)((invoice) => {
38889
+ setInvoiceFormMode({ mode: "Update" /* Update */, invoice });
38890
+ }, []);
38891
+ return /* @__PURE__ */ (0, import_jsx_runtime349.jsx)(
38080
38892
  View,
38081
38893
  {
38082
38894
  title: (stringOverrides == null ? void 0 : stringOverrides.title) || "Invoices",
38083
38895
  showHeader: showTitle,
38084
- children: /* @__PURE__ */ (0, import_jsx_runtime333.jsx)(InvoicesTable, {})
38896
+ children: invoiceFormMode !== null ? /* @__PURE__ */ (0, import_jsx_runtime349.jsx)(InvoiceDetail, __spreadProps(__spreadValues({}, invoiceFormMode), { onGoBack: goBackToInvoicesTable })) : /* @__PURE__ */ (0, import_jsx_runtime349.jsx)(InvoicesTable, { onCreateInvoice, onSelectInvoice })
38085
38897
  }
38086
38898
  );
38087
38899
  };
38088
38900
 
38089
38901
  // src/providers/BankTransactionsProvider/BankTransactionsProvider.tsx
38090
- var import_jsx_runtime334 = require("react/jsx-runtime");
38902
+ var import_jsx_runtime350 = require("react/jsx-runtime");
38091
38903
  var BankTransactionsProvider = ({
38092
38904
  children
38093
38905
  }) => {
38094
38906
  const bankTransactionsContextData = useAugmentedBankTransactions();
38095
- return /* @__PURE__ */ (0, import_jsx_runtime334.jsx)(BankTransactionsContext.Provider, { value: bankTransactionsContextData, children });
38907
+ return /* @__PURE__ */ (0, import_jsx_runtime350.jsx)(BankTransactionsContext.Provider, { value: bankTransactionsContextData, children });
38096
38908
  };
38097
38909
  // Annotate the CommonJS export names for ESM import in node:
38098
38910
  0 && (module.exports = {