@goplusvn/core 0.1.0 → 0.1.1
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/package.json +2 -1
- package/src/assets/erp_wallpaper.png +0 -0
- package/src/assets/goeat_logo.png +0 -0
- package/src/audit/audit-manager.ts +139 -0
- package/src/audit/index.ts +11 -0
- package/src/audit/memory-audit-logger.ts +86 -0
- package/src/audit/types.ts +50 -0
- package/src/auth/auth-service.ts +97 -0
- package/src/auth/index.ts +266 -0
- package/src/code-generation/index.ts +69 -0
- package/src/configs/auth-routes.ts +17 -0
- package/src/configs/crud.ts +136 -0
- package/src/configs/data/navigations.ts +781 -0
- package/src/configs/data/oauth-links.ts +10 -0
- package/src/configs/entities/material-categories.config.ts +125 -0
- package/src/configs/i18n.ts +12 -0
- package/src/configs/index.ts +26 -0
- package/src/configs/status.ts +25 -0
- package/src/configs/themes.ts +100 -0
- package/src/crud/components/crud-bulk-actions.tsx +91 -0
- package/src/crud/components/crud-card-view.tsx +241 -0
- package/src/crud/components/crud-context.tsx +122 -0
- package/src/crud/components/crud-delete-dialog.tsx +145 -0
- package/src/crud/components/crud-dialog.tsx +406 -0
- package/src/crud/components/crud-empty-state.tsx +104 -0
- package/src/crud/components/crud-export-button.tsx +170 -0
- package/src/crud/components/crud-field-renderer.tsx +653 -0
- package/src/crud/components/crud-filter-chips.tsx +102 -0
- package/src/crud/components/crud-filters/checkbox-filter.tsx +97 -0
- package/src/crud/components/crud-filters/datetime-filter.tsx +83 -0
- package/src/crud/components/crud-filters/filter-builder.tsx +66 -0
- package/src/crud/components/crud-filters/index.tsx +76 -0
- package/src/crud/components/crud-filters/radio-filter.tsx +86 -0
- package/src/crud/components/crud-filters/select-filter.tsx +141 -0
- package/src/crud/components/crud-filters/text-filter.tsx +86 -0
- package/src/crud/components/crud-form.tsx +642 -0
- package/src/crud/components/crud-import-dialog.tsx +440 -0
- package/src/crud/components/crud-infinite-scroll.tsx +116 -0
- package/src/crud/components/crud-page.tsx +1017 -0
- package/src/crud/components/crud-provider.tsx +277 -0
- package/src/crud/components/crud-row-actions.tsx +189 -0
- package/src/crud/components/crud-search.tsx +82 -0
- package/src/crud/components/crud-sheet.tsx +336 -0
- package/src/crud/components/crud-table-skeleton.tsx +26 -0
- package/src/crud/components/crud-table-toolbar.tsx +91 -0
- package/src/crud/components/crud-table.tsx +352 -0
- package/src/crud/components/crud-virtual-table.tsx +55 -0
- package/src/crud/components/index.tsx +20 -0
- package/src/crud/crud-filters/checkbox-filter.tsx +87 -0
- package/src/crud/crud-filters/datetime-filter.tsx +82 -0
- package/src/crud/crud-filters/filter-builder.tsx +64 -0
- package/src/crud/crud-filters/index.tsx +78 -0
- package/src/crud/crud-filters/radio-filter.tsx +79 -0
- package/src/crud/crud-filters/select-filter.tsx +148 -0
- package/src/crud/crud-filters/text-filter.tsx +81 -0
- package/src/crud/index.ts +43 -0
- package/src/crud/lib/crud-service.test.ts +334 -0
- package/src/crud/lib/crud-service.ts +358 -0
- package/src/crud/lib/crud-utils.test.ts +354 -0
- package/src/crud/lib/crud-utils.ts +299 -0
- package/src/crud/lib/crud-validator.ts +247 -0
- package/src/crud/lib/data-loader.ts +234 -0
- package/src/crud/lib/field-calculator.ts +241 -0
- package/src/crud/lib/field-formatter.ts +240 -0
- package/src/crud/lib/import-export-service.test.ts +290 -0
- package/src/crud/lib/import-export-service.ts +352 -0
- package/src/crud/lib/import-server-utils.ts +109 -0
- package/src/crud/lib/lazy-loader.ts +241 -0
- package/src/crud/lib/parse-filters.ts +85 -0
- package/src/crud/lib/permissions.ts +52 -0
- package/src/crud/lib/serialize-config.ts +60 -0
- package/src/crud/lib/stream-loader.ts +145 -0
- package/src/crud/lib/translate-config.ts +335 -0
- package/src/crud/lib/types.ts +11 -0
- package/src/crud/pages/entity-crud-page.tsx +144 -0
- package/src/crud/server.ts +8 -0
- package/src/home/constants.tsx +142 -0
- package/src/home/feature-showcase.tsx +171 -0
- package/src/home/home-page.tsx +191 -0
- package/src/home/hooks/index.ts +1 -0
- package/src/home/hooks/useWidgetPreferences.ts +167 -0
- package/src/home/index.ts +33 -0
- package/src/home/quick-access-dialog.tsx +271 -0
- package/src/home/quick-access-menu.tsx +267 -0
- package/src/home/types.ts +140 -0
- package/src/home/welcome-card.tsx +92 -0
- package/src/home/widget-container.tsx +258 -0
- package/src/home/widgets/base-widget.tsx +200 -0
- package/src/home/widgets/customers-widget.tsx +74 -0
- package/src/home/widgets/index.ts +6 -0
- package/src/home/widgets/orders-widget.tsx +87 -0
- package/src/home/widgets/revenue-widget.tsx +71 -0
- package/src/home/widgets/stock-widget.tsx +109 -0
- package/src/hooks/index.tsx +598 -0
- package/src/hooks/use-tenant.test.tsx +30 -0
- package/src/hooks/use-tenant.ts +5 -0
- package/src/index.ts +17 -0
- package/src/infrastructure/__tests__/architecture-verification.spec.ts +103 -0
- package/src/infrastructure/api-service.ts +317 -0
- package/src/infrastructure/cache/cache-manager.ts +107 -0
- package/src/infrastructure/cache/cache.ts +120 -0
- package/src/infrastructure/cache/index.ts +8 -0
- package/src/infrastructure/cache/types.ts +48 -0
- package/src/infrastructure/cron/cron-manager.ts +239 -0
- package/src/infrastructure/cron/index.ts +6 -0
- package/src/infrastructure/cron/types.ts +41 -0
- package/src/infrastructure/event-bus/event-bus.ts +145 -0
- package/src/infrastructure/event-bus/index.ts +2 -0
- package/src/infrastructure/event-bus/types.ts +22 -0
- package/src/infrastructure/index.ts +32 -0
- package/src/infrastructure/lock/decorators.ts +67 -0
- package/src/infrastructure/lock/index.ts +2 -0
- package/src/infrastructure/lock/lock-manager.ts +33 -0
- package/src/infrastructure/logger/index.ts +2 -0
- package/src/infrastructure/logger/logger.ts +96 -0
- package/src/infrastructure/logger/types.ts +25 -0
- package/src/layout/index.tsx +185 -0
- package/src/navigation/index.ts +91 -0
- package/src/notification/index.ts +14 -0
- package/src/notification/notification-service.ts +120 -0
- package/src/notification/storage/in-memory.ts +56 -0
- package/src/notification/storage/index.ts +1 -0
- package/src/notification/types.ts +51 -0
- package/src/organization/branch-service.ts +299 -0
- package/src/organization/branches.config.ts +154 -0
- package/src/organization/index.ts +5 -0
- package/src/plugin/apps-registry.ts +97 -0
- package/src/plugin/index.ts +5 -0
- package/src/plugin/types.ts +41 -0
- package/src/providers/index.tsx +109 -0
- package/src/providers/tenant-provider.tsx +45 -0
- package/src/rbac/components/roles/role-card.tsx +158 -0
- package/src/rbac/components/roles/role-stats-cards.tsx +29 -0
- package/src/rbac/components/roles/role-toolbar.tsx +123 -0
- package/src/rbac/hooks/use-role-operations.ts +159 -0
- package/src/rbac/hooks/use-roles-data.ts +59 -0
- package/src/rbac/index.ts +297 -0
- package/src/rbac/lib/permission-helpers.ts +63 -0
- package/src/rbac/pages/action-list-page.tsx +25 -0
- package/src/rbac/pages/resource-list-page.tsx +25 -0
- package/src/rbac/pages/role-list-page.tsx +378 -0
- package/src/rbac/permission-service.ts +140 -0
- package/src/rbac/permissions.ts +135 -0
- package/src/rbac/resource-service.ts +115 -0
- package/src/rbac/resource-validator.ts +119 -0
- package/src/rbac/role-service.ts +165 -0
- package/src/rbac/server.ts +16 -0
- package/src/rbac/types.ts +38 -0
- package/src/schemas/action.schema.ts +66 -0
- package/src/schemas/branch.schema.ts +52 -0
- package/src/schemas/coming-soon-schema.ts +9 -0
- package/src/schemas/company.schema.ts +44 -0
- package/src/schemas/forgot-passward-schema.ts +9 -0
- package/src/schemas/index.ts +30 -0
- package/src/schemas/material-category.schema.ts +43 -0
- package/src/schemas/material-pricing.schema.ts +74 -0
- package/src/schemas/material.schema.ts +76 -0
- package/src/schemas/materials.ts +52 -0
- package/src/schemas/new-passward-schema.ts +15 -0
- package/src/schemas/partner-company.schema.ts +149 -0
- package/src/schemas/register-schema.ts +36 -0
- package/src/schemas/resource.schema.ts +133 -0
- package/src/schemas/role.schema.ts +11 -0
- package/src/schemas/sign-in-schema.ts +24 -0
- package/src/schemas/supplier-pricing.schema.ts +15 -0
- package/src/schemas/supplier.schema.ts +120 -0
- package/src/schemas/system-category-group.schema.ts +67 -0
- package/src/schemas/system-category.schema.ts +77 -0
- package/src/schemas/system-config.schema.ts +118 -0
- package/src/schemas/uom.schema.ts +75 -0
- package/src/schemas/user-supplier.schema.ts +179 -0
- package/src/schemas/user.schema.ts +18 -0
- package/src/schemas/verify-email-schema.ts +9 -0
- package/src/schemas/warehouse.schema.ts +49 -0
- package/src/system/components/categories/category-list.tsx +529 -0
- package/src/system/components/categories/category-manager.tsx +89 -0
- package/src/system/components/categories/group-sidebar.tsx +308 -0
- package/src/system/components/settings/setting-dialogs.tsx +197 -0
- package/src/system/components/settings/setting-field.tsx +291 -0
- package/src/system/components/settings/setting-form-dialog.tsx +308 -0
- package/src/system/components/settings/settings-groups.ts +80 -0
- package/src/system/components/settings/settings-search.tsx +71 -0
- package/src/system/components/settings/settings-section.tsx +74 -0
- package/src/system/components/settings/settings-sidebar.tsx +81 -0
- package/src/system/constants.ts +3 -0
- package/src/system/index.ts +150 -0
- package/src/system/job-manager.ts +176 -0
- package/src/system/pages/components/categories/category-list.tsx +537 -0
- package/src/system/pages/components/categories/category-manager.tsx +90 -0
- package/src/system/pages/components/categories/group-sidebar.tsx +311 -0
- package/src/system/pages/components/settings/sales-rules-settings.tsx +222 -0
- package/src/system/pages/components/settings/setting-dialogs.tsx +197 -0
- package/src/system/pages/components/settings/setting-field.tsx +292 -0
- package/src/system/pages/components/settings/setting-form-dialog.tsx +308 -0
- package/src/system/pages/components/settings/settings-groups.ts +87 -0
- package/src/system/pages/components/settings/settings-page.tsx +372 -0
- package/src/system/pages/components/settings/settings-search.tsx +71 -0
- package/src/system/pages/components/settings/settings-section.tsx +74 -0
- package/src/system/pages/components/settings/settings-sidebar.tsx +81 -0
- package/src/system/pages/components/settings/system-settings.tsx +244 -0
- package/src/system/pages/system-category-page.tsx +15 -0
- package/src/system/pages/system-settings-page.tsx +380 -0
- package/src/system/schemas/system-category-group.schema.ts +46 -0
- package/src/system/schemas/system-category.schema.ts +56 -0
- package/src/system/services/settings-service.ts +127 -0
- package/src/system/services/system-category-service.ts +63 -0
- package/src/system/types.ts +45 -0
- package/src/types/index.ts +703 -0
- package/src/ui/auth/auth-layout.tsx +135 -0
- package/src/ui/auth/forgot-password-form.tsx +98 -0
- package/src/ui/auth/index.tsx +7 -0
- package/src/ui/auth/new-password-form.tsx +107 -0
- package/src/ui/auth/oauth-links.tsx +30 -0
- package/src/ui/auth/register-form.tsx +202 -0
- package/src/ui/auth/sign-in-form.tsx +238 -0
- package/src/ui/auth/verify-email-form.tsx +104 -0
- package/src/ui/crud/index.tsx +10 -0
- package/src/ui/data-display/accordion.tsx +65 -0
- package/src/ui/data-display/aspect-ratio.tsx +11 -0
- package/src/ui/data-display/avatar.tsx +163 -0
- package/src/ui/data-display/bento-grid.tsx +77 -0
- package/src/ui/data-display/carousel.tsx +249 -0
- package/src/ui/data-display/chart.tsx +363 -0
- package/src/ui/data-display/code-block-highlight.tsx +54 -0
- package/src/ui/data-display/collapsible.tsx +42 -0
- package/src/ui/data-display/compact-stat-bar.tsx +149 -0
- package/src/ui/data-display/data-table/data-table-context.tsx +255 -0
- package/src/ui/data-display/data-table/data-table-empty-state.tsx +133 -0
- package/src/ui/data-display/data-table/data-table-skeleton.tsx +145 -0
- package/src/ui/data-display/data-table/data-table-toolbar.tsx +353 -0
- package/src/ui/data-display/data-table/data-table.tsx +597 -0
- package/src/ui/data-display/data-table/index.ts +44 -0
- package/src/ui/data-display/data-table-column-header.tsx +75 -0
- package/src/ui/data-display/data-table-pagination.tsx +130 -0
- package/src/ui/data-display/data-table-view-options.tsx +59 -0
- package/src/ui/data-display/formatted-number-input.tsx +210 -0
- package/src/ui/data-display/highlight.tsx +20 -0
- package/src/ui/data-display/hover-card.tsx +48 -0
- package/src/ui/data-display/index.tsx +50 -0
- package/src/ui/data-display/iphone-15-pro.tsx +114 -0
- package/src/ui/data-display/kanban/index.ts +4 -0
- package/src/ui/data-display/kanban/kanban-board.tsx +192 -0
- package/src/ui/data-display/kanban/kanban-column.tsx +74 -0
- package/src/ui/data-display/kanban/kanban-item.tsx +50 -0
- package/src/ui/data-display/kanban/kanban-types.ts +21 -0
- package/src/ui/data-display/kpi-card.tsx +68 -0
- package/src/ui/data-display/media-grid.tsx +110 -0
- package/src/ui/data-display/safari.tsx +175 -0
- package/src/ui/data-display/show-more-text.tsx +55 -0
- package/src/ui/data-display/tabs.tsx +68 -0
- package/src/ui/data-display/timeline.tsx +256 -0
- package/src/ui/feedback/alert.tsx +60 -0
- package/src/ui/feedback/context-menu.tsx +245 -0
- package/src/ui/feedback/drawer.tsx +132 -0
- package/src/ui/feedback/error-dialog.tsx +273 -0
- package/src/ui/feedback/index.tsx +183 -0
- package/src/ui/feedback/progress.tsx +32 -0
- package/src/ui/feedback/sheet.tsx +148 -0
- package/src/ui/feedback/sonner.tsx +36 -0
- package/src/ui/forms/command.tsx +157 -0
- package/src/ui/forms/date-picker.tsx +73 -0
- package/src/ui/forms/date-range-picker.tsx +76 -0
- package/src/ui/forms/date-time-picker.tsx +109 -0
- package/src/ui/forms/editor/editor-menu-bar.tsx +394 -0
- package/src/ui/forms/editor/index.tsx +130 -0
- package/src/ui/forms/editor/multi-select-example.tsx +1234 -0
- package/src/ui/forms/emoji-picker.tsx +109 -0
- package/src/ui/forms/file-dropzone.tsx +169 -0
- package/src/ui/forms/file-thumbnail.tsx +29 -0
- package/src/ui/forms/index.tsx +201 -0
- package/src/ui/forms/input-file.tsx +99 -0
- package/src/ui/forms/input-group.tsx +46 -0
- package/src/ui/forms/input-otp.tsx +81 -0
- package/src/ui/forms/input-phone.tsx +172 -0
- package/src/ui/forms/input-spin.tsx +116 -0
- package/src/ui/forms/input-tags.tsx +219 -0
- package/src/ui/forms/input-time.tsx +42 -0
- package/src/ui/forms/multi-select.tsx +629 -0
- package/src/ui/forms/multiple-date-picker.tsx +74 -0
- package/src/ui/forms/radio-group.tsx +42 -0
- package/src/ui/forms/rating.tsx +158 -0
- package/src/ui/forms/time-picker.tsx +57 -0
- package/src/ui/index.tsx +17 -0
- package/src/ui/layout/animated-list.tsx +77 -0
- package/src/ui/layout/animated-sidebar.tsx +294 -0
- package/src/ui/layout/command-menu.tsx +355 -0
- package/src/ui/layout/customizer.tsx +324 -0
- package/src/ui/layout/footer.tsx +43 -0
- package/src/ui/layout/full-screen-toggle.tsx +52 -0
- package/src/ui/layout/header-breadcrumb.tsx +77 -0
- package/src/ui/layout/horizontal-layout-header.tsx +83 -0
- package/src/ui/layout/horizontal-layout.tsx +50 -0
- package/src/ui/layout/index.tsx +25 -0
- package/src/ui/layout/language-dropdown.tsx +103 -0
- package/src/ui/layout/logo.tsx +63 -0
- package/src/ui/layout/main-layout.tsx +57 -0
- package/src/ui/layout/mode-dropdown.tsx +58 -0
- package/src/ui/layout/notification-dropdown.tsx +127 -0
- package/src/ui/layout/page-tabs.tsx +306 -0
- package/src/ui/layout/route-cache.tsx +214 -0
- package/src/ui/layout/sidebar-group-icon-menu.tsx +195 -0
- package/src/ui/layout/sidebar.tsx +279 -0
- package/src/ui/layout/tab-content-cache.tsx +201 -0
- package/src/ui/layout/tab-navigation-provider.tsx +536 -0
- package/src/ui/layout/toggle-mobile-sidebar.tsx +33 -0
- package/src/ui/layout/top-bar-header-menubar.tsx +412 -0
- package/src/ui/layout/user-dropdown.tsx +188 -0
- package/src/ui/layout/vertical-layout-header.tsx +65 -0
- package/src/ui/layout/vertical-layout.tsx +47 -0
- package/src/ui/management/audit-log-page.tsx +209 -0
- package/src/ui/management/cache-management.tsx +349 -0
- package/src/ui/management/index.ts +3 -0
- package/src/ui/management/job-management.tsx +308 -0
- package/src/ui/pages/not-found.tsx +30 -0
- package/src/ui/primitives/badge.tsx +66 -0
- package/src/ui/primitives/breadcrumb.tsx +103 -0
- package/src/ui/primitives/button.tsx +129 -0
- package/src/ui/primitives/calendar.tsx +74 -0
- package/src/ui/primitives/card.tsx +86 -0
- package/src/ui/primitives/checkbox.tsx +31 -0
- package/src/ui/primitives/client.ts +30 -0
- package/src/ui/primitives/combobox.tsx +290 -0
- package/src/ui/primitives/dialog.tsx +121 -0
- package/src/ui/primitives/dropdown-menu.tsx +239 -0
- package/src/ui/primitives/dynamic-icon.tsx +24 -0
- package/src/ui/primitives/index.tsx +134 -0
- package/src/ui/primitives/input-number.tsx +131 -0
- package/src/ui/primitives/input.tsx +22 -0
- package/src/ui/primitives/keyboard.tsx +23 -0
- package/src/ui/primitives/label.tsx +24 -0
- package/src/ui/primitives/menubar.tsx +262 -0
- package/src/ui/primitives/navigation-menu.tsx +157 -0
- package/src/ui/primitives/pagination.tsx +118 -0
- package/src/ui/primitives/popover.tsx +56 -0
- package/src/ui/primitives/prefetch-link.tsx +60 -0
- package/src/ui/primitives/resizable.tsx +59 -0
- package/src/ui/primitives/scroll-area.tsx +63 -0
- package/src/ui/primitives/select.tsx +172 -0
- package/src/ui/primitives/separator.tsx +51 -0
- package/src/ui/primitives/sidebar.tsx +844 -0
- package/src/ui/primitives/slider.tsx +27 -0
- package/src/ui/primitives/status-badge.tsx +47 -0
- package/src/ui/primitives/sticky-layout.tsx +50 -0
- package/src/ui/primitives/switch.tsx +29 -0
- package/src/ui/primitives/table.tsx +116 -0
- package/src/ui/primitives/tabs.tsx +55 -0
- package/src/ui/primitives/toggle-group.tsx +70 -0
- package/src/ui/primitives/toggle.tsx +47 -0
- package/src/ui/primitives/tooltip.tsx +59 -0
- package/src/user/components/dangerous-zone.tsx +34 -0
- package/src/user/components/delete-account-form.tsx +40 -0
- package/src/user/components/index.ts +4 -0
- package/src/user/components/profile-info-form.tsx +390 -0
- package/src/user/components/profile-info.tsx +32 -0
- package/src/user/components/unified-profile-dialog.tsx +1019 -0
- package/src/user/components/user-stats.tsx +27 -0
- package/src/user/components/user-toolbar.tsx +137 -0
- package/src/user/components/users-card-view.tsx +253 -0
- package/src/user/index.ts +11 -0
- package/src/user/pages/user-list-page.tsx +234 -0
- package/src/user/pages/users-client-page.tsx +385 -0
- package/src/user/profile-page.tsx +19 -0
- package/src/user/schemas.ts +68 -0
- package/src/user/types.ts +34 -0
- package/src/user/user-service.ts +538 -0
- package/src/utils/index.ts +906 -0
- package/src/workflow/activity-timeline.tsx +412 -0
- package/src/workflow/approval-workflow.tsx +31 -0
- package/src/workflow/index.ts +2 -0
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useCallback, useMemo, useState } from "react";
|
|
4
|
+
|
|
5
|
+
import type {
|
|
6
|
+
ActiveFilter,
|
|
7
|
+
CrudPermissions,
|
|
8
|
+
CrudQueryParams,
|
|
9
|
+
EntityConfig,
|
|
10
|
+
SortingState,
|
|
11
|
+
} from "../../types";
|
|
12
|
+
import type { ReactNode } from "react";
|
|
13
|
+
import {
|
|
14
|
+
CrudConfigContext,
|
|
15
|
+
CrudSelectionContext,
|
|
16
|
+
CrudStateContext,
|
|
17
|
+
useCrudConfig,
|
|
18
|
+
useCrudSelection,
|
|
19
|
+
useCrudState,
|
|
20
|
+
} from "./crud-context";
|
|
21
|
+
import type {
|
|
22
|
+
CrudConfigContextValue,
|
|
23
|
+
CrudSelectionContextValue,
|
|
24
|
+
CrudStateContextValue,
|
|
25
|
+
CrudTranslations,
|
|
26
|
+
} from "./crud-context";
|
|
27
|
+
|
|
28
|
+
// Combined interface for backward compatibility
|
|
29
|
+
interface CrudContextValue
|
|
30
|
+
extends CrudConfigContextValue,
|
|
31
|
+
CrudStateContextValue,
|
|
32
|
+
CrudSelectionContextValue {}
|
|
33
|
+
|
|
34
|
+
interface CrudProviderProps {
|
|
35
|
+
children: ReactNode;
|
|
36
|
+
initialConfig?: EntityConfig;
|
|
37
|
+
initialPermissions?: CrudPermissions;
|
|
38
|
+
initialTranslations?: CrudTranslations;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function CrudProvider({
|
|
42
|
+
children,
|
|
43
|
+
initialConfig,
|
|
44
|
+
initialPermissions,
|
|
45
|
+
initialTranslations,
|
|
46
|
+
}: CrudProviderProps) {
|
|
47
|
+
// --- Config State ---
|
|
48
|
+
const [config, setConfig] = useState<EntityConfig | null>(
|
|
49
|
+
initialConfig || null,
|
|
50
|
+
);
|
|
51
|
+
const [permissions, setPermissions] = useState<CrudPermissions>({
|
|
52
|
+
create: false,
|
|
53
|
+
read: false,
|
|
54
|
+
update: false,
|
|
55
|
+
delete: false,
|
|
56
|
+
export: false,
|
|
57
|
+
import: false,
|
|
58
|
+
approve: false,
|
|
59
|
+
reject: false,
|
|
60
|
+
...initialPermissions,
|
|
61
|
+
});
|
|
62
|
+
const [translations, setTranslations] = useState<CrudTranslations>(
|
|
63
|
+
initialTranslations || {},
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
// --- State (Search, Filters, Pagination, Sorting) ---
|
|
67
|
+
const [search, setSearch] = useState<string>("");
|
|
68
|
+
const [filters, setFilters] = useState<ActiveFilter[]>([]);
|
|
69
|
+
const [pagination, setPagination] = useState({ page: 1, pageSize: 10 });
|
|
70
|
+
|
|
71
|
+
// Validate defaultSort field exists in visible table fields
|
|
72
|
+
const getValidDefaultSort = (): SortingState | null => {
|
|
73
|
+
if (!initialConfig?.defaultSort) return null;
|
|
74
|
+
|
|
75
|
+
const defaultSortField = initialConfig.defaultSort.field;
|
|
76
|
+
const fieldExists = initialConfig.fields.some(
|
|
77
|
+
(field) => field.name === defaultSortField && !field.hideInTable,
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
if (!fieldExists) {
|
|
81
|
+
console.warn(
|
|
82
|
+
`Default sort field "${defaultSortField}" is not visible in table. Using first visible sortable field instead.`,
|
|
83
|
+
);
|
|
84
|
+
// Find first visible sortable field
|
|
85
|
+
const firstSortableField = initialConfig.fields.find(
|
|
86
|
+
(field) => !field.hideInTable && field.sortable !== false,
|
|
87
|
+
);
|
|
88
|
+
if (firstSortableField) {
|
|
89
|
+
return {
|
|
90
|
+
field: firstSortableField.name,
|
|
91
|
+
direction: initialConfig.defaultSort.direction,
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return initialConfig.defaultSort;
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
const [sorting, setSorting] = useState<SortingState | null>(
|
|
101
|
+
getValidDefaultSort(),
|
|
102
|
+
);
|
|
103
|
+
|
|
104
|
+
// --- Selection State ---
|
|
105
|
+
const [selectedRows, setSelectedRows] = useState<Set<string>>(new Set());
|
|
106
|
+
|
|
107
|
+
// Filter helpers
|
|
108
|
+
const addFilter = useCallback((filter: ActiveFilter) => {
|
|
109
|
+
setFilters((prev) => {
|
|
110
|
+
const existing = prev.findIndex((f) => f.name === filter.name);
|
|
111
|
+
if (existing >= 0) {
|
|
112
|
+
const updated = [...prev];
|
|
113
|
+
updated[existing] = filter;
|
|
114
|
+
return updated;
|
|
115
|
+
}
|
|
116
|
+
return [...prev, filter];
|
|
117
|
+
});
|
|
118
|
+
}, []);
|
|
119
|
+
|
|
120
|
+
const removeFilter = useCallback((filterName: string) => {
|
|
121
|
+
setFilters((prev) => prev.filter((f) => f.name !== filterName));
|
|
122
|
+
}, []);
|
|
123
|
+
|
|
124
|
+
const updateFilter = useCallback((filterName: string, value: unknown) => {
|
|
125
|
+
setFilters((prev) =>
|
|
126
|
+
prev.map((f) => (f.name === filterName ? { ...f, value } : f)),
|
|
127
|
+
);
|
|
128
|
+
}, []);
|
|
129
|
+
|
|
130
|
+
const clearFilters = useCallback(() => {
|
|
131
|
+
setFilters([]);
|
|
132
|
+
}, []);
|
|
133
|
+
|
|
134
|
+
// Pagination helpers
|
|
135
|
+
const setPage = useCallback((page: number) => {
|
|
136
|
+
setPagination((prev) => ({ ...prev, page }));
|
|
137
|
+
}, []);
|
|
138
|
+
|
|
139
|
+
const setPageSize = useCallback((pageSize: number) => {
|
|
140
|
+
setPagination((prev) => ({ ...prev, pageSize, page: 1 }));
|
|
141
|
+
}, []);
|
|
142
|
+
|
|
143
|
+
// Selection helpers
|
|
144
|
+
const toggleRowSelection = useCallback((rowId: string) => {
|
|
145
|
+
setSelectedRows((prev) => {
|
|
146
|
+
const next = new Set(prev);
|
|
147
|
+
if (next.has(rowId)) {
|
|
148
|
+
next.delete(rowId);
|
|
149
|
+
} else {
|
|
150
|
+
next.add(rowId);
|
|
151
|
+
}
|
|
152
|
+
return next;
|
|
153
|
+
});
|
|
154
|
+
}, []);
|
|
155
|
+
|
|
156
|
+
const selectAllRows = useCallback((rowIds: string[]) => {
|
|
157
|
+
setSelectedRows((prev) => {
|
|
158
|
+
const allSelected = rowIds.every((id) => prev.has(id));
|
|
159
|
+
if (allSelected) {
|
|
160
|
+
return new Set();
|
|
161
|
+
}
|
|
162
|
+
return new Set(rowIds);
|
|
163
|
+
});
|
|
164
|
+
}, []);
|
|
165
|
+
|
|
166
|
+
const clearSelection = useCallback(() => {
|
|
167
|
+
setSelectedRows(new Set());
|
|
168
|
+
}, []);
|
|
169
|
+
|
|
170
|
+
// Query params builder
|
|
171
|
+
const getQueryParams = useCallback((): CrudQueryParams => {
|
|
172
|
+
const params: CrudQueryParams = {
|
|
173
|
+
page: pagination.page,
|
|
174
|
+
pageSize: pagination.pageSize,
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
// Add search if it exists and is not empty
|
|
178
|
+
if (search && search.trim().length > 0) {
|
|
179
|
+
params.search = search.trim();
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// Add sorting if exists
|
|
183
|
+
if (sorting) {
|
|
184
|
+
params.sort = sorting;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// Add filters if exists
|
|
188
|
+
if (filters.length > 0) {
|
|
189
|
+
params.filters = filters;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
console.log("getQueryParams:", params); // Debug log
|
|
193
|
+
|
|
194
|
+
return params;
|
|
195
|
+
}, [pagination, search, sorting, filters]);
|
|
196
|
+
|
|
197
|
+
// --- Context Values ---
|
|
198
|
+
|
|
199
|
+
const configValue = useMemo<CrudConfigContextValue>(
|
|
200
|
+
() => ({
|
|
201
|
+
config,
|
|
202
|
+
setConfig,
|
|
203
|
+
permissions,
|
|
204
|
+
setPermissions,
|
|
205
|
+
translations,
|
|
206
|
+
setTranslations,
|
|
207
|
+
}),
|
|
208
|
+
[config, permissions, translations],
|
|
209
|
+
);
|
|
210
|
+
|
|
211
|
+
const stateValue = useMemo<CrudStateContextValue>(
|
|
212
|
+
() => ({
|
|
213
|
+
search,
|
|
214
|
+
setSearch,
|
|
215
|
+
filters,
|
|
216
|
+
setFilters,
|
|
217
|
+
addFilter,
|
|
218
|
+
removeFilter,
|
|
219
|
+
updateFilter,
|
|
220
|
+
clearFilters,
|
|
221
|
+
pagination,
|
|
222
|
+
setPagination,
|
|
223
|
+
setPage,
|
|
224
|
+
setPageSize,
|
|
225
|
+
sorting,
|
|
226
|
+
setSorting,
|
|
227
|
+
getQueryParams,
|
|
228
|
+
}),
|
|
229
|
+
[
|
|
230
|
+
search,
|
|
231
|
+
filters,
|
|
232
|
+
pagination,
|
|
233
|
+
sorting,
|
|
234
|
+
addFilter,
|
|
235
|
+
removeFilter,
|
|
236
|
+
updateFilter,
|
|
237
|
+
clearFilters,
|
|
238
|
+
setPage,
|
|
239
|
+
setPageSize,
|
|
240
|
+
getQueryParams,
|
|
241
|
+
],
|
|
242
|
+
);
|
|
243
|
+
|
|
244
|
+
const selectionValue = useMemo<CrudSelectionContextValue>(
|
|
245
|
+
() => ({
|
|
246
|
+
selectedRows,
|
|
247
|
+
setSelectedRows,
|
|
248
|
+
toggleRowSelection,
|
|
249
|
+
selectAllRows,
|
|
250
|
+
clearSelection,
|
|
251
|
+
}),
|
|
252
|
+
[selectedRows, toggleRowSelection, selectAllRows, clearSelection],
|
|
253
|
+
);
|
|
254
|
+
|
|
255
|
+
return (
|
|
256
|
+
<CrudConfigContext.Provider value={configValue}>
|
|
257
|
+
<CrudStateContext.Provider value={stateValue}>
|
|
258
|
+
<CrudSelectionContext.Provider value={selectionValue}>
|
|
259
|
+
{children}
|
|
260
|
+
</CrudSelectionContext.Provider>
|
|
261
|
+
</CrudStateContext.Provider>
|
|
262
|
+
</CrudConfigContext.Provider>
|
|
263
|
+
);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
// Backward compatibility hook
|
|
267
|
+
export function useCrudContext(): CrudContextValue {
|
|
268
|
+
const configContext = useCrudConfig();
|
|
269
|
+
const stateContext = useCrudState();
|
|
270
|
+
const selectionContext = useCrudSelection();
|
|
271
|
+
|
|
272
|
+
return {
|
|
273
|
+
...configContext,
|
|
274
|
+
...stateContext,
|
|
275
|
+
...selectionContext,
|
|
276
|
+
};
|
|
277
|
+
}
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
Archive,
|
|
5
|
+
Copy,
|
|
6
|
+
Eye,
|
|
7
|
+
MoreHorizontal,
|
|
8
|
+
Pencil,
|
|
9
|
+
Trash2,
|
|
10
|
+
CheckCircle2,
|
|
11
|
+
XCircle,
|
|
12
|
+
} from "lucide-react";
|
|
13
|
+
|
|
14
|
+
import type { CrudPermissions, EntityConfig } from "../../types";
|
|
15
|
+
|
|
16
|
+
import { Button } from "../../ui";
|
|
17
|
+
import {
|
|
18
|
+
DropdownMenu,
|
|
19
|
+
DropdownMenuContent,
|
|
20
|
+
DropdownMenuItem,
|
|
21
|
+
DropdownMenuSeparator,
|
|
22
|
+
DropdownMenuTrigger,
|
|
23
|
+
} from "../../ui/primitives/client";
|
|
24
|
+
import { DynamicIcon } from "../../ui";
|
|
25
|
+
|
|
26
|
+
interface CrudRowActionsProps {
|
|
27
|
+
rowId: string;
|
|
28
|
+
rowData: Record<string, unknown>;
|
|
29
|
+
config: EntityConfig;
|
|
30
|
+
permissions: CrudPermissions;
|
|
31
|
+
onEdit?: (rowId: string, rowData?: Record<string, unknown>) => void;
|
|
32
|
+
onDelete?: (rowId: string) => void;
|
|
33
|
+
onCustomAction?: (
|
|
34
|
+
action: string,
|
|
35
|
+
rowId: string,
|
|
36
|
+
rowData: Record<string, unknown>,
|
|
37
|
+
) => void | Promise<void>;
|
|
38
|
+
translations?: {
|
|
39
|
+
edit?: string;
|
|
40
|
+
delete?: string;
|
|
41
|
+
actions?: string;
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function CrudRowActions({
|
|
46
|
+
rowId,
|
|
47
|
+
rowData,
|
|
48
|
+
config,
|
|
49
|
+
permissions,
|
|
50
|
+
onEdit,
|
|
51
|
+
onDelete,
|
|
52
|
+
onCustomAction,
|
|
53
|
+
translations,
|
|
54
|
+
}: CrudRowActionsProps) {
|
|
55
|
+
const t = {
|
|
56
|
+
edit: translations?.edit || "Edit",
|
|
57
|
+
delete: translations?.delete || "Delete",
|
|
58
|
+
actions: translations?.actions || "Actions",
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const getActionIcon = (action: string, icon?: string) => {
|
|
62
|
+
if (icon) {
|
|
63
|
+
return (
|
|
64
|
+
<DynamicIcon
|
|
65
|
+
name={icon as any}
|
|
66
|
+
className="mr-2 h-4 w-4"
|
|
67
|
+
aria-hidden="true"
|
|
68
|
+
/>
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
switch (action) {
|
|
73
|
+
case "copy":
|
|
74
|
+
case "duplicate":
|
|
75
|
+
return <Copy className="mr-2 h-4 w-4" aria-hidden="true" />;
|
|
76
|
+
case "view":
|
|
77
|
+
return <Eye className="mr-2 h-4 w-4" aria-hidden="true" />;
|
|
78
|
+
case "archive":
|
|
79
|
+
return <Archive className="mr-2 h-4 w-4" aria-hidden="true" />;
|
|
80
|
+
case "approve":
|
|
81
|
+
return <CheckCircle2 className="mr-2 h-4 w-4" aria-hidden="true" />;
|
|
82
|
+
case "reject":
|
|
83
|
+
return <XCircle className="mr-2 h-4 w-4" aria-hidden="true" />;
|
|
84
|
+
default:
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
const hasCustomActions = config.rowActions && config.rowActions.length > 0;
|
|
90
|
+
// Note: visibleWhen is removed during serialization, so all actions are visible
|
|
91
|
+
// For conditional visibility, handle it in the handler or use a different approach
|
|
92
|
+
const visibleCustomActions = config.rowActions || [];
|
|
93
|
+
|
|
94
|
+
const hasEditOrDelete =
|
|
95
|
+
(permissions.update && onEdit) || (permissions.delete && onDelete);
|
|
96
|
+
const hasApproveOrReject = permissions.approve || permissions.reject;
|
|
97
|
+
const hasAnyActions =
|
|
98
|
+
hasEditOrDelete || hasApproveOrReject || visibleCustomActions.length > 0;
|
|
99
|
+
|
|
100
|
+
if (!hasAnyActions) {
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return (
|
|
105
|
+
<DropdownMenu>
|
|
106
|
+
<DropdownMenuTrigger asChild>
|
|
107
|
+
<Button
|
|
108
|
+
variant="ghost"
|
|
109
|
+
className="h-8 w-8 p-0"
|
|
110
|
+
aria-label={`${t.actions} for row ${rowId}`}
|
|
111
|
+
aria-haspopup="true"
|
|
112
|
+
>
|
|
113
|
+
<span className="sr-only">Open menu</span>
|
|
114
|
+
<MoreHorizontal className="h-4 w-4" aria-hidden="true" />
|
|
115
|
+
</Button>
|
|
116
|
+
</DropdownMenuTrigger>
|
|
117
|
+
<DropdownMenuContent align="end" aria-label="Row actions">
|
|
118
|
+
{/* Edit Action */}
|
|
119
|
+
{permissions.update && onEdit && (
|
|
120
|
+
<DropdownMenuItem
|
|
121
|
+
onClick={() => onEdit(rowId, rowData)}
|
|
122
|
+
aria-label={`${t.edit} row ${rowId}`}
|
|
123
|
+
>
|
|
124
|
+
<Pencil className="mr-2 h-4 w-4" aria-hidden="true" />
|
|
125
|
+
{t.edit}
|
|
126
|
+
</DropdownMenuItem>
|
|
127
|
+
)}
|
|
128
|
+
|
|
129
|
+
{/* Custom Actions */}
|
|
130
|
+
{visibleCustomActions.length > 0 && (
|
|
131
|
+
<>
|
|
132
|
+
{hasEditOrDelete && <DropdownMenuSeparator />}
|
|
133
|
+
{visibleCustomActions.map((action, idx) => {
|
|
134
|
+
const handleClick = async () => {
|
|
135
|
+
if (action.handler) {
|
|
136
|
+
await action.handler(rowId, rowData);
|
|
137
|
+
} else if (onCustomAction) {
|
|
138
|
+
await onCustomAction(action.action, rowId, rowData);
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
// Check if user has permission for this custom action
|
|
143
|
+
const hasActionPermission =
|
|
144
|
+
action.action === "approve"
|
|
145
|
+
? permissions.approve
|
|
146
|
+
: action.action === "reject"
|
|
147
|
+
? permissions.reject
|
|
148
|
+
: true;
|
|
149
|
+
|
|
150
|
+
if (!hasActionPermission) return null;
|
|
151
|
+
|
|
152
|
+
const variant = action.variant || "default";
|
|
153
|
+
const isDestructive = variant === "destructive";
|
|
154
|
+
|
|
155
|
+
return (
|
|
156
|
+
<DropdownMenuItem
|
|
157
|
+
key={idx}
|
|
158
|
+
onClick={handleClick}
|
|
159
|
+
className={isDestructive ? "text-destructive" : ""}
|
|
160
|
+
aria-label={`${action.label} row ${rowId}`}
|
|
161
|
+
>
|
|
162
|
+
{getActionIcon(action.action, action.icon)}
|
|
163
|
+
{action.label}
|
|
164
|
+
</DropdownMenuItem>
|
|
165
|
+
);
|
|
166
|
+
})}
|
|
167
|
+
</>
|
|
168
|
+
)}
|
|
169
|
+
|
|
170
|
+
{/* Delete Action */}
|
|
171
|
+
{permissions.delete && onDelete && (
|
|
172
|
+
<>
|
|
173
|
+
{(hasEditOrDelete || visibleCustomActions.length > 0) && (
|
|
174
|
+
<DropdownMenuSeparator />
|
|
175
|
+
)}
|
|
176
|
+
<DropdownMenuItem
|
|
177
|
+
onClick={() => onDelete(rowId)}
|
|
178
|
+
className="text-destructive"
|
|
179
|
+
aria-label={`${t.delete} row ${rowId}`}
|
|
180
|
+
>
|
|
181
|
+
<Trash2 className="mr-2 h-4 w-4" aria-hidden="true" />
|
|
182
|
+
{t.delete}
|
|
183
|
+
</DropdownMenuItem>
|
|
184
|
+
</>
|
|
185
|
+
)}
|
|
186
|
+
</DropdownMenuContent>
|
|
187
|
+
</DropdownMenu>
|
|
188
|
+
);
|
|
189
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useEffect, useRef, useState } from "react";
|
|
4
|
+
import { Search } from "lucide-react";
|
|
5
|
+
|
|
6
|
+
import { Input } from "../../ui";
|
|
7
|
+
import { useCrudState } from "./crud-context";
|
|
8
|
+
|
|
9
|
+
interface CrudSearchProps {
|
|
10
|
+
placeholder?: string;
|
|
11
|
+
debounceMs?: number;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function CrudSearch({
|
|
15
|
+
placeholder = "Search...",
|
|
16
|
+
debounceMs = 300,
|
|
17
|
+
}: CrudSearchProps) {
|
|
18
|
+
const { search, setSearch } = useCrudState();
|
|
19
|
+
const [localSearch, setLocalSearch] = useState(search);
|
|
20
|
+
const lastSetValueRef = useRef<string>(search); // Track last value we set to context
|
|
21
|
+
const timeoutRef = useRef<NodeJS.Timeout | null>(null);
|
|
22
|
+
|
|
23
|
+
// Debounce search - only update context after user stops typing
|
|
24
|
+
useEffect(() => {
|
|
25
|
+
// Clear any pending timeout
|
|
26
|
+
if (timeoutRef.current) {
|
|
27
|
+
clearTimeout(timeoutRef.current);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
timeoutRef.current = setTimeout(() => {
|
|
31
|
+
// Only update context if value changed
|
|
32
|
+
if (localSearch !== lastSetValueRef.current) {
|
|
33
|
+
lastSetValueRef.current = localSearch;
|
|
34
|
+
setSearch(localSearch);
|
|
35
|
+
}
|
|
36
|
+
timeoutRef.current = null;
|
|
37
|
+
}, debounceMs);
|
|
38
|
+
|
|
39
|
+
return () => {
|
|
40
|
+
if (timeoutRef.current) {
|
|
41
|
+
clearTimeout(timeoutRef.current);
|
|
42
|
+
timeoutRef.current = null;
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
}, [localSearch, debounceMs, setSearch]);
|
|
46
|
+
|
|
47
|
+
// Sync with context when search changes externally (e.g., reset button)
|
|
48
|
+
// Only sync if the change didn't come from our own debounced update
|
|
49
|
+
useEffect(() => {
|
|
50
|
+
if (search !== lastSetValueRef.current) {
|
|
51
|
+
// External update - sync local state and update ref
|
|
52
|
+
lastSetValueRef.current = search;
|
|
53
|
+
setLocalSearch(search);
|
|
54
|
+
// Clear any pending debounce
|
|
55
|
+
if (timeoutRef.current) {
|
|
56
|
+
clearTimeout(timeoutRef.current);
|
|
57
|
+
timeoutRef.current = null;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}, [search]);
|
|
61
|
+
|
|
62
|
+
return (
|
|
63
|
+
<div className="relative">
|
|
64
|
+
<Search
|
|
65
|
+
className="absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground pointer-events-none"
|
|
66
|
+
aria-hidden="true"
|
|
67
|
+
/>
|
|
68
|
+
<Input
|
|
69
|
+
type="text"
|
|
70
|
+
placeholder={placeholder}
|
|
71
|
+
value={localSearch}
|
|
72
|
+
onChange={(e) => setLocalSearch(e.target.value)}
|
|
73
|
+
className="pl-9"
|
|
74
|
+
aria-label="Search table"
|
|
75
|
+
aria-describedby="search-description"
|
|
76
|
+
/>
|
|
77
|
+
<span id="search-description" className="sr-only">
|
|
78
|
+
Search and filter table data
|
|
79
|
+
</span>
|
|
80
|
+
</div>
|
|
81
|
+
);
|
|
82
|
+
}
|