nucleus-core-ts 0.8.6 → 0.8.8
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/client.js +1 -1
- package/dist/dist/index.d.ts +475 -12
- package/dist/fe/components/AbstractAnimatedBackground/index.js +437 -0
- package/dist/fe/components/AuthorizationPage/components/AuthorizationPage.js +841 -0
- package/dist/fe/components/AuthorizationPage/components/ClaimList.js +100 -0
- package/dist/fe/components/AuthorizationPage/components/RoleClaimEditor.js +232 -0
- package/dist/fe/components/AuthorizationPage/components/RoleList.js +115 -0
- package/dist/fe/components/AuthorizationPage/index.js +6 -0
- package/dist/fe/components/AuthorizationPage/store/index.js +117 -0
- package/dist/fe/components/AuthorizationPage/theme/index.js +137 -0
- package/dist/fe/components/AuthorizationPage/types/index.js +1 -0
- package/dist/fe/components/Button/components/Button.js +158 -0
- package/dist/fe/components/Button/components/ButtonSpinner.js +52 -0
- package/dist/fe/components/Button/index.js +3 -0
- package/dist/fe/components/Button/theme/index.js +186 -0
- package/dist/fe/components/Button/types/index.js +1 -0
- package/dist/fe/components/Button/utils/cn.js +5 -0
- package/dist/fe/components/Captcha/components/Captcha.js +311 -0
- package/dist/fe/components/Captcha/index.js +2 -0
- package/dist/fe/components/Captcha/theme.js +52 -0
- package/dist/fe/components/Captcha/types.js +1 -0
- package/dist/fe/components/ChangePasswordPage/components/ChangePasswordForm.js +242 -0
- package/dist/fe/components/ChangePasswordPage/components/ChangePasswordHeader.js +39 -0
- package/dist/fe/components/ChangePasswordPage/components/ChangePasswordPage.js +60 -0
- package/dist/fe/components/ChangePasswordPage/index.js +5 -0
- package/dist/fe/components/ChangePasswordPage/store/index.js +44 -0
- package/dist/fe/components/ChangePasswordPage/theme/index.js +87 -0
- package/dist/fe/components/ChangePasswordPage/types/index.js +1 -0
- package/dist/fe/components/Checkbox/components/Checkbox.js +115 -0
- package/dist/fe/components/Checkbox/components/CheckboxIcon.js +119 -0
- package/dist/fe/components/Checkbox/components/SwitchTrack.js +178 -0
- package/dist/fe/components/Checkbox/index.js +4 -0
- package/dist/fe/components/Checkbox/theme/index.js +221 -0
- package/dist/fe/components/Checkbox/types/index.js +1 -0
- package/dist/fe/components/Checkbox/utils/cn.js +5 -0
- package/dist/fe/components/DataTable/DataTable.js +225 -0
- package/dist/fe/components/DataTable/components/ActionCell.js +26 -0
- package/dist/fe/components/DataTable/components/DataCell.js +76 -0
- package/dist/fe/components/DataTable/components/EditableCell.js +221 -0
- package/dist/fe/components/DataTable/components/EmptyState.js +29 -0
- package/dist/fe/components/DataTable/components/HeaderCell.js +64 -0
- package/dist/fe/components/DataTable/components/InfiniteScrollTrigger.js +66 -0
- package/dist/fe/components/DataTable/components/LoadingSpinner.js +19 -0
- package/dist/fe/components/DataTable/components/ResizeHandle.js +41 -0
- package/dist/fe/components/DataTable/components/SelectionCell.js +105 -0
- package/dist/fe/components/DataTable/components/SkeletonRow.js +56 -0
- package/dist/fe/components/DataTable/components/SkeletonTable.js +83 -0
- package/dist/fe/components/DataTable/components/SortIcon.js +39 -0
- package/dist/fe/components/DataTable/components/TableHeader.js +49 -0
- package/dist/fe/components/DataTable/components/TableRow.js +118 -0
- package/dist/fe/components/DataTable/components/index.js +14 -0
- package/dist/fe/components/DataTable/hooks/index.js +2 -0
- package/dist/fe/components/DataTable/hooks/useAutoFitColumn.js +23 -0
- package/dist/fe/components/DataTable/hooks/useResizeColumn.js +122 -0
- package/dist/fe/components/DataTable/index.js +3 -0
- package/dist/fe/components/DataTable/store/index.js +97 -0
- package/dist/fe/components/DataTable/theme/index.js +144 -0
- package/dist/fe/components/DataTable/types/index.js +1 -0
- package/dist/fe/components/DataTable/utils/cn.js +5 -0
- package/dist/fe/components/DatePicker/components/CalendarGrid.js +95 -0
- package/dist/fe/components/DatePicker/components/CalendarHeader.js +152 -0
- package/dist/fe/components/DatePicker/components/DatePicker.js +381 -0
- package/dist/fe/components/DatePicker/components/MonthYearSelector.js +93 -0
- package/dist/fe/components/DatePicker/index.js +7 -0
- package/dist/fe/components/DatePicker/locales/index.js +1113 -0
- package/dist/fe/components/DatePicker/theme/index.js +315 -0
- package/dist/fe/components/DatePicker/types/index.js +1 -0
- package/dist/fe/components/DatePicker/utils/cn.js +5 -0
- package/dist/fe/components/DatePicker/utils/date.js +132 -0
- package/dist/fe/components/DevicesPage/components/DeviceCard.js +251 -0
- package/dist/fe/components/DevicesPage/components/DevicesHeader.js +42 -0
- package/dist/fe/components/DevicesPage/components/DevicesPage.js +450 -0
- package/dist/fe/components/DevicesPage/index.js +5 -0
- package/dist/fe/components/DevicesPage/store/index.js +55 -0
- package/dist/fe/components/DevicesPage/theme/index.js +131 -0
- package/dist/fe/components/DevicesPage/types/index.js +1 -0
- package/dist/fe/components/ForgotPasswordPage/components/ForgotPasswordForm.js +214 -0
- package/dist/fe/components/ForgotPasswordPage/components/ForgotPasswordHeader.js +42 -0
- package/dist/fe/components/ForgotPasswordPage/components/ForgotPasswordPage.js +59 -0
- package/dist/fe/components/ForgotPasswordPage/index.js +5 -0
- package/dist/fe/components/ForgotPasswordPage/store/index.js +28 -0
- package/dist/fe/components/ForgotPasswordPage/theme/index.js +87 -0
- package/dist/fe/components/ForgotPasswordPage/types/index.js +1 -0
- package/dist/fe/components/FormBuilder/components/FormBuilder.js +156 -0
- package/dist/fe/components/FormBuilder/components/FormField.js +218 -0
- package/dist/fe/components/FormBuilder/hooks/useFormBuilder.js +152 -0
- package/dist/fe/components/FormBuilder/index.js +4 -0
- package/dist/fe/components/FormBuilder/theme/index.js +134 -0
- package/dist/fe/components/FormBuilder/types/index.js +1 -0
- package/dist/fe/components/FormBuilder/utils/cn.js +5 -0
- package/dist/fe/components/FormBuilder/utils/fieldMapping.js +216 -0
- package/dist/fe/components/FormBuilder/utils/validation.js +78 -0
- package/dist/fe/components/LoginPage/components/LoginForm.js +214 -0
- package/dist/fe/components/LoginPage/components/LoginHeader.js +24 -0
- package/dist/fe/components/LoginPage/components/LoginPage.js +138 -0
- package/dist/fe/components/LoginPage/index.js +5 -0
- package/dist/fe/components/LoginPage/store/index.js +59 -0
- package/dist/fe/components/LoginPage/theme/index.js +98 -0
- package/dist/fe/components/LoginPage/types/index.js +1 -0
- package/dist/fe/components/MagicLinkVerifyPage/components/MagicLinkVerifyPage.js +200 -0
- package/dist/fe/components/MagicLinkVerifyPage/index.js +3 -0
- package/dist/fe/components/MagicLinkVerifyPage/store.js +20 -0
- package/dist/fe/components/MagicLinkVerifyPage/theme.js +36 -0
- package/dist/fe/components/MagicLinkVerifyPage/types.js +1 -0
- package/dist/fe/components/NucleusEntityShowcase.js +1409 -0
- package/dist/fe/components/NucleusTextInput/components/FloatingLabel.js +56 -0
- package/dist/fe/components/NucleusTextInput/components/InputIcons.js +258 -0
- package/dist/fe/components/NucleusTextInput/components/NucleusTextInput.js +321 -0
- package/dist/fe/components/NucleusTextInput/components/PasswordStrengthIndicator.js +104 -0
- package/dist/fe/components/NucleusTextInput/components/TypewriterText.js +56 -0
- package/dist/fe/components/NucleusTextInput/index.js +7 -0
- package/dist/fe/components/NucleusTextInput/theme/index.js +121 -0
- package/dist/fe/components/NucleusTextInput/types/index.js +1 -0
- package/dist/fe/components/NucleusTextInput/utils/cn.js +5 -0
- package/dist/fe/components/NucleusTextInput/utils/format.js +62 -0
- package/dist/fe/components/NucleusTextInput/utils/validation.js +191 -0
- package/dist/fe/components/ProfilePage/components/AddressCard.js +196 -0
- package/dist/fe/components/ProfilePage/components/PhoneCard.js +206 -0
- package/dist/fe/components/ProfilePage/components/ProfileHeader.js +150 -0
- package/dist/fe/components/ProfilePage/components/ProfilePage.js +1336 -0
- package/dist/fe/components/ProfilePage/index.js +6 -0
- package/dist/fe/components/ProfilePage/store/index.js +115 -0
- package/dist/fe/components/ProfilePage/theme/index.js +168 -0
- package/dist/fe/components/ProfilePage/types/index.js +1 -0
- package/dist/fe/components/RangePicker/components/RangePicker.js +338 -0
- package/dist/fe/components/RangePicker/components/RangeThumb.js +68 -0
- package/dist/fe/components/RangePicker/components/RangeTooltip.js +45 -0
- package/dist/fe/components/RangePicker/components/RangeTrack.js +32 -0
- package/dist/fe/components/RangePicker/index.js +5 -0
- package/dist/fe/components/RangePicker/theme/index.js +88 -0
- package/dist/fe/components/RangePicker/types/index.js +1 -0
- package/dist/fe/components/RangePicker/utils/cn.js +3 -0
- package/dist/fe/components/RegisterPage/components/PasswordStrengthIndicator.js +107 -0
- package/dist/fe/components/RegisterPage/components/RegisterForm.js +322 -0
- package/dist/fe/components/RegisterPage/components/RegisterHeader.js +23 -0
- package/dist/fe/components/RegisterPage/components/RegisterPage.js +85 -0
- package/dist/fe/components/RegisterPage/index.js +6 -0
- package/dist/fe/components/RegisterPage/store/index.js +106 -0
- package/dist/fe/components/RegisterPage/theme/index.js +128 -0
- package/dist/fe/components/RegisterPage/types/index.js +1 -0
- package/dist/fe/components/ResetPasswordPage/components/ResetPasswordForm.js +347 -0
- package/dist/fe/components/ResetPasswordPage/components/ResetPasswordHeader.js +42 -0
- package/dist/fe/components/ResetPasswordPage/components/ResetPasswordPage.js +61 -0
- package/dist/fe/components/ResetPasswordPage/index.js +5 -0
- package/dist/fe/components/ResetPasswordPage/store/index.js +36 -0
- package/dist/fe/components/ResetPasswordPage/theme/index.js +99 -0
- package/dist/fe/components/ResetPasswordPage/types/index.js +1 -0
- package/dist/fe/components/SearchBox/components/SearchBox.js +271 -0
- package/dist/fe/components/SearchBox/components/SearchBoxDropdown.js +87 -0
- package/dist/fe/components/SearchBox/index.js +5 -0
- package/dist/fe/components/SearchBox/theme/index.js +184 -0
- package/dist/fe/components/SearchBox/types/index.js +1 -0
- package/dist/fe/components/SearchBox/utils/cn.js +5 -0
- package/dist/fe/components/SearchBox/utils/debounce.js +22 -0
- package/dist/fe/components/SearchBox/utils/sanitize.js +48 -0
- package/dist/fe/components/SelectBox/components/SelectBox.js +364 -0
- package/dist/fe/components/SelectBox/components/SelectDropdown.js +92 -0
- package/dist/fe/components/SelectBox/components/SelectOptionItem.js +43 -0
- package/dist/fe/components/SelectBox/components/SelectTrigger.js +22 -0
- package/dist/fe/components/SelectBox/index.js +5 -0
- package/dist/fe/components/SelectBox/theme/index.js +98 -0
- package/dist/fe/components/SelectBox/types/index.js +1 -0
- package/dist/fe/components/SelectBox/utils/cn.js +3 -0
- package/dist/fe/components/SetPasswordPage/components/PasswordStrengthIndicator.js +107 -0
- package/dist/fe/components/SetPasswordPage/components/SetPasswordForm.js +142 -0
- package/dist/fe/components/SetPasswordPage/components/SetPasswordHeader.js +23 -0
- package/dist/fe/components/SetPasswordPage/components/SetPasswordPage.js +263 -0
- package/dist/fe/components/SetPasswordPage/index.js +7 -0
- package/dist/fe/components/SetPasswordPage/store/index.js +79 -0
- package/dist/fe/components/SetPasswordPage/theme/index.js +98 -0
- package/dist/fe/components/SetPasswordPage/types/index.js +12 -0
- package/dist/fe/components/UsersPage/components/InviteUserModal.js +262 -0
- package/dist/fe/components/UsersPage/components/Pagination.js +147 -0
- package/dist/fe/components/UsersPage/components/RoleAssignmentModal.js +186 -0
- package/dist/fe/components/UsersPage/components/StatsCards.js +124 -0
- package/dist/fe/components/UsersPage/components/UserDetailDrawer.js +444 -0
- package/dist/fe/components/UsersPage/components/UserFilters.js +142 -0
- package/dist/fe/components/UsersPage/components/UserListItem.js +125 -0
- package/dist/fe/components/UsersPage/components/UserListSkeleton.js +40 -0
- package/dist/fe/components/UsersPage/components/UsersPage.js +556 -0
- package/dist/fe/components/UsersPage/index.js +10 -0
- package/dist/fe/components/UsersPage/store/index.js +151 -0
- package/dist/fe/components/UsersPage/theme/index.js +231 -0
- package/dist/fe/components/UsersPage/types/index.js +1 -0
- package/dist/fe/components/VerifyEmailPage/components/VerifyEmailPage.js +290 -0
- package/dist/fe/components/VerifyEmailPage/index.js +3 -0
- package/dist/fe/components/VerifyEmailPage/store/index.js +45 -0
- package/dist/fe/components/VerifyEmailPage/theme/index.js +52 -0
- package/dist/fe/components/VerifyEmailPage/types/index.js +1 -0
- package/dist/fe/hooks/useNucleusEntity.js +247 -0
- package/dist/fe/index.js +28 -110
- package/dist/fe/types/index.js +1 -0
- package/dist/fe/utils/cn.js +5 -0
- package/dist/fe/utils/columnUtils.js +189 -0
- package/dist/fe/utils/endpointKeys.js +44 -0
- package/dist/index.js +1 -1
- package/dist/nucleus.config.d.ts +3 -0
- package/dist/src/Client/Proxy/httpProxy.js +1 -0
- package/dist/src/Client/Proxy/index.js +1 -1
- package/dist/src/Client/Proxy/server.js +1 -0
- package/dist/src/Client/Proxy/types.js +1 -0
- package/dist/src/Client/Proxy/utils.js +1 -0
- package/dist/src/Client/Proxy/wsProxy.js +1 -0
- package/package.json +1 -1
- package/scripts/build.ts +78 -8
- package/dist/dist/index-0yyw12k6.d.ts +0 -8
- package/dist/dist/index-tv67j5qd.d.ts +0 -488
- package/dist/index-0yyw12k6.js +0 -1
- package/dist/index-tv67j5qd.js +0 -1
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { batch, createStore } from "h-state";
|
|
3
|
+
const initialState = {
|
|
4
|
+
step: "verifying",
|
|
5
|
+
message: "Verifying your email...",
|
|
6
|
+
email: "",
|
|
7
|
+
cooldown: 0,
|
|
8
|
+
resendStatus: "idle",
|
|
9
|
+
resendMessage: ""
|
|
10
|
+
};
|
|
11
|
+
export const { useStore: useVerifyEmailStore } = createStore(initialState, {
|
|
12
|
+
setStep: (store)=>(step)=>{
|
|
13
|
+
store.step = step;
|
|
14
|
+
},
|
|
15
|
+
setMessage: (store)=>(message)=>{
|
|
16
|
+
store.message = message;
|
|
17
|
+
},
|
|
18
|
+
setEmail: (store)=>(email)=>{
|
|
19
|
+
store.email = email;
|
|
20
|
+
},
|
|
21
|
+
setCooldown: (store)=>(cooldown)=>{
|
|
22
|
+
store.cooldown = cooldown;
|
|
23
|
+
},
|
|
24
|
+
decrementCooldown: (store)=>()=>{
|
|
25
|
+
if (store.cooldown > 0) {
|
|
26
|
+
store.cooldown = store.cooldown - 1;
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
setResendStatus: (store)=>(status)=>{
|
|
30
|
+
store.resendStatus = status;
|
|
31
|
+
},
|
|
32
|
+
setResendMessage: (store)=>(message)=>{
|
|
33
|
+
store.resendMessage = message;
|
|
34
|
+
},
|
|
35
|
+
reset: (store)=>()=>{
|
|
36
|
+
batch(()=>{
|
|
37
|
+
store.step = "verifying";
|
|
38
|
+
store.message = "Verifying your email...";
|
|
39
|
+
store.email = "";
|
|
40
|
+
store.cooldown = 0;
|
|
41
|
+
store.resendStatus = "idle";
|
|
42
|
+
store.resendMessage = "";
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
});
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
export const verifyEmailPageTheme = {
|
|
2
|
+
container: {
|
|
3
|
+
base: "min-h-screen w-full flex items-center justify-center bg-gradient-to-br from-zinc-50 to-zinc-100 dark:from-zinc-900 dark:to-zinc-950"
|
|
4
|
+
},
|
|
5
|
+
card: {
|
|
6
|
+
base: "w-full max-w-md p-8",
|
|
7
|
+
background: "bg-white/80 dark:bg-zinc-900/80 backdrop-blur-xl",
|
|
8
|
+
border: "border border-white/20 dark:border-zinc-800/50",
|
|
9
|
+
shadow: "shadow-2xl",
|
|
10
|
+
rounded: "rounded-2xl"
|
|
11
|
+
},
|
|
12
|
+
content: {
|
|
13
|
+
wrapper: "flex flex-col items-center text-center"
|
|
14
|
+
},
|
|
15
|
+
states: {
|
|
16
|
+
verifying: {
|
|
17
|
+
spinner: "w-16 h-16 border-4 border-blue-500 border-t-transparent rounded-full animate-spin mb-6",
|
|
18
|
+
title: "text-2xl font-bold text-zinc-900 dark:text-white mb-2",
|
|
19
|
+
subtitle: "text-zinc-600 dark:text-zinc-400"
|
|
20
|
+
},
|
|
21
|
+
success: {
|
|
22
|
+
iconWrapper: "w-16 h-16 bg-green-100 dark:bg-green-900/30 rounded-full flex items-center justify-center mb-6",
|
|
23
|
+
icon: "w-8 h-8 text-green-500",
|
|
24
|
+
title: "text-2xl font-bold text-zinc-900 dark:text-white mb-2",
|
|
25
|
+
subtitle: "text-zinc-600 dark:text-zinc-400 mb-4",
|
|
26
|
+
redirectText: "text-sm text-zinc-500 dark:text-zinc-500"
|
|
27
|
+
},
|
|
28
|
+
error: {
|
|
29
|
+
iconWrapper: "w-16 h-16 bg-red-100 dark:bg-red-900/30 rounded-full flex items-center justify-center mb-6",
|
|
30
|
+
icon: "w-8 h-8 text-red-500",
|
|
31
|
+
title: "text-2xl font-bold text-zinc-900 dark:text-white mb-2",
|
|
32
|
+
subtitle: "text-zinc-600 dark:text-zinc-400 mb-4"
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
resendForm: {
|
|
36
|
+
wrapper: "w-full mt-4 p-4 bg-zinc-50 dark:bg-zinc-800/50 rounded-xl",
|
|
37
|
+
label: "text-sm text-zinc-600 dark:text-zinc-400 mb-3",
|
|
38
|
+
input: "w-full px-4 py-2 mb-3 border border-zinc-300 dark:border-zinc-600 rounded-lg bg-white dark:bg-zinc-800 text-zinc-900 dark:text-white placeholder-zinc-400 focus:outline-none focus:ring-2 focus:ring-blue-500",
|
|
39
|
+
button: "w-full px-4 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition-colors disabled:opacity-50 disabled:cursor-not-allowed",
|
|
40
|
+
buttonContent: "flex items-center justify-center gap-2",
|
|
41
|
+
buttonSpinner: "w-4 h-4 border-2 border-white border-t-transparent rounded-full animate-spin",
|
|
42
|
+
messageSuccess: "mt-2 text-sm text-green-600 dark:text-green-400",
|
|
43
|
+
messageError: "mt-2 text-sm text-red-600 dark:text-red-400"
|
|
44
|
+
},
|
|
45
|
+
backButton: "mt-4 px-6 py-2 text-zinc-600 dark:text-zinc-400 hover:text-zinc-900 dark:hover:text-white transition-colors"
|
|
46
|
+
};
|
|
47
|
+
export function extendVerifyEmailPageTheme(overrides) {
|
|
48
|
+
return {
|
|
49
|
+
...verifyEmailPageTheme,
|
|
50
|
+
...overrides
|
|
51
|
+
};
|
|
52
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useEffect, useRef, useState } from "react";
|
|
3
|
+
import { generateBulkEndpointKey, generateEntityEndpointKey } from "../utils/endpointKeys";
|
|
4
|
+
export function useNucleusEntity({ entity, apiActions, pageSize = 20, initialSort = [], initialFilters = [] }) {
|
|
5
|
+
const table = entity.table_name;
|
|
6
|
+
const [items, setItems] = useState([]);
|
|
7
|
+
const [meta, setMeta] = useState(null);
|
|
8
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
9
|
+
const [isLoadingMore, setIsLoadingMore] = useState(false);
|
|
10
|
+
const [error, setError] = useState(null);
|
|
11
|
+
const [search, setSearch] = useState("");
|
|
12
|
+
const [sort, setSort] = useState(initialSort);
|
|
13
|
+
const [filters, setFilters] = useState(initialFilters);
|
|
14
|
+
const [currentPage, setCurrentPage] = useState(1);
|
|
15
|
+
const isInitialMount = useRef(true);
|
|
16
|
+
const getEndpointKey = generateEntityEndpointKey;
|
|
17
|
+
const getBulkEndpointKey = generateBulkEndpointKey;
|
|
18
|
+
const buildPayload = (options)=>{
|
|
19
|
+
const payload = {
|
|
20
|
+
page: options?.page ?? currentPage,
|
|
21
|
+
limit: pageSize
|
|
22
|
+
};
|
|
23
|
+
const searchValue = options?.search ?? search;
|
|
24
|
+
if (searchValue) {
|
|
25
|
+
payload.search = searchValue;
|
|
26
|
+
const searchableColumns = entity.columns?.filter((col)=>[
|
|
27
|
+
"text",
|
|
28
|
+
"varchar",
|
|
29
|
+
"char"
|
|
30
|
+
].includes(col.type)).map((col)=>col.name);
|
|
31
|
+
if (searchableColumns && searchableColumns.length > 0) {
|
|
32
|
+
payload.searchFields = searchableColumns.join(",");
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
const sortValue = options?.sort ?? sort;
|
|
36
|
+
if (sortValue.length > 0) {
|
|
37
|
+
payload.sort = JSON.stringify(sortValue);
|
|
38
|
+
}
|
|
39
|
+
const filtersValue = options?.filters ?? filters;
|
|
40
|
+
if (filtersValue.length > 0) {
|
|
41
|
+
payload.filters = JSON.stringify(filtersValue);
|
|
42
|
+
}
|
|
43
|
+
return payload;
|
|
44
|
+
};
|
|
45
|
+
const loadData = (options)=>{
|
|
46
|
+
const endpointKey = getEndpointKey(table, "GET");
|
|
47
|
+
const action = apiActions[endpointKey];
|
|
48
|
+
if (!action) {
|
|
49
|
+
console.error(`Endpoint ${endpointKey} not found`);
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
setIsLoading(true);
|
|
53
|
+
setError(null);
|
|
54
|
+
const page = options?.page ?? 1;
|
|
55
|
+
setCurrentPage(page);
|
|
56
|
+
action.start({
|
|
57
|
+
payload: buildPayload({
|
|
58
|
+
...options,
|
|
59
|
+
page
|
|
60
|
+
}),
|
|
61
|
+
onAfterHandle: (data)=>{
|
|
62
|
+
const response = data;
|
|
63
|
+
if (response?.data?.items) {
|
|
64
|
+
setItems(response.data.items);
|
|
65
|
+
setMeta(response.data.meta ?? null);
|
|
66
|
+
}
|
|
67
|
+
setIsLoading(false);
|
|
68
|
+
},
|
|
69
|
+
onErrorHandle: (err)=>{
|
|
70
|
+
setError(err);
|
|
71
|
+
setIsLoading(false);
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
};
|
|
75
|
+
const loadMore = ()=>{
|
|
76
|
+
if (!meta || !meta.hasNextPage || isLoadingMore) return;
|
|
77
|
+
const endpointKey = getEndpointKey(table, "GET");
|
|
78
|
+
const action = apiActions[endpointKey];
|
|
79
|
+
if (!action) return;
|
|
80
|
+
setIsLoadingMore(true);
|
|
81
|
+
const nextPage = currentPage + 1;
|
|
82
|
+
action.start({
|
|
83
|
+
payload: buildPayload({
|
|
84
|
+
page: nextPage
|
|
85
|
+
}),
|
|
86
|
+
onAfterHandle: (data)=>{
|
|
87
|
+
const response = data;
|
|
88
|
+
if (response?.data?.items && response.data.items.length > 0) {
|
|
89
|
+
const responseItems = response.data.items;
|
|
90
|
+
setItems((prev)=>{
|
|
91
|
+
const existingIds = new Set(prev.map((item)=>item.id));
|
|
92
|
+
const newItems = responseItems.filter((item)=>!existingIds.has(item.id));
|
|
93
|
+
return [
|
|
94
|
+
...prev,
|
|
95
|
+
...newItems
|
|
96
|
+
];
|
|
97
|
+
});
|
|
98
|
+
setMeta(response.data.meta ?? null);
|
|
99
|
+
setCurrentPage(nextPage);
|
|
100
|
+
}
|
|
101
|
+
setIsLoadingMore(false);
|
|
102
|
+
},
|
|
103
|
+
onErrorHandle: (err)=>{
|
|
104
|
+
setError(err);
|
|
105
|
+
setIsLoadingMore(false);
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
};
|
|
109
|
+
const addItem = async (data)=>{
|
|
110
|
+
const endpointKey = getEndpointKey(table, "POST");
|
|
111
|
+
const action = apiActions[endpointKey];
|
|
112
|
+
if (!action) {
|
|
113
|
+
throw new Error(`Endpoint ${endpointKey} not found`);
|
|
114
|
+
}
|
|
115
|
+
return new Promise((resolve, reject)=>{
|
|
116
|
+
action.start({
|
|
117
|
+
payload: data,
|
|
118
|
+
onAfterHandle: ()=>{
|
|
119
|
+
loadData({
|
|
120
|
+
page: 1
|
|
121
|
+
});
|
|
122
|
+
resolve();
|
|
123
|
+
},
|
|
124
|
+
onErrorHandle: (err)=>{
|
|
125
|
+
reject(err);
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
};
|
|
130
|
+
const updateItem = async (id, data)=>{
|
|
131
|
+
const endpointKey = getEndpointKey(table, "PUT");
|
|
132
|
+
const action = apiActions[endpointKey];
|
|
133
|
+
if (!action) {
|
|
134
|
+
throw new Error(`Endpoint ${endpointKey} not found`);
|
|
135
|
+
}
|
|
136
|
+
return new Promise((resolve, reject)=>{
|
|
137
|
+
action.start({
|
|
138
|
+
payload: {
|
|
139
|
+
_id: id,
|
|
140
|
+
...data
|
|
141
|
+
},
|
|
142
|
+
onAfterHandle: ()=>{
|
|
143
|
+
loadData();
|
|
144
|
+
resolve();
|
|
145
|
+
},
|
|
146
|
+
onErrorHandle: (err)=>{
|
|
147
|
+
reject(err);
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
};
|
|
152
|
+
const deleteItem = async (id)=>{
|
|
153
|
+
const endpointKey = getEndpointKey(table, "DELETE");
|
|
154
|
+
const action = apiActions[endpointKey];
|
|
155
|
+
if (!action) {
|
|
156
|
+
throw new Error(`Endpoint ${endpointKey} not found`);
|
|
157
|
+
}
|
|
158
|
+
return new Promise((resolve, reject)=>{
|
|
159
|
+
action.start({
|
|
160
|
+
payload: {
|
|
161
|
+
_id: id
|
|
162
|
+
},
|
|
163
|
+
onAfterHandle: ()=>{
|
|
164
|
+
loadData();
|
|
165
|
+
resolve();
|
|
166
|
+
},
|
|
167
|
+
onErrorHandle: (err)=>{
|
|
168
|
+
reject(err);
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
};
|
|
173
|
+
const bulkAdd = async (bulkItems)=>{
|
|
174
|
+
const endpointKey = getBulkEndpointKey(table, "POST");
|
|
175
|
+
const action = apiActions[endpointKey];
|
|
176
|
+
if (!action) {
|
|
177
|
+
throw new Error(`Endpoint ${endpointKey} not found`);
|
|
178
|
+
}
|
|
179
|
+
return new Promise((resolve, reject)=>{
|
|
180
|
+
action.start({
|
|
181
|
+
payload: bulkItems,
|
|
182
|
+
onAfterHandle: ()=>{
|
|
183
|
+
loadData({
|
|
184
|
+
page: 1
|
|
185
|
+
});
|
|
186
|
+
resolve();
|
|
187
|
+
},
|
|
188
|
+
onErrorHandle: (err)=>{
|
|
189
|
+
reject(err);
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
});
|
|
193
|
+
};
|
|
194
|
+
const bulkDelete = async (ids)=>{
|
|
195
|
+
const endpointKey = getBulkEndpointKey(table, "DELETE");
|
|
196
|
+
const action = apiActions[endpointKey];
|
|
197
|
+
if (!action) {
|
|
198
|
+
throw new Error(`Endpoint ${endpointKey} not found`);
|
|
199
|
+
}
|
|
200
|
+
return new Promise((resolve, reject)=>{
|
|
201
|
+
action.start({
|
|
202
|
+
payload: ids,
|
|
203
|
+
onAfterHandle: ()=>{
|
|
204
|
+
loadData();
|
|
205
|
+
resolve();
|
|
206
|
+
},
|
|
207
|
+
onErrorHandle: (err)=>{
|
|
208
|
+
reject(err);
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
});
|
|
212
|
+
};
|
|
213
|
+
const refetch = ()=>{
|
|
214
|
+
loadData();
|
|
215
|
+
};
|
|
216
|
+
useEffect(()=>{
|
|
217
|
+
if (isInitialMount.current) {
|
|
218
|
+
isInitialMount.current = false;
|
|
219
|
+
loadData();
|
|
220
|
+
}
|
|
221
|
+
}, []);
|
|
222
|
+
const hasMore = meta?.hasNextPage ?? false;
|
|
223
|
+
return {
|
|
224
|
+
items,
|
|
225
|
+
meta,
|
|
226
|
+
isLoading,
|
|
227
|
+
isLoadingMore,
|
|
228
|
+
error,
|
|
229
|
+
loadData,
|
|
230
|
+
loadMore,
|
|
231
|
+
hasMore,
|
|
232
|
+
addItem,
|
|
233
|
+
updateItem,
|
|
234
|
+
deleteItem,
|
|
235
|
+
bulkAdd,
|
|
236
|
+
bulkDelete,
|
|
237
|
+
search,
|
|
238
|
+
setSearch,
|
|
239
|
+
sort,
|
|
240
|
+
setSort,
|
|
241
|
+
filters,
|
|
242
|
+
setFilters,
|
|
243
|
+
currentPage,
|
|
244
|
+
setCurrentPage,
|
|
245
|
+
refetch
|
|
246
|
+
};
|
|
247
|
+
}
|