@htlkg/data 0.0.21 → 0.0.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/hooks/index.d.ts +702 -94
- package/dist/hooks/index.js +793 -56
- package/dist/hooks/index.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +802 -65
- package/dist/index.js.map +1 -1
- package/dist/mutations/index.js +4 -4
- package/dist/mutations/index.js.map +1 -1
- package/dist/queries/index.js +5 -5
- package/dist/queries/index.js.map +1 -1
- package/package.json +11 -12
- package/src/hooks/accounts/index.ts +2 -0
- package/src/hooks/{useAccounts.ts → accounts/useAccounts.ts} +48 -5
- package/src/hooks/accounts/usePaginatedAccounts.ts +166 -0
- package/src/hooks/brands/index.ts +2 -0
- package/src/hooks/{useBrands.ts → brands/useBrands.ts} +1 -1
- package/src/hooks/brands/usePaginatedBrands.ts +206 -0
- package/src/hooks/contacts/index.ts +2 -0
- package/src/hooks/contacts/useContacts.ts +176 -0
- package/src/hooks/contacts/usePaginatedContacts.ts +268 -0
- package/src/hooks/createPaginatedDataHook.ts +359 -0
- package/src/hooks/data-hook-errors.property.test.ts +4 -4
- package/src/hooks/data-hook-filters.property.test.ts +4 -4
- package/src/hooks/data-hooks.property.test.ts +4 -4
- package/src/hooks/index.ts +101 -8
- package/src/hooks/productInstances/index.ts +1 -0
- package/src/hooks/{useProductInstances.ts → productInstances/useProductInstances.ts} +9 -6
- package/src/hooks/products/index.ts +1 -0
- package/src/hooks/{useProducts.ts → products/useProducts.ts} +4 -5
- package/src/hooks/reservations/index.ts +2 -0
- package/src/hooks/reservations/usePaginatedReservations.ts +258 -0
- package/src/hooks/{useReservations.ts → reservations/useReservations.ts} +65 -10
- package/src/hooks/users/index.ts +2 -0
- package/src/hooks/users/usePaginatedUsers.ts +213 -0
- package/src/hooks/{useUsers.ts → users/useUsers.ts} +1 -1
- package/src/mutations/accounts/accounts.test.ts +287 -0
- package/src/mutations/{accounts.ts → accounts/accounts.ts} +2 -2
- package/src/mutations/accounts/index.ts +1 -0
- package/src/mutations/brands/brands.test.ts +292 -0
- package/src/mutations/{brands.ts → brands/brands.ts} +2 -2
- package/src/mutations/brands/index.ts +1 -0
- package/src/mutations/reservations/index.ts +1 -0
- package/src/mutations/{reservations.test.ts → reservations/reservations.test.ts} +1 -1
- package/src/mutations/{reservations.ts → reservations/reservations.ts} +2 -2
- package/src/mutations/users/index.ts +1 -0
- package/src/mutations/users/users.test.ts +289 -0
- package/src/mutations/{users.ts → users/users.ts} +2 -2
- package/src/queries/accounts/accounts.test.ts +228 -0
- package/src/queries/accounts/index.ts +1 -0
- package/src/queries/brands/brands.test.ts +288 -0
- package/src/queries/brands/index.ts +1 -0
- package/src/queries/products/index.ts +1 -0
- package/src/queries/products/products.test.ts +347 -0
- package/src/queries/reservations/index.ts +1 -0
- package/src/queries/users/index.ts +1 -0
- package/src/queries/users/users.test.ts +301 -0
- /package/src/queries/{accounts.ts → accounts/accounts.ts} +0 -0
- /package/src/queries/{brands.ts → brands/brands.ts} +0 -0
- /package/src/queries/{products.ts → products/products.ts} +0 -0
- /package/src/queries/{reservations.test.ts → reservations/reservations.test.ts} +0 -0
- /package/src/queries/{reservations.ts → reservations/reservations.ts} +0 -0
- /package/src/queries/{users.ts → users/users.ts} +0 -0
package/dist/index.js
CHANGED
|
@@ -77,7 +77,7 @@ function generateServerClient(_options) {
|
|
|
77
77
|
return client;
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
-
// src/queries/brands.ts
|
|
80
|
+
// src/queries/brands/brands.ts
|
|
81
81
|
async function getBrand(client, id) {
|
|
82
82
|
try {
|
|
83
83
|
const { data, errors } = await client.models.Brand.get({ id });
|
|
@@ -149,7 +149,7 @@ async function listActiveBrands(client, options) {
|
|
|
149
149
|
});
|
|
150
150
|
}
|
|
151
151
|
|
|
152
|
-
// src/queries/accounts.ts
|
|
152
|
+
// src/queries/accounts/accounts.ts
|
|
153
153
|
async function getAccount(client, id) {
|
|
154
154
|
try {
|
|
155
155
|
const { data, errors } = await client.models.Account.get({ id });
|
|
@@ -205,7 +205,7 @@ async function getAccountWithBrands(client, id) {
|
|
|
205
205
|
}
|
|
206
206
|
}
|
|
207
207
|
|
|
208
|
-
// src/queries/users.ts
|
|
208
|
+
// src/queries/users/users.ts
|
|
209
209
|
async function getUser(client, id) {
|
|
210
210
|
try {
|
|
211
211
|
const { data, errors } = await client.models.User.get({ id });
|
|
@@ -282,7 +282,7 @@ async function listActiveUsers(client, options) {
|
|
|
282
282
|
});
|
|
283
283
|
}
|
|
284
284
|
|
|
285
|
-
// src/queries/products.ts
|
|
285
|
+
// src/queries/products/products.ts
|
|
286
286
|
async function getProduct(client, id) {
|
|
287
287
|
try {
|
|
288
288
|
const { data, errors } = await client.models.Product.get({ id });
|
|
@@ -487,7 +487,7 @@ function checkRestoreEligibility(deletedAt, retentionDays) {
|
|
|
487
487
|
};
|
|
488
488
|
}
|
|
489
489
|
|
|
490
|
-
// src/queries/reservations.ts
|
|
490
|
+
// src/queries/reservations/reservations.ts
|
|
491
491
|
async function getReservation2(client, id) {
|
|
492
492
|
try {
|
|
493
493
|
const { data, errors } = await client.models.Reservation.get({ id });
|
|
@@ -666,7 +666,7 @@ async function searchContacts(client, query2, brandId, options) {
|
|
|
666
666
|
}
|
|
667
667
|
}
|
|
668
668
|
|
|
669
|
-
// src/mutations/brands.ts
|
|
669
|
+
// src/mutations/brands/brands.ts
|
|
670
670
|
async function createBrand(client, input) {
|
|
671
671
|
try {
|
|
672
672
|
const { data, errors } = await client.models.Brand.create(input);
|
|
@@ -754,7 +754,7 @@ async function deleteBrand(client, id) {
|
|
|
754
754
|
}
|
|
755
755
|
}
|
|
756
756
|
|
|
757
|
-
// src/mutations/accounts.ts
|
|
757
|
+
// src/mutations/accounts/accounts.ts
|
|
758
758
|
async function createAccount(client, input) {
|
|
759
759
|
try {
|
|
760
760
|
const { data, errors } = await client.models.Account.create(input);
|
|
@@ -842,7 +842,7 @@ async function deleteAccount(client, id) {
|
|
|
842
842
|
}
|
|
843
843
|
}
|
|
844
844
|
|
|
845
|
-
// src/mutations/users.ts
|
|
845
|
+
// src/mutations/users/users.ts
|
|
846
846
|
async function createUser(client, input) {
|
|
847
847
|
try {
|
|
848
848
|
const { data, errors } = await client.models.User.create(input);
|
|
@@ -1144,7 +1144,7 @@ async function initializeSystemSettings(client, initializedBy) {
|
|
|
1144
1144
|
}
|
|
1145
1145
|
}
|
|
1146
1146
|
|
|
1147
|
-
// src/mutations/reservations.ts
|
|
1147
|
+
// src/mutations/reservations/reservations.ts
|
|
1148
1148
|
var STATUS_TRANSITIONS = {
|
|
1149
1149
|
confirmed: ["checked_in", "cancelled", "no_show"],
|
|
1150
1150
|
checked_in: ["checked_out", "cancelled"],
|
|
@@ -1606,7 +1606,7 @@ function createDataHook(config) {
|
|
|
1606
1606
|
defaultLimit,
|
|
1607
1607
|
selectionSet,
|
|
1608
1608
|
transform,
|
|
1609
|
-
buildFilter:
|
|
1609
|
+
buildFilter: buildFilter11,
|
|
1610
1610
|
computedProperties,
|
|
1611
1611
|
dataPropertyName = "data"
|
|
1612
1612
|
} = config;
|
|
@@ -1616,8 +1616,8 @@ function createDataHook(config) {
|
|
|
1616
1616
|
const loading = ref(false);
|
|
1617
1617
|
const error = ref(null);
|
|
1618
1618
|
const getFilter = () => {
|
|
1619
|
-
if (
|
|
1620
|
-
return
|
|
1619
|
+
if (buildFilter11) {
|
|
1620
|
+
return buildFilter11(options);
|
|
1621
1621
|
}
|
|
1622
1622
|
return baseFilter && Object.keys(baseFilter).length > 0 ? baseFilter : void 0;
|
|
1623
1623
|
};
|
|
@@ -1677,7 +1677,171 @@ function createDataHook(config) {
|
|
|
1677
1677
|
};
|
|
1678
1678
|
}
|
|
1679
1679
|
|
|
1680
|
-
// src/hooks/
|
|
1680
|
+
// src/hooks/createPaginatedDataHook.ts
|
|
1681
|
+
import { ref as ref2, computed as computed2, onMounted as onMounted2 } from "vue";
|
|
1682
|
+
var ACTIVE_FILTER = {
|
|
1683
|
+
or: [{ deletedAt: { attributeExists: false } }, { deletedAt: { eq: null } }]
|
|
1684
|
+
};
|
|
1685
|
+
var DELETED_FILTER = {
|
|
1686
|
+
deletedAt: { gt: "" }
|
|
1687
|
+
};
|
|
1688
|
+
function createPaginatedDataHook(config) {
|
|
1689
|
+
const {
|
|
1690
|
+
model,
|
|
1691
|
+
defaultPageSize = 25,
|
|
1692
|
+
selectionSet,
|
|
1693
|
+
transform,
|
|
1694
|
+
buildFilter: buildFilter11,
|
|
1695
|
+
dataPropertyName = "data",
|
|
1696
|
+
baseFilter
|
|
1697
|
+
} = config;
|
|
1698
|
+
return function usePaginatedData(options = {}) {
|
|
1699
|
+
const { filter: additionalFilter, pageSize = defaultPageSize, autoFetch = true } = options;
|
|
1700
|
+
const data = ref2([]);
|
|
1701
|
+
const loading = ref2(false);
|
|
1702
|
+
const initialLoading = ref2(false);
|
|
1703
|
+
const loadingMore = ref2(false);
|
|
1704
|
+
const error = ref2(null);
|
|
1705
|
+
const pagination = ref2({
|
|
1706
|
+
nextToken: null,
|
|
1707
|
+
hasMore: true,
|
|
1708
|
+
loadedCount: 0
|
|
1709
|
+
});
|
|
1710
|
+
const searchFilter = ref2(null);
|
|
1711
|
+
const hasMore = computed2(() => pagination.value.hasMore);
|
|
1712
|
+
const getFilter = () => {
|
|
1713
|
+
const filters = [];
|
|
1714
|
+
if (baseFilter) {
|
|
1715
|
+
filters.push(baseFilter);
|
|
1716
|
+
}
|
|
1717
|
+
if (buildFilter11) {
|
|
1718
|
+
const customFilter = buildFilter11(options);
|
|
1719
|
+
if (customFilter) {
|
|
1720
|
+
filters.push(customFilter);
|
|
1721
|
+
}
|
|
1722
|
+
}
|
|
1723
|
+
if (additionalFilter && Object.keys(additionalFilter).length > 0) {
|
|
1724
|
+
filters.push(additionalFilter);
|
|
1725
|
+
}
|
|
1726
|
+
if (searchFilter.value && Object.keys(searchFilter.value).length > 0) {
|
|
1727
|
+
filters.push(searchFilter.value);
|
|
1728
|
+
}
|
|
1729
|
+
if (filters.length === 0) {
|
|
1730
|
+
return void 0;
|
|
1731
|
+
}
|
|
1732
|
+
if (filters.length === 1) {
|
|
1733
|
+
return filters[0];
|
|
1734
|
+
}
|
|
1735
|
+
return { and: filters };
|
|
1736
|
+
};
|
|
1737
|
+
async function fetchPage(nextToken, append = false) {
|
|
1738
|
+
if (!append) {
|
|
1739
|
+
initialLoading.value = true;
|
|
1740
|
+
} else {
|
|
1741
|
+
loadingMore.value = true;
|
|
1742
|
+
}
|
|
1743
|
+
loading.value = true;
|
|
1744
|
+
error.value = null;
|
|
1745
|
+
try {
|
|
1746
|
+
const queryOptions = {
|
|
1747
|
+
limit: pageSize
|
|
1748
|
+
};
|
|
1749
|
+
const filter = getFilter();
|
|
1750
|
+
if (filter) {
|
|
1751
|
+
queryOptions.filter = filter;
|
|
1752
|
+
}
|
|
1753
|
+
if (nextToken) {
|
|
1754
|
+
queryOptions.nextToken = nextToken;
|
|
1755
|
+
}
|
|
1756
|
+
if (selectionSet) {
|
|
1757
|
+
queryOptions.selectionSet = selectionSet;
|
|
1758
|
+
}
|
|
1759
|
+
const response = await query(model, "list", queryOptions);
|
|
1760
|
+
if (hasErrors(response)) {
|
|
1761
|
+
throw new Error(getErrorMessage(response) || `Failed to fetch ${model}`);
|
|
1762
|
+
}
|
|
1763
|
+
const items = response.data || [];
|
|
1764
|
+
const transformedItems = transform ? items.map(transform) : items;
|
|
1765
|
+
if (append) {
|
|
1766
|
+
data.value = [...data.value, ...transformedItems];
|
|
1767
|
+
} else {
|
|
1768
|
+
data.value = transformedItems;
|
|
1769
|
+
}
|
|
1770
|
+
const responseNextToken = response.nextToken;
|
|
1771
|
+
pagination.value = {
|
|
1772
|
+
nextToken: responseNextToken || null,
|
|
1773
|
+
hasMore: !!responseNextToken,
|
|
1774
|
+
loadedCount: data.value.length
|
|
1775
|
+
};
|
|
1776
|
+
} catch (e) {
|
|
1777
|
+
error.value = e;
|
|
1778
|
+
console.error(`[use${model}] Error fetching ${model}:`, e);
|
|
1779
|
+
} finally {
|
|
1780
|
+
loading.value = false;
|
|
1781
|
+
initialLoading.value = false;
|
|
1782
|
+
loadingMore.value = false;
|
|
1783
|
+
}
|
|
1784
|
+
}
|
|
1785
|
+
async function loadMore() {
|
|
1786
|
+
if (loadingMore.value || !pagination.value.hasMore) {
|
|
1787
|
+
return;
|
|
1788
|
+
}
|
|
1789
|
+
await fetchPage(pagination.value.nextToken, true);
|
|
1790
|
+
}
|
|
1791
|
+
async function refetch() {
|
|
1792
|
+
pagination.value = {
|
|
1793
|
+
nextToken: null,
|
|
1794
|
+
hasMore: true,
|
|
1795
|
+
loadedCount: 0
|
|
1796
|
+
};
|
|
1797
|
+
await fetchPage(null, false);
|
|
1798
|
+
}
|
|
1799
|
+
function reset() {
|
|
1800
|
+
data.value = [];
|
|
1801
|
+
error.value = null;
|
|
1802
|
+
searchFilter.value = null;
|
|
1803
|
+
pagination.value = {
|
|
1804
|
+
nextToken: null,
|
|
1805
|
+
hasMore: true,
|
|
1806
|
+
loadedCount: 0
|
|
1807
|
+
};
|
|
1808
|
+
}
|
|
1809
|
+
async function setSearchFilter(filter) {
|
|
1810
|
+
searchFilter.value = filter;
|
|
1811
|
+
pagination.value = {
|
|
1812
|
+
nextToken: null,
|
|
1813
|
+
hasMore: true,
|
|
1814
|
+
loadedCount: 0
|
|
1815
|
+
};
|
|
1816
|
+
await fetchPage(null, false);
|
|
1817
|
+
}
|
|
1818
|
+
if (autoFetch) {
|
|
1819
|
+
onMounted2(() => {
|
|
1820
|
+
fetchPage(null, false);
|
|
1821
|
+
});
|
|
1822
|
+
}
|
|
1823
|
+
const result = {
|
|
1824
|
+
data,
|
|
1825
|
+
loading,
|
|
1826
|
+
initialLoading,
|
|
1827
|
+
loadingMore,
|
|
1828
|
+
error,
|
|
1829
|
+
pagination,
|
|
1830
|
+
hasMore,
|
|
1831
|
+
loadMore,
|
|
1832
|
+
refetch,
|
|
1833
|
+
reset,
|
|
1834
|
+
setSearchFilter,
|
|
1835
|
+
searchFilter
|
|
1836
|
+
};
|
|
1837
|
+
if (dataPropertyName !== "data") {
|
|
1838
|
+
result[dataPropertyName] = data;
|
|
1839
|
+
}
|
|
1840
|
+
return result;
|
|
1841
|
+
};
|
|
1842
|
+
}
|
|
1843
|
+
|
|
1844
|
+
// src/hooks/brands/useBrands.ts
|
|
1681
1845
|
function buildFilter(options) {
|
|
1682
1846
|
let filter = options.filter || {};
|
|
1683
1847
|
if (options.accountId) {
|
|
@@ -1707,23 +1871,96 @@ function useBrands(options = {}) {
|
|
|
1707
1871
|
};
|
|
1708
1872
|
}
|
|
1709
1873
|
|
|
1710
|
-
// src/hooks/
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1874
|
+
// src/hooks/brands/usePaginatedBrands.ts
|
|
1875
|
+
function buildFilter2(options) {
|
|
1876
|
+
const conditions = [];
|
|
1877
|
+
if (options.accountId) {
|
|
1878
|
+
conditions.push({ accountId: { eq: options.accountId } });
|
|
1879
|
+
}
|
|
1880
|
+
if (options.filter && Object.keys(options.filter).length > 0) {
|
|
1881
|
+
conditions.push(options.filter);
|
|
1882
|
+
}
|
|
1883
|
+
if (conditions.length === 0) {
|
|
1884
|
+
return void 0;
|
|
1885
|
+
}
|
|
1886
|
+
if (conditions.length === 1) {
|
|
1887
|
+
return conditions[0];
|
|
1888
|
+
}
|
|
1889
|
+
return { and: conditions };
|
|
1890
|
+
}
|
|
1891
|
+
function transformBrand(brand) {
|
|
1892
|
+
return {
|
|
1893
|
+
...brand,
|
|
1894
|
+
accountName: brand.account?.name || ""
|
|
1895
|
+
};
|
|
1896
|
+
}
|
|
1897
|
+
var BRAND_SELECTION_SET = [
|
|
1898
|
+
"id",
|
|
1899
|
+
"name",
|
|
1900
|
+
"accountId",
|
|
1901
|
+
"logo",
|
|
1902
|
+
"timezone",
|
|
1903
|
+
"status",
|
|
1904
|
+
"settings",
|
|
1905
|
+
"deletedAt",
|
|
1906
|
+
"deletedBy",
|
|
1907
|
+
"account.name"
|
|
1908
|
+
];
|
|
1909
|
+
var useActiveBrandsInternal = createPaginatedDataHook({
|
|
1910
|
+
model: "Brand",
|
|
1911
|
+
dataPropertyName: "brands",
|
|
1912
|
+
defaultPageSize: 25,
|
|
1913
|
+
selectionSet: BRAND_SELECTION_SET,
|
|
1914
|
+
transform: transformBrand,
|
|
1915
|
+
buildFilter: buildFilter2,
|
|
1916
|
+
baseFilter: ACTIVE_FILTER
|
|
1714
1917
|
});
|
|
1715
|
-
|
|
1716
|
-
|
|
1918
|
+
var useDeletedBrandsInternal = createPaginatedDataHook({
|
|
1919
|
+
model: "Brand",
|
|
1920
|
+
dataPropertyName: "brands",
|
|
1921
|
+
defaultPageSize: 25,
|
|
1922
|
+
selectionSet: BRAND_SELECTION_SET,
|
|
1923
|
+
transform: transformBrand,
|
|
1924
|
+
buildFilter: buildFilter2,
|
|
1925
|
+
baseFilter: DELETED_FILTER
|
|
1926
|
+
});
|
|
1927
|
+
function useActiveBrands(options = {}) {
|
|
1928
|
+
const result = useActiveBrandsInternal(options);
|
|
1717
1929
|
return {
|
|
1718
|
-
|
|
1930
|
+
brands: result.brands,
|
|
1719
1931
|
loading: result.loading,
|
|
1932
|
+
initialLoading: result.initialLoading,
|
|
1933
|
+
loadingMore: result.loadingMore,
|
|
1720
1934
|
error: result.error,
|
|
1721
|
-
|
|
1935
|
+
pagination: result.pagination,
|
|
1936
|
+
hasMore: result.hasMore,
|
|
1937
|
+
loadMore: result.loadMore,
|
|
1938
|
+
refetch: result.refetch,
|
|
1939
|
+
reset: result.reset,
|
|
1940
|
+
setSearchFilter: result.setSearchFilter,
|
|
1941
|
+
searchFilter: result.searchFilter
|
|
1942
|
+
};
|
|
1943
|
+
}
|
|
1944
|
+
function useDeletedBrands(options = {}) {
|
|
1945
|
+
const result = useDeletedBrandsInternal(options);
|
|
1946
|
+
return {
|
|
1947
|
+
brands: result.brands,
|
|
1948
|
+
loading: result.loading,
|
|
1949
|
+
initialLoading: result.initialLoading,
|
|
1950
|
+
loadingMore: result.loadingMore,
|
|
1951
|
+
error: result.error,
|
|
1952
|
+
pagination: result.pagination,
|
|
1953
|
+
hasMore: result.hasMore,
|
|
1954
|
+
loadMore: result.loadMore,
|
|
1955
|
+
refetch: result.refetch,
|
|
1956
|
+
reset: result.reset,
|
|
1957
|
+
setSearchFilter: result.setSearchFilter,
|
|
1958
|
+
searchFilter: result.searchFilter
|
|
1722
1959
|
};
|
|
1723
1960
|
}
|
|
1724
1961
|
|
|
1725
|
-
// src/hooks/useUsers.ts
|
|
1726
|
-
function
|
|
1962
|
+
// src/hooks/users/useUsers.ts
|
|
1963
|
+
function buildFilter3(options) {
|
|
1727
1964
|
let filter = options.filter || {};
|
|
1728
1965
|
if (options.brandId) {
|
|
1729
1966
|
filter = { ...filter, brandIds: { contains: options.brandId } };
|
|
@@ -1736,7 +1973,7 @@ function buildFilter2(options) {
|
|
|
1736
1973
|
var useUsersInternal = createDataHook({
|
|
1737
1974
|
model: "User",
|
|
1738
1975
|
dataPropertyName: "users",
|
|
1739
|
-
buildFilter:
|
|
1976
|
+
buildFilter: buildFilter3
|
|
1740
1977
|
});
|
|
1741
1978
|
function useUsers(options = {}) {
|
|
1742
1979
|
const result = useUsersInternal(options);
|
|
@@ -1748,8 +1985,419 @@ function useUsers(options = {}) {
|
|
|
1748
1985
|
};
|
|
1749
1986
|
}
|
|
1750
1987
|
|
|
1751
|
-
// src/hooks/
|
|
1752
|
-
function
|
|
1988
|
+
// src/hooks/users/usePaginatedUsers.ts
|
|
1989
|
+
function buildFilter4(options) {
|
|
1990
|
+
const conditions = [];
|
|
1991
|
+
if (options.brandId) {
|
|
1992
|
+
conditions.push({ brandIds: { contains: options.brandId } });
|
|
1993
|
+
}
|
|
1994
|
+
if (options.accountId) {
|
|
1995
|
+
conditions.push({ accountId: { eq: options.accountId } });
|
|
1996
|
+
}
|
|
1997
|
+
if (options.filter && Object.keys(options.filter).length > 0) {
|
|
1998
|
+
conditions.push(options.filter);
|
|
1999
|
+
}
|
|
2000
|
+
if (conditions.length === 0) {
|
|
2001
|
+
return void 0;
|
|
2002
|
+
}
|
|
2003
|
+
if (conditions.length === 1) {
|
|
2004
|
+
return conditions[0];
|
|
2005
|
+
}
|
|
2006
|
+
return { and: conditions };
|
|
2007
|
+
}
|
|
2008
|
+
function transformUser(user) {
|
|
2009
|
+
return {
|
|
2010
|
+
...user,
|
|
2011
|
+
accountName: user.account?.name || ""
|
|
2012
|
+
};
|
|
2013
|
+
}
|
|
2014
|
+
var USER_SELECTION_SET = [
|
|
2015
|
+
"id",
|
|
2016
|
+
"email",
|
|
2017
|
+
"accountId",
|
|
2018
|
+
"brandIds",
|
|
2019
|
+
"roles",
|
|
2020
|
+
"status",
|
|
2021
|
+
"lastLogin",
|
|
2022
|
+
"createdAt",
|
|
2023
|
+
"deletedAt",
|
|
2024
|
+
"deletedBy",
|
|
2025
|
+
"account.name"
|
|
2026
|
+
];
|
|
2027
|
+
var useActiveUsersInternal = createPaginatedDataHook({
|
|
2028
|
+
model: "User",
|
|
2029
|
+
dataPropertyName: "users",
|
|
2030
|
+
defaultPageSize: 25,
|
|
2031
|
+
selectionSet: USER_SELECTION_SET,
|
|
2032
|
+
transform: transformUser,
|
|
2033
|
+
buildFilter: buildFilter4,
|
|
2034
|
+
baseFilter: ACTIVE_FILTER
|
|
2035
|
+
});
|
|
2036
|
+
var useDeletedUsersInternal = createPaginatedDataHook({
|
|
2037
|
+
model: "User",
|
|
2038
|
+
dataPropertyName: "users",
|
|
2039
|
+
defaultPageSize: 25,
|
|
2040
|
+
selectionSet: USER_SELECTION_SET,
|
|
2041
|
+
transform: transformUser,
|
|
2042
|
+
buildFilter: buildFilter4,
|
|
2043
|
+
baseFilter: DELETED_FILTER
|
|
2044
|
+
});
|
|
2045
|
+
function useActiveUsers(options = {}) {
|
|
2046
|
+
const result = useActiveUsersInternal(options);
|
|
2047
|
+
return {
|
|
2048
|
+
users: result.users,
|
|
2049
|
+
loading: result.loading,
|
|
2050
|
+
initialLoading: result.initialLoading,
|
|
2051
|
+
loadingMore: result.loadingMore,
|
|
2052
|
+
error: result.error,
|
|
2053
|
+
pagination: result.pagination,
|
|
2054
|
+
hasMore: result.hasMore,
|
|
2055
|
+
loadMore: result.loadMore,
|
|
2056
|
+
refetch: result.refetch,
|
|
2057
|
+
reset: result.reset,
|
|
2058
|
+
setSearchFilter: result.setSearchFilter,
|
|
2059
|
+
searchFilter: result.searchFilter
|
|
2060
|
+
};
|
|
2061
|
+
}
|
|
2062
|
+
function useDeletedUsers(options = {}) {
|
|
2063
|
+
const result = useDeletedUsersInternal(options);
|
|
2064
|
+
return {
|
|
2065
|
+
users: result.users,
|
|
2066
|
+
loading: result.loading,
|
|
2067
|
+
initialLoading: result.initialLoading,
|
|
2068
|
+
loadingMore: result.loadingMore,
|
|
2069
|
+
error: result.error,
|
|
2070
|
+
pagination: result.pagination,
|
|
2071
|
+
hasMore: result.hasMore,
|
|
2072
|
+
loadMore: result.loadMore,
|
|
2073
|
+
refetch: result.refetch,
|
|
2074
|
+
reset: result.reset,
|
|
2075
|
+
setSearchFilter: result.setSearchFilter,
|
|
2076
|
+
searchFilter: result.searchFilter
|
|
2077
|
+
};
|
|
2078
|
+
}
|
|
2079
|
+
|
|
2080
|
+
// src/hooks/accounts/useAccounts.ts
|
|
2081
|
+
function transformAccount(account) {
|
|
2082
|
+
const brands = account.brands || [];
|
|
2083
|
+
return {
|
|
2084
|
+
...account,
|
|
2085
|
+
brands,
|
|
2086
|
+
brandCount: brands.length
|
|
2087
|
+
};
|
|
2088
|
+
}
|
|
2089
|
+
var useAccountsInternal = createDataHook({
|
|
2090
|
+
model: "Account",
|
|
2091
|
+
dataPropertyName: "accounts",
|
|
2092
|
+
// Include brands relationship for brand display
|
|
2093
|
+
selectionSet: [
|
|
2094
|
+
"id",
|
|
2095
|
+
"name",
|
|
2096
|
+
"logo",
|
|
2097
|
+
"subscription",
|
|
2098
|
+
"settings",
|
|
2099
|
+
"status",
|
|
2100
|
+
"deletedAt",
|
|
2101
|
+
"deletedBy",
|
|
2102
|
+
"brands.id",
|
|
2103
|
+
"brands.name",
|
|
2104
|
+
"brands.status"
|
|
2105
|
+
],
|
|
2106
|
+
transform: transformAccount
|
|
2107
|
+
});
|
|
2108
|
+
function useAccounts(options = {}) {
|
|
2109
|
+
const result = useAccountsInternal(options);
|
|
2110
|
+
return {
|
|
2111
|
+
accounts: result.accounts,
|
|
2112
|
+
loading: result.loading,
|
|
2113
|
+
error: result.error,
|
|
2114
|
+
refetch: result.refetch
|
|
2115
|
+
};
|
|
2116
|
+
}
|
|
2117
|
+
|
|
2118
|
+
// src/hooks/accounts/usePaginatedAccounts.ts
|
|
2119
|
+
function transformAccount2(account) {
|
|
2120
|
+
const brands = account.brands || [];
|
|
2121
|
+
return {
|
|
2122
|
+
...account,
|
|
2123
|
+
brands,
|
|
2124
|
+
brandCount: brands.length
|
|
2125
|
+
};
|
|
2126
|
+
}
|
|
2127
|
+
var ACCOUNT_SELECTION_SET = [
|
|
2128
|
+
"id",
|
|
2129
|
+
"name",
|
|
2130
|
+
"logo",
|
|
2131
|
+
"subscription",
|
|
2132
|
+
"settings",
|
|
2133
|
+
"status",
|
|
2134
|
+
"deletedAt",
|
|
2135
|
+
"deletedBy",
|
|
2136
|
+
"brands.id",
|
|
2137
|
+
"brands.name",
|
|
2138
|
+
"brands.status"
|
|
2139
|
+
];
|
|
2140
|
+
var useActiveAccountsInternal = createPaginatedDataHook({
|
|
2141
|
+
model: "Account",
|
|
2142
|
+
dataPropertyName: "accounts",
|
|
2143
|
+
defaultPageSize: 25,
|
|
2144
|
+
selectionSet: ACCOUNT_SELECTION_SET,
|
|
2145
|
+
transform: transformAccount2,
|
|
2146
|
+
baseFilter: ACTIVE_FILTER
|
|
2147
|
+
});
|
|
2148
|
+
var useDeletedAccountsInternal = createPaginatedDataHook({
|
|
2149
|
+
model: "Account",
|
|
2150
|
+
dataPropertyName: "accounts",
|
|
2151
|
+
defaultPageSize: 25,
|
|
2152
|
+
selectionSet: ACCOUNT_SELECTION_SET,
|
|
2153
|
+
transform: transformAccount2,
|
|
2154
|
+
baseFilter: DELETED_FILTER
|
|
2155
|
+
});
|
|
2156
|
+
function useActiveAccounts(options = {}) {
|
|
2157
|
+
const result = useActiveAccountsInternal(options);
|
|
2158
|
+
return {
|
|
2159
|
+
accounts: result.accounts,
|
|
2160
|
+
loading: result.loading,
|
|
2161
|
+
initialLoading: result.initialLoading,
|
|
2162
|
+
loadingMore: result.loadingMore,
|
|
2163
|
+
error: result.error,
|
|
2164
|
+
pagination: result.pagination,
|
|
2165
|
+
hasMore: result.hasMore,
|
|
2166
|
+
loadMore: result.loadMore,
|
|
2167
|
+
refetch: result.refetch,
|
|
2168
|
+
reset: result.reset,
|
|
2169
|
+
setSearchFilter: result.setSearchFilter,
|
|
2170
|
+
searchFilter: result.searchFilter
|
|
2171
|
+
};
|
|
2172
|
+
}
|
|
2173
|
+
function useDeletedAccounts(options = {}) {
|
|
2174
|
+
const result = useDeletedAccountsInternal(options);
|
|
2175
|
+
return {
|
|
2176
|
+
accounts: result.accounts,
|
|
2177
|
+
loading: result.loading,
|
|
2178
|
+
initialLoading: result.initialLoading,
|
|
2179
|
+
loadingMore: result.loadingMore,
|
|
2180
|
+
error: result.error,
|
|
2181
|
+
pagination: result.pagination,
|
|
2182
|
+
hasMore: result.hasMore,
|
|
2183
|
+
loadMore: result.loadMore,
|
|
2184
|
+
refetch: result.refetch,
|
|
2185
|
+
reset: result.reset,
|
|
2186
|
+
setSearchFilter: result.setSearchFilter,
|
|
2187
|
+
searchFilter: result.searchFilter
|
|
2188
|
+
};
|
|
2189
|
+
}
|
|
2190
|
+
|
|
2191
|
+
// src/hooks/reservations/useReservations.ts
|
|
2192
|
+
function buildFilter5(options) {
|
|
2193
|
+
const conditions = [];
|
|
2194
|
+
if (options.brandId) {
|
|
2195
|
+
conditions.push({ brandId: { eq: options.brandId } });
|
|
2196
|
+
}
|
|
2197
|
+
if (options.status) {
|
|
2198
|
+
conditions.push({ status: { eq: options.status } });
|
|
2199
|
+
}
|
|
2200
|
+
if (options.contactId) {
|
|
2201
|
+
conditions.push({ visitId: { eq: options.contactId } });
|
|
2202
|
+
}
|
|
2203
|
+
if (options.startDate) {
|
|
2204
|
+
conditions.push({ checkIn: { ge: options.startDate } });
|
|
2205
|
+
}
|
|
2206
|
+
if (options.endDate) {
|
|
2207
|
+
conditions.push({ checkIn: { le: options.endDate } });
|
|
2208
|
+
}
|
|
2209
|
+
if (options.filter) {
|
|
2210
|
+
conditions.push(options.filter);
|
|
2211
|
+
}
|
|
2212
|
+
if (conditions.length === 0) {
|
|
2213
|
+
return void 0;
|
|
2214
|
+
}
|
|
2215
|
+
if (conditions.length === 1) {
|
|
2216
|
+
return conditions[0];
|
|
2217
|
+
}
|
|
2218
|
+
return { and: conditions };
|
|
2219
|
+
}
|
|
2220
|
+
function transformReservation(r) {
|
|
2221
|
+
let snapshot = r.visit?.snapshot;
|
|
2222
|
+
if (typeof snapshot === "string") {
|
|
2223
|
+
try {
|
|
2224
|
+
snapshot = JSON.parse(snapshot);
|
|
2225
|
+
} catch {
|
|
2226
|
+
snapshot = null;
|
|
2227
|
+
}
|
|
2228
|
+
}
|
|
2229
|
+
return {
|
|
2230
|
+
...r,
|
|
2231
|
+
brandName: r.brand?.name || "Unknown Brand",
|
|
2232
|
+
guestName: snapshot ? `${snapshot.firstName || ""} ${snapshot.lastName || ""}`.trim() || "Unknown Guest" : "Unknown Guest",
|
|
2233
|
+
guestEmail: snapshot?.email || "",
|
|
2234
|
+
guestPhone: snapshot?.phone || ""
|
|
2235
|
+
};
|
|
2236
|
+
}
|
|
2237
|
+
var useReservationsInternal = createDataHook({
|
|
2238
|
+
model: "Reservation",
|
|
2239
|
+
dataPropertyName: "reservations",
|
|
2240
|
+
buildFilter: buildFilter5,
|
|
2241
|
+
// Include related data for brand name and guest info
|
|
2242
|
+
selectionSet: [
|
|
2243
|
+
"id",
|
|
2244
|
+
"brandId",
|
|
2245
|
+
"visitId",
|
|
2246
|
+
"checkIn",
|
|
2247
|
+
"checkOut",
|
|
2248
|
+
"room",
|
|
2249
|
+
"roomType",
|
|
2250
|
+
"status",
|
|
2251
|
+
"source",
|
|
2252
|
+
"channel",
|
|
2253
|
+
"confirmationCode",
|
|
2254
|
+
"totalAmount",
|
|
2255
|
+
"currency",
|
|
2256
|
+
"nights",
|
|
2257
|
+
"deletedAt",
|
|
2258
|
+
"deletedBy",
|
|
2259
|
+
"brand.name",
|
|
2260
|
+
"visit.snapshot"
|
|
2261
|
+
],
|
|
2262
|
+
transform: transformReservation,
|
|
2263
|
+
computedProperties: {
|
|
2264
|
+
confirmedReservations: (reservations) => reservations.filter((r) => r.status === "confirmed"),
|
|
2265
|
+
activeReservations: (reservations) => reservations.filter((r) => r.status === "confirmed" || r.status === "checked_in")
|
|
2266
|
+
}
|
|
2267
|
+
});
|
|
2268
|
+
function useReservations(options = {}) {
|
|
2269
|
+
const result = useReservationsInternal(options);
|
|
2270
|
+
return {
|
|
2271
|
+
reservations: result.reservations,
|
|
2272
|
+
confirmedReservations: result.confirmedReservations,
|
|
2273
|
+
activeReservations: result.activeReservations,
|
|
2274
|
+
loading: result.loading,
|
|
2275
|
+
error: result.error,
|
|
2276
|
+
refetch: result.refetch
|
|
2277
|
+
};
|
|
2278
|
+
}
|
|
2279
|
+
|
|
2280
|
+
// src/hooks/reservations/usePaginatedReservations.ts
|
|
2281
|
+
function buildFilter6(options) {
|
|
2282
|
+
const conditions = [];
|
|
2283
|
+
if (options.brandId) {
|
|
2284
|
+
conditions.push({ brandId: { eq: options.brandId } });
|
|
2285
|
+
}
|
|
2286
|
+
if (options.status) {
|
|
2287
|
+
conditions.push({ status: { eq: options.status } });
|
|
2288
|
+
}
|
|
2289
|
+
if (options.contactId) {
|
|
2290
|
+
conditions.push({ visitId: { eq: options.contactId } });
|
|
2291
|
+
}
|
|
2292
|
+
if (options.startDate) {
|
|
2293
|
+
conditions.push({ checkIn: { ge: options.startDate } });
|
|
2294
|
+
}
|
|
2295
|
+
if (options.endDate) {
|
|
2296
|
+
conditions.push({ checkIn: { le: options.endDate } });
|
|
2297
|
+
}
|
|
2298
|
+
if (options.filter && Object.keys(options.filter).length > 0) {
|
|
2299
|
+
conditions.push(options.filter);
|
|
2300
|
+
}
|
|
2301
|
+
if (conditions.length === 0) {
|
|
2302
|
+
return void 0;
|
|
2303
|
+
}
|
|
2304
|
+
if (conditions.length === 1) {
|
|
2305
|
+
return conditions[0];
|
|
2306
|
+
}
|
|
2307
|
+
return { and: conditions };
|
|
2308
|
+
}
|
|
2309
|
+
function transformReservation2(r) {
|
|
2310
|
+
let snapshot = r.visit?.snapshot;
|
|
2311
|
+
if (typeof snapshot === "string") {
|
|
2312
|
+
try {
|
|
2313
|
+
snapshot = JSON.parse(snapshot);
|
|
2314
|
+
} catch {
|
|
2315
|
+
snapshot = null;
|
|
2316
|
+
}
|
|
2317
|
+
}
|
|
2318
|
+
return {
|
|
2319
|
+
...r,
|
|
2320
|
+
brandName: r.brand?.name || "Unknown Brand",
|
|
2321
|
+
guestName: snapshot ? `${snapshot.firstName || ""} ${snapshot.lastName || ""}`.trim() || "Unknown Guest" : "Unknown Guest",
|
|
2322
|
+
guestEmail: snapshot?.email || "",
|
|
2323
|
+
guestPhone: snapshot?.phone || ""
|
|
2324
|
+
};
|
|
2325
|
+
}
|
|
2326
|
+
var RESERVATION_SELECTION_SET = [
|
|
2327
|
+
"id",
|
|
2328
|
+
"brandId",
|
|
2329
|
+
"visitId",
|
|
2330
|
+
"checkIn",
|
|
2331
|
+
"checkOut",
|
|
2332
|
+
"room",
|
|
2333
|
+
"roomType",
|
|
2334
|
+
"status",
|
|
2335
|
+
"source",
|
|
2336
|
+
"channel",
|
|
2337
|
+
"confirmationCode",
|
|
2338
|
+
"totalAmount",
|
|
2339
|
+
"currency",
|
|
2340
|
+
"nights",
|
|
2341
|
+
"deletedAt",
|
|
2342
|
+
"deletedBy",
|
|
2343
|
+
"brand.name",
|
|
2344
|
+
"visit.snapshot"
|
|
2345
|
+
];
|
|
2346
|
+
var useActiveReservationsInternal = createPaginatedDataHook({
|
|
2347
|
+
model: "Reservation",
|
|
2348
|
+
dataPropertyName: "reservations",
|
|
2349
|
+
defaultPageSize: 25,
|
|
2350
|
+
selectionSet: RESERVATION_SELECTION_SET,
|
|
2351
|
+
transform: transformReservation2,
|
|
2352
|
+
buildFilter: buildFilter6,
|
|
2353
|
+
baseFilter: ACTIVE_FILTER
|
|
2354
|
+
});
|
|
2355
|
+
var useDeletedReservationsInternal = createPaginatedDataHook({
|
|
2356
|
+
model: "Reservation",
|
|
2357
|
+
dataPropertyName: "reservations",
|
|
2358
|
+
defaultPageSize: 25,
|
|
2359
|
+
selectionSet: RESERVATION_SELECTION_SET,
|
|
2360
|
+
transform: transformReservation2,
|
|
2361
|
+
buildFilter: buildFilter6,
|
|
2362
|
+
baseFilter: DELETED_FILTER
|
|
2363
|
+
});
|
|
2364
|
+
function useActiveReservations(options = {}) {
|
|
2365
|
+
const result = useActiveReservationsInternal(options);
|
|
2366
|
+
return {
|
|
2367
|
+
reservations: result.reservations,
|
|
2368
|
+
loading: result.loading,
|
|
2369
|
+
initialLoading: result.initialLoading,
|
|
2370
|
+
loadingMore: result.loadingMore,
|
|
2371
|
+
error: result.error,
|
|
2372
|
+
pagination: result.pagination,
|
|
2373
|
+
hasMore: result.hasMore,
|
|
2374
|
+
loadMore: result.loadMore,
|
|
2375
|
+
refetch: result.refetch,
|
|
2376
|
+
reset: result.reset,
|
|
2377
|
+
setSearchFilter: result.setSearchFilter,
|
|
2378
|
+
searchFilter: result.searchFilter
|
|
2379
|
+
};
|
|
2380
|
+
}
|
|
2381
|
+
function useDeletedReservations(options = {}) {
|
|
2382
|
+
const result = useDeletedReservationsInternal(options);
|
|
2383
|
+
return {
|
|
2384
|
+
reservations: result.reservations,
|
|
2385
|
+
loading: result.loading,
|
|
2386
|
+
initialLoading: result.initialLoading,
|
|
2387
|
+
loadingMore: result.loadingMore,
|
|
2388
|
+
error: result.error,
|
|
2389
|
+
pagination: result.pagination,
|
|
2390
|
+
hasMore: result.hasMore,
|
|
2391
|
+
loadMore: result.loadMore,
|
|
2392
|
+
refetch: result.refetch,
|
|
2393
|
+
reset: result.reset,
|
|
2394
|
+
setSearchFilter: result.setSearchFilter,
|
|
2395
|
+
searchFilter: result.searchFilter
|
|
2396
|
+
};
|
|
2397
|
+
}
|
|
2398
|
+
|
|
2399
|
+
// src/hooks/products/useProducts.ts
|
|
2400
|
+
function buildFilter7(options) {
|
|
1753
2401
|
let filter = options.filter || {};
|
|
1754
2402
|
if (options.activeOnly) {
|
|
1755
2403
|
filter = { ...filter, isActive: { eq: true } };
|
|
@@ -1759,7 +2407,7 @@ function buildFilter3(options) {
|
|
|
1759
2407
|
var useProductsInternal = createDataHook({
|
|
1760
2408
|
model: "Product",
|
|
1761
2409
|
dataPropertyName: "products",
|
|
1762
|
-
buildFilter:
|
|
2410
|
+
buildFilter: buildFilter7,
|
|
1763
2411
|
computedProperties: {
|
|
1764
2412
|
activeProducts: (products) => products.filter((p) => p.isActive === true)
|
|
1765
2413
|
}
|
|
@@ -1775,8 +2423,8 @@ function useProducts(options = {}) {
|
|
|
1775
2423
|
};
|
|
1776
2424
|
}
|
|
1777
2425
|
|
|
1778
|
-
// src/hooks/useProductInstances.ts
|
|
1779
|
-
function
|
|
2426
|
+
// src/hooks/productInstances/useProductInstances.ts
|
|
2427
|
+
function buildFilter8(options) {
|
|
1780
2428
|
let filter = options.filter || {};
|
|
1781
2429
|
if (options.brandId) {
|
|
1782
2430
|
filter = { ...filter, brandId: { eq: options.brandId } };
|
|
@@ -1795,7 +2443,7 @@ function buildFilter4(options) {
|
|
|
1795
2443
|
var useProductInstancesInternal = createDataHook({
|
|
1796
2444
|
model: "ProductInstance",
|
|
1797
2445
|
dataPropertyName: "instances",
|
|
1798
|
-
buildFilter:
|
|
2446
|
+
buildFilter: buildFilter8,
|
|
1799
2447
|
computedProperties: {
|
|
1800
2448
|
enabledInstances: (instances) => instances.filter((i) => i.enabled)
|
|
1801
2449
|
}
|
|
@@ -1843,23 +2491,32 @@ function useProductInstances(options = {}) {
|
|
|
1843
2491
|
};
|
|
1844
2492
|
}
|
|
1845
2493
|
|
|
1846
|
-
// src/hooks/
|
|
1847
|
-
function
|
|
2494
|
+
// src/hooks/contacts/useContacts.ts
|
|
2495
|
+
function buildFilter9(options) {
|
|
1848
2496
|
const conditions = [];
|
|
1849
2497
|
if (options.brandId) {
|
|
1850
2498
|
conditions.push({ brandId: { eq: options.brandId } });
|
|
1851
2499
|
}
|
|
1852
|
-
if (options.
|
|
1853
|
-
conditions.push({
|
|
2500
|
+
if (options.search) {
|
|
2501
|
+
conditions.push({
|
|
2502
|
+
or: [
|
|
2503
|
+
{ email: { contains: options.search } },
|
|
2504
|
+
{ firstName: { contains: options.search } },
|
|
2505
|
+
{ lastName: { contains: options.search } }
|
|
2506
|
+
]
|
|
2507
|
+
});
|
|
1854
2508
|
}
|
|
1855
|
-
if (options.
|
|
1856
|
-
conditions.push({
|
|
2509
|
+
if (options.gdprConsent !== void 0) {
|
|
2510
|
+
conditions.push({ gdprConsent: { eq: options.gdprConsent } });
|
|
1857
2511
|
}
|
|
1858
|
-
if (options.
|
|
1859
|
-
conditions.push({
|
|
2512
|
+
if (options.marketingOptIn !== void 0) {
|
|
2513
|
+
conditions.push({ marketingOptIn: { eq: options.marketingOptIn } });
|
|
1860
2514
|
}
|
|
1861
|
-
if (options.
|
|
1862
|
-
|
|
2515
|
+
if (options.tags && options.tags.length > 0) {
|
|
2516
|
+
const tagConditions = options.tags.map((tag) => ({
|
|
2517
|
+
tags: { contains: tag }
|
|
2518
|
+
}));
|
|
2519
|
+
conditions.push({ or: tagConditions });
|
|
1863
2520
|
}
|
|
1864
2521
|
if (options.filter) {
|
|
1865
2522
|
conditions.push(options.filter);
|
|
@@ -1872,33 +2529,36 @@ function buildFilter5(options) {
|
|
|
1872
2529
|
}
|
|
1873
2530
|
return { and: conditions };
|
|
1874
2531
|
}
|
|
1875
|
-
var
|
|
1876
|
-
model: "
|
|
1877
|
-
dataPropertyName: "
|
|
1878
|
-
buildFilter:
|
|
2532
|
+
var useContactsInternal = createDataHook({
|
|
2533
|
+
model: "Contact",
|
|
2534
|
+
dataPropertyName: "contacts",
|
|
2535
|
+
buildFilter: buildFilter9,
|
|
1879
2536
|
computedProperties: {
|
|
1880
|
-
|
|
1881
|
-
|
|
2537
|
+
consentedContacts: (contacts) => contacts.filter((c) => c.gdprConsent === true),
|
|
2538
|
+
marketingContacts: (contacts) => contacts.filter((c) => c.marketingOptIn === true)
|
|
1882
2539
|
}
|
|
1883
2540
|
});
|
|
1884
|
-
function
|
|
1885
|
-
const result =
|
|
2541
|
+
function useContacts(options = {}) {
|
|
2542
|
+
const result = useContactsInternal(options);
|
|
1886
2543
|
return {
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
2544
|
+
contacts: result.contacts,
|
|
2545
|
+
consentedContacts: result.consentedContacts,
|
|
2546
|
+
marketingContacts: result.marketingContacts,
|
|
1890
2547
|
loading: result.loading,
|
|
1891
2548
|
error: result.error,
|
|
1892
2549
|
refetch: result.refetch
|
|
1893
2550
|
};
|
|
1894
2551
|
}
|
|
1895
2552
|
|
|
1896
|
-
// src/hooks/
|
|
1897
|
-
function
|
|
2553
|
+
// src/hooks/contacts/usePaginatedContacts.ts
|
|
2554
|
+
function buildFilter10(options) {
|
|
1898
2555
|
const conditions = [];
|
|
1899
2556
|
if (options.brandId) {
|
|
1900
2557
|
conditions.push({ brandId: { eq: options.brandId } });
|
|
1901
2558
|
}
|
|
2559
|
+
if (options.accountId) {
|
|
2560
|
+
conditions.push({ accountId: { eq: options.accountId } });
|
|
2561
|
+
}
|
|
1902
2562
|
if (options.search) {
|
|
1903
2563
|
conditions.push({
|
|
1904
2564
|
or: [
|
|
@@ -1920,7 +2580,7 @@ function buildFilter6(options) {
|
|
|
1920
2580
|
}));
|
|
1921
2581
|
conditions.push({ or: tagConditions });
|
|
1922
2582
|
}
|
|
1923
|
-
if (options.filter) {
|
|
2583
|
+
if (options.filter && Object.keys(options.filter).length > 0) {
|
|
1924
2584
|
conditions.push(options.filter);
|
|
1925
2585
|
}
|
|
1926
2586
|
if (conditions.length === 0) {
|
|
@@ -1931,24 +2591,88 @@ function buildFilter6(options) {
|
|
|
1931
2591
|
}
|
|
1932
2592
|
return { and: conditions };
|
|
1933
2593
|
}
|
|
1934
|
-
|
|
2594
|
+
function transformContact(contact) {
|
|
2595
|
+
return {
|
|
2596
|
+
...contact,
|
|
2597
|
+
name: `${contact.firstName || ""} ${contact.lastName || ""}`.trim() || contact.email,
|
|
2598
|
+
brandName: contact.brand?.name || ""
|
|
2599
|
+
};
|
|
2600
|
+
}
|
|
2601
|
+
var CONTACT_SELECTION_SET = [
|
|
2602
|
+
"id",
|
|
2603
|
+
"email",
|
|
2604
|
+
"phone",
|
|
2605
|
+
"firstName",
|
|
2606
|
+
"lastName",
|
|
2607
|
+
"locale",
|
|
2608
|
+
"brandId",
|
|
2609
|
+
"accountId",
|
|
2610
|
+
"gdprConsent",
|
|
2611
|
+
"gdprConsentDate",
|
|
2612
|
+
"marketingOptIn",
|
|
2613
|
+
"preferences",
|
|
2614
|
+
"tags",
|
|
2615
|
+
"totalVisits",
|
|
2616
|
+
"lastVisitDate",
|
|
2617
|
+
"firstVisitDate",
|
|
2618
|
+
"source",
|
|
2619
|
+
"status",
|
|
2620
|
+
"createdAt",
|
|
2621
|
+
"updatedAt",
|
|
2622
|
+
"deletedAt",
|
|
2623
|
+
"deletedBy",
|
|
2624
|
+
"brand.name"
|
|
2625
|
+
];
|
|
2626
|
+
var useActiveContactsInternal = createPaginatedDataHook({
|
|
1935
2627
|
model: "Contact",
|
|
1936
2628
|
dataPropertyName: "contacts",
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
2629
|
+
defaultPageSize: 25,
|
|
2630
|
+
selectionSet: CONTACT_SELECTION_SET,
|
|
2631
|
+
transform: transformContact,
|
|
2632
|
+
buildFilter: buildFilter10,
|
|
2633
|
+
baseFilter: ACTIVE_FILTER
|
|
1942
2634
|
});
|
|
1943
|
-
|
|
1944
|
-
|
|
2635
|
+
var useDeletedContactsInternal = createPaginatedDataHook({
|
|
2636
|
+
model: "Contact",
|
|
2637
|
+
dataPropertyName: "contacts",
|
|
2638
|
+
defaultPageSize: 25,
|
|
2639
|
+
selectionSet: CONTACT_SELECTION_SET,
|
|
2640
|
+
transform: transformContact,
|
|
2641
|
+
buildFilter: buildFilter10,
|
|
2642
|
+
baseFilter: DELETED_FILTER
|
|
2643
|
+
});
|
|
2644
|
+
function useActiveContacts(options = {}) {
|
|
2645
|
+
const result = useActiveContactsInternal(options);
|
|
1945
2646
|
return {
|
|
1946
2647
|
contacts: result.contacts,
|
|
1947
|
-
consentedContacts: result.consentedContacts,
|
|
1948
|
-
marketingContacts: result.marketingContacts,
|
|
1949
2648
|
loading: result.loading,
|
|
2649
|
+
initialLoading: result.initialLoading,
|
|
2650
|
+
loadingMore: result.loadingMore,
|
|
1950
2651
|
error: result.error,
|
|
1951
|
-
|
|
2652
|
+
pagination: result.pagination,
|
|
2653
|
+
hasMore: result.hasMore,
|
|
2654
|
+
loadMore: result.loadMore,
|
|
2655
|
+
refetch: result.refetch,
|
|
2656
|
+
reset: result.reset,
|
|
2657
|
+
setSearchFilter: result.setSearchFilter,
|
|
2658
|
+
searchFilter: result.searchFilter
|
|
2659
|
+
};
|
|
2660
|
+
}
|
|
2661
|
+
function useDeletedContacts(options = {}) {
|
|
2662
|
+
const result = useDeletedContactsInternal(options);
|
|
2663
|
+
return {
|
|
2664
|
+
contacts: result.contacts,
|
|
2665
|
+
loading: result.loading,
|
|
2666
|
+
initialLoading: result.initialLoading,
|
|
2667
|
+
loadingMore: result.loadingMore,
|
|
2668
|
+
error: result.error,
|
|
2669
|
+
pagination: result.pagination,
|
|
2670
|
+
hasMore: result.hasMore,
|
|
2671
|
+
loadMore: result.loadMore,
|
|
2672
|
+
refetch: result.refetch,
|
|
2673
|
+
reset: result.reset,
|
|
2674
|
+
setSearchFilter: result.setSearchFilter,
|
|
2675
|
+
searchFilter: result.searchFilter
|
|
1952
2676
|
};
|
|
1953
2677
|
}
|
|
1954
2678
|
|
|
@@ -2055,8 +2779,10 @@ function createSingleStore(shared, name, defaultValue) {
|
|
|
2055
2779
|
return shared(name, atom(defaultValue));
|
|
2056
2780
|
}
|
|
2057
2781
|
export {
|
|
2782
|
+
ACTIVE_FILTER,
|
|
2058
2783
|
ContactValidationError,
|
|
2059
2784
|
DEFAULT_SOFT_DELETE_RETENTION_DAYS,
|
|
2785
|
+
DELETED_FILTER,
|
|
2060
2786
|
ReservationValidationError,
|
|
2061
2787
|
SYSTEM_SETTINGS_KEY,
|
|
2062
2788
|
checkRestoreEligibility,
|
|
@@ -2065,6 +2791,7 @@ export {
|
|
|
2065
2791
|
createContact,
|
|
2066
2792
|
createContactSchema,
|
|
2067
2793
|
createDataHook,
|
|
2794
|
+
createPaginatedDataHook,
|
|
2068
2795
|
createProductInstance,
|
|
2069
2796
|
createReservation2 as createReservation,
|
|
2070
2797
|
createResourceStores,
|
|
@@ -2147,8 +2874,18 @@ export {
|
|
|
2147
2874
|
updateSystemSettings,
|
|
2148
2875
|
updateUser,
|
|
2149
2876
|
useAccounts,
|
|
2877
|
+
useActiveAccounts,
|
|
2878
|
+
useActiveBrands,
|
|
2879
|
+
useActiveContacts,
|
|
2880
|
+
useActiveReservations,
|
|
2881
|
+
useActiveUsers,
|
|
2150
2882
|
useBrands,
|
|
2151
2883
|
useContacts,
|
|
2884
|
+
useDeletedAccounts,
|
|
2885
|
+
useDeletedBrands,
|
|
2886
|
+
useDeletedContacts,
|
|
2887
|
+
useDeletedReservations,
|
|
2888
|
+
useDeletedUsers,
|
|
2152
2889
|
useProductInstances,
|
|
2153
2890
|
useProducts,
|
|
2154
2891
|
useReservations,
|