@stacksjs/defaults 0.75.529 → 0.75.535
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/ai/skills/stacks-actions/SKILL.md +1 -1
- package/ai/skills/stacks-build/SKILL.md +1 -1
- package/ai/skills/stacks-dashboard/SKILL.md +2 -2
- package/ai/skills/stacks-database/SKILL.md +1 -1
- package/ai/skills/stacks-migrations/SKILL.md +2 -2
- package/ai/skills/stacks-native/CATALOG.md +4 -4
- package/app/Actions/Dashboard/Commerce/CommerceCouponsAction.ts +27 -15
- package/app/Actions/Dashboard/Commerce/CommerceCouponsExportAction.ts +45 -0
- package/app/Actions/Dashboard/Commerce/CommerceCustomersAction.ts +22 -12
- package/app/Actions/Dashboard/Commerce/CommerceCustomersExportAction.ts +44 -0
- package/app/Actions/Dashboard/Commerce/CommercePosCheckoutAction.ts +9 -29
- package/app/Actions/Dashboard/Commerce/CommercePrintDevicesAction.ts +7 -9
- package/app/Actions/Dashboard/Commerce/CommerceProductDetailAction.ts +9 -8
- package/app/Actions/Dashboard/Commerce/CommerceTaxesAction.ts +7 -9
- package/app/Actions/Dashboard/Commerce/ManufacturerIndexAction.ts +8 -20
- package/app/Actions/Dashboard/Commerce/commerce-coupon-list.test.ts +203 -0
- package/app/Actions/Dashboard/Commerce/commerce-coupon-list.ts +248 -0
- package/app/Actions/Dashboard/Commerce/commerce-customer-list.test.ts +183 -0
- package/app/Actions/Dashboard/Commerce/commerce-customer-list.ts +186 -0
- package/app/Actions/Dashboard/Commerce/commerce-customer-records.test.ts +1 -34
- package/app/Actions/Dashboard/Commerce/commerce-customer-records.ts +0 -11
- package/app/Actions/Dashboard/Commerce/commerce-manufacturer-list.test.ts +118 -0
- package/app/Actions/Dashboard/Commerce/commerce-manufacturer-list.ts +41 -0
- package/app/Actions/Dashboard/Commerce/commerce-pos-catalog.test.ts +17 -5
- package/app/Actions/Dashboard/Commerce/commerce-pos-catalog.ts +17 -3
- package/app/Actions/Dashboard/Commerce/commerce-print-device-list.test.ts +99 -0
- package/app/Actions/Dashboard/Commerce/commerce-print-device-list.ts +18 -0
- package/app/Actions/Dashboard/Commerce/commerce-product-list.ts +5 -5
- package/app/Actions/Dashboard/Commerce/commerce-product-options.test.ts +81 -0
- package/app/Actions/Dashboard/Commerce/commerce-tax-rate-list.test.ts +99 -0
- package/app/Actions/Dashboard/Commerce/commerce-tax-rate-list.ts +18 -0
- package/app/Actions/Dashboard/Commerce/coupon-records.test.ts +1 -16
- package/app/Actions/Dashboard/Commerce/coupon-records.ts +6 -10
- package/app/Actions/Dashboard/Commerce/manufacturer-records.test.ts +5 -17
- package/app/Actions/Dashboard/Commerce/manufacturer-records.ts +0 -29
- package/app/Actions/Dashboard/Email/captured-mail.test.ts +16 -0
- package/app/Actions/Dashboard/Email/captured-mail.ts +9 -1
- package/app/Actions/Dashboard/Models/model-write.ts +36 -3
- package/app/Actions/Dashboard/Notifications/NotificationDeliveryHistoryAction.ts +13 -58
- package/app/Actions/Dashboard/Notifications/notification-delivery-history.ts +74 -0
- package/app/Actions/SitemapAction.ts +3 -1
- package/app/Models/Notification.ts +3 -1
- package/app/Models/NotificationDelivery.ts +4 -0
- package/app/Models/User.ts +10 -1
- package/bootstrap.ts +10 -2
- package/functions/commerce/tax-types.ts +21 -0
- package/functions/dashboard-list.test.ts +16 -0
- package/functions/dashboard-list.ts +14 -6
- package/functions/dashboard-model-record.test.ts +139 -0
- package/functions/dashboard-model-record.ts +353 -0
- package/functions/monitoring/errors.ts +22 -103
- package/functions/notifications/deliveries.ts +7 -38
- package/functions/queries.ts +7 -10
- package/ide/vscode/package.json +1 -1
- package/package.json +5 -5
- package/resources/components/Dashboard/Analytics/AnalyticsHub.stx +2 -2
- package/resources/components/Dashboard/Analytics/CampaignAnalytics.stx +22 -28
- package/resources/components/Dashboard/Analytics/EventAnalytics.stx +26 -34
- package/resources/components/Dashboard/Analytics/SalesAnalytics.stx +29 -37
- package/resources/components/Dashboard/Analytics/WebAnalyticsBreakdown.stx +12 -16
- package/resources/components/Dashboard/Analytics/WebAnalyticsDashboard.stx +43 -53
- package/resources/components/Dashboard/App/RequestsOverview.stx +2 -1
- package/resources/components/Dashboard/App/SourceInventory.stx +2 -1
- package/resources/components/Dashboard/Auth/AccessTokens.stx +3 -5
- package/resources/components/Dashboard/Billing/BillingPaymentMethodsPanel.stx +9 -11
- package/resources/components/Dashboard/Billing/BillingSettings.stx +1 -1
- package/resources/components/Dashboard/Buddy/BuddyAssistant.stx +4 -6
- package/resources/components/Dashboard/Commerce/CommerceCategoriesDashboard.stx +2 -2
- package/resources/components/Dashboard/Commerce/CommerceCategoriesTable.stx +3 -3
- package/resources/components/Dashboard/Commerce/CommerceCategoryDialog.stx +2 -2
- package/resources/components/Dashboard/Commerce/CommerceCategoryHierarchy.stx +3 -5
- package/resources/components/Dashboard/Commerce/CommerceCouponBreakdown.stx +17 -13
- package/resources/components/Dashboard/Commerce/CommerceCouponDialog.stx +1 -1
- package/resources/components/Dashboard/Commerce/CommerceCouponsDashboard.stx +57 -85
- package/resources/components/Dashboard/Commerce/CommerceCouponsTable.stx +32 -9
- package/resources/components/Dashboard/Commerce/CommerceCustomerDialog.stx +1 -1
- package/resources/components/Dashboard/Commerce/CommerceCustomersDashboard.stx +49 -83
- package/resources/components/Dashboard/Commerce/CommerceCustomersTable.stx +32 -9
- package/resources/components/Dashboard/Commerce/CommerceGiftCardBreakdown.stx +9 -15
- package/resources/components/Dashboard/Commerce/CommerceGiftCardDialog.stx +1 -1
- package/resources/components/Dashboard/Commerce/CommerceGiftCardsDashboard.stx +35 -119
- package/resources/components/Dashboard/Commerce/CommerceGiftCardsTable.stx +3 -3
- package/resources/components/Dashboard/Commerce/CommerceManufacturerDialog.stx +1 -1
- package/resources/components/Dashboard/Commerce/CommerceManufacturersDashboard.stx +3 -5
- package/resources/components/Dashboard/Commerce/CommerceManufacturersTable.stx +2 -2
- package/resources/components/Dashboard/Commerce/CommerceOrderDialog.stx +4 -4
- package/resources/components/Dashboard/Commerce/CommerceOrdersDashboard.stx +42 -129
- package/resources/components/Dashboard/Commerce/CommerceOrdersTable.stx +3 -3
- package/resources/components/Dashboard/Commerce/CommerceOverviewDashboard.stx +1 -1
- package/resources/components/Dashboard/Commerce/CommerceOverviewOrdersTable.stx +9 -11
- package/resources/components/Dashboard/Commerce/CommerceOverviewProductsTable.stx +5 -7
- package/resources/components/Dashboard/Commerce/CommerceOverviewStats.stx +14 -16
- package/resources/components/Dashboard/Commerce/CommercePaymentsBreakdown.stx +12 -18
- package/resources/components/Dashboard/Commerce/CommercePaymentsDashboard.stx +41 -120
- package/resources/components/Dashboard/Commerce/CommercePaymentsTable.stx +1 -1
- package/resources/components/Dashboard/Commerce/CommercePosCart.stx +13 -15
- package/resources/components/Dashboard/Commerce/CommercePosCatalog.stx +17 -19
- package/resources/components/Dashboard/Commerce/CommercePosCheckoutDialog.stx +2 -2
- package/resources/components/Dashboard/Commerce/CommercePosDashboard.stx +1 -1
- package/resources/components/Dashboard/Commerce/CommercePosReceiptDialog.stx +1 -1
- package/resources/components/Dashboard/Commerce/CommerceProductDetailDashboard.stx +5 -5
- package/resources/components/Dashboard/Commerce/CommerceProductDialog.stx +3 -3
- package/resources/components/Dashboard/Commerce/CommerceProductsDashboard.stx +41 -122
- package/resources/components/Dashboard/Commerce/CommerceProductsTable.stx +3 -3
- package/resources/components/Dashboard/Commerce/CommerceReviewEditDialog.stx +1 -1
- package/resources/components/Dashboard/Commerce/CommerceReviewsDashboard.stx +38 -122
- package/resources/components/Dashboard/Commerce/CommerceReviewsTable.stx +2 -2
- package/resources/components/Dashboard/Commerce/CommerceTaxDialog.stx +3 -3
- package/resources/components/Dashboard/Commerce/CommerceTaxesDashboard.stx +5 -4
- package/resources/components/Dashboard/Commerce/CommerceTaxesTable.stx +4 -3
- package/resources/components/Dashboard/Commerce/CommerceUnitDialog.stx +3 -7
- package/resources/components/Dashboard/Commerce/CommerceUnitsDashboard.stx +3 -5
- package/resources/components/Dashboard/Commerce/CommerceUnitsTable.stx +2 -2
- package/resources/components/Dashboard/Commerce/CommerceVariantDialog.stx +3 -3
- package/resources/components/Dashboard/Commerce/CommerceVariantsDashboard.stx +4 -4
- package/resources/components/Dashboard/Commerce/CommerceVariantsTable.stx +3 -5
- package/resources/components/Dashboard/Commerce/Delivery/CourierDialog.stx +1 -1
- package/resources/components/Dashboard/Commerce/Delivery/CouriersDashboard.stx +1 -1
- package/resources/components/Dashboard/Commerce/Delivery/CouriersTable.stx +2 -2
- package/resources/components/Dashboard/Commerce/Delivery/DeliveryOverviewDashboard.stx +44 -52
- package/resources/components/Dashboard/Commerce/Delivery/DeliveryPagination.stx +2 -2
- package/resources/components/Dashboard/Commerce/Delivery/DeliveryRouteDialog.stx +1 -1
- package/resources/components/Dashboard/Commerce/Delivery/DeliveryRoutesDashboard.stx +1 -1
- package/resources/components/Dashboard/Commerce/Delivery/DeliveryRoutesTable.stx +2 -2
- package/resources/components/Dashboard/Commerce/Delivery/DigitalDeliveriesDashboard.stx +1 -1
- package/resources/components/Dashboard/Commerce/Delivery/DigitalDeliveryTable.stx +2 -2
- package/resources/components/Dashboard/Commerce/Delivery/LicenseKeyDialog.stx +3 -3
- package/resources/components/Dashboard/Commerce/Delivery/LicenseKeysDashboard.stx +1 -1
- package/resources/components/Dashboard/Commerce/Delivery/LicenseKeysTable.stx +2 -2
- package/resources/components/Dashboard/Commerce/Delivery/ShippingMethodsDashboard.stx +1 -1
- package/resources/components/Dashboard/Commerce/Delivery/ShippingMethodsTable.stx +2 -2
- package/resources/components/Dashboard/Commerce/Delivery/ShippingRateDialog.stx +2 -2
- package/resources/components/Dashboard/Commerce/Delivery/ShippingRatesDashboard.stx +1 -1
- package/resources/components/Dashboard/Commerce/Delivery/ShippingRatesTable.stx +2 -2
- package/resources/components/Dashboard/Commerce/Delivery/ShippingZoneDialog.stx +1 -1
- package/resources/components/Dashboard/Commerce/Delivery/ShippingZonesDashboard.stx +1 -1
- package/resources/components/Dashboard/Commerce/Delivery/ShippingZonesTable.stx +4 -8
- package/resources/components/Dashboard/Commerce/PaymentDetailsDialog.stx +1 -3
- package/resources/components/Dashboard/Commerce/PrintDeviceBreakdown.stx +9 -15
- package/resources/components/Dashboard/Commerce/PrintDeviceDialog.stx +1 -1
- package/resources/components/Dashboard/Commerce/PrintDevicesDashboard.stx +3 -3
- package/resources/components/Dashboard/Commerce/PrintDevicesTable.stx +3 -3
- package/resources/components/Dashboard/Commerce/PrintLogBreakdown.stx +3 -9
- package/resources/components/Dashboard/Commerce/PrintLogDetailsDialog.stx +1 -1
- package/resources/components/Dashboard/Commerce/PrintLogsDashboard.stx +4 -4
- package/resources/components/Dashboard/Commerce/PrintLogsTable.stx +8 -10
- package/resources/components/Dashboard/Commerce/ProductWaitlistDashboard.stx +37 -109
- package/resources/components/Dashboard/Commerce/ProductWaitlistEntryDialog.stx +3 -3
- package/resources/components/Dashboard/Commerce/ProductWaitlistTable.stx +2 -2
- package/resources/components/Dashboard/Commerce/RestaurantWaitlistDashboard.stx +38 -112
- package/resources/components/Dashboard/Commerce/RestaurantWaitlistEntryDialog.stx +2 -2
- package/resources/components/Dashboard/Commerce/RestaurantWaitlistTable.stx +2 -2
- package/resources/components/Dashboard/Content/AuthorsDashboard.stx +4 -4
- package/resources/components/Dashboard/Content/BlogDashboard.stx +4 -4
- package/resources/components/Dashboard/Content/CommentsDashboard.stx +36 -83
- package/resources/components/Dashboard/Content/ContentDashboard.stx +12 -14
- package/resources/components/Dashboard/Content/ContentTaxonomyDashboard.stx +2 -2
- package/resources/components/Dashboard/Content/FileManagerDashboard.stx +8 -12
- package/resources/components/Dashboard/Content/FileStoragePanel.stx +6 -10
- package/resources/components/Dashboard/Content/FileUploadDialog.stx +1 -3
- package/resources/components/Dashboard/Content/PagesDashboard.stx +39 -78
- package/resources/components/Dashboard/Content/PostEditorDialog.stx +4 -8
- package/resources/components/Dashboard/Content/PostsDashboard.stx +44 -85
- package/resources/components/Dashboard/Content/SeoDashboard.stx +5 -4
- package/resources/components/Dashboard/Data/DataRecords.stx +140 -12
- package/resources/components/Dashboard/Deployments/DeploymentList.stx +4 -4
- package/resources/components/Dashboard/Deployments/DeploymentTable.stx +3 -1
- package/resources/components/Dashboard/Elements/DropdownNavigation.stx +5 -7
- package/resources/components/Dashboard/Email/CapturedMailDashboard.stx +1 -3
- package/resources/components/Dashboard/Email/CapturedMailList.stx +18 -20
- package/resources/components/Dashboard/Email/EmailActivityDashboard.stx +24 -28
- package/resources/components/Dashboard/Email/EmailSettingsList.stx +6 -8
- package/resources/components/Dashboard/Email/EmailSettingsNavigation.stx +10 -12
- package/resources/components/Dashboard/Email/EmailSidebar.stx +33 -37
- package/resources/components/Dashboard/Email/InboxMessageDetail.stx +1 -1
- package/resources/components/Dashboard/Email/InboxMessageList.stx +16 -18
- package/resources/components/Dashboard/Email/InboxSettingsDashboard.stx +1 -1
- package/resources/components/Dashboard/Environment/EnvironmentDashboard.stx +2 -2
- package/resources/components/Dashboard/GlobalSearch.stx +19 -21
- package/resources/components/Dashboard/Home/DashboardHome.stx +8 -1
- package/resources/components/Dashboard/Infrastructure/CloudDashboard.stx +1 -1
- package/resources/components/Dashboard/Infrastructure/DnsDashboard.stx +27 -13
- package/resources/components/Dashboard/Infrastructure/LogsDashboard.stx +1 -1
- package/resources/components/Dashboard/Infrastructure/MailboxesDashboard.stx +46 -8
- package/resources/components/Dashboard/Infrastructure/ServerlessDashboard.stx +1 -1
- package/resources/components/Dashboard/Infrastructure/ServersDashboard.stx +1 -1
- package/resources/components/Dashboard/Jobs/JobDetail.stx +1 -1
- package/resources/components/Dashboard/Jobs/JobHistory.stx +44 -57
- package/resources/components/Dashboard/Jobs/JobTable.stx +23 -25
- package/resources/components/Dashboard/Kanban/KanbanCardDialog.stx +1 -1
- package/resources/components/Dashboard/Library/ComponentsDashboard.stx +1 -1
- package/resources/components/Dashboard/Management/AssignmentDrawer.stx +5 -7
- package/resources/components/Dashboard/Management/PermissionsDashboard.stx +35 -43
- package/resources/components/Dashboard/Marketing/AbandonedCartsDashboard.stx +11 -13
- package/resources/components/Dashboard/Marketing/CampaignDialog.stx +1 -3
- package/resources/components/Dashboard/Marketing/CampaignsDashboard.stx +2 -2
- package/resources/components/Dashboard/Marketing/CampaignsTable.stx +2 -2
- package/resources/components/Dashboard/Marketing/MarketingListsDashboard.stx +1 -1
- package/resources/components/Dashboard/Marketing/MarketingListsTable.stx +2 -2
- package/resources/components/Dashboard/Marketing/SocialPostDialog.stx +1 -3
- package/resources/components/Dashboard/Marketing/SocialPostsDashboard.stx +2 -2
- package/resources/components/Dashboard/Marketing/SocialPostsTable.stx +2 -2
- package/resources/components/Dashboard/Models/ModelRecordActions.stx +11 -2
- package/resources/components/Dashboard/Models/ModelRecordCreate.stx +193 -0
- package/resources/components/Dashboard/Models/ModelRecordDetail.stx +144 -0
- package/resources/components/Dashboard/Models/ModelRecordEdit.stx +176 -0
- package/resources/components/Dashboard/Models/ModelRecordsDashboard.stx +52 -186
- package/resources/components/Dashboard/Models/ModelsOverview.stx +2 -4
- package/resources/components/Dashboard/Monitoring/ErrorDashboard.stx +47 -81
- package/resources/components/Dashboard/Monitoring/ErrorTable.stx +4 -2
- package/resources/components/Dashboard/NotFoundDashboard.stx +4 -4
- package/resources/components/Dashboard/Notifications/NotificationDeliveryHistory.stx +43 -77
- package/resources/components/Dashboard/Notifications/NotificationDeliveryOverview.stx +15 -17
- package/resources/components/Dashboard/Notifications/NotificationDeliveryTable.stx +1 -1
- package/resources/components/Dashboard/Operations/AuditDashboard.stx +1 -1
- package/resources/components/Dashboard/Operations/ChangeDashboard.stx +1 -1
- package/resources/components/Dashboard/Operations/IncidentDashboard.stx +1 -1
- package/resources/components/Dashboard/Operations/MigrationDashboard.stx +2 -2
- package/resources/components/Dashboard/Operations/RecoveryDashboard.stx +1 -1
- package/resources/components/Dashboard/Operations/SchedulerDashboard.stx +1 -1
- package/resources/components/Dashboard/Queries/QueryDashboard.stx +60 -86
- package/resources/components/Dashboard/Queries/QueryDetail.stx +5 -9
- package/resources/components/Dashboard/Realtime/RealtimeDashboard.stx +6 -8
- package/resources/components/Dashboard/Remote/RemoteConsole.stx +14 -20
- package/resources/components/Dashboard/Settings/AppearanceSettingsDashboard.stx +48 -54
- package/resources/components/Dashboard/Settings/MailSettingsDashboard.stx +8 -8
- package/resources/components/Dashboard/Settings/SettingsDashboard.stx +43 -47
- package/resources/components/Dashboard/Teams/TeamInvitationDashboard.stx +2 -2
- package/resources/components/Dashboard/UI/ActivityTable.stx +2 -1
- package/resources/components/Dashboard/UI/Button.stx +15 -0
- package/resources/components/Dashboard/UI/MetricCards.stx +5 -7
- package/resources/components/Dashboard/UI/Pagination.stx +3 -5
- package/resources/components/Dashboard/UI/QuickLinks.stx +2 -2
- package/resources/components/Dashboard/UI/Select.stx +1 -0
- package/resources/components/Dashboard/UI/Table.stx +139 -96
- package/resources/components/Dashboard/UI/Tabs.stx +18 -20
- package/routes/dashboard-api.ts +2 -0
- package/routes/dashboard.ts +246 -253
- package/routes/storefront.ts +31 -0
- package/stx-components-plugin.ts +12 -1
- package/views/dashboard/content/categories/index.stx +1 -1
- package/views/dashboard/content/tags/index.stx +1 -1
- package/views/dashboard/layouts/default.stx +27 -12
- package/views/dashboard/models/[model]/[id]/edit.stx +8 -0
- package/views/dashboard/models/[model]/[id].stx +8 -0
- package/views/dashboard/models/[model]/create.stx +8 -0
- package/resources/components/Dashboard/CreateRecordModal.stx +0 -138
- package/resources/components/Dashboard/Models/EditRecordModal.stx +0 -81
|
@@ -6,12 +6,15 @@ import type {
|
|
|
6
6
|
CouponSummary,
|
|
7
7
|
} from '../../../../app/Actions/Dashboard/Commerce/coupon-records'
|
|
8
8
|
import { DashboardApiError, dashboardApi } from '../../../../functions/dashboard-api'
|
|
9
|
+
import { useServerList } from '../../../../functions/dashboard-list'
|
|
9
10
|
import { pushToast } from '../../../../functions/toasts'
|
|
10
|
-
import { minorToInput } from '@stacksjs/commerce/money'
|
|
11
11
|
|
|
12
12
|
interface CouponIndexResponse {
|
|
13
13
|
records: CouponRecord[]
|
|
14
|
+
total: number
|
|
15
|
+
page: number
|
|
14
16
|
summary: CouponSummary
|
|
17
|
+
currency: string
|
|
15
18
|
}
|
|
16
19
|
|
|
17
20
|
interface CouponWritePayload {
|
|
@@ -29,16 +32,14 @@ interface CouponWritePayload {
|
|
|
29
32
|
endDate?: string
|
|
30
33
|
}
|
|
31
34
|
|
|
32
|
-
const emptySummary: CouponSummary = { total: 0, enabled: 0, scheduled: 0, expired: 0, redemptions: 0 }
|
|
33
|
-
const records = state<CouponRecord[]>([])
|
|
35
|
+
const emptySummary: CouponSummary = { total: 0, enabled: 0, active: 0, scheduled: 0, expired: 0, percentage: 0, fixedAmount: 0, redemptions: 0, mostUsed: [] }
|
|
34
36
|
const summary = state<CouponSummary>({ ...emptySummary })
|
|
35
|
-
|
|
37
|
+
/** The store currency: fixed amounts are minor units of it. */
|
|
38
|
+
const currency = state('USD')
|
|
36
39
|
const statusFilter = state('all')
|
|
37
40
|
const enabledFilter = state('all')
|
|
38
41
|
const typeFilter = state('all')
|
|
39
42
|
const sort = state('newest')
|
|
40
|
-
const loading = state(true)
|
|
41
|
-
const loadError = state('')
|
|
42
43
|
const dialogOpen = state(false)
|
|
43
44
|
const dialogMode = state<'add' | 'edit'>('add')
|
|
44
45
|
const editingRecord = state<CouponRecord | null>(null)
|
|
@@ -48,33 +49,44 @@ const saving = state(false)
|
|
|
48
49
|
const deleting = state(false)
|
|
49
50
|
const validationErrors = state<Record<string, string>>({})
|
|
50
51
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
52
|
+
const SELECT_SORTS: Record<string, { sort: string, direction: 'asc' | 'desc' }> = {
|
|
53
|
+
newest: { sort: 'newest', direction: 'desc' },
|
|
54
|
+
code: { sort: 'code', direction: 'asc' },
|
|
55
|
+
usage: { sort: 'usage', direction: 'desc' },
|
|
56
|
+
expiry: { sort: 'expiry', direction: 'asc' },
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// The server searches, filters, sorts and pages (stacksjs/stacks#3218), where
|
|
60
|
+
// this page used to do all of that with the newest 500 coupons.
|
|
61
|
+
const {
|
|
62
|
+
records,
|
|
63
|
+
total,
|
|
64
|
+
page,
|
|
65
|
+
perPage,
|
|
66
|
+
search,
|
|
67
|
+
loading,
|
|
68
|
+
loadError,
|
|
69
|
+
params,
|
|
70
|
+
load,
|
|
71
|
+
changePage,
|
|
72
|
+
changePageSize,
|
|
73
|
+
changeSort,
|
|
74
|
+
} = useServerList<CouponRecord>({
|
|
75
|
+
fetch: query => dashboardApi<CouponIndexResponse>(`/api/dashboard/commerce/coupons?${query}`),
|
|
76
|
+
defaultSort: () => SELECT_SORTS[sort()] ?? SELECT_SORTS.newest!,
|
|
77
|
+
columnSorts: { codeLabel: 'code', status: 'status', availability: 'availability', startDate: 'start', endDate: 'expiry' },
|
|
78
|
+
filters: () => ({ status: statusFilter(), enabled: enabledFilter(), type: typeFilter() }),
|
|
79
|
+
onLoad: (result) => {
|
|
80
|
+
const data = result as CouponIndexResponse
|
|
81
|
+
summary.set(data.summary ?? { ...emptySummary })
|
|
82
|
+
currency.set(data.currency || 'USD')
|
|
83
|
+
},
|
|
84
|
+
onError: error => pushToast('error', 'Could not load coupons', { detail: error instanceof Error ? error.message : String(error) }),
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
function matchingLabel(): string {
|
|
88
|
+
const count = total()
|
|
89
|
+
return `${count.toLocaleString()} matching ${count === 1 ? 'coupon' : 'coupons'}`
|
|
78
90
|
}
|
|
79
91
|
|
|
80
92
|
function metricCards(): Array<{ label: string, value: string, detail: string }> {
|
|
@@ -87,53 +99,13 @@ function metricCards(): Array<{ label: string, value: string, detail: string }>
|
|
|
87
99
|
]
|
|
88
100
|
}
|
|
89
101
|
|
|
102
|
+
/** Every matching coupon as CSV, built by the server, not just the page shown. */
|
|
90
103
|
function exportHref(): string {
|
|
91
|
-
|
|
92
|
-
record.code,
|
|
93
|
-
record.description,
|
|
94
|
-
record.status,
|
|
95
|
-
record.isActive ? 'Enabled' : 'Disabled',
|
|
96
|
-
record.discountType,
|
|
97
|
-
// A fixed amount is stored in minor units; the CSV carries the decimal.
|
|
98
|
-
record.discountType === 'fixed_amount' ? minorToInput(record.discountValue, 'USD') : String(record.discountValue),
|
|
99
|
-
String(record.usageCount),
|
|
100
|
-
record.usageLimit === null ? '' : String(record.usageLimit),
|
|
101
|
-
record.startDate,
|
|
102
|
-
record.endDate,
|
|
103
|
-
])
|
|
104
|
-
const escape = (value: string): string => `"${value.replaceAll('"', '""')}"`
|
|
105
|
-
const csv = [
|
|
106
|
-
['Code', 'Description', 'Status', 'Availability', 'Discount type', 'Discount value', 'Usage count', 'Usage limit', 'Start date', 'End date'],
|
|
107
|
-
...rows,
|
|
108
|
-
].map(row => row.map(escape).join(',')).join('\n')
|
|
109
|
-
return `data:text/csv;charset=utf-8,${encodeURIComponent(`\uFEFF${csv}`)}`
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* What the table is showing: a change returns it to the first page, as this
|
|
114
|
-
* page's own pager did before the table took over paging.
|
|
115
|
-
*/
|
|
116
|
-
function viewKey(): string {
|
|
117
|
-
return JSON.stringify([search(), statusFilter(), enabledFilter(), typeFilter(), sort()])
|
|
104
|
+
return `/api/dashboard/commerce/coupons/export?${params()}`
|
|
118
105
|
}
|
|
119
106
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
loadError.set('')
|
|
123
|
-
try {
|
|
124
|
-
const data = await dashboardApi<CouponIndexResponse>('/api/dashboard/commerce/coupons')
|
|
125
|
-
records.set(Array.isArray(data.records) ? data.records : [])
|
|
126
|
-
summary.set(data.summary ?? { ...emptySummary })
|
|
127
|
-
}
|
|
128
|
-
catch (error) {
|
|
129
|
-
loadError.set('Coupons could not be loaded.')
|
|
130
|
-
pushToast('error', 'Could not load coupons', {
|
|
131
|
-
detail: error instanceof Error ? error.message : String(error),
|
|
132
|
-
})
|
|
133
|
-
}
|
|
134
|
-
finally {
|
|
135
|
-
loading.set(false)
|
|
136
|
-
}
|
|
107
|
+
function loadCoupons(): Promise<void> {
|
|
108
|
+
return load()
|
|
137
109
|
}
|
|
138
110
|
|
|
139
111
|
function openAdd(): void {
|
|
@@ -233,11 +205,11 @@ onMount(() => {
|
|
|
233
205
|
})
|
|
234
206
|
</script>
|
|
235
207
|
|
|
236
|
-
<div class="
|
|
208
|
+
<div class="flex flex-col gap-6">
|
|
237
209
|
<PageHeader title="Coupons" description="Manage native Coupon records, availability, limits, and redemption state.">
|
|
238
210
|
<div class="flex flex-wrap gap-2">
|
|
239
211
|
<Button variant="secondary" :loading="loading()" @click="loadCoupons()"><span :if="!loading()" class="h-4 w-4 i-hugeicons-refresh"></span>Refresh</Button>
|
|
240
|
-
<Button tag="a" variant="secondary" :href="exportHref()"
|
|
212
|
+
<Button tag="a" variant="secondary" :href="exportHref()" download><span class="h-4 w-4 i-hugeicons-download-04"></span>Export filtered</Button>
|
|
241
213
|
<Button @click="openAdd()"><span class="h-4 w-4 i-hugeicons-add-01"></span>Add coupon</Button>
|
|
242
214
|
</div>
|
|
243
215
|
</PageHeader>
|
|
@@ -246,9 +218,9 @@ onMount(() => {
|
|
|
246
218
|
|
|
247
219
|
<MetricCards label="Coupon metrics" columns="grid-cols-2 lg:grid-cols-4" :items="metricCards()" />
|
|
248
220
|
|
|
249
|
-
<CommerceCouponBreakdown :
|
|
221
|
+
<CommerceCouponBreakdown :summary="summary()" />
|
|
250
222
|
|
|
251
|
-
<section class="
|
|
223
|
+
<section class="flex flex-col gap-3">
|
|
252
224
|
<div class="grid gap-3 grid-cols-1 sm:grid-cols-2 xl:grid-cols-6">
|
|
253
225
|
<label class="relative sm:col-span-2">
|
|
254
226
|
<span class="sr-only">Search coupons</span>
|
|
@@ -262,13 +234,13 @@ onMount(() => {
|
|
|
262
234
|
</div>
|
|
263
235
|
|
|
264
236
|
<div class="flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between">
|
|
265
|
-
<p class="text-gray-500 text-sm dark:text-neutral-400">{{
|
|
237
|
+
<p class="text-gray-500 text-sm dark:text-neutral-400">{{ matchingLabel() }}</p>
|
|
266
238
|
</div>
|
|
267
239
|
|
|
268
|
-
<CommerceCouponsTable :sort-reset-key="sort()" :page
|
|
240
|
+
<CommerceCouponsTable :sort-reset-key="sort()" :records="records()" :total="total()" :current-page="page()" :per-page="perPage()" :loading="loading()" :currency="currency()" @view="openDetails" @edit="openEdit" @delete="openDelete" @page-change="changePage" @page-size-change="changePageSize" @sort="changeSort" />
|
|
269
241
|
</section>
|
|
270
242
|
</div>
|
|
271
243
|
|
|
272
|
-
<CommerceCouponDialog :open="dialogOpen()" :mode="dialogMode()" :record="editingRecord()" :busy="saving()" :errors="validationErrors()" @submit="saveCoupon" @close="closeDialog()" />
|
|
273
|
-
<CommerceCouponDetailsDialog :open="Boolean(detailsRecord())" :record="detailsRecord()" @edit="openEdit" @delete="openDelete" @close="closeDetails()" />
|
|
244
|
+
<CommerceCouponDialog :open="dialogOpen()" :mode="dialogMode()" :record="editingRecord()" :currency="currency()" :busy="saving()" :errors="validationErrors()" @submit="saveCoupon" @close="closeDialog()" />
|
|
245
|
+
<CommerceCouponDetailsDialog :open="Boolean(detailsRecord())" :record="detailsRecord()" :currency="currency()" @edit="openEdit" @delete="openDelete" @close="closeDetails()" />
|
|
274
246
|
<CommerceCouponDeleteDialog :open="Boolean(deletingRecord())" :record="deletingRecord()" :busy="deleting()" @confirm="deleteCoupon()" @close="closeDelete()" />
|
|
@@ -8,10 +8,15 @@ const records = useReactiveProp('records', [] as CouponRecord[])
|
|
|
8
8
|
const loading = useReactiveProp('loading', false)
|
|
9
9
|
/** The parent's sort select: a change hands the order back from a header sort. */
|
|
10
10
|
const sortResetKey = useReactiveProp<unknown>('sortResetKey', '')
|
|
11
|
-
/** The parent's search and filters: a change returns to the first page. */
|
|
12
|
-
const pageResetKey = useReactiveProp<unknown>('pageResetKey', '')
|
|
13
11
|
const currency = useReactiveProp('currency', 'USD')
|
|
14
|
-
|
|
12
|
+
/**
|
|
13
|
+
* The server pages and sorts what the parent's search and filters match
|
|
14
|
+
* (stacksjs/stacks#3218): how many coupons match, the page shown and its size.
|
|
15
|
+
*/
|
|
16
|
+
const total = useReactiveProp('total', 0)
|
|
17
|
+
const currentPage = useReactiveProp('currentPage', 1)
|
|
18
|
+
const perPage = useReactiveProp('perPage', 25)
|
|
19
|
+
const emit = defineEmits(['view', 'edit', 'delete', 'page-change', 'page-size-change', 'sort'])
|
|
15
20
|
|
|
16
21
|
// A percentage is a rate, not money; a fixed amount is integer minor units.
|
|
17
22
|
function discount(record: CouponRecord): string {
|
|
@@ -48,9 +53,9 @@ const COLUMNS = [
|
|
|
48
53
|
]
|
|
49
54
|
|
|
50
55
|
const ROW_ACTIONS = [
|
|
51
|
-
{ action: 'view', label: 'View'
|
|
52
|
-
{ action: 'edit', label: 'Edit'
|
|
53
|
-
{ action: 'delete', label: 'Delete'
|
|
56
|
+
{ action: 'view', label: 'View' },
|
|
57
|
+
{ action: 'edit', label: 'Edit' },
|
|
58
|
+
{ action: 'delete', label: 'Delete' },
|
|
54
59
|
]
|
|
55
60
|
|
|
56
61
|
const rows = derived(() => records().map(record => ({
|
|
@@ -66,23 +71,41 @@ const rows = derived(() => records().map(record => ({
|
|
|
66
71
|
function handleRowAction(payload: { action: string, row: CouponRecord }): void {
|
|
67
72
|
emit(payload.action, payload.row)
|
|
68
73
|
}
|
|
74
|
+
|
|
75
|
+
function changePage(page: number): void {
|
|
76
|
+
emit('page-change', page)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function changePageSize(size: number): void {
|
|
80
|
+
emit('page-size-change', size)
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function changeSort(sort: { key: string, direction: string }): void {
|
|
84
|
+
emit('sort', sort)
|
|
85
|
+
}
|
|
69
86
|
</script>
|
|
70
87
|
|
|
71
88
|
{{--
|
|
72
89
|
No `searchable` or `filterable`: the parent dashboard owns the search box
|
|
73
|
-
and the filter selects.
|
|
90
|
+
and the filter selects. The server pages and sorts what they match.
|
|
74
91
|
--}}
|
|
75
92
|
<Table
|
|
76
93
|
:sort-reset-key="sortResetKey()"
|
|
77
|
-
:page-reset-key="pageResetKey()"
|
|
78
94
|
:columns="COLUMNS"
|
|
79
95
|
:data="rows()"
|
|
80
96
|
:loading="loading()"
|
|
81
97
|
:row-actions="ROW_ACTIONS"
|
|
82
98
|
action-label-key="codeLabel"
|
|
83
99
|
paginated
|
|
84
|
-
|
|
100
|
+
manual-pagination
|
|
101
|
+
manual-sort
|
|
102
|
+
:total="total()"
|
|
103
|
+
:current-page="currentPage()"
|
|
104
|
+
:page-size="perPage()"
|
|
85
105
|
empty-title="No coupons found"
|
|
86
106
|
empty-description="Add a coupon or adjust the current filters."
|
|
87
107
|
@row-action="handleRowAction"
|
|
108
|
+
@page-change="changePage"
|
|
109
|
+
@page-size-change="changePageSize"
|
|
110
|
+
@sort="changeSort"
|
|
88
111
|
/>
|
|
@@ -86,7 +86,7 @@ function errorMessages(): string[] {
|
|
|
86
86
|
>
|
|
87
87
|
<form id="customer-form" @submit.prevent="submit">
|
|
88
88
|
<ul :if="errorMessages().length > 0" class="mb-5 p-3 space-y-1 text-red-700 text-sm dark:text-red-300 bg-red-50 dark:bg-red-950/30 border border-red-200 rounded-lg dark:border-red-900">
|
|
89
|
-
<
|
|
89
|
+
<li :for="message in errorMessages()" :key="message">{{ message }}</li>
|
|
90
90
|
</ul>
|
|
91
91
|
<div class="grid gap-4 grid-cols-1 sm:grid-cols-2">
|
|
92
92
|
<label class="block"><span class="font-medium text-gray-700 text-sm dark:text-neutral-200">Name</span><input x-model="name" type="text" minlength="2" maxlength="255" required class="mt-1 px-3 py-2 w-full text-gray-900 text-sm dark:text-white bg-white dark:bg-neutral-900 border border-gray-300 rounded-md dark:border-neutral-700" /></label>
|
|
@@ -4,11 +4,14 @@ import type {
|
|
|
4
4
|
CommerceCustomerSummary,
|
|
5
5
|
} from '../../../../app/Actions/Dashboard/Commerce/commerce-customer-records'
|
|
6
6
|
import { DashboardApiError, dashboardApi } from '../../../../functions/dashboard-api'
|
|
7
|
+
import { useServerList } from '../../../../functions/dashboard-list'
|
|
7
8
|
import { pushToast } from '../../../../functions/toasts'
|
|
8
|
-
import { formatCurrency
|
|
9
|
+
import { formatCurrency } from '@stacksjs/commerce/money'
|
|
9
10
|
|
|
10
11
|
interface CustomerIndexResponse {
|
|
11
12
|
records: CommerceCustomerRecord[]
|
|
13
|
+
total: number
|
|
14
|
+
page: number
|
|
12
15
|
summary: CommerceCustomerSummary
|
|
13
16
|
currency: string
|
|
14
17
|
}
|
|
@@ -30,14 +33,10 @@ const emptySummary: CommerceCustomerSummary = {
|
|
|
30
33
|
totalSpent: 0,
|
|
31
34
|
averageSpent: 0,
|
|
32
35
|
}
|
|
33
|
-
const records = state<CommerceCustomerRecord[]>([])
|
|
34
36
|
const summary = state<CommerceCustomerSummary>({ ...emptySummary })
|
|
35
37
|
const currency = state('USD')
|
|
36
|
-
const search = state('')
|
|
37
38
|
const statusFilter = state('all')
|
|
38
39
|
const sort = state('name')
|
|
39
|
-
const loading = state(true)
|
|
40
|
-
const loadError = state('')
|
|
41
40
|
const dialogOpen = state(false)
|
|
42
41
|
const dialogMode = state<'add' | 'edit'>('add')
|
|
43
42
|
const editingRecord = state<CommerceCustomerRecord | null>(null)
|
|
@@ -47,44 +46,48 @@ const saving = state(false)
|
|
|
47
46
|
const deleting = state(false)
|
|
48
47
|
const validationErrors = state<Record<string, string>>({})
|
|
49
48
|
|
|
50
|
-
function timestamp(value: string): number {
|
|
51
|
-
if (!value)
|
|
52
|
-
return 0
|
|
53
|
-
const normalized = /^\d{4}-\d{2}-\d{2} \d/.test(value)
|
|
54
|
-
? `${value.replace(' ', 'T')}Z`
|
|
55
|
-
: value
|
|
56
|
-
const result = new Date(normalized).getTime()
|
|
57
|
-
return Number.isFinite(result) ? result : 0
|
|
58
|
-
}
|
|
59
|
-
|
|
60
49
|
function formatMoney(value: number): string {
|
|
61
50
|
return formatCurrency(value, currency())
|
|
62
51
|
}
|
|
63
52
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
53
|
+
const SELECT_SORTS: Record<string, { sort: string, direction: 'asc' | 'desc' }> = {
|
|
54
|
+
'name': { sort: 'name', direction: 'asc' },
|
|
55
|
+
'spend-high': { sort: 'spend', direction: 'desc' },
|
|
56
|
+
'recent-order': { sort: 'last-order', direction: 'desc' },
|
|
57
|
+
'newest': { sort: 'newest', direction: 'desc' },
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// The server searches, filters, sorts and pages (stacksjs/stacks#3218), where
|
|
61
|
+
// this page used to do all of that with the first 500 customers by name.
|
|
62
|
+
const {
|
|
63
|
+
records,
|
|
64
|
+
total,
|
|
65
|
+
page,
|
|
66
|
+
perPage,
|
|
67
|
+
search,
|
|
68
|
+
loading,
|
|
69
|
+
loadError,
|
|
70
|
+
params,
|
|
71
|
+
load,
|
|
72
|
+
changePage,
|
|
73
|
+
changePageSize,
|
|
74
|
+
changeSort,
|
|
75
|
+
} = useServerList<CommerceCustomerRecord>({
|
|
76
|
+
fetch: query => dashboardApi<CustomerIndexResponse>(`/api/dashboard/commerce/customers?${query}`),
|
|
77
|
+
defaultSort: () => SELECT_SORTS[sort()] ?? SELECT_SORTS.name!,
|
|
78
|
+
columnSorts: { nameLabel: 'name', emailLabel: 'email', totalSpent: 'spend', lastOrder: 'last-order', status: 'status' },
|
|
79
|
+
filters: () => ({ status: statusFilter() }),
|
|
80
|
+
onLoad: (result) => {
|
|
81
|
+
const data = result as CustomerIndexResponse
|
|
82
|
+
summary.set(data.summary ?? { ...emptySummary })
|
|
83
|
+
currency.set(data.currency || 'USD')
|
|
84
|
+
},
|
|
85
|
+
onError: error => pushToast('error', 'Could not load customers', { detail: error instanceof Error ? error.message : String(error) }),
|
|
86
|
+
})
|
|
84
87
|
|
|
85
88
|
function matchingLabel(): string {
|
|
86
|
-
const count =
|
|
87
|
-
return `${count} matching ${count === 1 ? 'customer' : 'customers'}`
|
|
89
|
+
const count = total()
|
|
90
|
+
return `${count.toLocaleString()} matching ${count === 1 ? 'customer' : 'customers'}`
|
|
88
91
|
}
|
|
89
92
|
|
|
90
93
|
function metricCards(): Array<{ label: string, value: string, detail: string }> {
|
|
@@ -97,50 +100,13 @@ function metricCards(): Array<{ label: string, value: string, detail: string }>
|
|
|
97
100
|
]
|
|
98
101
|
}
|
|
99
102
|
|
|
103
|
+
/** Every matching customer as CSV, built by the server, not just the page shown. */
|
|
100
104
|
function exportHref(): string {
|
|
101
|
-
|
|
102
|
-
record.name,
|
|
103
|
-
record.email,
|
|
104
|
-
record.phone,
|
|
105
|
-
record.status,
|
|
106
|
-
minorToInput(record.totalSpent, currency()),
|
|
107
|
-
record.lastOrder,
|
|
108
|
-
record.avatar,
|
|
109
|
-
])
|
|
110
|
-
const escape = (value: string): string => `"${value.replaceAll('"', '""')}"`
|
|
111
|
-
const csv = [
|
|
112
|
-
['Name', 'Email', 'Phone', 'Status', `Total spent (${currency()})`, 'Last order', 'Avatar URL'],
|
|
113
|
-
...rows,
|
|
114
|
-
].map(row => row.map(escape).join(',')).join('\n')
|
|
115
|
-
return `data:text/csv;charset=utf-8,${encodeURIComponent(`\uFEFF${csv}`)}`
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* What the table is showing: a change returns it to the first page, as this
|
|
120
|
-
* page's own pager did before the table took over paging.
|
|
121
|
-
*/
|
|
122
|
-
function viewKey(): string {
|
|
123
|
-
return JSON.stringify([search(), statusFilter(), sort()])
|
|
105
|
+
return `/api/dashboard/commerce/customers/export?${params()}`
|
|
124
106
|
}
|
|
125
107
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
loadError.set('')
|
|
129
|
-
try {
|
|
130
|
-
const data = await dashboardApi<CustomerIndexResponse>('/api/dashboard/commerce/customers')
|
|
131
|
-
records.set(Array.isArray(data.records) ? data.records : [])
|
|
132
|
-
summary.set(data.summary ?? { ...emptySummary })
|
|
133
|
-
currency.set(data.currency || 'USD')
|
|
134
|
-
}
|
|
135
|
-
catch (error) {
|
|
136
|
-
loadError.set('Customer records could not be loaded.')
|
|
137
|
-
pushToast('error', 'Could not load customers', {
|
|
138
|
-
detail: error instanceof Error ? error.message : String(error),
|
|
139
|
-
})
|
|
140
|
-
}
|
|
141
|
-
finally {
|
|
142
|
-
loading.set(false)
|
|
143
|
-
}
|
|
108
|
+
function loadCustomers(): Promise<void> {
|
|
109
|
+
return load()
|
|
144
110
|
}
|
|
145
111
|
|
|
146
112
|
function openAdd(): void {
|
|
@@ -237,11 +203,11 @@ onMount(() => {
|
|
|
237
203
|
})
|
|
238
204
|
</script>
|
|
239
205
|
|
|
240
|
-
<div class="
|
|
206
|
+
<div class="flex flex-col gap-6">
|
|
241
207
|
<PageHeader title="Customers" description="Manage native Customer records, contact details, status, and recorded spend.">
|
|
242
208
|
<div class="flex flex-wrap gap-2">
|
|
243
209
|
<Button variant="secondary" :loading="loading()" @click="loadCustomers()"><span :if="!loading()" class="h-4 w-4 i-hugeicons-refresh"></span>Refresh</Button>
|
|
244
|
-
<Button tag="a" variant="secondary" :href="exportHref()"
|
|
210
|
+
<Button tag="a" variant="secondary" :href="exportHref()" download><span class="h-4 w-4 i-hugeicons-download-04"></span>Export filtered</Button>
|
|
245
211
|
<Button @click="openAdd()"><span class="h-4 w-4 i-hugeicons-add-01"></span>Add customer</Button>
|
|
246
212
|
</div>
|
|
247
213
|
</PageHeader>
|
|
@@ -250,14 +216,14 @@ onMount(() => {
|
|
|
250
216
|
|
|
251
217
|
<MetricCards label="Customer metrics" columns="grid-cols-2 lg:grid-cols-4" :items="metricCards()" />
|
|
252
218
|
|
|
253
|
-
<section class="
|
|
219
|
+
<section class="flex flex-col gap-3">
|
|
254
220
|
<div class="grid gap-3 grid-cols-1 sm:grid-cols-2 lg:grid-cols-4">
|
|
255
221
|
<label class="relative sm:col-span-2">
|
|
256
222
|
<span class="sr-only">Search customers</span>
|
|
257
223
|
<span class="flex absolute inset-y-0 left-0 items-center pl-3 text-gray-400 pointer-events-none"><span class="h-4 w-4 i-hugeicons-search-01"></span></span>
|
|
258
224
|
<input x-model="search" type="search" placeholder="Search names, email, or phone" class="pl-9 pr-3 py-2 w-full text-gray-900 text-sm dark:text-white bg-white dark:bg-neutral-800 border border-gray-300 rounded-md dark:border-neutral-700" />
|
|
259
225
|
</label>
|
|
260
|
-
<label><span class="sr-only">Customer status</span><select x-model="statusFilter" class="px-3 py-2 w-full text-gray-900 text-sm dark:text-white bg-white dark:bg-neutral-800 border border-gray-300 rounded-md dark:border-neutral-700"><option value="all">Any status</option><option value="Active">Active</option><option value="Inactive">Inactive</option
|
|
226
|
+
<label><span class="sr-only">Customer status</span><select x-model="statusFilter" class="px-3 py-2 w-full text-gray-900 text-sm dark:text-white bg-white dark:bg-neutral-800 border border-gray-300 rounded-md dark:border-neutral-700"><option value="all">Any status</option><option value="Active">Active</option><option value="Inactive">Inactive</option></select></label>
|
|
261
227
|
<label><span class="sr-only">Sort customers</span><select x-model="sort" class="px-3 py-2 w-full text-gray-900 text-sm dark:text-white bg-white dark:bg-neutral-800 border border-gray-300 rounded-md dark:border-neutral-700"><option value="name">Name</option><option value="spend-high">Highest spend</option><option value="recent-order">Most recent order</option><option value="newest">Newest record</option></select></label>
|
|
262
228
|
</div>
|
|
263
229
|
|
|
@@ -265,7 +231,7 @@ onMount(() => {
|
|
|
265
231
|
<p class="text-gray-500 text-sm dark:text-neutral-400">{{ matchingLabel() }}</p>
|
|
266
232
|
</div>
|
|
267
233
|
|
|
268
|
-
<CommerceCustomersTable :sort-reset-key="sort()" :page
|
|
234
|
+
<CommerceCustomersTable :sort-reset-key="sort()" :records="records()" :total="total()" :current-page="page()" :per-page="perPage()" :loading="loading()" :currency="currency()" @view="openDetails" @edit="openEdit" @delete="openDelete" @page-change="changePage" @page-size-change="changePageSize" @sort="changeSort" />
|
|
269
235
|
</section>
|
|
270
236
|
</div>
|
|
271
237
|
|
|
@@ -7,10 +7,15 @@ const records = useReactiveProp('records', [] as CommerceCustomerRecord[])
|
|
|
7
7
|
const loading = useReactiveProp('loading', false)
|
|
8
8
|
/** The parent's sort select: a change hands the order back from a header sort. */
|
|
9
9
|
const sortResetKey = useReactiveProp<unknown>('sortResetKey', '')
|
|
10
|
-
/** The parent's search and filters: a change returns to the first page. */
|
|
11
|
-
const pageResetKey = useReactiveProp<unknown>('pageResetKey', '')
|
|
12
10
|
const currency = useReactiveProp('currency', 'USD')
|
|
13
|
-
|
|
11
|
+
/**
|
|
12
|
+
* The server pages and sorts what the parent's search and filter match
|
|
13
|
+
* (stacksjs/stacks#3218): how many customers match, the page shown and its size.
|
|
14
|
+
*/
|
|
15
|
+
const total = useReactiveProp('total', 0)
|
|
16
|
+
const currentPage = useReactiveProp('currentPage', 1)
|
|
17
|
+
const perPage = useReactiveProp('perPage', 25)
|
|
18
|
+
const emit = defineEmits(['view', 'edit', 'delete', 'page-change', 'page-size-change', 'sort'])
|
|
14
19
|
|
|
15
20
|
/** Only the customer cell is slotted, for its initial. */
|
|
16
21
|
const COLUMNS = [
|
|
@@ -33,9 +38,9 @@ const COLUMNS = [
|
|
|
33
38
|
]
|
|
34
39
|
|
|
35
40
|
const ROW_ACTIONS = [
|
|
36
|
-
{ action: 'view', label: 'View'
|
|
37
|
-
{ action: 'edit', label: 'Edit'
|
|
38
|
-
{ action: 'delete', label: 'Delete'
|
|
41
|
+
{ action: 'view', label: 'View' },
|
|
42
|
+
{ action: 'edit', label: 'Edit' },
|
|
43
|
+
{ action: 'delete', label: 'Delete' },
|
|
39
44
|
]
|
|
40
45
|
|
|
41
46
|
const rows = derived(() => records().map(record => ({
|
|
@@ -51,25 +56,43 @@ const rows = derived(() => records().map(record => ({
|
|
|
51
56
|
function handleRowAction(payload: { action: string, row: CommerceCustomerRecord }): void {
|
|
52
57
|
emit(payload.action, payload.row)
|
|
53
58
|
}
|
|
59
|
+
|
|
60
|
+
function changePage(page: number): void {
|
|
61
|
+
emit('page-change', page)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function changePageSize(size: number): void {
|
|
65
|
+
emit('page-size-change', size)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function changeSort(sort: { key: string, direction: string }): void {
|
|
69
|
+
emit('sort', sort)
|
|
70
|
+
}
|
|
54
71
|
</script>
|
|
55
72
|
|
|
56
73
|
{{--
|
|
57
74
|
No `searchable` or `filterable`: the parent dashboard owns the search box
|
|
58
|
-
and the filter selects.
|
|
75
|
+
and the filter selects. The server pages and sorts what they match.
|
|
59
76
|
--}}
|
|
60
77
|
<Table
|
|
61
78
|
:sort-reset-key="sortResetKey()"
|
|
62
|
-
:page-reset-key="pageResetKey()"
|
|
63
79
|
:columns="COLUMNS"
|
|
64
80
|
:data="rows()"
|
|
65
81
|
:loading="loading()"
|
|
66
82
|
:row-actions="ROW_ACTIONS"
|
|
67
83
|
action-label-key="nameLabel"
|
|
68
84
|
paginated
|
|
69
|
-
|
|
85
|
+
manual-pagination
|
|
86
|
+
manual-sort
|
|
87
|
+
:total="total()"
|
|
88
|
+
:current-page="currentPage()"
|
|
89
|
+
:page-size="perPage()"
|
|
70
90
|
empty-title="No customers found"
|
|
71
91
|
empty-description="Adjust the filters or add a native Customer record."
|
|
72
92
|
@row-action="handleRowAction"
|
|
93
|
+
@page-change="changePage"
|
|
94
|
+
@page-size-change="changePageSize"
|
|
95
|
+
@sort="changeSort"
|
|
73
96
|
>
|
|
74
97
|
<template #cell="{ row }">
|
|
75
98
|
<div class="flex gap-3 items-center">
|
|
@@ -40,9 +40,7 @@ function money(value: number, currency: string): string {
|
|
|
40
40
|
<article class="p-4 bg-white dark:bg-neutral-800 border border-gray-200 rounded-lg dark:border-neutral-700">
|
|
41
41
|
<h2 class="font-semibold text-gray-900 text-sm dark:text-white">Status distribution</h2>
|
|
42
42
|
<dl class="mt-4 space-y-3 text-sm">
|
|
43
|
-
<
|
|
44
|
-
<div class="flex justify-between"><dt class="text-gray-500 dark:text-neutral-400">{{ item.label }}</dt><dd class="font-medium text-gray-900 dark:text-white">{{ item.count }}</dd></div>
|
|
45
|
-
</template>
|
|
43
|
+
<div :for="item in statusRows()" :key="item.key" class="flex justify-between"><dt class="text-gray-500 dark:text-neutral-400">{{ item.label }}</dt><dd class="font-medium text-gray-900 dark:text-white">{{ item.count }}</dd></div>
|
|
46
44
|
</dl>
|
|
47
45
|
</article>
|
|
48
46
|
|
|
@@ -50,12 +48,10 @@ function money(value: number, currency: string): string {
|
|
|
50
48
|
<h2 class="font-semibold text-gray-900 text-sm dark:text-white">Outstanding by currency</h2>
|
|
51
49
|
<div :if="currencyRows().length === 0" class="mt-4 text-gray-500 text-sm dark:text-neutral-400">No balances recorded.</div>
|
|
52
50
|
<ul :if="currencyRows().length > 0" class="mt-4 space-y-3">
|
|
53
|
-
<
|
|
54
|
-
<
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
</li>
|
|
58
|
-
</template>
|
|
51
|
+
<li :for="item in currencyRows()" :key="item.currency" class="flex gap-4 justify-between text-sm">
|
|
52
|
+
<span class="text-gray-500 dark:text-neutral-400">{{ item.currency }} <span class="text-gray-500 text-xs dark:text-neutral-500">({{ item.cards }})</span></span>
|
|
53
|
+
<span class="font-medium text-gray-900 dark:text-white">{{ money(item.currentBalance, item.currency) }}</span>
|
|
54
|
+
</li>
|
|
59
55
|
</ul>
|
|
60
56
|
</article>
|
|
61
57
|
|
|
@@ -63,12 +59,10 @@ function money(value: number, currency: string): string {
|
|
|
63
59
|
<h2 class="font-semibold text-gray-900 text-sm dark:text-white">Redeemed by currency</h2>
|
|
64
60
|
<div :if="currencyRows().length === 0" class="mt-4 text-gray-500 text-sm dark:text-neutral-400">No redemption value recorded.</div>
|
|
65
61
|
<ul :if="currencyRows().length > 0" class="mt-4 space-y-3">
|
|
66
|
-
<
|
|
67
|
-
<
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
</li>
|
|
71
|
-
</template>
|
|
62
|
+
<li :for="item in currencyRows()" :key="item.currency" class="flex gap-4 justify-between text-sm">
|
|
63
|
+
<span class="text-gray-500 dark:text-neutral-400">{{ item.currency }}</span>
|
|
64
|
+
<span class="font-medium text-gray-900 dark:text-white">{{ money(item.redeemedBalance, item.currency) }}</span>
|
|
65
|
+
</li>
|
|
72
66
|
</ul>
|
|
73
67
|
</article>
|
|
74
68
|
</section>
|
|
@@ -162,7 +162,7 @@ function errorMessages(): string[] {
|
|
|
162
162
|
>
|
|
163
163
|
<form id="gift-card-form" @submit.prevent="submit">
|
|
164
164
|
<ul :if="errorMessages().length > 0" class="mb-5 p-3 space-y-1 text-red-700 text-sm dark:text-red-300 bg-red-50 dark:bg-red-950/30 border border-red-200 rounded-lg dark:border-red-900">
|
|
165
|
-
<
|
|
165
|
+
<li :for="message in errorMessages()" :key="message">{{ message }}</li>
|
|
166
166
|
</ul>
|
|
167
167
|
<div class="grid gap-4 grid-cols-1 sm:grid-cols-2">
|
|
168
168
|
<label class="block sm:col-span-2"><span class="font-medium text-gray-700 text-sm dark:text-neutral-200">Code</span><input x-model="code" type="text" maxlength="50" required spellcheck="false" class="mt-1 px-3 py-2 w-full font-mono text-gray-900 text-sm uppercase dark:text-white bg-white dark:bg-neutral-900 border border-gray-300 rounded-md dark:border-neutral-700" /></label>
|