@deenruv/admin-dashboard 1.0.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/LICENSE +23 -0
- package/README.md +30 -0
- package/dist/@types/resources.js +51 -0
- package/dist/DeenruvAdminPanel.js +118 -0
- package/dist/DeenruvDeveloperIndicator.js +57 -0
- package/dist/components/Aexol.js +4 -0
- package/dist/components/BrandLogo.js +22 -0
- package/dist/components/CanLeaveRouteDialog.js +8 -0
- package/dist/components/DataTable.js +13 -0
- package/dist/components/DeleteDialog.js +6 -0
- package/dist/components/DuplicateEntry.js +46 -0
- package/dist/components/GlobalSearch.js +134 -0
- package/dist/components/History/AddEntryForm.js +29 -0
- package/dist/components/History/DeleteEntryDialog.js +25 -0
- package/dist/components/History/EditEntryDialog.js +32 -0
- package/dist/components/History/History.js +13 -0
- package/dist/components/History/ModifyHistoryInfo.js +6 -0
- package/dist/components/History/Timeline.js +53 -0
- package/dist/components/History/index.js +5 -0
- package/dist/components/Menu/ActiveAdmins.js +24 -0
- package/dist/components/Menu/ChannelSwitcher.js +20 -0
- package/dist/components/Menu/LanguagesDropdown.js +26 -0
- package/dist/components/Menu/Navigation.js +270 -0
- package/dist/components/Menu/NavigationFooter.js +12 -0
- package/dist/components/Menu/Notifications.js +90 -0
- package/dist/components/Menu/index.js +67 -0
- package/dist/components/index.js +6 -0
- package/dist/graphql/base.js +95 -0
- package/dist/graphql/collections.js +94 -0
- package/dist/graphql/draft_order.js +307 -0
- package/dist/graphql/orders.js +157 -0
- package/dist/graphql/products.js +230 -0
- package/dist/graphql/scalars.js +22 -0
- package/dist/i18.js +13 -0
- package/dist/index.css +161 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +1 -0
- package/dist/locales/en/admins.json +57 -0
- package/dist/locales/en/assets.json +69 -0
- package/dist/locales/en/channels.json +66 -0
- package/dist/locales/en/collections.json +145 -0
- package/dist/locales/en/common.json +1127 -0
- package/dist/locales/en/countries.json +50 -0
- package/dist/locales/en/customerGroups.json +6 -0
- package/dist/locales/en/customers.json +109 -0
- package/dist/locales/en/dashboard.json +34 -0
- package/dist/locales/en/facets.json +78 -0
- package/dist/locales/en/globalSettings.json +15 -0
- package/dist/locales/en/index.js +52 -0
- package/dist/locales/en/orders.json +932 -0
- package/dist/locales/en/paymentMethods.json +59 -0
- package/dist/locales/en/permissions.json +94 -0
- package/dist/locales/en/products.json +194 -0
- package/dist/locales/en/promotions.json +65 -0
- package/dist/locales/en/roles.json +59 -0
- package/dist/locales/en/sellers.json +41 -0
- package/dist/locales/en/shippingMethods.json +84 -0
- package/dist/locales/en/stockLocations.json +40 -0
- package/dist/locales/en/system.json +41 -0
- package/dist/locales/en/table.json +201 -0
- package/dist/locales/en/taxCategories.json +47 -0
- package/dist/locales/en/taxRates.json +56 -0
- package/dist/locales/en/zones.json +47 -0
- package/dist/locales/index.js +2 -0
- package/dist/locales/pl/admins.json +57 -0
- package/dist/locales/pl/assets.json +69 -0
- package/dist/locales/pl/channels.json +66 -0
- package/dist/locales/pl/collections.json +145 -0
- package/dist/locales/pl/common.json +1128 -0
- package/dist/locales/pl/countries.json +50 -0
- package/dist/locales/pl/customerGroups.json +6 -0
- package/dist/locales/pl/customers.json +109 -0
- package/dist/locales/pl/dashboard.json +34 -0
- package/dist/locales/pl/facets.json +78 -0
- package/dist/locales/pl/globalSettings.json +15 -0
- package/dist/locales/pl/index.js +52 -0
- package/dist/locales/pl/orders.json +932 -0
- package/dist/locales/pl/paymentMethods.json +59 -0
- package/dist/locales/pl/permissions.json +94 -0
- package/dist/locales/pl/products.json +194 -0
- package/dist/locales/pl/promotions.json +65 -0
- package/dist/locales/pl/roles.json +59 -0
- package/dist/locales/pl/sellers.json +41 -0
- package/dist/locales/pl/shippingMethods.json +84 -0
- package/dist/locales/pl/stockLocations.json +40 -0
- package/dist/locales/pl/system.json +41 -0
- package/dist/locales/pl/table.json +201 -0
- package/dist/locales/pl/taxCategories.json +47 -0
- package/dist/locales/pl/taxRates.json +56 -0
- package/dist/locales/pl/zones.json +47 -0
- package/dist/notifications/OrderStatusNotification.js +47 -0
- package/dist/notifications/SystemStatusNotification.js +19 -0
- package/dist/pages/Custom404.js +5 -0
- package/dist/pages/LoginScreen.js +37 -0
- package/dist/pages/Root.js +252 -0
- package/dist/pages/admins/Detail.js +72 -0
- package/dist/pages/admins/List.js +56 -0
- package/dist/pages/admins/_components/AdminDetailView.js +34 -0
- package/dist/pages/admins/_components/RolesCard.js +31 -0
- package/dist/pages/admins/index.js +2 -0
- package/dist/pages/assets/List.js +82 -0
- package/dist/pages/assets/_components/Asset.js +114 -0
- package/dist/pages/assets/_components/AssetListView.js +29 -0
- package/dist/pages/assets/_components/EditAssetDialog.js +85 -0
- package/dist/pages/assets/_components/UploadAssetDialog.js +133 -0
- package/dist/pages/assets/_components/UploadProgress.js +20 -0
- package/dist/pages/assets/index.js +1 -0
- package/dist/pages/channels/Detail.js +149 -0
- package/dist/pages/channels/List.js +46 -0
- package/dist/pages/channels/_components/ChannelDetailView.js +51 -0
- package/dist/pages/channels/_components/DefaultsCard.js +25 -0
- package/dist/pages/channels/index.js +2 -0
- package/dist/pages/collections/Detail.js +61 -0
- package/dist/pages/collections/List.js +135 -0
- package/dist/pages/collections/_components/CollectionDetailView.js +52 -0
- package/dist/pages/collections/_components/CollectionProductVariantsDrawer.js +28 -0
- package/dist/pages/collections/_components/CombinationMode.js +6 -0
- package/dist/pages/collections/_components/ContentsCard.js +43 -0
- package/dist/pages/collections/_components/ContentsTable.js +102 -0
- package/dist/pages/collections/_components/DeleteCollectionsFromChannel.js +36 -0
- package/dist/pages/collections/_components/FacetsSelector.js +30 -0
- package/dist/pages/collections/_components/FiltersCard.js +101 -0
- package/dist/pages/collections/_components/MoveCollectionsToCollections.js +107 -0
- package/dist/pages/collections/_components/MoveEntityToChannels.js +115 -0
- package/dist/pages/collections/_components/PageHeader.js +11 -0
- package/dist/pages/collections/_components/SelectedCollectionsModal.js +22 -0
- package/dist/pages/collections/_components/VariantsSelector.js +43 -0
- package/dist/pages/collections/consts.js +7 -0
- package/dist/pages/collections/index.js +2 -0
- package/dist/pages/countries/Detail.js +57 -0
- package/dist/pages/countries/List.js +47 -0
- package/dist/pages/countries/_components/CountryDetailView.js +28 -0
- package/dist/pages/countries/index.js +2 -0
- package/dist/pages/customer-groups/Detail.js +76 -0
- package/dist/pages/customer-groups/List.js +41 -0
- package/dist/pages/customer-groups/_components/CustomerGroupsDetailView.js +21 -0
- package/dist/pages/customer-groups/index.js +2 -0
- package/dist/pages/customers/Detail.js +75 -0
- package/dist/pages/customers/List.js +60 -0
- package/dist/pages/customers/_components/Address.js +59 -0
- package/dist/pages/customers/_components/AddressDialog.js +56 -0
- package/dist/pages/customers/_components/AddressForm.js +77 -0
- package/dist/pages/customers/_components/AddressesCard.js +9 -0
- package/dist/pages/customers/_components/CustomerDetailSidebar.js +9 -0
- package/dist/pages/customers/_components/CustomerDetailView.js +41 -0
- package/dist/pages/customers/_components/CustomerGroupsCard.js +46 -0
- package/dist/pages/customers/_components/HistoryTab.js +65 -0
- package/dist/pages/customers/_components/OrdersTab.js +46 -0
- package/dist/pages/customers/_components/PersonalDataCard.js +6 -0
- package/dist/pages/customers/_components/VerifiedCard.js +6 -0
- package/dist/pages/customers/index.js +2 -0
- package/dist/pages/dashboard/Dashboard.js +10 -0
- package/dist/pages/dashboard/index.js +1 -0
- package/dist/pages/extensions/Extensions.js +74 -0
- package/dist/pages/extensions/index.js +1 -0
- package/dist/pages/facets/Detail.js +56 -0
- package/dist/pages/facets/List.js +48 -0
- package/dist/pages/facets/_components/AddFacetValueDialog.js +105 -0
- package/dist/pages/facets/_components/ColorSample.js +18 -0
- package/dist/pages/facets/_components/FacetDetailView.js +98 -0
- package/dist/pages/facets/index.js +2 -0
- package/dist/pages/global-settings/GlobalSettingsComponent.js +30 -0
- package/dist/pages/global-settings/index.js +71 -0
- package/dist/pages/index.js +25 -0
- package/dist/pages/orders/Detail.js +21 -0
- package/dist/pages/orders/List.js +132 -0
- package/dist/pages/orders/_components/AddPaymentDialog.js +50 -0
- package/dist/pages/orders/_components/AddressCard.js +260 -0
- package/dist/pages/orders/_components/CancelAndRefundDialog.js +29 -0
- package/dist/pages/orders/_components/ChangesRegister.js +68 -0
- package/dist/pages/orders/_components/ChangesRegisterTable.js +18 -0
- package/dist/pages/orders/_components/CouponCodesCard.js +85 -0
- package/dist/pages/orders/_components/CustomComponent.js +21 -0
- package/dist/pages/orders/_components/CustomerSelectCard.js +117 -0
- package/dist/pages/orders/_components/EditNoteButton.js +10 -0
- package/dist/pages/orders/_components/FulfillmentModal.js +85 -0
- package/dist/pages/orders/_components/LineItem.js +7 -0
- package/dist/pages/orders/_components/ManualOrderChangeModal.js +47 -0
- package/dist/pages/orders/_components/ModifyAcceptModal.js +22 -0
- package/dist/pages/orders/_components/ModifyingCard.js +77 -0
- package/dist/pages/orders/_components/OrderHistory.js +59 -0
- package/dist/pages/orders/_components/OrderLineActionModal/ActionQuantityPrice.js +58 -0
- package/dist/pages/orders/_components/OrderLineActionModal/index.js +7 -0
- package/dist/pages/orders/_components/OrderLineActionModal/types.js +1 -0
- package/dist/pages/orders/_components/OrderLineCustomFields.js +26 -0
- package/dist/pages/orders/_components/OrderSummary.js +10 -0
- package/dist/pages/orders/_components/PaymentMetadata.js +6 -0
- package/dist/pages/orders/_components/Payments.js +113 -0
- package/dist/pages/orders/_components/PossibleOrderStates.js +54 -0
- package/dist/pages/orders/_components/PriceChangedInfo.js +16 -0
- package/dist/pages/orders/_components/ProductsCard.js +308 -0
- package/dist/pages/orders/_components/ProductsTable.js +29 -0
- package/dist/pages/orders/_components/PromotionsList.js +73 -0
- package/dist/pages/orders/_components/RealizationCard.js +98 -0
- package/dist/pages/orders/_components/RefundCard.js +11 -0
- package/dist/pages/orders/_components/RefundPaymentCard.js +13 -0
- package/dist/pages/orders/_components/ShippingMethod.js +112 -0
- package/dist/pages/orders/_components/SpecialLineItem.js +7 -0
- package/dist/pages/orders/_components/SurchargeCard.js +99 -0
- package/dist/pages/orders/_components/SurchargeTable.js +8 -0
- package/dist/pages/orders/_components/TaxSummary.js +11 -0
- package/dist/pages/orders/_components/ToRealizationForm.js +64 -0
- package/dist/pages/orders/_components/TopActions.js +219 -0
- package/dist/pages/orders/_components/index.js +25 -0
- package/dist/pages/orders/index.js +2 -0
- package/dist/pages/payment-methods/Detail.js +67 -0
- package/dist/pages/payment-methods/List.js +41 -0
- package/dist/pages/payment-methods/_components/OptionsCard.js +60 -0
- package/dist/pages/payment-methods/_components/PaymentMethodDetailView.js +53 -0
- package/dist/pages/payment-methods/index.js +2 -0
- package/dist/pages/product-variants/Detail.js +4 -0
- package/dist/pages/product-variants/List.js +76 -0
- package/dist/pages/product-variants/index.js +2 -0
- package/dist/pages/products/Detail.js +75 -0
- package/dist/pages/products/List.js +79 -0
- package/dist/pages/products/_components/AddOptionGroupDialog.js +65 -0
- package/dist/pages/products/_components/AssetsCard.js +35 -0
- package/dist/pages/products/_components/BasicFieldsCard.js +6 -0
- package/dist/pages/products/_components/ChannelsCard.js +6 -0
- package/dist/pages/products/_components/CollectionsCard.js +6 -0
- package/dist/pages/products/_components/Container.js +4 -0
- package/dist/pages/products/_components/DiscountRatingCard.js +6 -0
- package/dist/pages/products/_components/FacetValuesCard.js +6 -0
- package/dist/pages/products/_components/ImagesCard.js +6 -0
- package/dist/pages/products/_components/OptionGroup.js +93 -0
- package/dist/pages/products/_components/OptionValueCard.js +59 -0
- package/dist/pages/products/_components/OptionsCard.js +38 -0
- package/dist/pages/products/_components/OptionsTab.js +40 -0
- package/dist/pages/products/_components/PriceCard.js +27 -0
- package/dist/pages/products/_components/ProductDetailSidebar.js +30 -0
- package/dist/pages/products/_components/ProductDetailView.js +54 -0
- package/dist/pages/products/_components/SettingsCard.js +6 -0
- package/dist/pages/products/_components/StockCard.js +40 -0
- package/dist/pages/products/_components/Variant.js +149 -0
- package/dist/pages/products/_components/VariantsTab.js +46 -0
- package/dist/pages/products/index.js +2 -0
- package/dist/pages/promotions/Detail.js +80 -0
- package/dist/pages/promotions/List.js +38 -0
- package/dist/pages/promotions/_components/ActionsCard.js +67 -0
- package/dist/pages/promotions/_components/BasicFieldsCard.js +6 -0
- package/dist/pages/promotions/_components/ConditionsCard.js +70 -0
- package/dist/pages/promotions/_components/CustomerGroupsSelector.js +25 -0
- package/dist/pages/promotions/_components/EnabledCard.js +6 -0
- package/dist/pages/promotions/_components/OptionsCard.js +6 -0
- package/dist/pages/promotions/_components/PromotionDetailSidebar.js +15 -0
- package/dist/pages/promotions/_components/PromotionDetailView.js +66 -0
- package/dist/pages/promotions/_components/PromotionFieldRender.js +4 -0
- package/dist/pages/promotions/index.js +2 -0
- package/dist/pages/roles/Detail.js +72 -0
- package/dist/pages/roles/List.js +70 -0
- package/dist/pages/roles/_components/PermissionsCard.js +7 -0
- package/dist/pages/roles/_components/PermissionsTable.js +42 -0
- package/dist/pages/roles/_components/RoleDetailView.js +49 -0
- package/dist/pages/roles/index.js +2 -0
- package/dist/pages/sellers/Detail.js +48 -0
- package/dist/pages/sellers/List.js +37 -0
- package/dist/pages/sellers/_components/SellerDetailView.js +20 -0
- package/dist/pages/sellers/index.js +2 -0
- package/dist/pages/shipping-methods/Detail.js +105 -0
- package/dist/pages/shipping-methods/List.js +40 -0
- package/dist/pages/shipping-methods/_components/CalculatorCard.js +79 -0
- package/dist/pages/shipping-methods/_components/CheckerCard.js +76 -0
- package/dist/pages/shipping-methods/_components/Lines.js +20 -0
- package/dist/pages/shipping-methods/_components/ShippingMethodDetailView.js +67 -0
- package/dist/pages/shipping-methods/_components/TestCard.js +62 -0
- package/dist/pages/shipping-methods/index.js +2 -0
- package/dist/pages/status/Status.js +6 -0
- package/dist/pages/status/_components/FilterToolbar.js +29 -0
- package/dist/pages/status/_components/Health.js +21 -0
- package/dist/pages/status/_components/JobResultPopover.js +8 -0
- package/dist/pages/status/_components/Jobs.js +199 -0
- package/dist/pages/status/_components/JsonExplorer.js +44 -0
- package/dist/pages/status/_components/JsonPopup.js +8 -0
- package/dist/pages/status/index.js +1 -0
- package/dist/pages/stock-locations/Detail.js +77 -0
- package/dist/pages/stock-locations/List.js +38 -0
- package/dist/pages/stock-locations/_components/StockLocationDetailView.js +22 -0
- package/dist/pages/stock-locations/index.js +2 -0
- package/dist/pages/tax-categories/Detail.js +85 -0
- package/dist/pages/tax-categories/List.js +46 -0
- package/dist/pages/tax-categories/_components/TaxCategoryDetailView.js +24 -0
- package/dist/pages/tax-categories/index.js +2 -0
- package/dist/pages/tax-rates/Detail.js +62 -0
- package/dist/pages/tax-rates/List.js +64 -0
- package/dist/pages/tax-rates/_components/TaxRateDetailView.js +64 -0
- package/dist/pages/tax-rates/index.js +2 -0
- package/dist/pages/zones/Detail.js +86 -0
- package/dist/pages/zones/List.js +52 -0
- package/dist/pages/zones/_components/ZoneDetailView.js +49 -0
- package/dist/pages/zones/index.js +2 -0
- package/dist/version.js +1 -0
- package/package.json +122 -0
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { Button, Label, Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, DialogTrigger, apiClient, cn, useOrder, OrderDetailSelector, Badge, CustomCard, useTranslation, priceFormatter, } from '@deenruv/react-ui-devkit';
|
|
4
|
+
import { eligibleShippingMethodsSelector } from "../../../graphql/draft_order";
|
|
5
|
+
import { Edit, Truck, Package, AlertCircle, Check, Loader2 } from 'lucide-react';
|
|
6
|
+
import { useEffect, useMemo, useState } from 'react';
|
|
7
|
+
import { toast } from 'sonner';
|
|
8
|
+
export const ShippingMethod = () => {
|
|
9
|
+
const { mode, order, setOrder, modifiedOrder, setModifiedOrder } = useOrder();
|
|
10
|
+
const currentOrder = useMemo(() => (mode === 'update' ? (modifiedOrder ? modifiedOrder : order) : order), [mode, order, modifiedOrder]);
|
|
11
|
+
const { t } = useTranslation('orders');
|
|
12
|
+
const [open, setOpen] = useState(false);
|
|
13
|
+
const [localSelectedShippingMethod, setLocalSelectedShippingMethod] = useState(undefined);
|
|
14
|
+
const [isSubmitting, setIsSubmitting] = useState(false);
|
|
15
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
16
|
+
const [shippingMethods, setShippingMethods] = useState([]);
|
|
17
|
+
const selectedShipping = useMemo(() => shippingMethods.find((method) => method.id === currentOrder?.shippingLines?.[0]?.shippingMethod.id), [shippingMethods, currentOrder]);
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
const fetch = async () => {
|
|
20
|
+
if (order && order.id) {
|
|
21
|
+
setIsLoading(true);
|
|
22
|
+
try {
|
|
23
|
+
const { eligibleShippingMethodsForDraftOrder } = await apiClient('query')({
|
|
24
|
+
eligibleShippingMethodsForDraftOrder: [{ orderId: order.id }, eligibleShippingMethodsSelector],
|
|
25
|
+
});
|
|
26
|
+
if (!eligibleShippingMethodsForDraftOrder) {
|
|
27
|
+
toast.error(t('toasts.orderLoadingDraftShippingError', { value: order.id }));
|
|
28
|
+
}
|
|
29
|
+
setShippingMethods(eligibleShippingMethodsForDraftOrder);
|
|
30
|
+
// Set the currently selected method when opening the dialog
|
|
31
|
+
if (currentOrder?.shippingLines?.[0]?.shippingMethod.id) {
|
|
32
|
+
setLocalSelectedShippingMethod(currentOrder.shippingLines[0].shippingMethod.id);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
toast.error(t('toasts.orderLoadingDraftShippingError', { value: order.id }));
|
|
37
|
+
}
|
|
38
|
+
finally {
|
|
39
|
+
setIsLoading(false);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
fetch();
|
|
44
|
+
}, [t, currentOrder]);
|
|
45
|
+
const selectShippingMethod = async (orderId, shippingMethodId) => {
|
|
46
|
+
setIsSubmitting(true);
|
|
47
|
+
try {
|
|
48
|
+
if (mode === 'update' && selectedShipping && modifiedOrder) {
|
|
49
|
+
const currentShipping = shippingMethods.find((m) => m.id === shippingMethodId);
|
|
50
|
+
if (!currentShipping) {
|
|
51
|
+
toast.error(t('selectShipmentMethod.methodNotFound', 'Selected shipping method not found'));
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
setModifiedOrder({
|
|
55
|
+
...modifiedOrder,
|
|
56
|
+
shippingLines: [
|
|
57
|
+
{
|
|
58
|
+
...modifiedOrder.shippingLines[0],
|
|
59
|
+
price: currentShipping.price,
|
|
60
|
+
priceWithTax: currentShipping.priceWithTax,
|
|
61
|
+
shippingMethod: {
|
|
62
|
+
...modifiedOrder.shippingLines[0].shippingMethod,
|
|
63
|
+
id: currentShipping.id,
|
|
64
|
+
name: currentShipping.name,
|
|
65
|
+
code: currentShipping.code,
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
],
|
|
69
|
+
});
|
|
70
|
+
toast.success(t('selectShipmentMethod.shippingAdded', 'Shipping method updated successfully'));
|
|
71
|
+
setOpen(false);
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
const { setDraftOrderShippingMethod } = await apiClient('mutation')({
|
|
75
|
+
setDraftOrderShippingMethod: [
|
|
76
|
+
{ orderId, shippingMethodId },
|
|
77
|
+
{
|
|
78
|
+
__typename: true,
|
|
79
|
+
'...on Order': OrderDetailSelector,
|
|
80
|
+
'...on IneligibleShippingMethodError': { message: true, errorCode: true },
|
|
81
|
+
'...on NoActiveOrderError': { message: true, errorCode: true },
|
|
82
|
+
'...on OrderModificationError': { message: true, errorCode: true },
|
|
83
|
+
},
|
|
84
|
+
],
|
|
85
|
+
});
|
|
86
|
+
if (setDraftOrderShippingMethod.__typename === 'Order') {
|
|
87
|
+
setOrder(setDraftOrderShippingMethod);
|
|
88
|
+
toast.success(t('selectShipmentMethod.shippingAdded', 'Shipping method added successfully'));
|
|
89
|
+
setOpen(false);
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
toast.error(`${setDraftOrderShippingMethod.errorCode}: ${setDraftOrderShippingMethod.message}`);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
catch (error) {
|
|
96
|
+
toast.error(t('selectShipmentMethod.error', 'Failed to set shipping method'));
|
|
97
|
+
}
|
|
98
|
+
finally {
|
|
99
|
+
setIsSubmitting(false);
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
return (_jsx(CustomCard, { notCollapsible: true, color: "orange", description: t('selectShipmentMethod.cardDescription', 'Choose how this order will be delivered to the customer'), title: t('selectShipmentMethod.cardTitle', 'Shipping Method'), icon: _jsx(Truck, {}), upperRight: mode !== 'view' && (_jsxs(Dialog, { open: open, onOpenChange: setOpen, defaultOpen: false, children: [!order?.lines.length ? (_jsx(TooltipProvider, { children: _jsxs(Tooltip, { children: [_jsx(TooltipTrigger, { asChild: true, children: _jsx(Button, { variant: "ghost", size: "icon", className: "size-8 cursor-not-allowed opacity-50", children: _jsx(Edit, { size: 16, className: "text-muted-foreground" }) }) }), _jsx(TooltipContent, { align: "end", className: "border border-red-200 bg-red-50", children: _jsx("p", { className: "text-xs text-red-500", children: t('selectShipmentMethod.noSelectedTip', 'Add products to the order first') }) })] }) })) : (_jsx(DialogTrigger, { asChild: true, children: _jsx(Button, { variant: "ghost", size: "icon", className: "size-8", children: _jsx(Edit, { size: 16, className: "text-orange-500 dark:text-orange-400" }) }) })), _jsxs(DialogContent, { className: "max-w-[70vw] p-6", children: [_jsxs("div", { className: "flex flex-col gap-6", children: [_jsxs(DialogHeader, { children: [_jsxs(DialogTitle, { className: "flex items-center gap-2 text-xl", children: [_jsx(Truck, { className: "size-5 text-orange-500 dark:text-orange-400" }), t('selectShipmentMethod.setMethodTitle', 'Select Shipping Method')] }), _jsx(DialogDescription, { className: "text-muted-foreground mt-2", children: t('selectShipmentMethod.setMethodDescription', 'Choose how this order will be delivered') })] }), isLoading ? (_jsxs("div", { className: "flex flex-col items-center justify-center py-12", children: [_jsx("div", { className: "size-10 animate-spin rounded-full border-4 border-orange-200 border-t-orange-500" }), _jsx("p", { className: "text-muted-foreground mt-4 text-sm", children: t('selectShipmentMethod.loading', 'Loading shipping methods...') })] })) : (_jsx(_Fragment, { children: shippingMethods.length === 0 ? (_jsxs("div", { className: "flex flex-col items-center justify-center gap-3 py-12 text-center", children: [_jsx("div", { className: "rounded-full bg-orange-100 p-3 dark:bg-orange-900/30", children: _jsx(AlertCircle, { className: "size-6 text-orange-500 dark:text-orange-400" }) }), _jsxs("div", { children: [_jsx("p", { className: "font-medium", children: t('selectShipmentMethod.noMethods', 'No shipping methods available') }), _jsx("p", { className: "text-muted-foreground mt-1 text-sm", children: t('selectShipmentMethod.noMethodsHint', 'Make sure the order has products and a shipping address') })] })] })) : (_jsx("div", { className: "grid grid-cols-1 gap-3 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4", children: shippingMethods.map((shippingMethod) => (_jsx("div", { className: "w-full", children: _jsxs("button", { onClick: () => setLocalSelectedShippingMethod(shippingMethod.id), className: cn('relative flex w-full flex-col gap-2 rounded-lg border p-4 transition-all', 'hover:border-orange-500/70 hover:shadow-sm', localSelectedShippingMethod === shippingMethod.id
|
|
103
|
+
? 'border-orange-500 bg-orange-50 shadow-sm dark:border-orange-400 dark:bg-orange-900/10'
|
|
104
|
+
: 'border-border'), children: [localSelectedShippingMethod === shippingMethod.id && (_jsx("div", { className: "absolute right-2 top-2", children: _jsx(Check, { className: "size-4 text-green-500" }) })), _jsxs("div", { className: "mb-1 flex items-center gap-2", children: [_jsx(Package, { className: "size-4 text-orange-500 dark:text-orange-400" }), _jsx("h3", { className: "text-base font-medium", children: shippingMethod.name })] }), _jsx(Badge, { variant: "outline", className: "w-fit text-xs", children: shippingMethod.code }), _jsxs("div", { className: "border-border mt-2 w-full border-t pt-2", children: [_jsxs("div", { className: "flex items-center justify-between gap-2", children: [_jsx("span", { className: "text-muted-foreground text-xs", children: "Base price: " }), _jsx("span", { className: "text-sm font-medium", children: priceFormatter(shippingMethod.price, order?.currencyCode) })] }), _jsxs("div", { className: "mt-1 flex items-center justify-between gap-2", children: [_jsx("span", { className: "text-muted-foreground text-xs", children: "With tax: " }), _jsx("span", { className: "text-sm font-medium text-orange-600 dark:text-orange-400", children: priceFormatter(shippingMethod.priceWithTax, order?.currencyCode) })] })] })] }) }, shippingMethod.id))) })) }))] }), _jsxs("div", { className: "mt-4 flex justify-end gap-2", children: [_jsx(Button, { variant: "outline", onClick: () => setOpen(false), disabled: isSubmitting, children: t('common.cancel', 'Cancel') }), _jsx(Button, { disabled: !localSelectedShippingMethod || !order?.id || isSubmitting || isLoading, className: "gap-2", onClick: async () => {
|
|
105
|
+
const method = shippingMethods.find((method) => method.id === localSelectedShippingMethod);
|
|
106
|
+
if (method && order?.id)
|
|
107
|
+
await selectShippingMethod(order.id, method.id);
|
|
108
|
+
}, children: isSubmitting ? (_jsxs(_Fragment, { children: [_jsx(Loader2, { className: "size-4 animate-spin" }), t('common.processing', 'Processing...')] })) : (_jsxs(_Fragment, { children: [_jsx(Check, { className: "size-4" }), t('selectShipmentMethod.save', 'Save Shipping Method')] })) })] })] })] })), children: _jsx("div", { className: "border-border bg-muted/50 rounded-lg border p-3", children: _jsx("div", { className: "flex items-start gap-3", children: !order?.lines.length ? (_jsxs(_Fragment, { children: [_jsx("div", { className: "mt-0.5 flex size-8 items-center justify-center rounded-full bg-amber-100 dark:bg-amber-900/30", children: _jsx(AlertCircle, { className: "size-4 text-amber-500" }) }), _jsx("div", { className: "flex-1", children: _jsx("p", { className: "text-muted-foreground text-sm italic", children: t('selectShipmentMethod.noSelectedTip', 'Add products to the order first') }) })] })) : !selectedShipping ? (_jsx(_Fragment, { children: _jsxs("div", { className: "flex-1", children: [_jsx("p", { className: "text-muted-foreground text-sm italic", children: t('selectShipmentMethod.noSelected', 'No shipping method selected') }), mode !== 'view' && (_jsxs(Button, { variant: "outline", size: "sm", className: "mt-2 gap-2", onClick: () => {
|
|
109
|
+
if (order?.lines.length)
|
|
110
|
+
setOpen(true);
|
|
111
|
+
}, disabled: !order?.lines.length, children: [_jsx(Truck, { className: "size-3.5" }), t('selectShipmentMethod.addMethod', 'Add Shipping Method')] }))] }) })) : (_jsxs("div", { className: "relative flex w-full flex-col gap-2", children: [_jsxs("div", { className: "mb-1 flex items-center gap-2", children: [_jsx(Package, { className: "size-4 text-orange-500 dark:text-orange-400" }), _jsx(Label, { className: "text-sm font-medium", children: selectedShipping.name })] }), _jsx(Badge, { variant: "outline", className: "w-fit text-xs", children: selectedShipping.code }), _jsxs("div", { className: "border-border mt-2 w-full border-t pt-2", children: [_jsxs("div", { className: "flex items-center justify-between gap-2", children: [_jsx("span", { className: "text-muted-foreground text-xs", children: "Base price: " }), _jsx("span", { className: "text-sm font-medium", children: priceFormatter(selectedShipping.price, order?.currencyCode) })] }), _jsxs("div", { className: "mt-1 flex items-center justify-between gap-2", children: [_jsx("span", { className: "text-muted-foreground text-xs", children: "With tax: " }), _jsx("span", { className: "text-sm font-medium text-orange-600 dark:text-orange-400", children: priceFormatter(selectedShipping.priceWithTax, order?.currencyCode) })] })] })] }, selectedShipping.id)) }) }) }));
|
|
112
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Button, priceFormatter } from '@deenruv/react-ui-devkit';
|
|
3
|
+
import { Minus, Package, Plus } from 'lucide-react';
|
|
4
|
+
export const SpecialLineItem = ({ variant, adjustLineItem }) => {
|
|
5
|
+
const imageUrl = variant?.featuredAsset?.preview || variant?.product?.featuredAsset?.preview;
|
|
6
|
+
return (_jsx("div", { className: "flex h-full w-2/5 flex-col gap-4", children: _jsxs("div", { className: "bg-card text-card-foreground flex size-full flex-col space-y-3 rounded-lg border p-3 shadow-sm", children: [imageUrl ? (_jsx("img", { alt: `${variant?.product.name} image`, className: "aspect-square h-64 w-full rounded-md border bg-white object-cover shadow-sm", height: "56", width: "56", src: imageUrl || '/placeholder.svg' })) : (_jsx("div", { className: "bg-muted/30 flex size-14 items-center justify-center rounded-md border", children: _jsx(Package, { className: "text-muted-foreground size-6" }) })), _jsxs("div", { className: "flex flex-col gap-2", children: [_jsxs("div", { className: "flex min-w-0 flex-1 flex-col", children: [_jsx("span", { className: "line-clamp-1 text-sm font-medium md:text-base", children: variant?.product.name }), variant?.name && variant.name !== variant?.product.name && (_jsx("span", { className: "text-muted-foreground line-clamp-1 text-xs", children: variant.name }))] }), _jsxs("div", { className: "flex min-w-0 flex-1 flex-col", children: [_jsx("span", { className: "line-clamp-1 select-none text-sm font-medium md:text-base", children: "Price (TAX)" }), _jsxs("span", { className: "text-muted-foreground line-clamp-1 text-xs", children: [priceFormatter(variant.price), " (", priceFormatter(variant.priceWithTax), ")"] })] }), variant.sku ? (_jsxs("div", { className: "flex min-w-0 flex-1 flex-col", children: [_jsx("span", { className: "line-clamp-1 select-none text-sm font-medium md:text-base", children: "SKU" }), variant.sku && _jsx("span", { className: "text-muted-foreground line-clamp-1 text-xs", children: variant.sku })] })) : null] }), variant?.quantity ? (_jsx("div", { className: "ml-auto", children: adjustLineItem ? (_jsx("div", { className: "flex items-center", children: _jsxs("div", { className: "bg-background inline-flex items-center rounded-md border shadow-sm", children: [_jsx(Button, { variant: "ghost", size: "sm", type: "button", onClick: () => adjustLineItem(Math.max(1, (variant.quantity || 1) - 1)), className: "hover:bg-muted h-8 rounded-r-none border-r px-2", "aria-label": "Decrease quantity", children: _jsx(Minus, { className: "size-3.5" }) }), _jsx("span", { className: "px-3 py-1 text-sm font-medium tabular-nums", children: variant?.quantity }), _jsx(Button, { variant: "ghost", size: "sm", type: "button", onClick: () => adjustLineItem((variant.quantity || 0) + 1), className: "hover:bg-muted h-8 rounded-l-none border-l px-2", "aria-label": "Increase quantity", children: _jsx(Plus, { className: "size-3.5" }) })] }) })) : null })) : null] }) }));
|
|
7
|
+
};
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
+
import { SurchargeTable } from './';
|
|
4
|
+
import { useTranslation, Button, Checkbox, Input, Label, useGFFLP, useOrder, CustomCard, } from '@deenruv/react-ui-devkit';
|
|
5
|
+
import { useCallback, useState } from 'react';
|
|
6
|
+
import { PlusCircle, DollarSign, Tag, FileText, Percent, Receipt, Loader2 } from 'lucide-react';
|
|
7
|
+
export const SurchargeCard = () => {
|
|
8
|
+
const { t } = useTranslation('orders');
|
|
9
|
+
const { setModifyOrderInput, modifyOrderInput, setModifiedOrder, modifiedOrder } = useOrder();
|
|
10
|
+
const [isSubmitting, setIsSubmitting] = useState(false);
|
|
11
|
+
const { state, setField } = useGFFLP('SurchargeInput', 'description', 'price', 'priceIncludesTax', 'sku', 'taxDescription', 'taxRate')({
|
|
12
|
+
description: {
|
|
13
|
+
initialValue: '',
|
|
14
|
+
validate: (v) => {
|
|
15
|
+
if (!v || v === '')
|
|
16
|
+
return [t('surcharge.validation.descriptionRequired', 'Description is required')];
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
sku: {
|
|
20
|
+
initialValue: '',
|
|
21
|
+
validate: (v) => {
|
|
22
|
+
if (!v || v === '')
|
|
23
|
+
return [t('surcharge.validation.skuRequired', 'SKU is required')];
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
price: {
|
|
27
|
+
initialValue: 0,
|
|
28
|
+
validate: (v) => {
|
|
29
|
+
if (v === undefined || v === null)
|
|
30
|
+
return [t('surcharge.validation.priceRequired', 'Price is required')];
|
|
31
|
+
if (v <= 0)
|
|
32
|
+
return [t('surcharge.validation.pricePositive', 'Price must be greater than zero')];
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
priceIncludesTax: {
|
|
36
|
+
initialValue: false,
|
|
37
|
+
},
|
|
38
|
+
taxDescription: {
|
|
39
|
+
initialValue: '',
|
|
40
|
+
},
|
|
41
|
+
taxRate: {
|
|
42
|
+
initialValue: 0,
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
const handleAddSurcharge = useCallback(async () => {
|
|
46
|
+
// Validate all fields
|
|
47
|
+
if (!state.description?.value || !state.sku?.value || !state.price?.value || state.price?.value <= 0) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
setIsSubmitting(true);
|
|
51
|
+
try {
|
|
52
|
+
const orderWithSurcharge = Object.assign({}, modifyOrderInput);
|
|
53
|
+
const { description, price, priceIncludesTax, sku, taxDescription, taxRate } = state;
|
|
54
|
+
const surchargesArray = modifyOrderInput?.surcharges || [];
|
|
55
|
+
surchargesArray.push({
|
|
56
|
+
description: description?.value || '',
|
|
57
|
+
price: price?.value,
|
|
58
|
+
priceIncludesTax: priceIncludesTax?.value || false,
|
|
59
|
+
sku: sku?.value,
|
|
60
|
+
taxDescription: taxDescription?.value,
|
|
61
|
+
taxRate: taxRate?.value,
|
|
62
|
+
});
|
|
63
|
+
orderWithSurcharge.surcharges = surchargesArray;
|
|
64
|
+
if (modifiedOrder)
|
|
65
|
+
setModifiedOrder({
|
|
66
|
+
...modifiedOrder,
|
|
67
|
+
surcharges: [
|
|
68
|
+
...modifiedOrder.surcharges,
|
|
69
|
+
{
|
|
70
|
+
description: description?.value || '',
|
|
71
|
+
price: taxRate?.value && priceIncludesTax?.value ? price?.value / (1 + taxRate.value / 100) : price?.value,
|
|
72
|
+
sku: sku?.value,
|
|
73
|
+
createdAt: new Date().toDateString(),
|
|
74
|
+
priceWithTax: taxRate?.value && !priceIncludesTax?.value
|
|
75
|
+
? +price?.value * (+taxRate?.value / 100) + +price?.value
|
|
76
|
+
: +price?.value,
|
|
77
|
+
taxRate: taxRate?.value || 0,
|
|
78
|
+
},
|
|
79
|
+
],
|
|
80
|
+
});
|
|
81
|
+
setModifyOrderInput(orderWithSurcharge);
|
|
82
|
+
// Reset form fields
|
|
83
|
+
setField('description', '');
|
|
84
|
+
setField('sku', '');
|
|
85
|
+
setField('price', 0);
|
|
86
|
+
setField('priceIncludesTax', false);
|
|
87
|
+
setField('taxDescription', '');
|
|
88
|
+
setField('taxRate', 0);
|
|
89
|
+
}
|
|
90
|
+
finally {
|
|
91
|
+
setIsSubmitting(false);
|
|
92
|
+
}
|
|
93
|
+
}, [state, modifiedOrder, modifyOrderInput, setModifiedOrder, setModifyOrderInput, setField]);
|
|
94
|
+
return (_jsx(CustomCard, { color: "yellow", description: t('surcharge.description', 'Add additional fees or charges to this order'), title: t('surcharge.title', 'Order Surcharges'), icon: _jsx(Receipt, { className: "size-5 text-yellow-500 dark:text-yellow-400" }), bottomRight: _jsx(Button, { onClick: handleAddSurcharge, disabled: isSubmitting ||
|
|
95
|
+
!state.description?.value ||
|
|
96
|
+
!state.sku?.value ||
|
|
97
|
+
!state.price?.value ||
|
|
98
|
+
state.price?.value <= 0, className: "ml-auto gap-2", children: isSubmitting ? (_jsxs(_Fragment, { children: [_jsx(Loader2, { className: "size-4 animate-spin" }), t('surcharge.processing', 'Processing...')] })) : (_jsxs(_Fragment, { children: [_jsx(PlusCircle, { className: "size-4" }), t('surcharge.addButton', 'Add Surcharge')] })) }), children: _jsxs("div", { className: "space-y-6", children: [_jsx(SurchargeTable, {}), _jsx("div", { children: _jsxs("div", { className: "mb-4 grid grid-cols-1 gap-4 md:grid-cols-3 lg:grid-cols-5", children: [_jsxs("div", { className: "space-y-2", children: [_jsxs(Label, { htmlFor: "surcharge-description", className: "text-sm font-medium", children: [t('surcharge.labels.description', 'Description'), " ", _jsx("span", { className: "text-red-500", children: "*" })] }), _jsxs("div", { className: "relative", children: [_jsx(Input, { id: "surcharge-description", placeholder: t('surcharge.placeholders.description', 'Enter surcharge description'), value: state.description?.value || '', onChange: (e) => setField('description', e.target.value), className: "pl-9", errors: state.description?.errors }), _jsx("div", { className: "text-muted-foreground absolute left-3 top-1/2 -translate-y-1/2", children: _jsx(FileText, { className: "size-4" }) })] })] }), _jsxs("div", { className: "space-y-2", children: [_jsxs(Label, { htmlFor: "surcharge-sku", className: "text-sm font-medium", children: [t('surcharge.labels.sku', 'SKU'), " ", _jsx("span", { className: "text-red-500", children: "*" })] }), _jsxs("div", { className: "relative", children: [_jsx(Input, { id: "surcharge-sku", placeholder: t('surcharge.placeholders.sku', 'Enter SKU code'), value: state.sku?.value || '', onChange: (e) => setField('sku', e.target.value), className: "pl-9", errors: state.sku?.errors }), _jsx("div", { className: "text-muted-foreground absolute left-3 top-1/2 -translate-y-1/2", children: _jsx(Tag, { className: "size-4" }) })] })] }), _jsxs("div", { className: "space-y-2", children: [_jsxs(Label, { htmlFor: "surcharge-price", className: "text-sm font-medium", children: [t('surcharge.labels.price', 'Price'), " ", _jsx("span", { className: "text-red-500", children: "*" })] }), _jsxs("div", { className: "relative", children: [_jsx(Input, { id: "surcharge-price", type: "currency", endAdornment: modifiedOrder?.currencyCode, step: "0.01", min: "0", placeholder: t('surcharge.placeholders.price', 'Enter price'), value: state.price?.value || '', onChange: (e) => setField('price', +e.target.value), className: "pl-9", errors: state.price?.errors }), _jsx("div", { className: "text-muted-foreground absolute left-3 top-1/2 -translate-y-1/2", children: _jsx(DollarSign, { className: "size-4" }) })] })] }), _jsxs("div", { className: "space-y-2", children: [_jsx(Label, { htmlFor: "surcharge-tax-rate", className: "text-sm font-medium", children: t('surcharge.labels.taxRate', 'Tax Rate (%)') }), _jsxs("div", { className: "relative", children: [_jsx(Input, { id: "surcharge-tax-rate", type: "number", step: "0.01", min: "0", placeholder: t('surcharge.placeholders.taxRate', 'Enter tax rate'), value: state.taxRate?.value || 0, onChange: (e) => setField('taxRate', +e.target.value), className: "pl-9" }), _jsx("div", { className: "text-muted-foreground absolute left-3 top-1/2 -translate-y-1/2", children: _jsx(Percent, { className: "size-4" }) })] })] }), _jsxs("div", { className: "space-y-2", children: [_jsx(Label, { htmlFor: "surcharge-tax-description", className: "text-sm font-medium", children: t('surcharge.labels.taxDescription', 'Tax Description') }), _jsxs("div", { className: "relative", children: [_jsx(Input, { id: "surcharge-tax-description", placeholder: t('surcharge.placeholders.taxDescription', 'Enter tax description'), value: state.taxDescription?.value || '', onChange: (e) => setField('taxDescription', e.target.value), className: "pl-9" }), _jsx("div", { className: "text-muted-foreground absolute left-3 top-1/2 -translate-y-1/2", children: _jsx(FileText, { className: "size-4" }) })] })] }), _jsxs("div", { className: "space-y-2", children: [_jsx(Label, { htmlFor: "surcharge-tax-included", className: "text-sm font-medium", children: t('surcharge.labels.includesTax', { value: state.taxRate?.value }) }), _jsxs("div", { className: "flex items-center gap-2 pt-2", children: [_jsx(Checkbox, { id: "surcharge-tax-included", checked: state.priceIncludesTax?.value || false, onCheckedChange: (e) => setField('priceIncludesTax', Boolean(e)) }), _jsx(Label, { htmlFor: "surcharge-tax-included", className: "cursor-pointer text-sm", children: t('surcharge.placeholders.taxIncluded', 'Tax is included in the price') })] })] })] }) })] }) }));
|
|
99
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { BooleanCell, Separator, Table, TableBody, TableCell, TableHead, TableHeader, TableRow, priceFormatter, useOrder, useTranslation, } from '@deenruv/react-ui-devkit';
|
|
3
|
+
export const SurchargeTable = () => {
|
|
4
|
+
const { t } = useTranslation('orders');
|
|
5
|
+
const { modifyOrderInput, order } = useOrder();
|
|
6
|
+
const surcharges = modifyOrderInput?.surcharges;
|
|
7
|
+
return surcharges?.length ? (_jsxs(_Fragment, { children: [_jsxs(Table, { children: [_jsx(TableHeader, { children: _jsxs(TableRow, { noHover: true, children: [_jsx(TableHead, { children: t('surcharge.labels.description') }), _jsx(TableHead, { children: t('surcharge.labels.sku') }), _jsx(TableHead, { children: t('surcharge.labels.price') }), _jsx(TableHead, { children: t('surcharge.labels.includesTax') }), _jsx(TableHead, { children: t('surcharge.labels.taxRate') }), _jsx(TableHead, { children: t('surcharge.labels.taxDescription') })] }) }), _jsx(TableBody, { children: surcharges?.map(({ description, price, priceIncludesTax, sku, taxDescription, taxRate }, index) => (_jsxs(TableRow, { noHover: true, children: [_jsx(TableCell, { className: "capitalize", children: description }), _jsx(TableCell, { children: sku }), _jsx(TableCell, { children: priceFormatter(price, order?.currencyCode) }), _jsx(TableCell, { children: _jsx(BooleanCell, { value: priceIncludesTax }) }), _jsx(TableCell, { children: taxRate }), _jsx(TableCell, { children: taxDescription })] }, index))) })] }), _jsx(Separator, { className: "my-4" })] })) : null;
|
|
8
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow, useOrder, ScrollArea, CustomCard, useTranslation, priceFormatter, } from '@deenruv/react-ui-devkit';
|
|
3
|
+
import { ReceiptText, Percent, Calculator, AlertCircle } from 'lucide-react';
|
|
4
|
+
export const TaxSummary = () => {
|
|
5
|
+
const { order } = useOrder();
|
|
6
|
+
const { t } = useTranslation('orders');
|
|
7
|
+
if (!order)
|
|
8
|
+
return null;
|
|
9
|
+
const totalTax = order.taxSummary.reduce((sum, { taxTotal }) => sum + taxTotal, 0);
|
|
10
|
+
return (_jsx(CustomCard, { color: "indigo", description: t('taxSummary.subTitle', 'Breakdown of taxes applied to this order'), title: t('taxSummary.title'), icon: _jsx(ReceiptText, {}), collapsed: true, children: _jsx(ScrollArea, { className: "max-h-[350px] px-6 pb-6", children: _jsxs(Table, { children: [_jsx(TableHeader, { children: _jsxs(TableRow, { noHover: true, className: "border-border border-b", children: [_jsx(TableHead, { className: "py-3", children: t('taxSummary.description') }), _jsx(TableHead, { className: "py-3", children: t('taxSummary.taxRate') }), _jsx(TableHead, { className: "py-3", children: t('taxSummary.taxBase') }), _jsx(TableHead, { className: "py-3", children: t('taxSummary.taxTotal') })] }) }), _jsx(TableBody, { children: order.taxSummary.length ? (_jsxs(_Fragment, { children: [order.taxSummary.map(({ description, taxRate, taxBase, taxTotal }) => (_jsxs(TableRow, { noHover: true, className: "group", children: [_jsx(TableCell, { className: "py-3 font-medium", children: _jsxs("div", { className: "flex items-center gap-2", children: [_jsx(Calculator, { className: "size-4 text-indigo-500 dark:text-indigo-400" }), _jsx("span", { className: "capitalize", children: description })] }) }), _jsx(TableCell, { className: "py-3", children: _jsxs("div", { className: "flex items-center gap-1", children: [_jsx(Percent, { className: "text-muted-foreground size-3.5" }), _jsxs("span", { className: "font-medium", children: [taxRate, "%"] })] }) }), _jsx(TableCell, { className: "py-3 font-mono text-sm", children: priceFormatter(taxBase, order.currencyCode) }), _jsx(TableCell, { className: "py-3 font-mono text-sm font-medium", children: priceFormatter(taxTotal, order.currencyCode) })] }, description))), _jsxs(TableRow, { noHover: true, className: "border-border bg-muted/30 border-t", children: [_jsx(TableCell, { colSpan: 3, className: "py-3 text-right font-medium", children: t('taxSummary.taxTotal', 'Total Tax') }), _jsx(TableCell, { className: "py-3 font-mono text-sm font-bold", children: priceFormatter(totalTax, order.currencyCode) })] })] })) : (_jsx(TableRow, { noHover: true, children: _jsx(TableCell, { colSpan: 4, className: "text-muted-foreground py-6 text-center", children: _jsxs("div", { className: "flex flex-col items-center justify-center gap-2", children: [_jsx("div", { className: "rounded-full bg-indigo-100 p-3 dark:bg-indigo-900/30", children: _jsx(AlertCircle, { className: "size-6 text-indigo-500 dark:text-indigo-400" }) }), _jsx("p", { children: t('taxSummary.noTaxSummary', 'No tax information available') }), _jsx("p", { className: "text-muted-foreground text-xs", children: t('taxSummary.noTaxSummaryHint', 'Tax information will appear here when taxes are applied to the order') })] }) }) })) })] }) }) }));
|
|
11
|
+
};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Button, Calendar, Popover, PopoverContent, PopoverTrigger, Label, Select, SelectTrigger, SelectValue, SelectContent, SelectGroup, SelectItem, Textarea, cn, useOrder, AssetsModalInput, ImageWithPreview, useTranslation, } from '@deenruv/react-ui-devkit';
|
|
3
|
+
import { format } from 'date-fns';
|
|
4
|
+
import { CalendarIcon } from 'lucide-react';
|
|
5
|
+
import { useState } from 'react';
|
|
6
|
+
import { toast } from 'sonner';
|
|
7
|
+
const colors = ['BIAŁA', 'ŻÓŁTA', 'POMARAŃCZOWA', 'RÓŻOWA', 'ZIELONA', 'CZERWONA'];
|
|
8
|
+
export const ToRealizationForm = ({ onRealizationFinished }) => {
|
|
9
|
+
const { t } = useTranslation('orders');
|
|
10
|
+
const { order } = useOrder();
|
|
11
|
+
const [plannedDate, setPlannedDate] = useState(new Date());
|
|
12
|
+
const [deadlineDate, setDeadlineDate] = useState(new Date(new Date().getTime() + 7 * 24 * 60 * 60 * 1000));
|
|
13
|
+
const [color, setColor] = useState(colors[0]);
|
|
14
|
+
const [note, setNote] = useState('');
|
|
15
|
+
const [selectedAsset, setSelectedAsset] = useState(order?.lines.map((line) => ({
|
|
16
|
+
id: line.productVariant.featuredAsset?.id || '',
|
|
17
|
+
orderLineID: line.id,
|
|
18
|
+
preview: line.productVariant.featuredAsset?.preview || '',
|
|
19
|
+
})) || []);
|
|
20
|
+
const addRealization = async () => {
|
|
21
|
+
if (!order || !deadlineDate || !plannedDate)
|
|
22
|
+
return;
|
|
23
|
+
// const { registerRealization } = await apiClient('mutation')({
|
|
24
|
+
// registerRealization: [
|
|
25
|
+
// {
|
|
26
|
+
// input: {
|
|
27
|
+
// orderID: order.id,
|
|
28
|
+
// color,
|
|
29
|
+
// finalPlannedAt: format(deadlineDate, 'yyyy-MM-dd'),
|
|
30
|
+
// plannedAt: format(plannedDate, 'yyyy-MM-dd'),
|
|
31
|
+
// assets: selectedAsset,
|
|
32
|
+
// note,
|
|
33
|
+
// },
|
|
34
|
+
// },
|
|
35
|
+
// { url: true },
|
|
36
|
+
// ],
|
|
37
|
+
// });
|
|
38
|
+
// if (registerRealization?.url) {
|
|
39
|
+
// window.open(registerRealization.url, '_blank');
|
|
40
|
+
// onRealizationFinished();
|
|
41
|
+
// }
|
|
42
|
+
};
|
|
43
|
+
return (_jsxs("div", { className: "flex max-h-[60vh] w-auto min-w-[60vw] max-w-[95vw] flex-col gap-2 overflow-y-auto pr-1", children: [_jsxs("div", { className: "flex gap-4", children: [_jsxs("div", { className: "flex w-[280px] flex-col gap-4", children: [_jsxs("div", { children: [_jsx(Label, { children: t('changeStatus.planned') }), _jsxs(Popover, { children: [_jsx(PopoverTrigger, { asChild: true, children: _jsxs(Button, { variant: 'outline', className: cn('w-[280px] justify-start text-left font-normal', !plannedDate && 'text-muted-foreground'), children: [_jsx(CalendarIcon, { className: "mr-2 size-4" }), plannedDate ? format(plannedDate, 'PPP') : _jsx("span", { children: t('changeStatus.datePlaceholder') })] }) }), _jsx(PopoverContent, { className: "w-auto p-0", children: _jsx(Calendar, { mode: "single", selected: plannedDate, onSelect: setPlannedDate }) })] })] }), _jsxs("div", { children: [_jsx(Label, { children: t('changeStatus.deadline') }), _jsxs(Popover, { children: [_jsx(PopoverTrigger, { asChild: true, children: _jsxs(Button, { variant: 'outline', className: cn('w-[280px] justify-start text-left font-normal', !plannedDate && 'text-muted-foreground'), children: [_jsx(CalendarIcon, { className: "mr-2 size-4" }), deadlineDate ? format(deadlineDate, 'PPP') : _jsx("span", { children: t('changeStatus.datePlaceholder') })] }) }), _jsx(PopoverContent, { className: "w-auto p-0", children: _jsx(Calendar, { mode: "single", selected: deadlineDate, onSelect: setDeadlineDate }) })] })] }), _jsxs("div", { children: [_jsx(Label, { children: t('changeStatus.color') }), _jsxs(Select, { name: "color", value: color, onValueChange: (e) => setColor(e), children: [_jsx(SelectTrigger, { className: " w-[280px] ", children: _jsx(SelectValue, {}) }), _jsx(SelectContent, { children: _jsx(SelectGroup, { children: colors.map((c) => (_jsx(SelectItem, { value: c, children: c }, c))) }) })] })] }), _jsxs("div", { children: [_jsx(Label, { children: t('changeStatus.info') }), _jsx(Textarea, { className: "h-[60px] w-[280px] resize-none", maxLength: 64, value: note, onChange: (e) => setNote(e.currentTarget.value) }), _jsx(Label, { className: "text-muted-foreground text-xs", children: t('changeStatus.charLeft', { value: 64 - note.length }) })] })] }), _jsxs("div", { className: "flex flex-1 flex-col gap-2", children: [_jsx(Label, { children: t('changeStatus.selectImages') }), _jsx("div", { className: "flex max-h-[calc(60vh-70px)] flex-1 flex-col gap-2 overflow-y-auto pr-2", children: order?.lines.map((line) => (_jsx(Line, { line: line, asset: selectedAsset.find((a) => a.orderLineID === line.id), onAssetChange: (image) => setSelectedAsset((prev) => prev.map((p) => p.orderLineID === line.id
|
|
44
|
+
? { orderLineID: p.orderLineID, id: image?.id || '', preview: image?.preview || '' }
|
|
45
|
+
: p)) }, line.id))) })] })] }), _jsx(Button, { className: "ml-auto w-min", onClick: async () => {
|
|
46
|
+
if (!plannedDate) {
|
|
47
|
+
toast.error(t('changeStatus.plannedError'));
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
if (!deadlineDate) {
|
|
51
|
+
toast.error(t('changeStatus.deadlineError'));
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
if (!color) {
|
|
55
|
+
toast.error(t('changeStatus.colorError'));
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
await addRealization();
|
|
59
|
+
}, children: t('changeStatus.button') })] }));
|
|
60
|
+
};
|
|
61
|
+
const Line = ({ line, asset, onAssetChange }) => {
|
|
62
|
+
console.log(asset);
|
|
63
|
+
return (_jsxs("div", { className: "flex items-center gap-4", children: [_jsx(ImageWithPreview, { src: asset?.preview, imageClassName: "h-20 w-20 object-contain", alt: asset?.id || line.id }), _jsx("span", { className: "flex-1", children: line.productVariant?.name }), _jsx(AssetsModalInput, { value: asset, setValue: onAssetChange })] }, line.id));
|
|
64
|
+
};
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { AlertDialogHeader, AlertDialogFooter, Button, DropdownMenu, AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogTitle, AlertDialogTrigger, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger, Routes, OrderStateBadge, apiClient, usePluginStore, useOrder, useServer, ConfirmationDialog, SimpleSelect, useTranslation, } from '@deenruv/react-ui-devkit';
|
|
3
|
+
import { FulfillmentModal } from "./FulfillmentModal";
|
|
4
|
+
import { ManualOrderChangeModal } from "./ManualOrderChangeModal";
|
|
5
|
+
import { PossibleOrderStates } from "./PossibleOrderStates";
|
|
6
|
+
import { DeletionResult, HistoryEntryType } from '@deenruv/admin-types';
|
|
7
|
+
import { ChevronLeft, EllipsisVerticalIcon, Info } from 'lucide-react';
|
|
8
|
+
import { useMemo, useState } from 'react';
|
|
9
|
+
import { useNavigate } from 'react-router-dom';
|
|
10
|
+
import { toast } from 'sonner';
|
|
11
|
+
import { ORDER_STATE } from "../../../graphql/base";
|
|
12
|
+
import { addFulfillmentToOrderResultSelector } from "../../../graphql/draft_order";
|
|
13
|
+
import { CancelAndRefundDialog, ModifyAcceptModal } from './index.js';
|
|
14
|
+
import React from 'react';
|
|
15
|
+
export const TopActions = () => {
|
|
16
|
+
const { currentPossibilities, manualChange, setManualChange, fetchOrderHistory, fetchOrder, order, changeOrderState, cancelOrder: _cancelOrder, cancelAndRefundOrder, } = useOrder();
|
|
17
|
+
const orderProcess = useServer((p) => p.serverConfig?.orderProcess || []);
|
|
18
|
+
const { t } = useTranslation('orders');
|
|
19
|
+
const navigate = useNavigate();
|
|
20
|
+
const { getDetailViewActions } = usePluginStore();
|
|
21
|
+
const actions = useMemo(() => getDetailViewActions('orders-detail-view'), []);
|
|
22
|
+
const [cancellationReason, setCancellationReason] = useState('');
|
|
23
|
+
const reasonOptions = useMemo(() => {
|
|
24
|
+
const options = [
|
|
25
|
+
t('cancellationReasons.clientRequest'),
|
|
26
|
+
t('cancellationReasons.notAvailable'),
|
|
27
|
+
t('cancellationReasons.mistake'),
|
|
28
|
+
];
|
|
29
|
+
return options.map((o) => ({
|
|
30
|
+
value: o,
|
|
31
|
+
label: o,
|
|
32
|
+
}));
|
|
33
|
+
}, []);
|
|
34
|
+
const isOrderValid = useMemo(() => {
|
|
35
|
+
const isVariantValid = !!order?.lines.every((line) => line.productVariant);
|
|
36
|
+
const isCustomerValid = !!order?.customer?.id;
|
|
37
|
+
const isBillingAddressValid = !!order?.billingAddress?.streetLine1;
|
|
38
|
+
const isShippingAddressValid = !!order?.shippingAddress?.streetLine1;
|
|
39
|
+
const isShippingMethodValid = !!order?.shippingLines?.length;
|
|
40
|
+
if (order?.state === ORDER_STATE.ARRANGING_ADDITIONAL_PAYMENT) {
|
|
41
|
+
const settledPaymentsAmount = order.payments
|
|
42
|
+
?.filter((payment) => payment.state === ORDER_STATE.PAYMENT_SETTLED)
|
|
43
|
+
.reduce((acc, payment) => acc + payment.amount, 0) || 0;
|
|
44
|
+
return settledPaymentsAmount < order.totalWithTax;
|
|
45
|
+
}
|
|
46
|
+
return (isVariantValid && isCustomerValid && isBillingAddressValid && isShippingAddressValid && isShippingMethodValid);
|
|
47
|
+
}, [order]);
|
|
48
|
+
const onSubmit = async () => {
|
|
49
|
+
if (!isOrderValid || !order) {
|
|
50
|
+
toast.error(t('topActions.fillAll'), { position: 'top-center', closeButton: true });
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
const history = await fetchOrderHistory();
|
|
54
|
+
let state = ORDER_STATE.ARRANGING_PAYMENT;
|
|
55
|
+
if (history && order.state === ORDER_STATE.ARRANGING_ADDITIONAL_PAYMENT) {
|
|
56
|
+
const previousState = history
|
|
57
|
+
.filter((h) => h.type === HistoryEntryType.ORDER_STATE_TRANSITION)
|
|
58
|
+
.find((h) => h.data.to === ORDER_STATE.MODIFYING);
|
|
59
|
+
if (previousState) {
|
|
60
|
+
state = previousState.data.from;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
changeOrderState(state).catch((err) => {
|
|
64
|
+
const errorMessage = `
|
|
65
|
+
${err?.message || t('topActions.errMsg')}
|
|
66
|
+
${err?.transitionError || ''}
|
|
67
|
+
`;
|
|
68
|
+
toast(errorMessage);
|
|
69
|
+
});
|
|
70
|
+
};
|
|
71
|
+
const fulfillOrder = async (input) => {
|
|
72
|
+
if (!order)
|
|
73
|
+
return;
|
|
74
|
+
const { addFulfillmentToOrder } = await apiClient('mutation')({
|
|
75
|
+
addFulfillmentToOrder: [{ input }, addFulfillmentToOrderResultSelector],
|
|
76
|
+
});
|
|
77
|
+
if (addFulfillmentToOrder.__typename === 'Fulfillment') {
|
|
78
|
+
const { transitionFulfillmentToState } = await apiClient('mutation')({
|
|
79
|
+
transitionFulfillmentToState: [
|
|
80
|
+
{ id: addFulfillmentToOrder.id, state: ORDER_STATE.SHIPPED },
|
|
81
|
+
{
|
|
82
|
+
__typename: true,
|
|
83
|
+
'...on Fulfillment': {
|
|
84
|
+
id: true,
|
|
85
|
+
},
|
|
86
|
+
'...on FulfillmentStateTransitionError': {
|
|
87
|
+
errorCode: true,
|
|
88
|
+
fromState: true,
|
|
89
|
+
message: true,
|
|
90
|
+
toState: true,
|
|
91
|
+
transitionError: true,
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
],
|
|
95
|
+
});
|
|
96
|
+
if (transitionFulfillmentToState.__typename === 'Fulfillment') {
|
|
97
|
+
fetchOrder(order.id);
|
|
98
|
+
fetchOrderHistory();
|
|
99
|
+
toast.success(t('topActions.fulfillmentAdded'));
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
toast.error(`${transitionFulfillmentToState.message}`, { position: 'top-center' });
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
toast.error(`${addFulfillmentToOrder.message}`, { position: 'top-center' });
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
const cancelOrder = (lines, cancelShipping) => _cancelOrder({ cancelShipping, lines, reason: cancellationReason })
|
|
111
|
+
.then(() => {
|
|
112
|
+
toast.info(t('topActions.orderCanceledSuccessfully'));
|
|
113
|
+
})
|
|
114
|
+
.catch((err) => {
|
|
115
|
+
toast.error(t('topActions.orderCancelError', { value: err.message }));
|
|
116
|
+
});
|
|
117
|
+
const cancelAndRefund = (amount, lines, reason, shipping, cancelShipping, adjustment) => cancelAndRefundOrder({ adjustment, amount, cancelShipping, lines, reason, shipping })
|
|
118
|
+
.then(() => {
|
|
119
|
+
toast.info(t('topActions.orderRefundedSuccessfully'));
|
|
120
|
+
})
|
|
121
|
+
.catch(() => {
|
|
122
|
+
toast.error(t('topActions.orderRefundError'));
|
|
123
|
+
});
|
|
124
|
+
const deleteDraftOrder = async () => {
|
|
125
|
+
if (!order)
|
|
126
|
+
return;
|
|
127
|
+
const { deleteDraftOrder } = await apiClient('mutation')({
|
|
128
|
+
deleteDraftOrder: [{ orderId: order.id }, { message: true, result: true }],
|
|
129
|
+
});
|
|
130
|
+
if (deleteDraftOrder.result === DeletionResult.DELETED) {
|
|
131
|
+
toast.info(t('topActions.draftDeletedSuccessfully'));
|
|
132
|
+
navigate(-1);
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
toast.error(t('topActions.draftDeleteError', { value: deleteDraftOrder.message }), { position: 'top-center' });
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
const changeOrderStatus = async (newState) => {
|
|
139
|
+
if (!newState)
|
|
140
|
+
return;
|
|
141
|
+
changeOrderState(newState).catch((err) => {
|
|
142
|
+
toast.error(err?.message
|
|
143
|
+
? t('changeStatus.changeStatusFailedMsg', { value: err.message })
|
|
144
|
+
: t('changeStatus.changeStatusFailed'));
|
|
145
|
+
});
|
|
146
|
+
setManualChange({ state: false });
|
|
147
|
+
};
|
|
148
|
+
const outstandingPaymentAmount = (order) => {
|
|
149
|
+
const paymentIsValid = (p) => p?.state !== 'Cancelled' && p.state !== 'Declined' && p.state !== 'Error';
|
|
150
|
+
let amountCovered = 0;
|
|
151
|
+
for (const payment of order.payments?.filter(paymentIsValid) ?? []) {
|
|
152
|
+
const refunds = payment.refunds.filter((r) => r.state !== 'Failed') ?? [];
|
|
153
|
+
const refundsTotal = (refunds || []).reduce((sum, i) => sum + i['total'], 0);
|
|
154
|
+
amountCovered += payment.amount - refundsTotal;
|
|
155
|
+
}
|
|
156
|
+
return order.totalWithTax - amountCovered;
|
|
157
|
+
};
|
|
158
|
+
const canAddFulfillment = useMemo(() => {
|
|
159
|
+
if (!order)
|
|
160
|
+
return false;
|
|
161
|
+
const allFulfillmentLines = (order.fulfillments ?? [])
|
|
162
|
+
.filter((fulfillment) => fulfillment.state !== 'Cancelled')
|
|
163
|
+
.reduce((all, fulfillment) => [...all, ...fulfillment.lines], []);
|
|
164
|
+
let allItemsFulfilled = true;
|
|
165
|
+
for (const line of order.lines) {
|
|
166
|
+
const totalFulfilledCount = allFulfillmentLines
|
|
167
|
+
.filter((row) => row.orderLineId === line.id)
|
|
168
|
+
.reduce((sum, row) => sum + row.quantity, 0);
|
|
169
|
+
if (totalFulfilledCount < line.quantity) {
|
|
170
|
+
allItemsFulfilled = false;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
return (!allItemsFulfilled &&
|
|
174
|
+
outstandingPaymentAmount(order) === 0 &&
|
|
175
|
+
(order.nextStates.includes('Shipped') ||
|
|
176
|
+
order.nextStates.includes('PartiallyShipped') ||
|
|
177
|
+
order.nextStates.includes('Delivered')));
|
|
178
|
+
}, [order, currentPossibilities]);
|
|
179
|
+
// const canCompleteOrder = useMemo(() => {
|
|
180
|
+
// return !!(
|
|
181
|
+
// order?.fulfillments?.some((f) => f.state === ORDER_STATE.SHIPPED) ||
|
|
182
|
+
// !currentPossibilities?.to.some((state) => COMPLETE_ORDER_STATES.includes(state as ORDER_STATE))
|
|
183
|
+
// );
|
|
184
|
+
// }, [order, currentPossibilities]);
|
|
185
|
+
const needFulfillment = useMemo(() => {
|
|
186
|
+
const statesNotFromDeenruv = orderProcess.filter((state) => !Object.values(ORDER_STATE).includes(state.name));
|
|
187
|
+
const states = [ORDER_STATE.PARTIALLY_DELIVERED, ORDER_STATE.SHIPPED, ORDER_STATE.PAYMENT_SETTLED];
|
|
188
|
+
const doExternalStatesNeedFulfillment = statesNotFromDeenruv.filter((state) => state.to.some((s) => states.includes(s)));
|
|
189
|
+
states.push(...doExternalStatesNeedFulfillment.map((state) => state.name));
|
|
190
|
+
return states.includes(order?.state) && order?.state !== ORDER_STATE.SHIPPED;
|
|
191
|
+
}, [order, currentPossibilities]);
|
|
192
|
+
const inModifyState = useMemo(() => order?.state === ORDER_STATE.MODIFYING, [order]);
|
|
193
|
+
const exitingModifyStates = useMemo(() => [ORDER_STATE.DRAFT, ORDER_STATE.ARRANGING_ADDITIONAL_PAYMENT].includes(order?.state), [order]);
|
|
194
|
+
if (!order)
|
|
195
|
+
return null;
|
|
196
|
+
return (_jsxs("div", { className: "flex items-center gap-4 ", children: [currentPossibilities && (_jsx(ManualOrderChangeModal, { open: manualChange.state, setOpen: setManualChange, wantedState: manualChange.toAction, order: order, currentPossibilities: currentPossibilities, onConfirm: (e) => changeOrderStatus(e) })), _jsxs(Button, { variant: "outline", size: "icon", className: "size-7", onClick: () => {
|
|
197
|
+
if (order?.state === ORDER_STATE.DRAFT) {
|
|
198
|
+
toast.error(t('create.leaveToastMessage'), {
|
|
199
|
+
position: 'top-center',
|
|
200
|
+
action: {
|
|
201
|
+
label: t('create.leaveToastButton'),
|
|
202
|
+
onClick: () => navigate(Routes.orders.list, { viewTransition: true }),
|
|
203
|
+
},
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
else
|
|
207
|
+
navigate(Routes.orders.list, { viewTransition: true });
|
|
208
|
+
}, children: [_jsx(ChevronLeft, { className: "size-4" }), _jsx("span", { className: "sr-only", children: t('create.back') })] }), _jsx("h1", { className: "flex-1 shrink-0 whitespace-nowrap text-xl font-semibold tracking-tight sm:grow-0", children: t('create.orderId', { value: order?.id }) }), _jsx(OrderStateBadge, { state: order?.state }), _jsxs("div", { className: "hidden items-center gap-2 md:ml-auto md:flex", children: [actions?.inline?.map(({ component }) => React.createElement(component)) || null, exitingModifyStates ? (_jsx(Button, { size: "sm", onClick: onSubmit, disabled: !isOrderValid, children: order.state === ORDER_STATE.ARRANGING_ADDITIONAL_PAYMENT
|
|
209
|
+
? t('create.addPaymentButton')
|
|
210
|
+
: t('create.completeOrderButton') })) : needFulfillment ? (_jsx(FulfillmentModal, { order: order, onSubmitted: fulfillOrder, disabled: !canAddFulfillment })) : inModifyState ? (_jsx(ModifyAcceptModal, {})) : null, (order.state === ORDER_STATE.ARRANGING_PAYMENT ||
|
|
211
|
+
order.state === ORDER_STATE.ARRANGING_ADDITIONAL_PAYMENT) && (_jsxs("div", { className: "flex items-center gap-2 text-sm", children: [_jsx(Info, { size: 20, className: "text-blue-500" }), _jsx("p", { children: t('addPaymentInfo') })] })), order.state === ORDER_STATE.SHIPPED && (_jsxs("div", { className: "flex items-center gap-2 text-sm", children: [_jsx(Info, { size: 20, className: "text-blue-500" }), _jsx("p", { children: t('markFulfillmentInfo') })] }))] }), _jsxs(DropdownMenu, { children: [_jsx(DropdownMenuTrigger, { asChild: true, children: _jsx(Button, { variant: "outline", size: "icon", children: _jsx(EllipsisVerticalIcon, { className: "size-4" }) }) }), _jsxs(DropdownMenuContent, { align: "end", children: [_jsx(DropdownMenuItem, { asChild: true, children: _jsx(PossibleOrderStates, { orderState: order.state }) }), order.state !== ORDER_STATE.CANCELLED &&
|
|
212
|
+
order.state !== ORDER_STATE.DRAFT &&
|
|
213
|
+
currentPossibilities?.to.length && (_jsx(DropdownMenuItem, { asChild: true, children: _jsx(Button, { onClick: () => setManualChange({ state: true, toAction: undefined }), variant: "ghost", className: "w-full cursor-pointer justify-start px-4 py-2 text-orange-400 hover:text-orange-400 focus-visible:ring-transparent dark:text-orange-400 dark:hover:text-orange-400 dark:focus-visible:ring-transparent", children: t('topActions.manualChangeStatus') }) })), actions?.dropdown?.map(({ component }) => React.createElement(component)) || null, order.state === ORDER_STATE.PARTIALLY_DELIVERED ||
|
|
214
|
+
order.state === ORDER_STATE.SHIPPED ||
|
|
215
|
+
order.state === ORDER_STATE.PAYMENT_SETTLED ||
|
|
216
|
+
order.state === ORDER_STATE.PAYMENT_AUTHORIZED ||
|
|
217
|
+
order.state === ORDER_STATE.PARTIALLY_SHIPPED ? (_jsx(DropdownMenuItem, { asChild: true, children: _jsx(Button, { variant: "ghost", className: "w-full cursor-pointer justify-start px-4 py-2 text-blue-400 hover:text-blue-400 dark:text-blue-400 dark:hover:text-blue-400", onClick: changeOrderStatus.bind(null, ORDER_STATE.MODIFYING), children: t('create.modifyOrder') }) })) : null, order.state === ORDER_STATE.ARRANGING_PAYMENT && (_jsx(DropdownMenuItem, { asChild: true, children: _jsx(ConfirmationDialog, { onConfirm: () => cancelOrder(), title: t('create.areYouSure'), description: t('create.cancelOrderMessage'), additionalElement: _jsx(SimpleSelect, { label: t('cancellationLabel'), value: cancellationReason, onValueChange: setCancellationReason, options: reasonOptions }), children: _jsx(Button, { variant: "ghost", className: "w-full justify-start px-4 py-2 text-red-400 hover:text-red-400 dark:text-red-400 dark:hover:text-red-400", children: t('create.cancelOrder') }) }) })), (order.state === ORDER_STATE.PAYMENT_SETTLED ||
|
|
218
|
+
order.state === ORDER_STATE.ARRANGING_ADDITIONAL_PAYMENT) && (_jsx(CancelAndRefundDialog, { refundReason: cancellationReason, setRefundReason: setCancellationReason, onConfirm: cancelAndRefund })), order.state === ORDER_STATE.DRAFT && (_jsx(DropdownMenuItem, { asChild: true, children: _jsxs(AlertDialog, { children: [_jsx(AlertDialogTrigger, { asChild: true, children: _jsx(Button, { variant: "ghost", className: "w-full justify-start px-4 py-2 text-red-400 hover:text-red-400 dark:hover:text-red-400", children: t('deleteDraft.button') }) }), _jsxs(AlertDialogContent, { children: [_jsxs(AlertDialogHeader, { children: [_jsx(AlertDialogTitle, { children: t('deleteDraft.title') }), _jsx(AlertDialogDescription, { children: t('deleteDraft.descriptionDraft') })] }), _jsxs(AlertDialogFooter, { children: [_jsx(AlertDialogCancel, { children: t('deleteDraft.cancel') }), _jsx(AlertDialogAction, { onClick: () => deleteDraftOrder(), children: t('deleteDraft.confirm') })] })] })] }) }))] })] })] }));
|
|
219
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export * from './AddressCard.js';
|
|
2
|
+
export * from './CustomerSelectCard.js';
|
|
3
|
+
export * from './FulfillmentModal.js';
|
|
4
|
+
export * from './LineItem.js';
|
|
5
|
+
export * from './ShippingMethod.js';
|
|
6
|
+
export * from './OrderSummary.js';
|
|
7
|
+
export * from './ManualOrderChangeModal.js';
|
|
8
|
+
export * from './OrderHistory.js';
|
|
9
|
+
export * from './PossibleOrderStates.js';
|
|
10
|
+
export * from './RealizationCard.js';
|
|
11
|
+
export * from './ProductsCard.js';
|
|
12
|
+
export * from './TaxSummary.js';
|
|
13
|
+
export * from './TopActions.js';
|
|
14
|
+
export * from './AddPaymentDialog.js';
|
|
15
|
+
export * from './ModifyAcceptModal.js';
|
|
16
|
+
export * from './ChangesRegister.js';
|
|
17
|
+
export * from './Payments.js';
|
|
18
|
+
export * from './OrderLineActionModal/index.js';
|
|
19
|
+
export * from './CouponCodesCard.js';
|
|
20
|
+
export * from './SurchargeCard.js';
|
|
21
|
+
export * from './SurchargeTable.js';
|
|
22
|
+
export * from './PriceChangedInfo.js';
|
|
23
|
+
export * from './ChangesRegisterTable.js';
|
|
24
|
+
export * from './CancelAndRefundDialog.js';
|
|
25
|
+
export * from './ProductsTable.js';
|