@mohasinac/appkit 4.10.0 → 4.11.0
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/_internal/client/features/layout/DashboardLayoutClient.d.ts +6 -1
- package/dist/_internal/client/features/layout/DashboardLayoutClient.js +4 -1
- package/dist/_internal/client/features/lottery/LotteryPullForm.d.ts +1 -1
- package/dist/_internal/client/features/lottery/LotteryPullForm.js +2 -2
- package/dist/_internal/server/features/admin/daily-digest-actions.d.ts +18 -0
- package/dist/_internal/server/features/admin/daily-digest-actions.js +37 -0
- package/dist/_internal/server/features/audit-log/actions.d.ts +25 -0
- package/dist/_internal/server/features/audit-log/actions.js +38 -0
- package/dist/_internal/server/features/brands/actions.js +0 -2
- package/dist/_internal/server/features/brands/og.d.ts +4 -1
- package/dist/_internal/server/features/brands/og.js +1 -1
- package/dist/_internal/server/features/grouped/data.d.ts +4 -0
- package/dist/_internal/server/features/grouped/data.js +24 -0
- package/dist/_internal/server/features/grouped/index.d.ts +1 -1
- package/dist/_internal/server/features/grouped/index.js +1 -1
- package/dist/_internal/server/features/orders/actions.js +9 -0
- package/dist/_internal/server/features/orders/adapters.js +25 -0
- package/dist/_internal/server/functions/scheduled.d.ts +3 -1
- package/dist/_internal/server/functions/scheduled.js +17 -1
- package/dist/_internal/server/jobs/core/dailyStatusDigest.d.ts +40 -0
- package/dist/_internal/server/jobs/core/dailyStatusDigest.js +164 -0
- package/dist/_internal/server/jobs/core/hardBanCascade.js +11 -0
- package/dist/_internal/server/jobs/core/testerSandboxCleanup.d.ts +1 -0
- package/dist/_internal/server/jobs/core/testerSandboxCleanup.js +4 -1
- package/dist/_internal/server/jobs/core/testerSandboxRefresh.d.ts +12 -0
- package/dist/_internal/server/jobs/core/testerSandboxRefresh.js +85 -0
- package/dist/_internal/server/jobs/core/whatsappNotify.js +16 -0
- package/dist/_internal/server/jobs/handlers/dailyStatusDigest.d.ts +2 -0
- package/dist/_internal/server/jobs/handlers/dailyStatusDigest.js +4 -0
- package/dist/_internal/server/jobs/handlers/index.d.ts +2 -0
- package/dist/_internal/server/jobs/handlers/index.js +3 -0
- package/dist/_internal/server/jobs/handlers/testerSandboxRefresh.d.ts +2 -0
- package/dist/_internal/server/jobs/handlers/testerSandboxRefresh.js +2 -0
- package/dist/_internal/server/notifications/channel-health.d.ts +27 -0
- package/dist/_internal/server/notifications/channel-health.js +101 -0
- package/dist/_internal/shared/features/brands/schema.d.ts +0 -6
- package/dist/_internal/shared/features/brands/schema.js +0 -1
- package/dist/_internal/shared/features/categories/bundle-schemas.d.ts +7 -0
- package/dist/_internal/shared/features/categories/bundle-schemas.js +3 -0
- package/dist/_internal/shared/features/orders/schema.d.ts +8 -8
- package/dist/client.d.ts +21 -6
- package/dist/client.js +13 -3
- package/dist/constants/api-endpoints.d.ts +6 -9
- package/dist/constants/api-endpoints.js +2 -3
- package/dist/contracts/client-auth.d.ts +3 -7
- package/dist/contracts/email.d.ts +1 -0
- package/dist/features/account/components/AddressForm.js +24 -2
- package/dist/features/account/components/BecomeSellerView.d.ts +1 -2
- package/dist/features/account/components/BecomeSellerView.js +1 -1
- package/dist/features/account/components/NotificationBell.js +1 -1
- package/dist/features/account/components/UserBidsView.d.ts +1 -0
- package/dist/features/account/components/UserBidsView.js +47 -0
- package/dist/features/account/components/UserOrdersView.d.ts +4 -11
- package/dist/features/account/components/UserOrdersView.js +54 -4
- package/dist/features/account/components/UserReturnsView.d.ts +4 -9
- package/dist/features/account/components/UserReturnsView.js +37 -3
- package/dist/features/account/components/index.d.ts +3 -2
- package/dist/features/account/components/index.js +1 -0
- package/dist/features/admin/actions/admin-actions.js +22 -0
- package/dist/features/admin/actions/admin-coupon-actions.js +10 -0
- package/dist/features/admin/actions/notification-actions.js +4 -3
- package/dist/features/admin/components/AdminAdsView.d.ts +2 -3
- package/dist/features/admin/components/AdminAdsView.js +86 -89
- package/dist/features/admin/components/AdminAllEventEntriesView.js +18 -3
- package/dist/features/admin/components/AdminAuditLogView.d.ts +11 -0
- package/dist/features/admin/components/AdminAuditLogView.js +95 -0
- package/dist/features/admin/components/AdminBlogEditorView.js +37 -3
- package/dist/features/admin/components/AdminBrandEditorView.js +10 -6
- package/dist/features/admin/components/AdminBundleEditorView.js +18 -2
- package/dist/features/admin/components/AdminCarouselEditorView.js +2 -2
- package/dist/features/admin/components/AdminCarouselGroupEditorView.js +2 -2
- package/dist/features/admin/components/AdminCartsView.js +34 -4
- package/dist/features/admin/components/AdminCategoryEditorView.js +5 -4
- package/dist/features/admin/components/AdminCouponEditorView.js +2 -2
- package/dist/features/admin/components/AdminFaqEditorView.js +2 -2
- package/dist/features/admin/components/AdminHistoryView.js +11 -1
- package/dist/features/admin/components/AdminNotificationsView.js +27 -1
- package/dist/features/admin/components/AdminOrderEditorView.d.ts +10 -1
- package/dist/features/admin/components/AdminOrderEditorView.js +4 -3
- package/dist/features/admin/components/AdminOrdersView.js +92 -24
- package/dist/features/admin/components/AdminPayoutMarkPaidModal.d.ts +7 -0
- package/dist/features/admin/components/AdminPayoutMarkPaidModal.js +47 -0
- package/dist/features/admin/components/AdminPayoutsView.js +15 -31
- package/dist/features/admin/components/AdminProductEditorView.js +26 -3
- package/dist/features/admin/components/AdminSiteSettingsView.js +20 -1
- package/dist/features/admin/components/AdminStoreAddressesView.js +22 -2
- package/dist/features/admin/components/AdminStoresView.js +7 -0
- package/dist/features/admin/components/AdminSublistingCategoryEditorView.js +2 -2
- package/dist/features/admin/components/AdminTesterChecklistItemEditorView.js +2 -2
- package/dist/features/admin/components/AdminUserEditorView.d.ts +2 -2
- package/dist/features/admin/components/AdminUserEditorView.js +4 -2
- package/dist/features/admin/components/AdminUsersView.js +1 -1
- package/dist/features/admin/components/AdminWishlistsView.js +14 -1
- package/dist/features/admin/components/DataListingView.d.ts +2 -2
- package/dist/features/admin/components/ViewAuditLogEntryModal.d.ts +19 -0
- package/dist/features/admin/components/ViewAuditLogEntryModal.js +22 -0
- package/dist/features/admin/components/ViewNotificationModal.d.ts +21 -0
- package/dist/features/admin/components/ViewNotificationModal.js +15 -0
- package/dist/features/admin/components/analytics/AdminPageViewsReportView.d.ts +4 -7
- package/dist/features/admin/components/analytics/AdminPageViewsReportView.js +56 -36
- package/dist/features/admin/components/index.d.ts +8 -1
- package/dist/features/admin/components/index.js +4 -0
- package/dist/features/admin/constants/filter-tabs.d.ts +49 -0
- package/dist/features/admin/constants/filter-tabs.js +27 -0
- package/dist/features/admin/hooks/useAdminListing.d.ts +6 -0
- package/dist/features/admin/hooks/useAdminListing.js +3 -1
- package/dist/features/admin/hooks/useAdminListingData.d.ts +9 -1
- package/dist/features/admin/hooks/useAdminListingData.js +9 -2
- package/dist/features/admin/repository/site-settings.repository.d.ts +5 -0
- package/dist/features/admin/schemas/firestore.d.ts +12 -0
- package/dist/features/analytics/types.d.ts +1 -1
- package/dist/features/analytics/types.js +8 -0
- package/dist/features/auctions/schemas/index.d.ts +5 -0
- package/dist/features/audit-log/repository/audit-log.repository.d.ts +45 -0
- package/dist/features/audit-log/repository/audit-log.repository.js +30 -0
- package/dist/features/audit-log/schemas/firestore.d.ts +59 -0
- package/dist/features/audit-log/schemas/firestore.js +35 -0
- package/dist/features/auth/actions/index.d.ts +0 -1
- package/dist/features/auth/actions/index.js +0 -1
- package/dist/features/auth/hooks/useAuth.d.ts +8 -35
- package/dist/features/auth/hooks/useAuth.js +21 -37
- package/dist/features/auth/permissions/constants.d.ts +1 -1
- package/dist/features/auth/permissions/constants.js +2 -0
- package/dist/features/blog/schemas/index.d.ts +32 -0
- package/dist/features/catalogue/components/AdminCatalogueApprovalsView.js +31 -3
- package/dist/features/catalogue/components/CatalogueItemEditorView.js +2 -1
- package/dist/features/categories/components/BrandDetailPageView.js +14 -12
- package/dist/features/categories/components/CategoryDetailPageView.js +7 -3
- package/dist/features/categories/components/CategoryHighlightsAndFaqSection.d.ts +14 -0
- package/dist/features/categories/components/CategoryHighlightsAndFaqSection.js +22 -0
- package/dist/features/categories/components/CategoryProductsView.d.ts +1 -5
- package/dist/features/categories/components/CategoryProductsView.js +1 -1
- package/dist/features/categories/components/CategorySelectorCreate.js +16 -2
- package/dist/features/categories/schemas/firestore.d.ts +19 -2
- package/dist/features/categories/schemas/index.d.ts +24 -3
- package/dist/features/categories/schemas/index.js +3 -1
- package/dist/features/categories/types/index.d.ts +7 -0
- package/dist/features/checkout/actions/checkout-value-otp-actions.d.ts +17 -3
- package/dist/features/checkout/actions/checkout-value-otp-actions.js +101 -22
- package/dist/features/contact/components/ContactForm.js +17 -4
- package/dist/features/contact/email.d.ts +1 -0
- package/dist/features/contact/email.js +3 -0
- package/dist/features/events/components/AdminEventEditorView.js +54 -2
- package/dist/features/events/components/AdminEventEntriesView.d.ts +2 -16
- package/dist/features/events/components/AdminEventEntriesView.js +56 -89
- package/dist/features/events/components/EventFormDrawer.js +5 -1
- package/dist/features/events/components/EventRaffleEntryForm.d.ts +1 -3
- package/dist/features/events/components/EventRaffleEntryForm.js +1 -1
- package/dist/features/events/schemas/index.d.ts +22 -0
- package/dist/features/grouped/repository/grouped-listings.repository.d.ts +4 -0
- package/dist/features/grouped/repository/grouped-listings.repository.js +18 -0
- package/dist/features/homepage/components/CharacterHotspotForm.js +202 -187
- package/dist/features/homepage/components/SectionCarousel.d.ts +1 -7
- package/dist/features/homepage/components/SectionCarousel.js +1 -1
- package/dist/features/layout/TitleBarLayout.d.ts +1 -1
- package/dist/features/layout/TitleBarLayout.js +3 -3
- package/dist/features/media/MediaImage.js +39 -3
- package/dist/features/media/types/index.d.ts +10 -0
- package/dist/features/media/types/index.js +1 -0
- package/dist/features/media/upload/MediaUploadField.d.ts +7 -1
- package/dist/features/media/upload/MediaUploadField.js +11 -7
- package/dist/features/media/upload/video-poster.d.ts +2 -0
- package/dist/features/media/upload/video-poster.js +16 -1
- package/dist/features/media/upload/video-poster.test.js +1 -1
- package/dist/features/orders/components/OrderStatusTimeline.d.ts +12 -0
- package/dist/features/orders/components/OrderStatusTimeline.js +55 -0
- package/dist/features/orders/components/index.d.ts +2 -0
- package/dist/features/orders/components/index.js +1 -0
- package/dist/features/orders/constants/payment-window.d.ts +25 -0
- package/dist/features/orders/constants/payment-window.js +25 -0
- package/dist/features/orders/repository/orders.repository.d.ts +32 -0
- package/dist/features/orders/repository/orders.repository.js +56 -0
- package/dist/features/orders/schemas/index.d.ts +24 -24
- package/dist/features/orders/types/index.d.ts +33 -0
- package/dist/features/pre-orders/schemas/index.d.ts +5 -0
- package/dist/features/products/components/BidHistory.js +9 -1
- package/dist/features/products/components/GroupSettingsPanel.js +25 -3
- package/dist/features/products/components/PrizeDrawDetailPageView.js +1 -1
- package/dist/features/products/components/PrizeDrawEntryActions.d.ts +1 -4
- package/dist/features/products/components/PrizeDrawEntryActions.js +1 -1
- package/dist/features/products/components/ProductDetailActions.d.ts +1 -2
- package/dist/features/products/components/ProductDetailActions.js +1 -1
- package/dist/features/products/components/ProductGrid.js +15 -1
- package/dist/features/products/constants/action-defs.d.ts +1 -0
- package/dist/features/products/constants/action-defs.js +1 -0
- package/dist/features/products/schemas/index.d.ts +5 -0
- package/dist/features/promotions/components/CouponsIndexListing.d.ts +1 -3
- package/dist/features/promotions/components/CouponsIndexListing.js +1 -1
- package/dist/features/search/components/SearchView.d.ts +1 -3
- package/dist/features/search/components/SearchView.js +1 -1
- package/dist/features/seller/components/QuickProductForm.js +2 -1
- package/dist/features/seller/components/SellerBidsView.js +66 -107
- package/dist/features/seller/components/SellerGoogleReviewsView.js +17 -1
- package/dist/features/seller/components/SellerOrdersView.d.ts +15 -3
- package/dist/features/seller/components/SellerOrdersView.js +134 -163
- package/dist/features/seller/components/SellerPayoutMethodsView.js +60 -48
- package/dist/features/seller/components/SellerPayoutSettingsView.js +69 -4
- package/dist/features/seller/components/SellerPayoutsView.d.ts +12 -0
- package/dist/features/seller/components/SellerPayoutsView.js +25 -5
- package/dist/features/seller/components/SellerProductShell.d.ts +10 -3
- package/dist/features/seller/components/SellerProductShell.js +89 -36
- package/dist/features/seller/components/SellerProductsFilterDrawer.d.ts +2 -7
- package/dist/features/seller/components/SellerProductsFilterDrawer.js +4 -4
- package/dist/features/seller/components/SellerProductsView.d.ts +2 -4
- package/dist/features/seller/components/SellerProductsView.js +131 -189
- package/dist/features/seller/components/SellerReviewsView.js +95 -133
- package/dist/features/seller/components/SellerShippingConfigsView.js +47 -67
- package/dist/features/seller/components/SellerShippingView.js +41 -4
- package/dist/features/seller/components/SellerStoreCategoriesView.js +51 -59
- package/dist/features/seller/components/SellerStorefrontView.d.ts +6 -1
- package/dist/features/seller/components/SellerStorefrontView.js +42 -5
- package/dist/features/seller/components/index.d.ts +2 -2
- package/dist/features/seller/components/index.js +2 -2
- package/dist/features/shell/FormShell.d.ts +24 -4
- package/dist/features/shell/FormShell.js +12 -6
- package/dist/features/shell/QuickFormDrawer.js +67 -12
- package/dist/features/shell/StepForm.d.ts +30 -1
- package/dist/features/shell/StepForm.js +47 -4
- package/dist/features/shell/index.d.ts +1 -1
- package/dist/features/shell/index.js +1 -1
- package/dist/features/shipments/components/AdminShipmentEditorView.js +2 -2
- package/dist/features/shipments/schemas/validation.d.ts +14 -4
- package/dist/features/tester/components/AdminTesterFeedbackListView.js +23 -2
- package/dist/features/tester/components/TesterChecklistStepRow.js +1 -1
- package/dist/features/tester/components/TesterHubView.js +3 -2
- package/dist/features/tester/seed-data/orders-tester-seed-data.js +9 -1
- package/dist/features/tester/seed-data/products-tester-seed-data.js +43 -32
- package/dist/features/tester/seed-data/tester-checklist-seed-data.js +404 -15
- package/dist/index.d.ts +15 -3
- package/dist/index.js +22 -5
- package/dist/next/routing/route-map.d.ts +11 -0
- package/dist/next/routing/route-map.js +5 -0
- package/dist/providers/email-resend/provider.js +1 -0
- package/dist/providers/firebase-client/auth.d.ts +1 -0
- package/dist/providers/firebase-client/auth.js +7 -1
- package/dist/repositories/index.d.ts +1 -0
- package/dist/repositories/index.js +1 -0
- package/dist/schemas/registry.d.ts +61 -25
- package/dist/security/pii-mask.js +1 -1
- package/dist/seed/categories-seed-data.js +69 -0
- package/dist/seed/products-auctions-seed-data.js +11 -0
- package/dist/seed/products-standard-seed-data.js +93 -4
- package/dist/seed/site-settings-seed-data.js +13 -1
- package/dist/seed/store-extensions-seed-data.js +1 -1
- package/dist/server-entry.d.ts +2 -1
- package/dist/server-entry.js +20 -2
- package/dist/server.d.ts +7 -2
- package/dist/server.js +8 -3
- package/dist/styles.css +1 -1
- package/dist/tailwind-utilities.css +1 -1
- package/dist/ui/components/Form.d.ts +11 -2
- package/dist/ui/components/Form.js +4 -3
- package/dist/ui/components/FormField.d.ts +3 -1
- package/dist/ui/components/FormField.js +22 -4
- package/dist/ui/components/ListingLayout.d.ts +1 -2
- package/dist/ui/components/ListingLayout.js +1 -1
- package/dist/ui/components/RecordDetailModal.d.ts +68 -0
- package/dist/ui/components/RecordDetailModal.js +8 -0
- package/dist/ui/components/SlottedListingView.js +9 -1
- package/dist/ui/forms/FormErrorSummary.d.ts +25 -0
- package/dist/ui/forms/FormErrorSummary.js +37 -0
- package/dist/ui/forms/FormShell.d.ts +37 -2
- package/dist/ui/forms/FormShell.js +37 -7
- package/dist/ui/forms/FormShell.style.css +17 -0
- package/dist/ui/forms/index.d.ts +2 -0
- package/dist/ui/forms/index.js +1 -0
- package/dist/ui/index.d.ts +4 -0
- package/dist/ui/index.js +5 -0
- package/dist/utils/media-url.d.ts +3 -1
- package/dist/utils/media-url.js +20 -1
- package/dist/validation/schemas.d.ts +4 -4
- package/package.json +1 -1
- package/dist/_internal/client/features/classified/ClassifiedDetailView.d.ts +0 -9
- package/dist/_internal/client/features/classified/ClassifiedDetailView.js +0 -55
- package/dist/_internal/client/features/digital-code/DigitalCodeDetailView.d.ts +0 -18
- package/dist/_internal/client/features/digital-code/DigitalCodeDetailView.js +0 -21
- package/dist/_internal/client/features/live/LiveItemDetailView.d.ts +0 -9
- package/dist/_internal/client/features/live/LiveItemDetailView.js +0 -25
- package/dist/_internal/server/jobs/core/prizeRevealClose.d.ts +0 -2
- package/dist/_internal/server/jobs/core/prizeRevealClose.js +0 -28
- package/dist/_internal/server/jobs/core/prizeRevealExpiry.d.ts +0 -2
- package/dist/_internal/server/jobs/core/prizeRevealExpiry.js +0 -61
- package/dist/_internal/server/jobs/core/prizeRevealOpen.d.ts +0 -2
- package/dist/_internal/server/jobs/core/prizeRevealOpen.js +0 -68
- package/dist/_internal/server/jobs/core/prizeRevealReminder.d.ts +0 -2
- package/dist/_internal/server/jobs/core/prizeRevealReminder.js +0 -49
- package/dist/_internal/server/jobs/handlers/prizeRevealClose.d.ts +0 -2
- package/dist/_internal/server/jobs/handlers/prizeRevealClose.js +0 -2
- package/dist/_internal/server/jobs/handlers/prizeRevealExpiry.d.ts +0 -2
- package/dist/_internal/server/jobs/handlers/prizeRevealExpiry.js +0 -2
- package/dist/_internal/server/jobs/handlers/prizeRevealOpen.d.ts +0 -2
- package/dist/_internal/server/jobs/handlers/prizeRevealOpen.js +0 -2
- package/dist/_internal/server/jobs/handlers/prizeRevealReminder.d.ts +0 -2
- package/dist/_internal/server/jobs/handlers/prizeRevealReminder.js +0 -2
- package/dist/features/auth/consent-otp.d.ts +0 -57
- package/dist/features/auth/consent-otp.js +0 -127
- package/dist/features/cart/components/CheckoutOtpModal.d.ts +0 -15
- package/dist/features/cart/components/CheckoutOtpModal.js +0 -12
- package/dist/features/checkout/actions/checkout-actions.d.ts +0 -31
- package/dist/features/checkout/actions/checkout-actions.js +0 -124
- package/dist/features/classified/components/ClassifiedIndexListing.d.ts +0 -5
- package/dist/features/classified/components/ClassifiedIndexListing.js +0 -123
- package/dist/features/classified/components/ClassifiedListView.d.ts +0 -6
- package/dist/features/classified/components/ClassifiedListView.js +0 -44
- package/dist/features/digital-codes/components/DigitalCodesIndexListing.d.ts +0 -5
- package/dist/features/digital-codes/components/DigitalCodesIndexListing.js +0 -114
- package/dist/features/digital-codes/components/DigitalCodesListView.d.ts +0 -6
- package/dist/features/digital-codes/components/DigitalCodesListView.js +0 -38
- package/dist/features/live/components/LiveItemsIndexListing.d.ts +0 -5
- package/dist/features/live/components/LiveItemsIndexListing.js +0 -115
- package/dist/features/live/components/LiveItemsListView.d.ts +0 -6
- package/dist/features/live/components/LiveItemsListView.js +0 -44
- package/dist/features/seller/components/SellerTemplatesView.d.ts +0 -12
- package/dist/features/seller/components/SellerTemplatesView.js +0 -276
- package/dist/react/hooks/useVisibleItems.d.ts +0 -37
- package/dist/react/hooks/useVisibleItems.js +0 -59
- package/dist/ui/components/TabStrip.d.ts +0 -34
- package/dist/ui/components/TabStrip.js +0 -56
- package/dist/ui/components/TabStrip.style.css +0 -97
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
3
|
import { normalizeError } from "../../../errors/normalize";
|
|
4
|
-
import { useCallback,
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import { useBottomActions } from "../../layout";
|
|
4
|
+
import { useCallback, useState } from "react";
|
|
5
|
+
import { useQueryClient } from "@tanstack/react-query";
|
|
6
|
+
import { Alert, Badge, Button, Checkbox, Div, Modal, Row, Select, SideDrawer, Span, Stack, Text, Textarea } from "../../../ui";
|
|
8
7
|
import { ACTIONS } from "../../../_internal/shared/actions/action-registry";
|
|
8
|
+
import { SELLER_BULK_ACTIONS, ROW_ACTION_META } from "../../products/constants/action-defs";
|
|
9
9
|
import { SELLER_ENDPOINTS } from "../../../constants/api-endpoints";
|
|
10
|
-
import { sortBy } from "../../../
|
|
10
|
+
import { sortBy, sieveFilter, SIEVE_OP } from "../../../utils/sieve-builder";
|
|
11
|
+
import { DataListingView } from "../../admin/components/DataListingView";
|
|
11
12
|
const SORT_OPTIONS = [
|
|
12
13
|
{ value: sortBy("createdAt", "DESC"), label: "Newest" },
|
|
13
14
|
{ value: sortBy("createdAt", "ASC"), label: "Oldest" },
|
|
@@ -32,124 +33,29 @@ function statusBadge(status) {
|
|
|
32
33
|
return _jsx(Badge, { variant: map[status] ?? "default", children: status });
|
|
33
34
|
}
|
|
34
35
|
export function SellerReviewsView({ reviewsApiBase = SELLER_ENDPOINTS.REVIEWS, replyApiBase = SELLER_ENDPOINTS.REVIEWS, }) {
|
|
35
|
-
const
|
|
36
|
-
const [
|
|
37
|
-
const [loading, setLoading] = useState(true);
|
|
38
|
-
const [error, setError] = useState(null);
|
|
39
|
-
// Filters
|
|
40
|
-
const [rating, setRating] = useState("");
|
|
41
|
-
const [replied, setReplied] = useState("");
|
|
42
|
-
const [sort, setSort] = useState(SORT_OPTIONS[0].value);
|
|
43
|
-
const [search, setSearch] = useState("");
|
|
44
|
-
const [page, setPage] = useState(1);
|
|
36
|
+
const queryClient = useQueryClient();
|
|
37
|
+
const refetchReviews = useCallback(() => queryClient.invalidateQueries({ queryKey: ["seller", "reviews", "listing"] }), [queryClient]);
|
|
45
38
|
// Reply drawer
|
|
46
39
|
const [replyTarget, setReplyTarget] = useState(null);
|
|
47
40
|
const [replyText, setReplyText] = useState("");
|
|
48
41
|
const [replySaving, setReplySaving] = useState(false);
|
|
49
42
|
const [replyError, setReplyError] = useState(null);
|
|
50
43
|
// S-STORE-4-C — bulk reply + contest + feedback selection
|
|
51
|
-
const [selectedIds, setSelectedIds] = useState(new Set());
|
|
52
44
|
const [bulkReplyOpen, setBulkReplyOpen] = useState(false);
|
|
53
45
|
const [bulkReplyText, setBulkReplyText] = useState("");
|
|
54
46
|
const [bulkSaving, setBulkSaving] = useState(false);
|
|
47
|
+
const [bulkTargetIds, setBulkTargetIds] = useState([]);
|
|
48
|
+
const [bulkClearSelection, setBulkClearSelection] = useState(null);
|
|
55
49
|
const [contestTarget, setContestTarget] = useState(null);
|
|
56
50
|
const [contestReason, setContestReason] = useState("");
|
|
57
51
|
const [feedbackTarget, setFeedbackTarget] = useState(null);
|
|
58
52
|
const [feedbackText, setFeedbackText] = useState("");
|
|
59
|
-
const toggleSelected = useCallback((id) => {
|
|
60
|
-
setSelectedIds((prev) => {
|
|
61
|
-
const next = new Set(prev);
|
|
62
|
-
if (next.has(id))
|
|
63
|
-
next.delete(id);
|
|
64
|
-
else
|
|
65
|
-
next.add(id);
|
|
66
|
-
return next;
|
|
67
|
-
});
|
|
68
|
-
}, []);
|
|
69
|
-
const clearSelection = useCallback(() => setSelectedIds(new Set()), []);
|
|
70
|
-
const submitBulkReply = useCallback(async () => {
|
|
71
|
-
if (!bulkReplyText.trim() || selectedIds.size === 0)
|
|
72
|
-
return;
|
|
73
|
-
setBulkSaving(true);
|
|
74
|
-
await Promise.all(Array.from(selectedIds).map((id) => fetch(`${replyApiBase}/${id}/reply`, {
|
|
75
|
-
method: "POST",
|
|
76
|
-
headers: { "Content-Type": "application/json" },
|
|
77
|
-
body: JSON.stringify({ reply: bulkReplyText }),
|
|
78
|
-
}).catch(() => null)));
|
|
79
|
-
setBulkSaving(false);
|
|
80
|
-
setBulkReplyOpen(false);
|
|
81
|
-
setBulkReplyText("");
|
|
82
|
-
clearSelection();
|
|
83
|
-
fetchReviewsRef.current?.();
|
|
84
|
-
}, [bulkReplyText, selectedIds, replyApiBase, clearSelection]);
|
|
85
|
-
const submitContest = useCallback(async () => {
|
|
86
|
-
if (!contestTarget)
|
|
87
|
-
return;
|
|
88
|
-
await fetch(SELLER_ENDPOINTS.REVIEW_CONTEST(contestTarget.id), {
|
|
89
|
-
method: "POST",
|
|
90
|
-
headers: { "Content-Type": "application/json" },
|
|
91
|
-
body: JSON.stringify({ reason: contestReason }),
|
|
92
|
-
}).catch(() => null);
|
|
93
|
-
setContestTarget(null);
|
|
94
|
-
setContestReason("");
|
|
95
|
-
fetchReviewsRef.current?.();
|
|
96
|
-
}, [contestTarget, contestReason]);
|
|
97
|
-
const submitFeedback = useCallback(async () => {
|
|
98
|
-
if (!feedbackTarget)
|
|
99
|
-
return;
|
|
100
|
-
await fetch(SELLER_ENDPOINTS.REVIEW_FEEDBACK(feedbackTarget.id), {
|
|
101
|
-
method: "POST",
|
|
102
|
-
headers: { "Content-Type": "application/json" },
|
|
103
|
-
body: JSON.stringify({ feedback: feedbackText }),
|
|
104
|
-
}).catch(() => null);
|
|
105
|
-
setFeedbackTarget(null);
|
|
106
|
-
setFeedbackText("");
|
|
107
|
-
}, [feedbackTarget, feedbackText]);
|
|
108
|
-
const fetchReviewsRef = useMemo(() => ({ current: null }), []);
|
|
109
|
-
const fetchReviews = useCallback(async () => {
|
|
110
|
-
setLoading(true);
|
|
111
|
-
setError(null);
|
|
112
|
-
try {
|
|
113
|
-
const params = new URLSearchParams({ page: String(page), pageSize: "20", sorts: sort });
|
|
114
|
-
if (rating)
|
|
115
|
-
params.set("rating", rating);
|
|
116
|
-
if (replied)
|
|
117
|
-
params.set("replied", replied);
|
|
118
|
-
const res = await fetch(`${reviewsApiBase}?${params}`);
|
|
119
|
-
const json = await res.json();
|
|
120
|
-
if (!res.ok)
|
|
121
|
-
throw new Error(json?.error ?? "Failed to load reviews");
|
|
122
|
-
setReviews(json?.data?.reviews ?? []);
|
|
123
|
-
setMeta(json?.data?.meta ?? null);
|
|
124
|
-
}
|
|
125
|
-
catch (err) {
|
|
126
|
-
void normalizeError(err);
|
|
127
|
-
setError(err.message);
|
|
128
|
-
}
|
|
129
|
-
finally {
|
|
130
|
-
setLoading(false);
|
|
131
|
-
}
|
|
132
|
-
}, [reviewsApiBase, rating, replied, sort, page]);
|
|
133
|
-
// The API route has no ?q= support (only rating/replied/sorts) — filter
|
|
134
|
-
// the fetched page client-side, same category of post-fetch narrowing the
|
|
135
|
-
// route itself already does for `replied`.
|
|
136
|
-
const visibleReviews = useMemo(() => {
|
|
137
|
-
const q = search.trim().toLowerCase();
|
|
138
|
-
if (!q)
|
|
139
|
-
return reviews;
|
|
140
|
-
return reviews.filter((r) => r.productTitle?.toLowerCase().includes(q) ||
|
|
141
|
-
r.userName?.toLowerCase().includes(q) ||
|
|
142
|
-
r.comment?.toLowerCase().includes(q) ||
|
|
143
|
-
r.title?.toLowerCase().includes(q));
|
|
144
|
-
}, [reviews, search]);
|
|
145
|
-
useEffect(() => { fetchReviews(); }, [fetchReviews]);
|
|
146
|
-
useEffect(() => { fetchReviewsRef.current = fetchReviews; }, [fetchReviews, fetchReviewsRef]);
|
|
147
53
|
const openReply = (review) => {
|
|
148
54
|
setReplyTarget(review);
|
|
149
55
|
setReplyText(review.sellerReply ?? "");
|
|
150
56
|
setReplyError(null);
|
|
151
57
|
};
|
|
152
|
-
const handleReplySave = async () => {
|
|
58
|
+
const handleReplySave = async (onDone) => {
|
|
153
59
|
if (!replyTarget)
|
|
154
60
|
return;
|
|
155
61
|
setReplySaving(true);
|
|
@@ -164,7 +70,7 @@ export function SellerReviewsView({ reviewsApiBase = SELLER_ENDPOINTS.REVIEWS, r
|
|
|
164
70
|
if (!res.ok)
|
|
165
71
|
throw new Error(json?.error ?? "Failed to save reply");
|
|
166
72
|
setReplyTarget(null);
|
|
167
|
-
|
|
73
|
+
onDone();
|
|
168
74
|
}
|
|
169
75
|
catch (err) {
|
|
170
76
|
void normalizeError(err);
|
|
@@ -174,31 +80,87 @@ export function SellerReviewsView({ reviewsApiBase = SELLER_ENDPOINTS.REVIEWS, r
|
|
|
174
80
|
setReplySaving(false);
|
|
175
81
|
}
|
|
176
82
|
};
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
83
|
+
const submitContest = useCallback(async (onDone) => {
|
|
84
|
+
if (!contestTarget)
|
|
85
|
+
return;
|
|
86
|
+
await fetch(SELLER_ENDPOINTS.REVIEW_CONTEST(contestTarget.id), {
|
|
87
|
+
method: "POST",
|
|
88
|
+
headers: { "Content-Type": "application/json" },
|
|
89
|
+
body: JSON.stringify({ reason: contestReason }),
|
|
90
|
+
}).catch(() => null);
|
|
91
|
+
setContestTarget(null);
|
|
92
|
+
setContestReason("");
|
|
93
|
+
onDone();
|
|
94
|
+
}, [contestTarget, contestReason]);
|
|
95
|
+
const submitFeedback = useCallback(async () => {
|
|
96
|
+
if (!feedbackTarget)
|
|
97
|
+
return;
|
|
98
|
+
await fetch(SELLER_ENDPOINTS.REVIEW_FEEDBACK(feedbackTarget.id), {
|
|
99
|
+
method: "POST",
|
|
100
|
+
headers: { "Content-Type": "application/json" },
|
|
101
|
+
body: JSON.stringify({ feedback: feedbackText }),
|
|
102
|
+
}).catch(() => null);
|
|
103
|
+
setFeedbackTarget(null);
|
|
104
|
+
setFeedbackText("");
|
|
105
|
+
}, [feedbackTarget, feedbackText]);
|
|
106
|
+
const submitBulkReply = useCallback(async () => {
|
|
107
|
+
if (!bulkReplyText.trim() || bulkTargetIds.length === 0)
|
|
108
|
+
return;
|
|
109
|
+
setBulkSaving(true);
|
|
110
|
+
await Promise.all(bulkTargetIds.map((id) => fetch(`${replyApiBase}/${id}/reply`, {
|
|
111
|
+
method: "POST",
|
|
112
|
+
headers: { "Content-Type": "application/json" },
|
|
113
|
+
body: JSON.stringify({ reply: bulkReplyText }),
|
|
114
|
+
}).catch(() => null)));
|
|
115
|
+
setBulkSaving(false);
|
|
116
|
+
setBulkReplyOpen(false);
|
|
117
|
+
setBulkReplyText("");
|
|
118
|
+
bulkClearSelection?.();
|
|
119
|
+
setBulkTargetIds([]);
|
|
120
|
+
await refetchReviews();
|
|
121
|
+
}, [bulkReplyText, bulkTargetIds, replyApiBase, bulkClearSelection, refetchReviews]);
|
|
122
|
+
const config = {
|
|
123
|
+
portal: "seller",
|
|
124
|
+
title: "Reviews",
|
|
125
|
+
searchPlaceholder: "Search product, reviewer, or comment…",
|
|
126
|
+
emptyLabel: "No reviews found.",
|
|
127
|
+
filterKeys: ["rating", "replied"],
|
|
128
|
+
defaultSort: SORT_OPTIONS[0].value,
|
|
129
|
+
queryKey: ["seller", "reviews", "listing"],
|
|
130
|
+
endpoint: reviewsApiBase,
|
|
131
|
+
sortOptions: SORT_OPTIONS,
|
|
132
|
+
hideTableView: true,
|
|
133
|
+
mapRows: (response) => response.reviews ?? [],
|
|
134
|
+
getTotal: (response, rows) => response.meta?.total ?? rows.length,
|
|
135
|
+
buildFilters: (state) => {
|
|
136
|
+
const clauses = [];
|
|
137
|
+
if (state.rating)
|
|
138
|
+
clauses.push(sieveFilter("rating", SIEVE_OP.EQ, state.rating));
|
|
139
|
+
if (state.replied)
|
|
140
|
+
clauses.push(sieveFilter("replied", SIEVE_OP.EQ, state.replied));
|
|
141
|
+
return clauses.length ? clauses.join(",") : undefined;
|
|
142
|
+
},
|
|
143
|
+
renderFilterPanel: ({ pendingFilters, setPendingFilters }) => (_jsxs(Stack, { gap: "md", children: [_jsx(Select, { label: "Rating", value: pendingFilters.rating || "", onChange: (e) => setPendingFilters((p) => ({ ...p, rating: e.target.value })), options: [
|
|
144
|
+
{ value: "", label: "All ratings" },
|
|
145
|
+
{ value: "5", label: "5 stars" },
|
|
146
|
+
{ value: "4", label: "4 stars" },
|
|
147
|
+
{ value: "3", label: "3 stars" },
|
|
148
|
+
{ value: "2", label: "2 stars" },
|
|
149
|
+
{ value: "1", label: "1 star" },
|
|
150
|
+
] }), _jsx(Select, { label: "Reply status", value: pendingFilters.replied || "", onChange: (e) => setPendingFilters((p) => ({ ...p, replied: e.target.value })), options: [
|
|
151
|
+
{ value: "", label: "All reply statuses" },
|
|
152
|
+
{ value: "true", label: "Store replied" },
|
|
153
|
+
{ value: "false", label: "Awaiting reply" },
|
|
154
|
+
] })] })),
|
|
155
|
+
buildBulkActions: (selection) => SELLER_BULK_ACTIONS.reviews.map((id) => ({
|
|
156
|
+
...ROW_ACTION_META[id],
|
|
157
|
+
onClick: () => {
|
|
158
|
+
setBulkTargetIds(selection.selectedIds);
|
|
159
|
+
setBulkClearSelection(() => selection.clearSelection);
|
|
160
|
+
setBulkReplyOpen(true);
|
|
161
|
+
},
|
|
162
|
+
})),
|
|
163
|
+
renderCards: (rows, _view, selection, isLoading) => (_jsx(Stack, { gap: "md", children: isLoading ? (_jsx(Div, { className: "text-center", padding: "y-xl", children: _jsx(Text, { className: "text-[var(--appkit-color-text-muted)]", children: "Loading reviews\u2026" }) })) : rows.length === 0 ? (_jsx(Div, { className: "text-center", padding: "y-3xl", children: _jsx(Text, { className: "text-[var(--appkit-color-text-muted)]", children: "No reviews found." }) })) : (rows.map((review) => (_jsx(Div, { className: "border border-[var(--appkit-color-border)] bg-[var(--appkit-color-surface)]", rounded: "lg", padding: "md", children: _jsxs(Row, { align: "start", justify: "between", gap: "3", wrap: true, children: [_jsxs(Row, { align: "start", className: "flex-1 min-w-0", gap: "3", children: [_jsx(Checkbox, { checked: selection.selectedIds.includes(review.id), onChange: () => selection.toggleSelect(review.id), "aria-label": "Select review" }), _jsxs(Div, { className: "flex-1 min-w-0", children: [_jsx(Text, { className: "truncate", weight: "medium", children: review.productTitle }), _jsxs(Row, { className: "mt-1", align: "center", gap: "sm", wrap: true, children: [_jsx(Stars, { rating: review.rating }), _jsxs(Text, { className: "text-[var(--appkit-color-text-muted)]", size: "sm", children: ["by ", review.userName] }), review.verified && _jsx(Badge, { variant: "success", children: "Verified" }), statusBadge(review.status), _jsx(Badge, { variant: review.sellerReply ? "success" : "warning", children: review.sellerReply ? "Store replied" : "Awaiting store reply" })] }), review.title && _jsx(Text, { className: "mt-2", weight: "medium", children: review.title }), _jsx(Text, { className: "mt-1 text-[var(--appkit-color-text-secondary)] line-clamp-3", size: "sm", children: review.comment }), review.sellerReply && (_jsxs(Div, { className: "mt-2 pl-[0.75rem] border-l-2 border-[var(--appkit-color-primary)]", children: [_jsx(Text, { className: "text-[var(--appkit-color-text-muted)]", size: "xs", children: "Store reply:" }), _jsx(Text, { size: "sm", children: review.sellerReply })] }))] })] }), _jsxs(Row, { className: "flex-shrink-0", gap: "sm", children: [_jsx(Button, { variant: "outline", size: "sm", onClick: () => openReply(review), children: review.sellerReply ? "Edit Reply" : ACTIONS.STORE["reply-review"].label }), _jsx(Button, { variant: "ghost", size: "sm", onClick: () => setContestTarget(review), children: ACTIONS.STORE["contest-review"].label }), _jsx(Button, { variant: "ghost", size: "sm", onClick: () => setFeedbackTarget(review), children: ACTIONS.STORE["buyer-feedback"].label })] })] }) }, review.id)))) })),
|
|
164
|
+
};
|
|
165
|
+
return (_jsxs(_Fragment, { children: [_jsx(DataListingView, { config: config }), _jsx(SideDrawer, { isOpen: !!replyTarget, onClose: () => setReplyTarget(null), title: replyTarget?.sellerReply ? "Edit Reply" : "Reply to Review", mode: "create", children: _jsxs(Stack, { gap: "md", className: `${__P.p4}`, children: [replyTarget && (_jsxs(Div, { className: `${__P.p3} bg-[var(--appkit-color-surface-muted)]`, rounded: "default", children: [_jsx(Stars, { rating: replyTarget.rating }), _jsx(Text, { className: "mt-1", size: "sm", children: replyTarget.comment })] })), replyError && _jsx(Alert, { variant: "error", children: replyError }), _jsxs(Div, { children: [_jsx(Text, { className: "mb-1.5", size: "sm", weight: "medium", children: "Store reply" }), _jsx(Textarea, { rows: 5, value: replyText, onChange: (e) => setReplyText(e.target.value), maxLength: 1000, placeholder: "Write your response to this review\u2026" }), _jsxs(Text, { className: "text-[var(--appkit-color-text-muted)] mt-1", size: "xs", align: "end", children: [replyText.length, "/1000"] })] }), _jsxs(Row, { justify: "end", gap: "sm", children: [_jsx(Button, { variant: "outline", onClick: () => setReplyTarget(null), disabled: replySaving, children: "Cancel" }), _jsx(Button, { variant: "primary", onClick: () => handleReplySave(refetchReviews), disabled: replySaving || !replyText.trim(), isLoading: replySaving, children: replyTarget?.sellerReply ? "Update Reply" : "Post Reply" })] })] }) }), _jsx(Modal, { isOpen: bulkReplyOpen, onClose: () => setBulkReplyOpen(false), title: "Bulk reply to selected reviews", actions: _jsxs(Row, { gap: "sm", children: [_jsx(Button, { variant: "ghost", onClick: () => setBulkReplyOpen(false), disabled: bulkSaving, children: "Cancel" }), _jsx(Button, { variant: "primary", onClick: () => void submitBulkReply(), disabled: !bulkReplyText.trim() || bulkSaving, isLoading: bulkSaving, children: "Send reply" })] }), children: _jsxs(Stack, { gap: "md", padding: "2xs", children: [_jsx(Text, { className: "text-[var(--appkit-color-text-muted)]", size: "sm", children: "The same reply will be posted on all selected reviews." }), _jsx(Textarea, { value: bulkReplyText, onChange: (e) => setBulkReplyText(e.target.value), rows: 5, placeholder: "Thanks for your review\u2026", label: "Reply" })] }) }), _jsx(Modal, { isOpen: !!contestTarget, onClose: () => setContestTarget(null), title: "Contest this review", actions: _jsxs(Row, { gap: "sm", children: [_jsx(Button, { variant: "ghost", onClick: () => setContestTarget(null), children: "Cancel" }), _jsx(Button, { variant: "primary", onClick: () => void submitContest(refetchReviews), disabled: !contestReason.trim(), children: "Submit" })] }), children: _jsxs(Stack, { gap: "md", padding: "2xs", children: [_jsx(Text, { className: "text-[var(--appkit-color-text-muted)]", size: "sm", children: "Flag this review for admin investigation. Provide a clear reason \u2014 fake, abusive, off-topic, etc." }), _jsx(Textarea, { value: contestReason, onChange: (e) => setContestReason(e.target.value), rows: 4, label: "Reason" })] }) }), _jsx(Modal, { isOpen: !!feedbackTarget, onClose: () => setFeedbackTarget(null), title: "Send feedback to buyer", actions: _jsxs(Row, { gap: "sm", children: [_jsx(Button, { variant: "ghost", onClick: () => setFeedbackTarget(null), children: "Cancel" }), _jsx(Button, { variant: "primary", onClick: () => void submitFeedback(), disabled: !feedbackText.trim(), children: "Send" })] }), children: _jsxs(Stack, { gap: "md", padding: "2xs", children: [_jsx(Text, { className: "text-[var(--appkit-color-text-muted)]", size: "sm", children: "Private message sent to the buyer's notification inbox. Does not appear on the public review." }), _jsx(Textarea, { value: feedbackText, onChange: (e) => setFeedbackText(e.target.value), rows: 4, label: "Feedback" })] }) })] }));
|
|
204
166
|
}
|
|
@@ -1,18 +1,15 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
3
|
import { normalizeError } from "../../../errors/normalize";
|
|
4
|
-
import {
|
|
4
|
+
import { sortBy } from "@mohasinac/appkit/client";
|
|
5
5
|
import { useState, useCallback } from "react";
|
|
6
6
|
import { useEntityDelete } from "../../../react/hooks/useEntityDelete";
|
|
7
|
-
import {
|
|
8
|
-
import { useUrlTable } from "../../../react/hooks/useUrlTable";
|
|
9
|
-
import { Button, ConfirmDeleteModal, DataTable, Badge, Div, ListingToolbar, RowActionMenu, Span, Text, useToast, } from "../../../ui";
|
|
7
|
+
import { Badge, ConfirmDeleteModal, Div, RowActionMenu, Span, Text, useToast, } from "../../../ui";
|
|
10
8
|
import { SELLER_ENDPOINTS } from "../../../constants/api-endpoints";
|
|
11
9
|
import { ACTIONS } from "../../../_internal/shared/actions/action-registry";
|
|
12
10
|
import { ROUTES } from "../../../constants/index";
|
|
13
|
-
import { toRecordArray, toStringValue
|
|
14
|
-
import {
|
|
15
|
-
const PAGE_SIZE = 50;
|
|
11
|
+
import { toRecordArray, toStringValue } from "../hooks/useSellerListingData";
|
|
12
|
+
import { DataListingView } from "../../admin/components/DataListingView";
|
|
16
13
|
const DEFAULT_SORT = "-createdAt";
|
|
17
14
|
const SORT_OPTIONS = [
|
|
18
15
|
{ value: sortBy("createdAt", "DESC"), label: "Newest" },
|
|
@@ -42,43 +39,15 @@ const COLUMNS = [
|
|
|
42
39
|
},
|
|
43
40
|
];
|
|
44
41
|
export function SellerShippingConfigsView({ onCreateClick, onEditClick, onDelete, onSetDefault, }) {
|
|
45
|
-
const table = useUrlTable({ defaults: { sort: DEFAULT_SORT } });
|
|
46
|
-
const [searchInput, setSearchInput] = useState(table.get(TABLE_KEYS.QUERY) || "");
|
|
47
42
|
const [deleteTargetId, setDeleteTargetId] = useState(null);
|
|
48
43
|
const { deletingId, handleDelete: performDelete } = useEntityDelete({
|
|
49
44
|
endpoint: SELLER_ENDPOINTS.SHIPPING_CONFIG_BY_ID,
|
|
50
45
|
deleteFn: onDelete,
|
|
51
46
|
successMessage: "Shipping config deleted.",
|
|
52
|
-
onSuccess: () => { refetch?.(); },
|
|
53
47
|
fetchOptions: { credentials: "include" },
|
|
54
48
|
});
|
|
55
49
|
const [settingDefaultId, setSettingDefaultId] = useState(null);
|
|
56
50
|
const { showToast } = useToast();
|
|
57
|
-
const commitSearch = useCallback(() => {
|
|
58
|
-
table.set(TABLE_KEYS.QUERY, searchInput.trim());
|
|
59
|
-
}, [searchInput, table]);
|
|
60
|
-
const resetAll = useCallback(() => {
|
|
61
|
-
table.setMany({ [TABLE_KEYS.QUERY]: "", [TABLE_KEYS.SORT]: "" });
|
|
62
|
-
setSearchInput("");
|
|
63
|
-
}, [table]);
|
|
64
|
-
const hasActiveState = !!table.get(TABLE_KEYS.QUERY) || table.get(TABLE_KEYS.SORT) !== DEFAULT_SORT;
|
|
65
|
-
const { rows, isLoading, errorMessage, refetch } = useSellerListingData({
|
|
66
|
-
queryKey: ["seller", "shipping-configs"],
|
|
67
|
-
endpoint: SELLER_ENDPOINTS.SHIPPING_CONFIGS,
|
|
68
|
-
page: 1,
|
|
69
|
-
pageSize: PAGE_SIZE,
|
|
70
|
-
sorts: table.get(TABLE_KEYS.SORT) || DEFAULT_SORT,
|
|
71
|
-
q: table.get(TABLE_KEYS.QUERY) || undefined,
|
|
72
|
-
mapRows: (response) => toRecordArray(response.items).map((item, index) => ({
|
|
73
|
-
id: toStringValue(item.id, `sc-${index}`),
|
|
74
|
-
raw: item,
|
|
75
|
-
label: String(item.label ?? ""),
|
|
76
|
-
method: String(item.method ?? ""),
|
|
77
|
-
estimatedDays: typeof item.estimatedDays === "number" ? item.estimatedDays : null,
|
|
78
|
-
isDefault: Boolean(item.isDefault),
|
|
79
|
-
isActive: Boolean(item.isActive),
|
|
80
|
-
})),
|
|
81
|
-
});
|
|
82
51
|
const handleDelete = useCallback(async (id) => {
|
|
83
52
|
try {
|
|
84
53
|
await performDelete(id);
|
|
@@ -103,7 +72,6 @@ export function SellerShippingConfigsView({ onCreateClick, onEditClick, onDelete
|
|
|
103
72
|
body: JSON.stringify({ isDefault: true }),
|
|
104
73
|
});
|
|
105
74
|
}
|
|
106
|
-
refetch?.();
|
|
107
75
|
showToast("Default shipping config updated.", "success");
|
|
108
76
|
}
|
|
109
77
|
catch (err) {
|
|
@@ -113,42 +81,54 @@ export function SellerShippingConfigsView({ onCreateClick, onEditClick, onDelete
|
|
|
113
81
|
finally {
|
|
114
82
|
setSettingDefaultId(null);
|
|
115
83
|
}
|
|
116
|
-
}, [onSetDefault,
|
|
84
|
+
}, [onSetDefault, showToast]);
|
|
117
85
|
const handleCreate = useCallback(() => {
|
|
118
|
-
if (onCreateClick)
|
|
86
|
+
if (onCreateClick)
|
|
119
87
|
onCreateClick();
|
|
120
|
-
|
|
121
|
-
else {
|
|
88
|
+
else
|
|
122
89
|
window.location.href = String(ROUTES.STORE.SHIPPING_CONFIGS_NEW);
|
|
123
|
-
}
|
|
124
90
|
}, [onCreateClick]);
|
|
125
91
|
const handleEdit = useCallback((id) => {
|
|
126
|
-
if (onEditClick)
|
|
92
|
+
if (onEditClick)
|
|
127
93
|
onEditClick(id);
|
|
128
|
-
|
|
129
|
-
else {
|
|
94
|
+
else
|
|
130
95
|
window.location.href = String(ROUTES.STORE.SHIPPING_CONFIGS_EDIT(id));
|
|
131
|
-
}
|
|
132
96
|
}, [onEditClick]);
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
97
|
+
const config = {
|
|
98
|
+
portal: "seller",
|
|
99
|
+
title: "Shipping Configs",
|
|
100
|
+
searchPlaceholder: "Search shipping configs...",
|
|
101
|
+
emptyLabel: "No shipping configs yet — define your first shipping rule",
|
|
102
|
+
filterKeys: [],
|
|
103
|
+
defaultSort: DEFAULT_SORT,
|
|
104
|
+
queryKey: ["seller", "shipping-configs", "listing"],
|
|
105
|
+
endpoint: SELLER_ENDPOINTS.SHIPPING_CONFIGS,
|
|
106
|
+
sortOptions: SORT_OPTIONS,
|
|
107
|
+
columns: COLUMNS,
|
|
108
|
+
mapRows: (response) => toRecordArray(response.items).map((item, index) => ({
|
|
109
|
+
id: toStringValue(item.id, `sc-${index}`),
|
|
110
|
+
raw: item,
|
|
111
|
+
label: String(item.label ?? ""),
|
|
112
|
+
method: String(item.method ?? ""),
|
|
113
|
+
estimatedDays: typeof item.estimatedDays === "number" ? item.estimatedDays : null,
|
|
114
|
+
isDefault: Boolean(item.isDefault),
|
|
115
|
+
isActive: Boolean(item.isActive),
|
|
116
|
+
})),
|
|
117
|
+
getTotal: (response, mappedRows) => (typeof response.total === "number" ? response.total : mappedRows.length),
|
|
118
|
+
buildFilters: () => undefined,
|
|
119
|
+
primaryAction: { label: "New Config", onClick: handleCreate },
|
|
120
|
+
renderRowActions: (row) => (_jsx(RowActionMenu, { actions: [
|
|
121
|
+
{ label: ACTIONS.STORE["edit-listing"].label, onClick: () => handleEdit(row.id) },
|
|
122
|
+
...(!row.isDefault
|
|
123
|
+
? [{ label: "Set as Default", disabled: settingDefaultId === row.id, onClick: () => handleSetDefault(row.id) }]
|
|
124
|
+
: []),
|
|
125
|
+
{
|
|
126
|
+
label: ACTIONS.STORE["delete-listing"].label,
|
|
127
|
+
destructive: true,
|
|
128
|
+
onClick: () => setDeleteTargetId(row.id),
|
|
129
|
+
disabled: deletingId === row.id,
|
|
130
|
+
},
|
|
131
|
+
] })),
|
|
132
|
+
};
|
|
133
|
+
return (_jsxs(_Fragment, { children: [_jsx(DataListingView, { config: config }), deleteTargetId && (_jsx(ConfirmDeleteModal, { isOpen: true, title: "Delete Shipping Config", message: "Are you sure you want to delete this shipping configuration? This cannot be undone.", onConfirm: () => handleDelete(deleteTargetId), onClose: () => setDeleteTargetId(null), isDeleting: deletingId === deleteTargetId }))] }));
|
|
154
134
|
}
|
|
@@ -1,12 +1,26 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
import { useCallback, useEffect, useState } from "react";
|
|
3
|
+
import { useCallback, useEffect, useMemo, useState } from "react";
|
|
4
|
+
import { z } from "zod";
|
|
4
5
|
import { Alert, Badge, Div, FormField, Heading, Row, Stack, Text } from "../../../ui";
|
|
5
6
|
import { StackedViewShell } from "../../../ui";
|
|
7
|
+
import { FormShellContext, useFormShellState, applyZodIssues, FormErrorSummary } from "../../../ui/forms";
|
|
6
8
|
import { StoreAddressSelectorCreate } from "../../stores/components/StoreAddressSelectorCreate";
|
|
7
9
|
import { StepForm } from "../../shell";
|
|
8
10
|
import { SELLER_ENDPOINTS } from "../../../constants/api-endpoints";
|
|
9
11
|
import { normalizeError } from "../../../errors/normalize";
|
|
12
|
+
const shippingDraftSchema = z.object({
|
|
13
|
+
customCarrierName: z.string().min(1, "Carrier name is required"),
|
|
14
|
+
customShippingPrice: z.string(),
|
|
15
|
+
pickupAddressId: z.string().optional(),
|
|
16
|
+
freeShippingThreshold: z.string().optional(),
|
|
17
|
+
fragileSurcharge: z.string().optional(),
|
|
18
|
+
}).superRefine((v, ctx) => {
|
|
19
|
+
const price = parseFloat(v.customShippingPrice);
|
|
20
|
+
if (v.customShippingPrice.trim() === "" || Number.isNaN(price) || price < 0) {
|
|
21
|
+
ctx.addIssue({ code: z.ZodIssueCode.custom, path: ["customShippingPrice"], message: "Enter a valid shipping price (0 for free)" });
|
|
22
|
+
}
|
|
23
|
+
});
|
|
10
24
|
const DEFAULT_DRAFT = {
|
|
11
25
|
customCarrierName: "",
|
|
12
26
|
customShippingPrice: "",
|
|
@@ -22,6 +36,11 @@ export function SellerShippingView({ apiBase = SELLER_ENDPOINTS.SHIPPING }) {
|
|
|
22
36
|
const [error, setError] = useState(null);
|
|
23
37
|
const [success, setSuccess] = useState(false);
|
|
24
38
|
const [currentStep, setCurrentStep] = useState(0);
|
|
39
|
+
const { shellCtx, setFieldError, clearErrors, validate } = useFormShellState(shippingDraftSchema);
|
|
40
|
+
useEffect(() => {
|
|
41
|
+
validate(draft);
|
|
42
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
43
|
+
}, [draft, validate]);
|
|
25
44
|
useEffect(() => {
|
|
26
45
|
fetch(apiBase)
|
|
27
46
|
.then((r) => r.json())
|
|
@@ -65,8 +84,14 @@ export function SellerShippingView({ apiBase = SELLER_ENDPOINTS.SHIPPING }) {
|
|
|
65
84
|
body: JSON.stringify(body),
|
|
66
85
|
});
|
|
67
86
|
const json = await res.json();
|
|
68
|
-
if (!res.ok)
|
|
69
|
-
|
|
87
|
+
if (!res.ok) {
|
|
88
|
+
if (Array.isArray(json?.issues) && json.issues.length > 0) {
|
|
89
|
+
applyZodIssues(json.issues, setFieldError);
|
|
90
|
+
}
|
|
91
|
+
setError(json?.error ?? "Failed to save");
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
clearErrors();
|
|
70
95
|
setSuccess(true);
|
|
71
96
|
const cfg = json?.data?.shippingConfig ?? { method: "custom", isConfigured: false };
|
|
72
97
|
setCurrent(cfg);
|
|
@@ -83,18 +108,30 @@ export function SellerShippingView({ apiBase = SELLER_ENDPOINTS.SHIPPING }) {
|
|
|
83
108
|
const steps = [
|
|
84
109
|
{
|
|
85
110
|
label: "Carrier",
|
|
111
|
+
fields: ["customCarrierName", "customShippingPrice"],
|
|
86
112
|
render: ({ values, onChange }) => (_jsxs(Stack, { gap: "md", children: [_jsx(Heading, { level: 3, className: "mb-2", children: "Shipping Carrier" }), current && (_jsx(Row, { className: "mb-2", align: "center", gap: "sm", children: _jsx(Badge, { variant: current.isConfigured ? "success" : "warning", children: current.isConfigured ? "Configured" : "Not configured" }) })), _jsx(Text, { className: "text-[var(--appkit-color-text-muted)]", size: "sm", children: "Set a fixed shipping fee and carrier name for all orders. You enter the carrier and tracking number yourself when you ship each order." }), _jsxs(Stack, { gap: "md", className: "mt-2", children: [_jsx(FormField, { name: "customCarrierName", label: "Carrier Name", type: "text", value: values.customCarrierName, onChange: (v) => onChange({ customCarrierName: v }), placeholder: "e.g. India Post, DTDC, Delhivery", disabled: busy }), _jsx(FormField, { name: "customShippingPrice", label: "Shipping Price (\u20B9)", type: "number", value: values.customShippingPrice, onChange: (v) => onChange({ customShippingPrice: v }), placeholder: "0 for free shipping", helpText: "Charged to buyer at checkout. Enter 0 for free shipping.", disabled: busy })] })] })),
|
|
87
113
|
},
|
|
88
114
|
{
|
|
89
115
|
label: "Pickup Address",
|
|
116
|
+
fields: ["pickupAddressId"],
|
|
90
117
|
render: ({ values, onChange }) => (_jsxs(Stack, { gap: "md", children: [_jsx(Heading, { level: 3, className: "mb-2", children: "Pickup Address" }), current?.pickupAddress && (_jsxs(Alert, { variant: "info", children: ["Current pickup: ", current.pickupAddress.locationName ?? "", current.pickupAddress.city ? `, ${current.pickupAddress.city}` : ""] })), _jsx(StoreAddressSelectorCreate, { value: values.pickupAddressId, onChange: (id) => onChange({ pickupAddressId: id }), label: "Pickup Address", disabled: busy })] })),
|
|
91
118
|
},
|
|
92
119
|
{
|
|
93
120
|
label: "Rules",
|
|
121
|
+
fields: ["freeShippingThreshold", "fragileSurcharge"],
|
|
94
122
|
render: ({ values, onChange }) => (_jsxs(Stack, { gap: "md", children: [_jsx(Heading, { level: 3, className: "mb-2", children: "Shipping Rules" }), _jsx(FormField, { name: "freeShippingThreshold", label: "Free Shipping Threshold (\u20B9)", type: "number", value: values.freeShippingThreshold, onChange: (v) => onChange({ freeShippingThreshold: v }), placeholder: "e.g. 500 \u2014 orders above this get free shipping", helpText: "Leave blank or 0 to disable free shipping offers.", disabled: busy }), _jsx(FormField, { name: "fragileSurcharge", label: "Fragile Item Surcharge (\u20B9)", type: "number", value: values.fragileSurcharge, onChange: (v) => onChange({ fragileSurcharge: v }), placeholder: "e.g. 50 \u2014 added for items marked fragile", helpText: "Leave blank or 0 to disable the fragile surcharge.", disabled: busy })] })),
|
|
95
123
|
},
|
|
96
124
|
];
|
|
125
|
+
const fieldToStepIndex = useMemo(() => {
|
|
126
|
+
const map = {};
|
|
127
|
+
steps.forEach((step, i) => {
|
|
128
|
+
step.fields?.forEach((field) => { map[field] = i; });
|
|
129
|
+
});
|
|
130
|
+
return map;
|
|
131
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
132
|
+
}, [steps.length]);
|
|
133
|
+
const wizardShellCtx = useMemo(() => ({ ...shellCtx, fieldToStepIndex, goToStep: (n) => setCurrentStep(n) }), [shellCtx, fieldToStepIndex, setCurrentStep]);
|
|
97
134
|
return (_jsx(StackedViewShell, { portal: "seller", title: "Shipping Configuration", sections: [
|
|
98
|
-
_jsxs(Div, { children: [error && _jsx(Alert, { variant: "error", className: "mb-4", children: error }), success && _jsx(Alert, { variant: "success", className: "mb-4", children: "Shipping configuration saved." }), _jsx(StepForm, { steps: steps, values: draft, onChange: update, onComplete: handleSave, formId: "seller-shipping", currentStep: currentStep, onStepChange: setCurrentStep, completeLabel: "Save Configuration", isLoading: busy })] }, "shipping"),
|
|
135
|
+
_jsxs(Div, { children: [error && _jsx(Alert, { variant: "error", className: "mb-4", children: error }), success && _jsx(Alert, { variant: "success", className: "mb-4", children: "Shipping configuration saved." }), _jsxs(FormShellContext.Provider, { value: wizardShellCtx, children: [_jsx(FormErrorSummary, {}), _jsx(StepForm, { steps: steps, values: draft, onChange: update, onComplete: handleSave, formId: "seller-shipping", currentStep: currentStep, onStepChange: setCurrentStep, completeLabel: "Save Configuration", isLoading: busy })] })] }, "shipping"),
|
|
99
136
|
] }));
|
|
100
137
|
}
|