@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,132 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Permission, SortOrder, typedGql, scalars } from '@deenruv/admin-types';
|
|
3
|
+
import { Routes, apiClient, DetailList, deepMerge, OrderStateBadge, priceFormatter, TableLabel, useQuery, ListLocations, useTranslation, MultipleSelector, useServer, } from '@deenruv/react-ui-devkit';
|
|
4
|
+
import { useCallback } from 'react';
|
|
5
|
+
import { useNavigate } from 'react-router-dom';
|
|
6
|
+
import { toast } from 'sonner';
|
|
7
|
+
const tableId = 'orders-list-view';
|
|
8
|
+
const { selector } = ListLocations[tableId];
|
|
9
|
+
const createDraftOrder = async () => {
|
|
10
|
+
const response = await apiClient('mutation')({
|
|
11
|
+
createDraftOrder: { id: true },
|
|
12
|
+
});
|
|
13
|
+
return response.createDraftOrder.id;
|
|
14
|
+
};
|
|
15
|
+
const fetch = async ({ page, perPage, filter, filterOperator, sort }, additionalSelector) => {
|
|
16
|
+
const response = await apiClient('query')({
|
|
17
|
+
['orders']: [
|
|
18
|
+
{
|
|
19
|
+
options: {
|
|
20
|
+
take: perPage,
|
|
21
|
+
skip: (page - 1) * perPage,
|
|
22
|
+
filterOperator: filterOperator,
|
|
23
|
+
sort: sort ? { [sort.key]: sort.sortDir } : { createdAt: SortOrder.DESC },
|
|
24
|
+
...(filter && { filter }),
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
{ items: deepMerge(selector, additionalSelector ?? {}), totalItems: true },
|
|
28
|
+
],
|
|
29
|
+
});
|
|
30
|
+
return response['orders'];
|
|
31
|
+
};
|
|
32
|
+
const PaymentMethodsQuery = typedGql('query', { scalars })({
|
|
33
|
+
paymentMethods: [{}, { items: { code: true, name: true } }],
|
|
34
|
+
});
|
|
35
|
+
export const OrdersListPage = () => {
|
|
36
|
+
const { data } = useQuery(PaymentMethodsQuery);
|
|
37
|
+
const { t } = useTranslation('table');
|
|
38
|
+
const { t: tCommon } = useTranslation('common');
|
|
39
|
+
const navigate = useNavigate();
|
|
40
|
+
const orderStates = useServer((state) => state.serverConfig?.orderProcess.map((p) => p.name) ?? []);
|
|
41
|
+
const getMethodName = useCallback((code) => code
|
|
42
|
+
? (data?.paymentMethods.items.find((i) => i.code === code)?.name ??
|
|
43
|
+
code?.replace(/-/g, ' ').replace(/\b\w/g, (char) => char.toUpperCase()))
|
|
44
|
+
: '-', [data]);
|
|
45
|
+
return (_jsx(DetailList, { filterFields: [
|
|
46
|
+
{ key: 'orderPlacedAt', operator: 'DateOperators' },
|
|
47
|
+
{ key: 'code', operator: 'StringOperators' },
|
|
48
|
+
{ key: 'customerLastName', operator: 'StringOperators' },
|
|
49
|
+
{ key: 'total', operator: 'NumberOperators' },
|
|
50
|
+
{ key: 'totalWithTax', operator: 'NumberOperators' },
|
|
51
|
+
{
|
|
52
|
+
key: 'state',
|
|
53
|
+
component: (props) => {
|
|
54
|
+
const value = props?.value?.in
|
|
55
|
+
? props.value.in.map((state) => ({
|
|
56
|
+
label: tCommon(`search.inOperator.${state}`),
|
|
57
|
+
value: state,
|
|
58
|
+
}))
|
|
59
|
+
: [];
|
|
60
|
+
return (_jsx(MultipleSelector, { value: value, options: orderStates.map((state) => ({
|
|
61
|
+
label: tCommon(`search.inOperator.${state}`),
|
|
62
|
+
value: state,
|
|
63
|
+
})), onChange: (options) => {
|
|
64
|
+
if (options.length === 0) {
|
|
65
|
+
props.onChange({});
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
props.onChange({ in: options.map((o) => o.value) });
|
|
69
|
+
} }));
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
], detailLinkColumn: "id", searchFields: ['code', 'customerLastName'], entityName: "Order", route: {
|
|
73
|
+
create: () => {
|
|
74
|
+
createDraftOrder()
|
|
75
|
+
.then((id) => {
|
|
76
|
+
if (!id)
|
|
77
|
+
toast.error('Failed to create draft order');
|
|
78
|
+
navigate(Routes.orders.to(id), { viewTransition: true });
|
|
79
|
+
})
|
|
80
|
+
.catch(() => toast.error('Failed to create draft order'));
|
|
81
|
+
},
|
|
82
|
+
edit: (id) => navigate(Routes.orders.to(id), { viewTransition: true }),
|
|
83
|
+
}, tableId: tableId, fetch: fetch, createPermissions: [Permission.CreateOrder], deletePermissions: [Permission.DeleteOrder], hideColumns: ['active', 'totalQuantity', 'currencyCode'], additionalColumns: [
|
|
84
|
+
{
|
|
85
|
+
accessorKey: 'payments',
|
|
86
|
+
header: () => _jsx(TableLabel, { children: t('columns.payments') }),
|
|
87
|
+
accessorFn: (order) => {
|
|
88
|
+
const sorted = order.payments
|
|
89
|
+
?.sort((a, b) => {
|
|
90
|
+
return a.createdAt > b.createdAt ? -1 : 1;
|
|
91
|
+
})
|
|
92
|
+
.filter((payment) => payment.state === 'Settled');
|
|
93
|
+
return getMethodName(sorted?.at(0)?.method);
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
accessorKey: 'shippingAddress',
|
|
98
|
+
header: () => _jsx(TableLabel, { children: t('columns.shippingAddress') }),
|
|
99
|
+
accessorFn: (order) => {
|
|
100
|
+
if (!order.shippingAddress)
|
|
101
|
+
return '';
|
|
102
|
+
return order.shippingAddress.fullName;
|
|
103
|
+
},
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
accessorKey: 'customer',
|
|
107
|
+
header: () => _jsx(TableLabel, { children: t('columns.customer') }),
|
|
108
|
+
accessorFn: (order) => order.customer?.emailAddress,
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
accessorKey: 'state',
|
|
112
|
+
header: () => _jsx(TableLabel, { children: t('columns.state') }),
|
|
113
|
+
accessorFn: (order) => order?.state,
|
|
114
|
+
cell: ({ row }) => _jsx(OrderStateBadge, { state: row.original.state }),
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
accessorKey: 'totalWithTax',
|
|
118
|
+
header: () => _jsx(TableLabel, { children: t('columns.total') }),
|
|
119
|
+
accessorFn: (order) => priceFormatter(order.totalWithTax, order.currencyCode),
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
accessorKey: 'shipping',
|
|
123
|
+
header: () => _jsx(TableLabel, { children: t('columns.shipping') }),
|
|
124
|
+
accessorFn: (order) => priceFormatter(order.shipping, order.currencyCode),
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
accessorKey: 'code',
|
|
128
|
+
header: () => _jsx(TableLabel, { children: t('columns.code') }),
|
|
129
|
+
accessorFn: (order) => order.code,
|
|
130
|
+
},
|
|
131
|
+
] }));
|
|
132
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Button, Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger, Input, Label, ORDER_STATE, Select, SelectContent, SelectItem, SelectTrigger, SelectValue, useServer, useTranslation, priceFormatter, } from '@deenruv/react-ui-devkit';
|
|
3
|
+
import { PAYMENT_STATE } from "../../../graphql/base";
|
|
4
|
+
import { useMemo, useState } from 'react';
|
|
5
|
+
import { toast } from 'sonner';
|
|
6
|
+
import { CheckCircle, CreditCard, DollarSign, FileText } from 'lucide-react';
|
|
7
|
+
const validateForm = (input) => {
|
|
8
|
+
const errors = [];
|
|
9
|
+
if (!input.method) {
|
|
10
|
+
errors.push({ key: 'method', message: 'Payment method is required' });
|
|
11
|
+
}
|
|
12
|
+
if (!input.transactionId) {
|
|
13
|
+
errors.push({ key: 'transactionId', message: 'Transaction ID is required' });
|
|
14
|
+
}
|
|
15
|
+
return errors;
|
|
16
|
+
};
|
|
17
|
+
export const AddPaymentDialog = ({ order, onSubmit }) => {
|
|
18
|
+
const [form, setForm] = useState({
|
|
19
|
+
method: '',
|
|
20
|
+
transactionId: '',
|
|
21
|
+
});
|
|
22
|
+
const { t } = useTranslation('orders');
|
|
23
|
+
const paymentMethodsType = useServer((p) => p.paymentMethodsType);
|
|
24
|
+
const paidAmount = useMemo(() => order.payments?.filter((el) => el.state === PAYMENT_STATE.SETTLED).reduce((acc, val) => (acc += val.amount), 0) ||
|
|
25
|
+
0, [order.payments]);
|
|
26
|
+
const needsPayment = useMemo(() => order.totalWithTax > paidAmount, [order.totalWithTax, paidAmount]);
|
|
27
|
+
const isFormValid = useMemo(() => validateForm(form), [form]);
|
|
28
|
+
const paymentAmount = useMemo(() => order.totalWithTax - paidAmount || 0, [order.totalWithTax, paidAmount, order?.currencyCode]);
|
|
29
|
+
const [open, setOpen] = useState(false);
|
|
30
|
+
const disabled = useMemo(() => ![
|
|
31
|
+
ORDER_STATE.ARRANGING_PAYMENT,
|
|
32
|
+
ORDER_STATE.ARRANGING_ADDITIONAL_PAYMENT,
|
|
33
|
+
ORDER_STATE.DRAFT,
|
|
34
|
+
ORDER_STATE.MODIFYING,
|
|
35
|
+
].includes(order.state) || !needsPayment, [needsPayment, order.state]);
|
|
36
|
+
return (_jsxs(Dialog, { open: open, onOpenChange: setOpen, children: [_jsx(DialogTrigger, { asChild: true, children: _jsxs(Button, { variant: !disabled ? 'action' : 'ghost', size: "sm", disabled: disabled, className: "gap-2", onClick: setOpen.bind(null, true), children: [_jsx(DollarSign, { className: "size-4" }), paymentAmount > 0
|
|
37
|
+
? t('create.buttonAddPayment', {
|
|
38
|
+
value: priceFormatter(paymentAmount, order.currencyCode),
|
|
39
|
+
})
|
|
40
|
+
: t('create.notEnoughPayment')] }) }), _jsxs(DialogContent, { className: "max-w-md", children: [_jsxs(DialogHeader, { children: [_jsxs("div", { className: "mb-2 flex items-center gap-2", children: [_jsx(CreditCard, { className: "size-5 text-teal-500 dark:text-teal-400" }), _jsx(DialogTitle, { children: t('create.addPaymentTitle') })] }), _jsx(DialogDescription, { children: t('create.addPaymentDescription') })] }), _jsxs("form", { className: "mt-4 flex w-full flex-col gap-4", onSubmit: (e) => {
|
|
41
|
+
e.preventDefault();
|
|
42
|
+
if (isFormValid.length > 0) {
|
|
43
|
+
isFormValid.forEach((err) => toast.error(err.message));
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
onSubmit({ ...form, orderId: order.id, metadata: {} });
|
|
47
|
+
setForm({ method: '', transactionId: '' });
|
|
48
|
+
setOpen(false);
|
|
49
|
+
}, children: [_jsxs("div", { className: "space-y-1", children: [_jsx(Label, { htmlFor: "payment-method", children: t('table.paymentMethod') }), _jsxs(Select, { value: form.method, onValueChange: (v) => setForm({ ...form, method: v }), children: [_jsx(SelectTrigger, { id: "payment-method", className: "w-full", children: _jsx(SelectValue, { placeholder: t('selectPaymentMethod') }) }), _jsx(SelectContent, { children: paymentMethodsType.map((method) => (_jsx(SelectItem, { value: method.code, children: method.name }, method.id))) })] })] }), _jsxs("div", { className: "space-y-1", children: [_jsx(Label, { htmlFor: "transaction-id", children: t('filterField.transactionId') }), _jsx(Input, { id: "transaction-id", value: form.transactionId || '', onChange: (e) => setForm({ ...form, transactionId: e.currentTarget.value }), placeholder: t('enterTransactionId') })] }), _jsxs("div", { className: "bg-muted/50 mt-2 rounded-md p-3", children: [_jsxs("div", { className: "flex items-center gap-2", children: [_jsx(FileText, { className: "size-4 text-teal-500 dark:text-teal-400" }), _jsx("span", { className: "text-sm font-medium", children: t('payments.summary') })] }), _jsxs("div", { className: "mt-2 space-y-1", children: [_jsxs("div", { className: "flex justify-between text-sm", children: [_jsxs("span", { className: "text-muted-foreground", children: [t('payments.total'), ":"] }), _jsx("span", { className: "font-medium", children: priceFormatter(order.totalWithTax, order.currencyCode) })] }), _jsxs("div", { className: "flex justify-between text-sm", children: [_jsxs("span", { className: "text-muted-foreground", children: [t('payments.alreadyPaid'), ":"] }), _jsx("span", { className: "font-medium", children: priceFormatter(paidAmount, order.currencyCode) })] }), _jsxs("div", { className: "flex justify-between border-t pt-1 text-sm font-medium", children: [_jsxs("span", { children: [t('payments.toPay'), ":"] }), _jsx("span", { className: "text-teal-600 dark:text-teal-400", children: priceFormatter(paymentAmount, order.currencyCode) })] })] })] }), _jsxs(DialogFooter, { className: "mt-4 gap-2", children: [_jsx(DialogClose, { asChild: true, children: _jsx(Button, { variant: "outline", children: t('payments.cancel') }) }), _jsxs(Button, { type: "submit", disabled: isFormValid.length > 0, className: "gap-2", children: [_jsx(CheckCircle, { className: "size-4" }), t('payments.add')] })] })] })] })] }));
|
|
50
|
+
};
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
+
import { Card, Button, Tabs, TabsList, TabsTrigger, TabsContent, CardDescription, ScrollArea, Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, DialogTrigger, apiClient, useOrder, cn, CustomCard, useGFFLP, useTranslation, useMutation, } from '@deenruv/react-ui-devkit';
|
|
4
|
+
import { addressBaseSelector } from "../../../graphql/draft_order";
|
|
5
|
+
import { Edit, MapPin, Building, Check, Loader2, User, Phone, Globe } from 'lucide-react';
|
|
6
|
+
import { useEffect, useMemo, useState } from 'react';
|
|
7
|
+
import { toast } from 'sonner';
|
|
8
|
+
import { AddressForm } from "../../customers/_components/AddressForm.js";
|
|
9
|
+
import { CreateCustomerAddressMutation } from "../../customers/_components/AddressDialog.js";
|
|
10
|
+
export const AddressCard = ({ type }) => {
|
|
11
|
+
const [tab, setTab] = useState('select');
|
|
12
|
+
const { mode, order, modifiedOrder, setModifiedOrder, setBillingAddress, setShippingAddress, setOrder } = useOrder();
|
|
13
|
+
const currentOrder = useMemo(() => (mode === 'update' ? (modifiedOrder ? modifiedOrder : order) : order), [mode, order, modifiedOrder]);
|
|
14
|
+
const { t } = useTranslation('orders');
|
|
15
|
+
const [createForCustomer, setCreateForCustomer] = useState(false);
|
|
16
|
+
const [submitting, setSubmitting] = useState(false);
|
|
17
|
+
const [open, setOpen] = useState(false);
|
|
18
|
+
const [createAddress] = useMutation(CreateCustomerAddressMutation);
|
|
19
|
+
const currentAddress = useMemo(() => {
|
|
20
|
+
return type === 'shipping' &&
|
|
21
|
+
currentOrder?.shippingAddress &&
|
|
22
|
+
currentOrder.shippingAddress.streetLine1 &&
|
|
23
|
+
currentOrder.shippingAddress.countryCode
|
|
24
|
+
? currentOrder.shippingAddress
|
|
25
|
+
: type === 'billing' &&
|
|
26
|
+
currentOrder?.billingAddress &&
|
|
27
|
+
currentOrder.billingAddress.countryCode &&
|
|
28
|
+
currentOrder.billingAddress.streetLine1
|
|
29
|
+
? currentOrder.billingAddress
|
|
30
|
+
: undefined;
|
|
31
|
+
}, [currentOrder, type]);
|
|
32
|
+
const [selectedAddress, setSelectedAddress] = useState(undefined);
|
|
33
|
+
const isShipping = type === 'shipping';
|
|
34
|
+
const { state, setState } = useGFFLP('CreateAddressInput', 'city', 'company', 'countryCode', 'postalCode', 'fullName', 'phoneNumber', 'postalCode', 'streetLine1', 'streetLine2', 'province', 'customFields')({
|
|
35
|
+
fullName: {
|
|
36
|
+
initialValue: '',
|
|
37
|
+
validate: (v) => {
|
|
38
|
+
if (!v || v === '')
|
|
39
|
+
return [t('selectAddress.nameRequired')];
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
company: { initialValue: '' },
|
|
43
|
+
streetLine1: {
|
|
44
|
+
initialValue: '',
|
|
45
|
+
validate: (v) => {
|
|
46
|
+
if (!v || v === '')
|
|
47
|
+
return [t('selectAddress.streetRequired')];
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
streetLine2: { initialValue: '' },
|
|
51
|
+
postalCode: {
|
|
52
|
+
initialValue: '',
|
|
53
|
+
validate: (v) => {
|
|
54
|
+
if (!v || v === '')
|
|
55
|
+
return [t('selectAddress.postalCodeRequired')];
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
countryCode: {
|
|
59
|
+
initialValue: '',
|
|
60
|
+
validate: (v) => {
|
|
61
|
+
if (!v || v === '')
|
|
62
|
+
return [t('selectAddress.countryRequired')];
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
phoneNumber: {
|
|
66
|
+
initialValue: '',
|
|
67
|
+
validate: (v) => {
|
|
68
|
+
if (!v || v === '')
|
|
69
|
+
return [t('selectAddress.phoneNumberRequired')];
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
city: {
|
|
73
|
+
initialValue: '',
|
|
74
|
+
validate: (v) => {
|
|
75
|
+
if (!v || v === '')
|
|
76
|
+
return [t('selectAddress.cityRequired')];
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
province: { initialValue: '' },
|
|
80
|
+
customFields: { initialValue: {} },
|
|
81
|
+
});
|
|
82
|
+
useEffect(() => {
|
|
83
|
+
if (selectedAddress) {
|
|
84
|
+
setState({
|
|
85
|
+
...selectedAddress,
|
|
86
|
+
countryCode: selectedAddress.country?.code || '',
|
|
87
|
+
streetLine1: selectedAddress.streetLine1 || '',
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
}, [selectedAddress]);
|
|
91
|
+
const submitAddress = async () => {
|
|
92
|
+
if (!order?.customer?.id)
|
|
93
|
+
return;
|
|
94
|
+
if (!!order?.customer?.addresses?.length && tab === 'select' && !selectedAddress)
|
|
95
|
+
return;
|
|
96
|
+
const input = {
|
|
97
|
+
fullName: state.fullName?.validatedValue,
|
|
98
|
+
company: state.company?.validatedValue,
|
|
99
|
+
streetLine1: state.streetLine1?.validatedValue || '',
|
|
100
|
+
streetLine2: state.streetLine2?.validatedValue,
|
|
101
|
+
countryCode: state.countryCode?.validatedValue || '',
|
|
102
|
+
city: state.city?.validatedValue,
|
|
103
|
+
phoneNumber: state.phoneNumber?.validatedValue,
|
|
104
|
+
postalCode: state.postalCode?.validatedValue,
|
|
105
|
+
province: state.province?.validatedValue,
|
|
106
|
+
...('customFields' in state ? { customFields: state.customFields.value } : {}),
|
|
107
|
+
};
|
|
108
|
+
if (!order?.customer?.addresses?.length) {
|
|
109
|
+
await createAddress({ customerId: order.customer.id, input }).then((resp) => {
|
|
110
|
+
const addressTypeKey = type === 'shipping' ? 'shippingAddress' : 'billingAddress';
|
|
111
|
+
if (resp.createCustomerAddress.id) {
|
|
112
|
+
setOpen(false);
|
|
113
|
+
toast.success(t('selectAddress.newAddress', { address: resp.createCustomerAddress.streetLine1 }));
|
|
114
|
+
setSelectedAddress(resp.createCustomerAddress);
|
|
115
|
+
setTab('select');
|
|
116
|
+
setCreateForCustomer(false);
|
|
117
|
+
const { id, ...address } = resp.createCustomerAddress;
|
|
118
|
+
if (currentOrder) {
|
|
119
|
+
const setAddress = type === 'shipping' ? setShippingAddress : setBillingAddress;
|
|
120
|
+
setAddress({
|
|
121
|
+
...address,
|
|
122
|
+
countryCode: state.countryCode?.validatedValue || 'PL',
|
|
123
|
+
});
|
|
124
|
+
setOrder({
|
|
125
|
+
...currentOrder,
|
|
126
|
+
[addressTypeKey]: resp.createCustomerAddress,
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
else
|
|
131
|
+
toast.error(t('selectAddress.addressFailedCreateToast'));
|
|
132
|
+
});
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
if (mode === 'update' && modifiedOrder) {
|
|
136
|
+
const addressTypeKey = type === 'shipping' ? 'shippingAddress' : 'billingAddress';
|
|
137
|
+
setModifiedOrder({
|
|
138
|
+
...modifiedOrder,
|
|
139
|
+
[addressTypeKey]: input,
|
|
140
|
+
});
|
|
141
|
+
toast.success(t('selectAddress.addressUpdated'));
|
|
142
|
+
setOpen(false);
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
setSubmitting(true);
|
|
146
|
+
try {
|
|
147
|
+
const newAddress = tab === 'select' && selectedAddress
|
|
148
|
+
? {
|
|
149
|
+
fullName: selectedAddress.fullName,
|
|
150
|
+
company: selectedAddress.company,
|
|
151
|
+
streetLine1: selectedAddress.streetLine1,
|
|
152
|
+
streetLine2: selectedAddress.streetLine2,
|
|
153
|
+
countryCode: selectedAddress.country?.code || '',
|
|
154
|
+
city: selectedAddress.city,
|
|
155
|
+
phoneNumber: selectedAddress.phoneNumber,
|
|
156
|
+
postalCode: selectedAddress.postalCode,
|
|
157
|
+
province: selectedAddress.province,
|
|
158
|
+
...('customFields' in selectedAddress ? { customFields: selectedAddress.customFields } : {}),
|
|
159
|
+
}
|
|
160
|
+
: input;
|
|
161
|
+
const setAddress = type === 'shipping' ? setShippingAddress : setBillingAddress;
|
|
162
|
+
setAddress(newAddress)
|
|
163
|
+
.then(() => {
|
|
164
|
+
toast.success(t('selectAddress.addressSuccessSelectToast'));
|
|
165
|
+
setOpen(false);
|
|
166
|
+
})
|
|
167
|
+
.catch(() => toast.error(t(tab === 'create' ? 'selectAddress.addressFailedCreateToast' : 'selectAddress.addressFailedSelectToast')));
|
|
168
|
+
if (tab === 'create' && createForCustomer && order.customer?.id) {
|
|
169
|
+
const { createCustomerAddress } = await apiClient('mutation')({
|
|
170
|
+
createCustomerAddress: [{ customerId: order.customer.id, input: newAddress }, addressBaseSelector],
|
|
171
|
+
});
|
|
172
|
+
if (createCustomerAddress.streetLine1) {
|
|
173
|
+
toast.success(t('selectAddress.newAddress', { address: createCustomerAddress.streetLine1 }));
|
|
174
|
+
setSelectedAddress(createCustomerAddress);
|
|
175
|
+
setTab('select');
|
|
176
|
+
setCreateForCustomer(false);
|
|
177
|
+
}
|
|
178
|
+
else {
|
|
179
|
+
toast.error(t('selectAddress.addressAddFailed'));
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
catch {
|
|
184
|
+
toast.error(t('selectAddress.addressError'));
|
|
185
|
+
}
|
|
186
|
+
finally {
|
|
187
|
+
setSubmitting(false);
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
useEffect(() => {
|
|
191
|
+
if (!currentAddress || Object.values(currentAddress).every((x) => x === null || x === '')) {
|
|
192
|
+
const defaultAddress = order?.customer?.addresses?.find((i) => type === 'billing' ? !!i.defaultBillingAddress : !!i.defaultShippingAddress);
|
|
193
|
+
if (defaultAddress) {
|
|
194
|
+
setTab('select');
|
|
195
|
+
setSelectedAddress(defaultAddress);
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
const sameAddressInSaved = currentAddress &&
|
|
200
|
+
order?.customer?.addresses?.find((i) => i.streetLine1 === currentAddress.streetLine1 &&
|
|
201
|
+
i.city === currentAddress.city &&
|
|
202
|
+
i.company === currentAddress.company &&
|
|
203
|
+
i.fullName === currentAddress.fullName &&
|
|
204
|
+
i.postalCode === currentAddress.postalCode &&
|
|
205
|
+
i.province === currentAddress.province &&
|
|
206
|
+
i.streetLine2 === currentAddress.streetLine2 &&
|
|
207
|
+
i.phoneNumber === currentAddress.phoneNumber &&
|
|
208
|
+
i.country.code === currentAddress.countryCode &&
|
|
209
|
+
i.country.name === currentAddress.country);
|
|
210
|
+
if (sameAddressInSaved) {
|
|
211
|
+
setTab('select');
|
|
212
|
+
setSelectedAddress(sameAddressInSaved);
|
|
213
|
+
setState({ countryCode: sameAddressInSaved.country?.code || '', ...sameAddressInSaved });
|
|
214
|
+
}
|
|
215
|
+
else {
|
|
216
|
+
setSelectedAddress(undefined);
|
|
217
|
+
if (currentAddress) {
|
|
218
|
+
setState({
|
|
219
|
+
...currentAddress,
|
|
220
|
+
countryCode: currentAddress.countryCode || '',
|
|
221
|
+
streetLine1: currentAddress.streetLine1 || '',
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
return () => {
|
|
226
|
+
setTab('select');
|
|
227
|
+
setSelectedAddress(undefined);
|
|
228
|
+
};
|
|
229
|
+
}, [currentAddress, order, type]);
|
|
230
|
+
const color = isShipping ? 'purple' : 'cyan';
|
|
231
|
+
const iconColor = isShipping ? 'text-purple-500 dark:text-purple-400' : 'text-cyan-500 dark:text-cyan-400';
|
|
232
|
+
return (_jsx(CustomCard, { notCollapsible: true, title: t(isShipping ? 'selectAddress.shippingHeader' : 'selectAddress.billingHeader'), description: t(isShipping ? 'selectAddress.shippingDescription' : 'selectAddress.billingDescription'), icon: isShipping ? _jsx(MapPin, {}) : _jsx(Building, {}), color: currentAddress ? color : 'gray', upperRight: mode !== 'view' && (_jsxs(Dialog, { open: open, onOpenChange: setOpen, children: [_jsx(DialogTrigger, { asChild: true, children: _jsx(Button, { variant: "ghost", size: "icon", className: "size-8", children: _jsx(Edit, { size: 16, className: iconColor }) }) }), _jsxs(DialogContent, { className: "flex h-[80vh] max-h-[80vh] min-h-[80vh] flex-col", children: [_jsxs(DialogHeader, { children: [_jsxs(DialogTitle, { className: "flex items-center gap-2 text-xl", children: [isShipping ? (_jsx(MapPin, { className: `size-5 ${iconColor}` })) : (_jsx(Building, { className: `size-5 ${iconColor}` })), t('selectAddress.selectAddress')] }), _jsx(DialogDescription, { className: "text-muted-foreground mt-2", children: isShipping
|
|
233
|
+
? order?.customer?.addresses?.length
|
|
234
|
+
? t('selectAddress.selectShippingAddress')
|
|
235
|
+
: t('selectAddress.createShippingAddress')
|
|
236
|
+
: order?.customer?.addresses?.length
|
|
237
|
+
? t('selectAddress.selectBillingAddress')
|
|
238
|
+
: t('selectAddress.createBillingAddress') })] }), _jsxs(Tabs, { value: tab, defaultValue: 'select', onValueChange: (e) => setTab(e), className: "flex flex-1 basis-1 flex-col overflow-hidden", children: [order?.customer?.addresses?.length ? (_jsxs(TabsList, { className: "my-4 grid w-full grid-cols-2", children: [_jsx(TabsTrigger, { className: "w-full", value: "select", children: t('selectAddress.selectAddress') }), _jsx(TabsTrigger, { className: "w-full", value: "create", children: t('selectAddress.editAddress') })] })) : null, order?.customer?.addresses?.length ? (_jsxs(_Fragment, { children: [_jsx(TabsContent, { value: "select", className: cn('flex flex-1 flex-col overflow-hidden focus-visible:ring-transparent', tab !== 'select' && 'hidden'), children: _jsx(ScrollArea, { className: "pr-4", children: _jsx("div", { className: "flex flex-col gap-3 px-1", children: order?.customer?.addresses?.map((address, index) => (_jsxs(Card, { className: cn('flex cursor-pointer items-start justify-between gap-4 p-4 transition-all', 'hover:border-primary/70 hover:shadow-sm', selectedAddress?.id === address.id
|
|
239
|
+
? 'border-primary bg-primary/5 shadow-sm'
|
|
240
|
+
: 'border-border'), onClick: () => setSelectedAddress(address), children: [_jsxs("div", { className: "flex-1", children: [_jsxs("div", { className: "mb-1 flex items-center gap-2", children: [_jsx(User, { className: `size-4 ${iconColor}` }), _jsx("p", { className: "font-medium", children: address.fullName }), selectedAddress?.id === address.id && (_jsx("div", { className: "ml-auto", children: _jsx(Check, { className: "size-4 text-green-500" }) }))] }), _jsx(CardDescription, { className: "text-sm", children: `${address.streetLine1} ${address.streetLine2 ? ', ' + address.streetLine2 : ''}` }), _jsx(CardDescription, { className: "text-sm", children: `${address.postalCode} ${address.city} ${address.country?.name || address.country?.code}` }), _jsx(CardDescription, { className: "text-sm", children: `${t('selectAddress.phoneNumberShort', { value: address.phoneNumber })} ${address.company ? '• ' + address.company : ''} ` }), _jsxs("div", { className: "mt-2 flex gap-2", children: [address.defaultBillingAddress && (_jsx("span", { className: "rounded-full bg-cyan-100 px-2 py-0.5 text-xs text-cyan-800 dark:bg-cyan-900/50 dark:text-cyan-300", children: t('selectAddress.isDefaultBilling') })), address.defaultShippingAddress && (_jsx("span", { className: "rounded-full bg-purple-100 px-2 py-0.5 text-xs text-purple-800 dark:bg-purple-900/50 dark:text-purple-300", children: t('selectAddress.isDefaultShipping') }))] })] }), _jsx(Button, { variant: "ghost", size: "icon", className: "size-8", onClick: (e) => {
|
|
241
|
+
e.stopPropagation();
|
|
242
|
+
setState({ countryCode: address.country?.code || '', ...address });
|
|
243
|
+
setTab('create');
|
|
244
|
+
}, children: _jsx(Edit, { size: 16, className: iconColor }) })] }, `${address.id}-${index}`))) }) }) }), _jsx(TabsContent, { value: "create", className: cn('flex flex-1 flex-col overflow-hidden focus-visible:ring-transparent', tab !== 'create' && 'hidden'), children: _jsx(ScrollArea, { className: "pr-4", children: _jsx(AddressForm, { initialValues: {
|
|
245
|
+
country: { code: state.countryCode.validatedValue },
|
|
246
|
+
streetLine1: state.streetLine1.validatedValue,
|
|
247
|
+
streetLine2: state.streetLine2.validatedValue,
|
|
248
|
+
city: state.city.validatedValue,
|
|
249
|
+
company: state.company.validatedValue,
|
|
250
|
+
fullName: state.fullName.validatedValue,
|
|
251
|
+
phoneNumber: state.phoneNumber.validatedValue,
|
|
252
|
+
postalCode: state.postalCode.validatedValue,
|
|
253
|
+
province: state.province?.validatedValue,
|
|
254
|
+
...(state.customFields?.validatedValue
|
|
255
|
+
? { customFields: state.customFields?.validatedValue }
|
|
256
|
+
: {}),
|
|
257
|
+
}, onInputChange: setState }) }) })] })) : (_jsx(AddressForm, { onInputChange: setState }))] }), _jsxs("div", { className: "mt-4 flex justify-end gap-2", children: [_jsx(Button, { variant: "outline", onClick: () => setOpen(false), disabled: submitting, children: t('common.cancel', 'Cancel') }), _jsx(Button, { className: "gap-2", disabled: submitting || (!!order?.customer?.addresses?.length && tab === 'select' && !selectedAddress), onClick: submitAddress, children: submitting ? (_jsxs(_Fragment, { children: [_jsx(Loader2, { className: "size-4 animate-spin" }), t('common.submitting')] })) : (_jsxs(_Fragment, { children: [_jsx(Check, { className: "size-4" }), !order?.customer?.addresses?.length
|
|
258
|
+
? 'Create'
|
|
259
|
+
: t(tab === 'select' ? 'selectAddress.selectAddress' : 'selectAddress.editAddress')] })) })] })] })] })), children: _jsx("div", { className: "border-border bg-muted/50 rounded-lg border p-3", children: _jsx("div", { className: "flex items-start gap-3", children: !currentAddress ? (_jsxs(_Fragment, { children: [_jsx("div", { className: `mt-0.5 flex size-8 items-center justify-center rounded-full ${isShipping ? 'bg-purple-100 dark:bg-purple-900/30' : 'bg-cyan-100 dark:bg-cyan-900/30'}`, children: isShipping ? (_jsx(MapPin, { className: `size-4 ${iconColor}` })) : (_jsx(Building, { className: `size-4 ${iconColor}` })) }), _jsxs("div", { className: "flex-1", children: [_jsx("p", { className: "text-muted-foreground text-sm italic", children: t(isShipping ? 'selectAddress.noShippingAddress' : 'selectAddress.noBillingAddress') }), mode !== 'view' && (_jsxs(Button, { variant: "outline", size: "sm", className: "mt-2 gap-2", onClick: () => setOpen(true), children: [_jsx(Edit, { className: "size-3.5" }), t('selectAddress.addAddress', 'Add Address')] }))] })] })) : (_jsx(_Fragment, { children: _jsx("div", { className: "flex-1", children: _jsxs("div", { className: "space-y-2", children: [_jsxs("div", { className: "flex items-center gap-2", children: [_jsx(User, { className: `max-h-4 min-h-4 min-w-4 max-w-4 ${iconColor}` }), _jsx("p", { className: "text-sm font-medium", children: currentAddress?.fullName })] }), _jsxs("div", { className: "flex items-center gap-2", children: [_jsx(MapPin, { className: `max-h-4 min-h-4 min-w-4 max-w-4 ${iconColor}` }), _jsxs("p", { className: "text-sm", children: [currentAddress.streetLine1, " ", currentAddress?.streetLine2] })] }), _jsxs("div", { className: "flex items-center gap-2", children: [_jsx(Globe, { className: `max-h-4 min-h-4 min-w-4 max-w-4 ${iconColor}` }), _jsxs("p", { className: "text-sm", children: [currentAddress.city, " ", currentAddress.postalCode, " ", currentAddress.province, ' ', currentAddress.country] })] }), _jsx("div", { className: "border-border mt-1 flex items-center justify-between border-t pt-1", children: _jsxs("div", { className: "flex items-center gap-2", children: [currentAddress.company && (_jsxs("div", { className: "flex items-center gap-1", children: [_jsx(Building, { className: "text-muted-foreground size-4" }), _jsx("span", { className: "text-muted-foreground text-sm", children: currentAddress.company })] })), currentAddress.phoneNumber && (_jsxs("div", { className: "flex items-center gap-1", children: [_jsx(Phone, { className: "text-muted-foreground size-4" }), _jsx("span", { className: "text-muted-foreground text-sm", children: t('selectAddress.phoneNumberShort', { value: currentAddress.phoneNumber }) })] }))] }) })] }) }) })) }) }) }));
|
|
260
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useState } from 'react';
|
|
3
|
+
import { Button, Dialog, DialogClose, DialogContent, DialogFooter, DialogHeader, DialogTitle, DialogTrigger, DropdownMenuItem, useOrder, } from '@deenruv/react-ui-devkit';
|
|
4
|
+
import { Undo2 } from 'lucide-react';
|
|
5
|
+
import { useTranslation } from 'react-i18next';
|
|
6
|
+
import { ProductsTable } from "./";
|
|
7
|
+
import { RefundPaymentCard } from "./RefundPaymentCard.js";
|
|
8
|
+
export const CancelAndRefundDialog = ({ refundReason, setRefundReason, onConfirm, }) => {
|
|
9
|
+
const { t } = useTranslation('orders');
|
|
10
|
+
const { order } = useOrder();
|
|
11
|
+
const [open, setOpen] = useState(false);
|
|
12
|
+
const [refundAmount, setRefundAmount] = useState(0);
|
|
13
|
+
const [refundLines, setRefundLines] = useState([]);
|
|
14
|
+
const [cancelShipping, setCancelShipping] = useState(false);
|
|
15
|
+
useEffect(() => {
|
|
16
|
+
if (!order)
|
|
17
|
+
return;
|
|
18
|
+
const wholeLines = order?.lines.filter((l) => refundLines.some((rL) => l.id === rL.orderLineId)) ?? [];
|
|
19
|
+
let _refundAmount = refundLines
|
|
20
|
+
.map((rL, i) => wholeLines[i].discountedUnitPriceWithTax * rL.quantity)
|
|
21
|
+
.reduce((prev, acc) => prev + acc, 0);
|
|
22
|
+
if (cancelShipping && order?.shipping) {
|
|
23
|
+
_refundAmount = +order?.shipping;
|
|
24
|
+
}
|
|
25
|
+
console.log('RA', _refundAmount);
|
|
26
|
+
setRefundAmount(_refundAmount);
|
|
27
|
+
}, [cancelShipping, refundLines, order]);
|
|
28
|
+
return (_jsxs(Dialog, { open: open, onOpenChange: setOpen, children: [_jsx(DialogTrigger, { asChild: true, children: _jsx(DropdownMenuItem, { asChild: true, onSelect: (e) => e.preventDefault(), 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('cancelAndRefund.trigger') }) }) }), _jsxs(DialogContent, { className: "flex h-[80vh] max-w-[80vw] flex-col gap-0 overflow-hidden", children: [_jsx(DialogHeader, { children: _jsxs("div", { className: "mb-2 flex items-center gap-2", children: [_jsx(Undo2, { className: "h-5 w-5 text-rose-500 dark:text-rose-400" }), _jsx(DialogTitle, { children: t('cancelAndRefund.title') })] }) }), _jsx(ProductsTable, { refundLines, setRefundLines }), _jsx(RefundPaymentCard, { refundReason, setRefundReason, cancelShipping, setCancelShipping, refundAmount, setRefundAmount }), _jsxs(DialogFooter, { className: "mt-auto gap-2", children: [_jsx(DialogClose, { asChild: true, children: _jsx(Button, { variant: "outline", children: t('payments.cancel') }) }), _jsxs(Button, { type: "submit", className: "gap-2", onClick: () => onConfirm(refundAmount, refundLines, refundReason, 0, cancelShipping, 0), children: [_jsx(Undo2, { className: "h-4 w-4" }), t('cancelAndRefund.refund')] })] })] })] }));
|
|
29
|
+
};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { Card, CardContent, CardHeader, CardTitle, Table, TableBody, TableCell, TableHead, TableHeader, TableRow, Badge, ScrollArea, useOrder, formatPrice, useTranslation, } from '@deenruv/react-ui-devkit';
|
|
4
|
+
import { useCallback } from 'react';
|
|
5
|
+
import { ArrowRight, Plus, DollarSign, Package, Tag, FileText, Loader, Euro, Building, Pin, Component, } from 'lucide-react';
|
|
6
|
+
import { ChangesRegisterTable } from "./ChangesRegisterTable.js";
|
|
7
|
+
export const ChangesRegister = ({ changes }) => {
|
|
8
|
+
const { t } = useTranslation('orders');
|
|
9
|
+
const { order } = useOrder();
|
|
10
|
+
console.log('CH', changes);
|
|
11
|
+
const getFieldName = (path) => {
|
|
12
|
+
const fieldKey = path.split('.').pop() || '';
|
|
13
|
+
return t(`changes.keys.${fieldKey}`, fieldKey);
|
|
14
|
+
};
|
|
15
|
+
const PriceJSX = useCallback((value) => {
|
|
16
|
+
let icon;
|
|
17
|
+
switch (order?.currencyCode) {
|
|
18
|
+
case 'USD':
|
|
19
|
+
icon = _jsx(DollarSign, { className: "size-3.5" });
|
|
20
|
+
break;
|
|
21
|
+
case 'EUR':
|
|
22
|
+
icon = _jsx(Euro, { className: "size-3.5" });
|
|
23
|
+
break;
|
|
24
|
+
default:
|
|
25
|
+
icon = order?.currencyCode;
|
|
26
|
+
}
|
|
27
|
+
return (_jsxs("span", { className: "flex items-center gap-1", children: [icon, formatPrice(value)] }));
|
|
28
|
+
}, [order]);
|
|
29
|
+
if (!changes) {
|
|
30
|
+
return (_jsx(Card, { className: "border-muted", children: _jsxs(CardContent, { className: "flex flex-col items-center justify-center py-16 text-center", children: [_jsx("div", { className: "mb-4", children: _jsx(Loader, { className: "size-10 animate-spin text-orange-500" }) }), _jsx("h3", { className: "mb-2 text-xl font-medium", children: t('changes.loading.title') }), _jsx("p", { className: "text-muted-foreground max-w-md", children: t('changes.loading.description') })] }) }));
|
|
31
|
+
}
|
|
32
|
+
if (Object.values(Object.fromEntries(Object.entries(changes).filter(([key]) => key !== 'rest'))).every((item) => !item.length)) {
|
|
33
|
+
return (_jsxs(Card, { className: "border-l-4 border-l-gray-300 dark:border-l-gray-600", children: [_jsx(CardHeader, { children: _jsxs(CardTitle, { className: "flex items-center gap-2", children: [_jsx(FileText, { className: "size-5 text-gray-500" }), t('changes.emptyState.noChanges', 'No Changes')] }) }), _jsx(CardContent, { children: _jsx("p", { className: "text-muted-foreground", children: t('changes.emptyState.noChangesDescription', 'No modifications have been made to this order.') }) })] }));
|
|
34
|
+
}
|
|
35
|
+
return changes ? (_jsxs("div", { className: "space-y-6", children: [changes.existingLines.length > 0 && (_jsxs(Card, { className: "border-l-4 border-l-amber-500 shadow-sm dark:border-l-amber-400", children: [_jsx(CardHeader, { children: _jsxs(CardTitle, { className: "flex items-center gap-2", children: [_jsx(ArrowRight, { className: "size-5 text-amber-500 dark:text-amber-400" }), t('changes.existingLines', 'Changes to Existing Items')] }) }), _jsx(CardContent, { className: "space-y-6", children: changes.existingLines.map((change) => (_jsxs("div", { className: "rounded-md border p-4", children: [_jsxs("div", { className: "mb-3 flex flex-wrap items-center gap-2", children: [_jsx("h4", { className: "font-medium", children: change.variantName }), _jsx(Badge, { variant: "outline", className: "font-mono text-xs", children: change.lineID })] }), _jsx(ScrollArea, { children: _jsxs(Table, { children: [_jsx(TableHeader, { children: _jsxs(TableRow, { children: [_jsx(TableHead, { className: "w-1/3", children: t('changes.property', 'Property') }), _jsx(TableHead, { className: "w-1/3", children: t('changes.previous', 'Previous') }), _jsx(TableHead, { className: "w-1/3", children: t('changes.current', 'Current') })] }) }), _jsx(TableBody, { children: change.changes.map((propertyChange, index) => (_jsxs(TableRow, { children: [_jsx(TableCell, { className: "font-medium", children: getFieldName(propertyChange.path) }), _jsx(TableCell, { className: "text-red-600 dark:text-red-400", children: propertyChange.path.toLowerCase().includes('price')
|
|
36
|
+
? PriceJSX(propertyChange.removed)
|
|
37
|
+
: propertyChange.removed }), _jsx(TableCell, { className: "font-medium text-green-600 dark:text-green-400", children: propertyChange.path.toLowerCase().includes('price')
|
|
38
|
+
? PriceJSX(propertyChange.added)
|
|
39
|
+
: propertyChange.added })] }, index))) })] }) })] }, change.lineID))) })] })), changes.newLines.length > 0 && (_jsxs(Card, { className: "border-l-4 border-l-green-500 shadow-sm dark:border-l-green-400", children: [_jsx(CardHeader, { children: _jsxs(CardTitle, { className: "flex items-center gap-2", children: [_jsx(Plus, { className: "size-5 text-green-500 dark:text-green-400" }), t('changes.newLines', 'Newly Added Items')] }) }), _jsx(CardContent, { children: _jsx(ScrollArea, { className: "max-h-[300px]", children: _jsxs(Table, { children: [_jsx(TableHeader, { children: _jsxs(TableRow, { children: [_jsx(TableHead, { children: t('changes.product', 'Product') }), _jsx(TableHead, { children: t('changes.unitPrice', 'Unit Price') }), _jsx(TableHead, { children: t('changes.unitPriceWithTax', 'Unit Price (with Tax)') }), _jsx(TableHead, { children: t('changes.quantity', 'Quantity') }), _jsx(TableHead, { children: t('changes.total', 'Total') })] }) }), _jsx(TableBody, { children: changes.newLines
|
|
40
|
+
.flatMap((lineChange) => {
|
|
41
|
+
const brandNewLine = lineChange.changes.find((ch) => ch.changed === 'added' && ch.path === '');
|
|
42
|
+
const productChange = lineChange.changes.find((change) => typeof change.value === 'object' && change.value !== null && 'productVariant' in change.value);
|
|
43
|
+
if (!productChange || typeof productChange.value !== 'object') {
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
const item = productChange.value;
|
|
47
|
+
const variant = item.productVariant || {};
|
|
48
|
+
const quantityChange = lineChange.changes.find((change) => change.path.includes('quantity'));
|
|
49
|
+
const linePriceChange = lineChange.changes.find((change) => change.path.includes('linePrice') && !change.path.includes('WithTax'));
|
|
50
|
+
const linePriceWithTaxChange = lineChange.changes.find((change) => change.path.includes('linePriceWithTax'));
|
|
51
|
+
const quantity = quantityChange ? Number(quantityChange.added) : 1;
|
|
52
|
+
const linePrice = brandNewLine
|
|
53
|
+
? Number(brandNewLine.value.discountedLinePrice)
|
|
54
|
+
: linePriceChange
|
|
55
|
+
? Number(linePriceChange.added)
|
|
56
|
+
: 0;
|
|
57
|
+
const linePriceWithTax = brandNewLine
|
|
58
|
+
? Number(brandNewLine.value.discountedLinePriceWithTax)
|
|
59
|
+
: linePriceWithTaxChange
|
|
60
|
+
? Number(linePriceWithTaxChange.added)
|
|
61
|
+
: 0;
|
|
62
|
+
return (_jsxs(TableRow, { children: [_jsx(TableCell, { className: "font-medium", children: _jsxs("div", { className: "flex items-center gap-2", children: [_jsx(Package, { className: "size-4 text-green-500 dark:text-green-400" }), variant.name || lineChange.variantName || t('changes.unknownProduct', 'Unknown Product')] }) }), _jsx(TableCell, { children: PriceJSX(linePrice) }), _jsx(TableCell, { children: PriceJSX(linePriceWithTax) }), _jsx(TableCell, { className: "font-medium", children: quantity }), _jsx(TableCell, { className: "font-medium text-green-600 dark:text-green-400", children: PriceJSX(quantity * linePriceWithTax) })] }, lineChange.lineID));
|
|
63
|
+
})
|
|
64
|
+
.filter(Boolean) })] }) }) })] })), changes.surcharges.length > 0 && (_jsxs(Card, { className: "border-l-4 border-l-blue-500 shadow-sm dark:border-l-blue-400", children: [_jsx(CardHeader, { children: _jsxs(CardTitle, { className: "flex items-center gap-2", children: [_jsx(Plus, { className: "size-5 text-blue-500 dark:text-blue-400" }), t('changes.surcharges', 'Added Surcharges')] }) }), _jsx(CardContent, { children: _jsx(ScrollArea, { className: "max-h-[300px]", children: _jsxs(Table, { children: [_jsx(TableHeader, { children: _jsxs(TableRow, { children: [_jsx(TableHead, { children: t('changes.description', 'Description') }), _jsx(TableHead, { children: t('changes.sku', 'SKU') }), _jsx(TableHead, { children: t('changes.price', 'Price') }), _jsx(TableHead, { children: t('changes.priceWithTax', 'Price with Tax') })] }) }), _jsx(TableBody, { children: changes.surcharges.map((surcharge, index) => {
|
|
65
|
+
const item = (surcharge.value || {});
|
|
66
|
+
return (_jsxs(TableRow, { children: [_jsx(TableCell, { className: "font-medium", children: _jsxs("div", { className: "flex items-center gap-2", children: [_jsx(FileText, { className: "size-4 text-blue-500 dark:text-blue-400" }), String(item.description || '') || t('changes.unnamedSurcharge', 'Unnamed Surcharge')] }) }), _jsx(TableCell, { children: _jsxs("div", { className: "flex items-center gap-2", children: [_jsx(Tag, { className: "text-muted-foreground size-4" }), _jsx("code", { className: "bg-muted rounded px-1 py-0.5 font-mono text-xs", children: String(item.sku || '') || '—' })] }) }), _jsx(TableCell, { children: PriceJSX(Number(item.price)) }), _jsx(TableCell, { className: "font-medium text-blue-600 dark:text-blue-400", children: PriceJSX(Number(item.priceWithTax)) })] }, index));
|
|
67
|
+
}) })] }) }) })] })), changes.billingAddress.length > 0 && (_jsxs(Card, { className: "border-l-4 border-l-purple-500 shadow-sm dark:border-l-purple-400", children: [_jsx(CardHeader, { children: _jsxs(CardTitle, { className: "flex items-center gap-2", children: [_jsx(Building, { className: "size-5 text-purple-500 dark:text-purple-400" }), t('changes.billingAddress')] }) }), _jsx(CardContent, { children: _jsx(ChangesRegisterTable, { changes: changes.billingAddress }) })] })), changes.shippingAddress.length > 0 && (_jsxs(Card, { className: "border-l-4 border-l-indigo-500 shadow-sm dark:border-l-indigo-400", children: [_jsx(CardHeader, { children: _jsxs(CardTitle, { className: "flex items-center gap-2", children: [_jsx(Pin, { className: "size-5 text-indigo-500 dark:text-indigo-400" }), t('changes.shippingAddress')] }) }), _jsx(CardContent, { children: _jsx(ChangesRegisterTable, { changes: changes.shippingAddress }) })] })), changes.shippingMethod.length > 0 && (_jsxs(Card, { className: "border-l-4 border-l-orange-500 shadow-sm dark:border-l-orange-400", children: [_jsx(CardHeader, { children: _jsxs(CardTitle, { className: "flex items-center gap-2", children: [_jsx(Component, { className: "size-5 text-orange-500 dark:text-orange-400" }), t('changes.shippingMethod')] }) }), _jsx(CardContent, { children: _jsx(ChangesRegisterTable, { changes: changes.shippingMethod }) })] }))] })) : (_jsx(Card, { className: "border-muted", children: _jsxs(CardContent, { className: "flex flex-col items-center justify-center py-16 text-center", children: [_jsx("div", { className: "mb-4", children: _jsx(Loader, { className: "size-10 animate-spin text-orange-500" }) }), _jsx("h3", { className: "mb-2 text-xl font-medium", children: "Checking for Changes" }), _jsx("p", { className: "text-muted-foreground max-w-md", children: "Order changes are being checked. This may take a moment..." })] }) }));
|
|
68
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { ScrollArea, Table, TableBody, TableCell, TableHead, TableHeader, TableRow, useTranslation, } from '@deenruv/react-ui-devkit';
|
|
3
|
+
export const ChangesRegisterTable = ({ changes }) => {
|
|
4
|
+
const { t } = useTranslation('orders');
|
|
5
|
+
return (_jsx(ScrollArea, { children: _jsxs(Table, { children: [_jsx(TableHeader, { children: _jsxs(TableRow, { children: [_jsx(TableHead, { className: "w-1/3", children: t('changes.property', 'Property') }), _jsx(TableHead, { className: "w-1/3", children: t('changes.previous', 'Previous') }), _jsx(TableHead, { className: "w-1/3", children: t('changes.current', 'Current') })] }) }), _jsx(TableBody, { children: changes.map((change, index) => {
|
|
6
|
+
return (_jsxs(TableRow, { children: [change.changed === 'added', _jsx(TableCell, { className: "font-medium", children: _jsx("div", { className: "flex items-center gap-2", children: change.path.includes('Address')
|
|
7
|
+
? t(`changes.keys.${change.path.split('.').pop()}`)
|
|
8
|
+
: t(`changes.keys.${change.path}`) }) }), _jsx(TableCell, { className: "font-medium text-red-600 dark:text-red-400", children: _jsx("div", { className: "flex items-center gap-2", children: change.changed === 'added'
|
|
9
|
+
? '—'
|
|
10
|
+
: change.changed === 'removed'
|
|
11
|
+
? change.value
|
|
12
|
+
: change.removed }) }), _jsx(TableCell, { className: "font-medium text-green-600 dark:text-green-400", children: _jsx("div", { className: "flex items-center gap-2", children: change.changed === 'added'
|
|
13
|
+
? change.value
|
|
14
|
+
: change.changed === 'removed'
|
|
15
|
+
? '—'
|
|
16
|
+
: change.added }) })] }, index));
|
|
17
|
+
}) })] }) }));
|
|
18
|
+
};
|