@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,75 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useParams } from 'react-router-dom';
|
|
3
|
+
import { useValidators, createDeenruvForm, DetailView, useMutation, useTranslation, } from '@deenruv/react-ui-devkit';
|
|
4
|
+
import { CustomerDetailView } from "./_components/CustomerDetailView";
|
|
5
|
+
import { CustomerDetailSidebar } from "./_components/CustomerDetailSidebar";
|
|
6
|
+
import { OrdersTab } from "./_components/OrdersTab";
|
|
7
|
+
import { HistoryTab } from "./_components/HistoryTab";
|
|
8
|
+
import { $, Permission, scalars, typedGql } from '@deenruv/admin-types';
|
|
9
|
+
import { useMemo } from 'react';
|
|
10
|
+
const CreateCustomerMutation = typedGql('mutation', { scalars })({
|
|
11
|
+
createCustomer: [{ input: $('input', 'CreateCustomerInput!') }, { '...on Customer': { id: true } }],
|
|
12
|
+
});
|
|
13
|
+
const UpdateCustomerMutation = typedGql('mutation', { scalars })({
|
|
14
|
+
updateCustomer: [{ input: $('input', 'UpdateCustomerInput!') }, { '...on Customer': { id: true } }],
|
|
15
|
+
});
|
|
16
|
+
const RemoveCustomerMutation = typedGql('mutation', { scalars })({
|
|
17
|
+
deleteCustomer: [{ id: $('id', 'ID!') }, { result: true }],
|
|
18
|
+
});
|
|
19
|
+
export const CustomersDetailPage = () => {
|
|
20
|
+
const { id } = useParams();
|
|
21
|
+
const { t } = useTranslation('customers');
|
|
22
|
+
const [create] = useMutation(CreateCustomerMutation);
|
|
23
|
+
const [update] = useMutation(UpdateCustomerMutation);
|
|
24
|
+
const [remove] = useMutation(RemoveCustomerMutation);
|
|
25
|
+
const { stringValidator, emailValidator } = useValidators();
|
|
26
|
+
const defaultTabs = useMemo(() => {
|
|
27
|
+
const tabs = [];
|
|
28
|
+
if (id) {
|
|
29
|
+
tabs.push({ label: t('orders.header'), name: 'orders', component: _jsx(OrdersTab, {}), hideSidebar: true });
|
|
30
|
+
tabs.push({ label: t('history.header'), name: 'history', component: _jsx(HistoryTab, {}), hideSidebar: true });
|
|
31
|
+
}
|
|
32
|
+
return tabs;
|
|
33
|
+
}, [id]);
|
|
34
|
+
return (_jsx("div", { className: "relative flex flex-col gap-y-4", children: _jsx(DetailView, { id: id, locationId: "customers-detail-view", main: {
|
|
35
|
+
name: 'customer',
|
|
36
|
+
label: t('customer'),
|
|
37
|
+
component: _jsx(CustomerDetailView, {}),
|
|
38
|
+
sidebar: _jsx(CustomerDetailSidebar, {}),
|
|
39
|
+
form: createDeenruvForm({
|
|
40
|
+
key: 'CreateCustomerInput',
|
|
41
|
+
keys: ['title', 'phoneNumber', 'firstName', 'lastName', 'emailAddress', 'customFields'],
|
|
42
|
+
config: {
|
|
43
|
+
firstName: stringValidator(t('validation.firstNameRequired')),
|
|
44
|
+
lastName: stringValidator(t('validation.lastNameRequired')),
|
|
45
|
+
emailAddress: emailValidator,
|
|
46
|
+
},
|
|
47
|
+
onSubmitted: (data) => {
|
|
48
|
+
const sharedInput = {
|
|
49
|
+
emailAddress: data.emailAddress?.validatedValue,
|
|
50
|
+
firstName: data.firstName?.validatedValue,
|
|
51
|
+
lastName: data.lastName?.validatedValue,
|
|
52
|
+
phoneNumber: data.phoneNumber?.validatedValue,
|
|
53
|
+
title: data.title?.validatedValue,
|
|
54
|
+
...('customFields' in data && data.customFields?.validatedValue
|
|
55
|
+
? { customFields: data.customFields.validatedValue }
|
|
56
|
+
: {}),
|
|
57
|
+
};
|
|
58
|
+
if (!sharedInput.emailAddress || !sharedInput.firstName || !sharedInput.lastName)
|
|
59
|
+
return;
|
|
60
|
+
const input = sharedInput;
|
|
61
|
+
return id ? update({ input: { id, ...input } }) : create({ input });
|
|
62
|
+
},
|
|
63
|
+
onDeleted: () => {
|
|
64
|
+
if (id)
|
|
65
|
+
return remove({ id });
|
|
66
|
+
else
|
|
67
|
+
throw new Error('No id');
|
|
68
|
+
},
|
|
69
|
+
}),
|
|
70
|
+
}, defaultTabs: defaultTabs, permissions: {
|
|
71
|
+
create: Permission.CreateCustomer,
|
|
72
|
+
edit: Permission.UpdateCustomer,
|
|
73
|
+
delete: Permission.DeleteCustomer,
|
|
74
|
+
} }) }));
|
|
75
|
+
};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Permission, SortOrder } from '@deenruv/admin-types';
|
|
3
|
+
import { apiClient, deepMerge, DetailList, Routes, BooleanCell, TableLabel, ListBadge, ListLocations, useTranslation, EntityChannelManagementBulkAction, } from '@deenruv/react-ui-devkit';
|
|
4
|
+
const tableId = 'customers-list-view';
|
|
5
|
+
const { selector } = ListLocations[tableId];
|
|
6
|
+
const fetch = async ({ page, perPage, filter, filterOperator, sort }, additionalSelector) => {
|
|
7
|
+
const response = await apiClient('query')({
|
|
8
|
+
customers: [
|
|
9
|
+
{
|
|
10
|
+
options: {
|
|
11
|
+
take: perPage,
|
|
12
|
+
skip: (page - 1) * perPage,
|
|
13
|
+
filterOperator: filterOperator,
|
|
14
|
+
sort: sort ? { [sort.key]: sort.sortDir } : { createdAt: SortOrder.DESC },
|
|
15
|
+
...(filter && { filter }),
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
{ items: deepMerge(selector, additionalSelector ?? {}), totalItems: true },
|
|
19
|
+
],
|
|
20
|
+
});
|
|
21
|
+
return response['customers'];
|
|
22
|
+
};
|
|
23
|
+
const onRemove = async (items) => {
|
|
24
|
+
try {
|
|
25
|
+
const ids = items.map((item) => item.id);
|
|
26
|
+
const { deleteCustomers } = await apiClient('mutation')({
|
|
27
|
+
deleteCustomers: [{ ids }, { message: true, result: true }],
|
|
28
|
+
});
|
|
29
|
+
return !!deleteCustomers.length;
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
return error;
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
export const CustomersListPage = () => {
|
|
36
|
+
const { t } = useTranslation('table');
|
|
37
|
+
return (_jsx(DetailList, { detailLinkColumn: "id", filterFields: [
|
|
38
|
+
{ key: 'phoneNumber', operator: 'StringOperators' },
|
|
39
|
+
{ key: 'emailAddress', operator: 'StringOperators' },
|
|
40
|
+
{ key: 'firstName', operator: 'StringOperators' },
|
|
41
|
+
{ key: 'lastName', operator: 'StringOperators' },
|
|
42
|
+
{ key: 'postalCode', operator: 'StringOperators' },
|
|
43
|
+
{ key: 'title', operator: 'StringOperators' },
|
|
44
|
+
], searchFields: ['firstName', 'lastName', 'emailAddress', 'postalCode'], hideColumns: ['customFields', 'user', 'title'], additionalBulkActions: [...EntityChannelManagementBulkAction(tableId)], additionalColumns: [
|
|
45
|
+
{
|
|
46
|
+
id: 'verified',
|
|
47
|
+
accessorKey: 'verified',
|
|
48
|
+
header: () => _jsx(TableLabel, { children: t('columns.verified') }),
|
|
49
|
+
cell: ({ row }) => _jsx(BooleanCell, { value: !!row.original.user?.verified }),
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
id: 'fullName',
|
|
53
|
+
accessorKey: 'fullName',
|
|
54
|
+
header: () => _jsx(TableLabel, { children: t('columns.fullName') }),
|
|
55
|
+
cell: ({ row }) => {
|
|
56
|
+
return _jsx(ListBadge, { children: `${row.original.firstName} ${row.original.lastName}` });
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
], entityName: 'Customer', route: Routes['customers'], tableId: tableId, fetch: fetch, onRemove: onRemove, createPermissions: [Permission.CreateCustomer], deletePermissions: [Permission.DeleteCustomer] }));
|
|
60
|
+
};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Card, CardContent, CardFooter, Button, DropdownMenu, DropdownMenuTrigger, DropdownMenuContent, DropdownMenuItem, DropdownMenuSeparator, useMutation, Tooltip, TooltipTrigger, TooltipContent, useTranslation, } from '@deenruv/react-ui-devkit';
|
|
3
|
+
import { AddressDialog } from "./AddressDialog";
|
|
4
|
+
import { CreditCard, MoreHorizontal, Trash, Truck } from 'lucide-react';
|
|
5
|
+
import { typedGql, scalars, $ } from '@deenruv/admin-types';
|
|
6
|
+
import { toast } from 'sonner';
|
|
7
|
+
const DeleteCustomerAddressMutation = typedGql('mutation', { scalars })({
|
|
8
|
+
deleteCustomerAddress: [{ id: $('addressId', 'ID!') }, { success: true }],
|
|
9
|
+
});
|
|
10
|
+
const SetAsDefaultBillingAddressMutation = typedGql('mutation', { scalars })({
|
|
11
|
+
updateCustomerAddress: [
|
|
12
|
+
{
|
|
13
|
+
input: {
|
|
14
|
+
id: $('addressId', 'ID!'),
|
|
15
|
+
defaultBillingAddress: true,
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
{ id: true },
|
|
19
|
+
],
|
|
20
|
+
});
|
|
21
|
+
const SetAsDefaultShippingAddressMutation = typedGql('mutation', { scalars })({
|
|
22
|
+
updateCustomerAddress: [
|
|
23
|
+
{
|
|
24
|
+
input: {
|
|
25
|
+
id: $('addressId', 'ID!'),
|
|
26
|
+
defaultShippingAddress: true,
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
{ id: true },
|
|
30
|
+
],
|
|
31
|
+
});
|
|
32
|
+
export const Address = ({ address, customerId, onActionCompleted }) => {
|
|
33
|
+
const { t } = useTranslation('customers');
|
|
34
|
+
const [deleteAddress] = useMutation(DeleteCustomerAddressMutation);
|
|
35
|
+
const [setAsDefaultBillingAddress] = useMutation(SetAsDefaultBillingAddressMutation);
|
|
36
|
+
const [setAsDefaultShippingAddress] = useMutation(SetAsDefaultShippingAddressMutation);
|
|
37
|
+
return (_jsxs(Card, { className: "bg-secondary text-primary flex w-56 flex-col justify-between", children: [_jsxs(CardContent, { className: "mt-4 flex flex-col gap-1", children: [_jsx("h5", { className: "mb-2", children: address.streetLine1 }), _jsx("span", { className: "block text-sm", children: address?.fullName }), _jsxs("span", { className: "block text-sm", children: [address.streetLine1, " ", address?.streetLine2] }), _jsxs("span", { className: "block text-sm", children: [address.city, " ", address.postalCode, " ", address.province, " ", address.country.code] }), _jsxs("span", { className: "block text-sm", children: [address.company, " ", address.phoneNumber && t('addresses.phoneNumberShort', { value: address.phoneNumber })] })] }), _jsxs(CardFooter, { className: "justify-between", children: [_jsxs("div", { className: "flex items-center gap-3", children: [address.defaultBillingAddress && (_jsxs(Tooltip, { children: [_jsx(TooltipTrigger, { children: _jsx(CreditCard, { size: 20 }) }), _jsx(TooltipContent, { children: t('selectAddress.defaultBilling') })] })), address.defaultShippingAddress && (_jsxs(Tooltip, { children: [_jsx(TooltipTrigger, { children: _jsx(Truck, { size: 20 }) }), _jsx(TooltipContent, { children: t('selectAddress.defaultShipping') })] }))] }), _jsxs("div", { className: "flex items-center", children: [_jsx(AddressDialog, { address: address, customerId: customerId, onActionCompleted: onActionCompleted, children: _jsx(Button, { variant: "outline", className: "h-8 px-8", children: t('addresses.edit') }) }), _jsxs(DropdownMenu, { children: [_jsx(DropdownMenuTrigger, { asChild: true, children: _jsxs(Button, { variant: "outline", className: "size-8 p-0", children: [_jsx("span", { className: "sr-only", children: t('selectAddress.more') }), _jsx(MoreHorizontal, { className: "size-4" })] }) }), _jsxs(DropdownMenuContent, { align: "end", children: [_jsxs(DropdownMenuItem, { className: "flex items-center gap-2", disabled: address.defaultBillingAddress ?? undefined, onClick: () => setAsDefaultBillingAddress({ addressId: address.id }).then((resp) => {
|
|
38
|
+
if (resp.updateCustomerAddress.id) {
|
|
39
|
+
toast.success(t('selectAddress.addressSuccessSetAsDefaultBillingToast'));
|
|
40
|
+
onActionCompleted();
|
|
41
|
+
}
|
|
42
|
+
else
|
|
43
|
+
toast.error(t('selectAddress.addressFailedSetAsDefaultToast'));
|
|
44
|
+
}), children: [_jsx(CreditCard, { size: 16 }), t('selectAddress.setAsDefaultBilling')] }), _jsxs(DropdownMenuItem, { className: "flex items-center gap-2", disabled: address.defaultShippingAddress ?? undefined, onClick: () => setAsDefaultShippingAddress({ addressId: address.id }).then((resp) => {
|
|
45
|
+
if (resp.updateCustomerAddress.id) {
|
|
46
|
+
toast.success(t('selectAddress.addressSuccessSetAsDefaultShippingToast'));
|
|
47
|
+
onActionCompleted();
|
|
48
|
+
}
|
|
49
|
+
else
|
|
50
|
+
toast.error(t('selectAddress.addressFailedSetAsDefaultToast'));
|
|
51
|
+
}), children: [_jsx(Truck, { size: 16 }), t('selectAddress.setAsDefaultShipping')] }), _jsx(DropdownMenuSeparator, {}), _jsx(DropdownMenuItem, { onClick: () => deleteAddress({ addressId: address.id }).then((resp) => {
|
|
52
|
+
if (resp.deleteCustomerAddress.success) {
|
|
53
|
+
toast.success(t('selectAddress.addressSuccessDeleteToast'));
|
|
54
|
+
onActionCompleted();
|
|
55
|
+
}
|
|
56
|
+
else
|
|
57
|
+
toast.error(t('selectAddress.addressFailedDeleteToast'));
|
|
58
|
+
}), children: _jsxs("div", { className: "flex items-center gap-2 text-red-400 hover:text-red-400 dark:hover:text-red-400", children: [_jsx(Trash, { size: 16 }), t('selectAddress.deleteAddress')] }) })] })] })] })] })] }));
|
|
59
|
+
};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useCallback, useMemo, useRef, useState } from 'react';
|
|
3
|
+
import { Button, Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle, DialogTrigger, useMutation, useTranslation, } from '@deenruv/react-ui-devkit';
|
|
4
|
+
import { typedGql, scalars, $ } from '@deenruv/admin-types';
|
|
5
|
+
import { toast } from 'sonner';
|
|
6
|
+
import { AddressForm } from "./AddressForm.js";
|
|
7
|
+
import { addressBaseSelector } from "../../../graphql/draft_order.js";
|
|
8
|
+
export const CreateCustomerAddressMutation = typedGql('mutation', { scalars })({
|
|
9
|
+
createCustomerAddress: [
|
|
10
|
+
{ customerId: $('customerId', 'ID!'), input: $('input', 'CreateAddressInput!') },
|
|
11
|
+
{
|
|
12
|
+
id: true,
|
|
13
|
+
...addressBaseSelector,
|
|
14
|
+
},
|
|
15
|
+
],
|
|
16
|
+
});
|
|
17
|
+
export const UpdateCustomerAddressMutation = typedGql('mutation', { scalars })({
|
|
18
|
+
updateCustomerAddress: [{ input: $('input', 'UpdateAddressInput!') }, { id: true }],
|
|
19
|
+
});
|
|
20
|
+
export const AddressDialog = ({ address, customerId, onActionCompleted, children, }) => {
|
|
21
|
+
const formRef = useRef(null);
|
|
22
|
+
const [createAddress] = useMutation(CreateCustomerAddressMutation);
|
|
23
|
+
const [updateAddress] = useMutation(UpdateCustomerAddressMutation);
|
|
24
|
+
const { t } = useTranslation('customers');
|
|
25
|
+
const [open, setOpen] = useState(false);
|
|
26
|
+
const isEdit = useMemo(() => !!address, [address]);
|
|
27
|
+
const [input, setInput] = useState();
|
|
28
|
+
const handleSubmit = useCallback(async () => {
|
|
29
|
+
if (!input)
|
|
30
|
+
return;
|
|
31
|
+
const isValid = formRef.current?.validate();
|
|
32
|
+
console.log('VALID', isValid);
|
|
33
|
+
if (!isValid)
|
|
34
|
+
return;
|
|
35
|
+
isEdit
|
|
36
|
+
? await updateAddress({ input: { ...input, id: address?.id } }).then((resp) => {
|
|
37
|
+
if (resp.updateCustomerAddress.id) {
|
|
38
|
+
setOpen(false);
|
|
39
|
+
toast.success(t('selectAddress.addressSuccessUpdateToast'));
|
|
40
|
+
onActionCompleted();
|
|
41
|
+
}
|
|
42
|
+
else
|
|
43
|
+
toast.error(t('selectAddress.addressFailedUpdateToast'));
|
|
44
|
+
})
|
|
45
|
+
: await createAddress({ customerId, input }).then((resp) => {
|
|
46
|
+
if (resp.createCustomerAddress.id) {
|
|
47
|
+
setOpen(false);
|
|
48
|
+
toast.success(t('selectAddress.addressSuccessCreateToast'));
|
|
49
|
+
onActionCompleted();
|
|
50
|
+
}
|
|
51
|
+
else
|
|
52
|
+
toast.error(t('selectAddress.addressFailedCreateToast'));
|
|
53
|
+
});
|
|
54
|
+
}, [input, isEdit, customerId]);
|
|
55
|
+
return (_jsxs(Dialog, { open: open, onOpenChange: setOpen, children: [_jsx(DialogTrigger, { asChild: true, children: children }), _jsxs(DialogContent, { className: "flex max-h-[80vh] flex-col", children: [_jsx(DialogHeader, { className: "mb-4", children: _jsx(DialogTitle, { children: t(isEdit ? 'selectAddress.editAddress' : 'selectAddress.createAddress') }) }), _jsx(AddressForm, { ref: formRef, initialValues: address, onInputChange: setInput, addressId: address?.id }), _jsxs(DialogFooter, { className: "mt-2", children: [_jsx(Button, { className: "w-min place-self-end", onClick: handleSubmit, children: t('addresses.save') }), _jsx(Button, { className: "w-min place-self-end", onClick: () => setOpen(false), children: t('addresses.cancel') })] })] })] }));
|
|
56
|
+
};
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef, useEffect, useImperativeHandle } from 'react';
|
|
3
|
+
import { Input, SimpleSelect, useGFFLP, useServer, EntityCustomFields, useTranslation, } from '@deenruv/react-ui-devkit';
|
|
4
|
+
export const AddressForm = forwardRef(({ initialValues: address, addressId, onInputChange }, ref) => {
|
|
5
|
+
const { t } = useTranslation('customers');
|
|
6
|
+
const countries = useServer((p) => p.countries);
|
|
7
|
+
const { state, setField, checkIfAllFieldsAreValid } = useGFFLP('CreateAddressInput', 'city', 'company', 'countryCode', 'fullName', 'phoneNumber', 'postalCode', 'streetLine1', 'streetLine2', 'province', 'customFields')({
|
|
8
|
+
fullName: {
|
|
9
|
+
initialValue: address?.fullName,
|
|
10
|
+
validate: (v) => {
|
|
11
|
+
if (!v || v === '')
|
|
12
|
+
return [t('selectAddress.nameRequired')];
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
company: { initialValue: address?.company },
|
|
16
|
+
streetLine1: {
|
|
17
|
+
initialValue: address?.streetLine1,
|
|
18
|
+
validate: (v) => {
|
|
19
|
+
if (!v || v === '')
|
|
20
|
+
return [t('selectAddress.streetRequired')];
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
streetLine2: { initialValue: address?.streetLine2 },
|
|
24
|
+
postalCode: {
|
|
25
|
+
initialValue: address?.postalCode,
|
|
26
|
+
validate: (v) => {
|
|
27
|
+
if (!v || v === '')
|
|
28
|
+
return [t('selectAddress.postalCodeRequired')];
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
countryCode: {
|
|
32
|
+
initialValue: address?.country.code,
|
|
33
|
+
validate: (v) => {
|
|
34
|
+
if (!v || v === '')
|
|
35
|
+
return [t('selectAddress.countryRequired')];
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
phoneNumber: {
|
|
39
|
+
initialValue: address?.phoneNumber,
|
|
40
|
+
validate: (v) => {
|
|
41
|
+
if (!v || v === '')
|
|
42
|
+
return [t('selectAddress.phoneNumberRequired')];
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
city: {
|
|
46
|
+
initialValue: address?.city,
|
|
47
|
+
validate: (v) => {
|
|
48
|
+
if (!v || v === '')
|
|
49
|
+
return [t('selectAddress.cityRequired')];
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
province: { initialValue: address?.province },
|
|
53
|
+
});
|
|
54
|
+
useImperativeHandle(ref, () => ({
|
|
55
|
+
validate: checkIfAllFieldsAreValid,
|
|
56
|
+
}));
|
|
57
|
+
useEffect(() => {
|
|
58
|
+
const input = {
|
|
59
|
+
countryCode: state.countryCode.validatedValue,
|
|
60
|
+
streetLine1: state.streetLine1.validatedValue,
|
|
61
|
+
streetLine2: state.streetLine2.validatedValue,
|
|
62
|
+
city: state.city.validatedValue,
|
|
63
|
+
company: state.company.validatedValue,
|
|
64
|
+
fullName: state.fullName.validatedValue,
|
|
65
|
+
phoneNumber: state.phoneNumber.validatedValue,
|
|
66
|
+
postalCode: state.postalCode.validatedValue,
|
|
67
|
+
province: state.province?.validatedValue,
|
|
68
|
+
...(state.customFields?.validatedValue ? { customFields: state.customFields?.validatedValue } : {}),
|
|
69
|
+
};
|
|
70
|
+
onInputChange(input);
|
|
71
|
+
}, [state]);
|
|
72
|
+
return (_jsxs("form", { className: "flex flex-col gap-3 overflow-auto", children: [_jsx(Input, { label: t('selectAddress.inputNameLabel'), placeholder: t('selectAddress.inputNamePlaceholder'), value: state.fullName?.value ?? undefined, defaultValue: state?.fullName?.value ?? undefined, onChange: (e) => setField('fullName', e.target.value), errors: state.fullName?.errors, required: true }), _jsx(Input, { label: t('selectAddress.inputCompanyLabel'), placeholder: t('selectAddress.inputCompanyPlaceholder'), value: state.company?.value ?? undefined, defaultValue: state?.company?.value ?? undefined, onChange: (e) => setField('company', e.target.value), errors: state.company?.errors }), _jsx(Input, { label: t('selectAddress.inputStreetLabel'), placeholder: t('selectAddress.inputStreetPlaceholder'), value: state.streetLine1?.value, defaultValue: state?.streetLine1?.value, onChange: (e) => setField('streetLine1', e.target.value), errors: state.streetLine1?.errors, required: true }), _jsx(Input, { label: t('selectAddress.inputStreet2Label'), placeholder: t('selectAddress.inputStreet2Placeholder'), value: state.streetLine2?.value ?? undefined, defaultValue: state?.streetLine2?.value ?? undefined, onChange: (e) => setField('streetLine2', e.target.value), errors: state.streetLine2?.errors }), _jsx(Input, { label: t('selectAddress.inputCityLabel'), placeholder: t('selectAddress.inputCityPlaceholder'), defaultValue: state?.city?.value ?? undefined, onChange: (e) => setField('city', e.target.value), errors: state.city?.errors, required: true }), _jsx(Input, { label: t('selectAddress.inputProvinceLabel'), placeholder: t('selectAddress.inputProvincePlaceholder'), defaultValue: state?.province?.value ?? undefined, onChange: (e) => setField('province', e.target.value), errors: state.province?.errors }), _jsx(Input, { label: t('selectAddress.inputPostalLabel'), placeholder: t('selectAddress.inputPostalPlaceholder'), value: state.postalCode?.value ?? undefined, defaultValue: state?.postalCode?.value ?? undefined, onChange: (e) => setField('postalCode', e.target.value), errors: state.postalCode?.errors, required: true }), _jsx(Input, { label: t('selectAddress.inputPhoneLabel'), placeholder: t('selectAddress.inputPhonePlaceholder'), value: state.phoneNumber?.value ?? undefined, defaultValue: state?.phoneNumber?.value ?? undefined, onChange: (e) => setField('phoneNumber', e.target.value), errors: state.phoneNumber?.errors, required: true }), _jsx(SimpleSelect, { label: t('selectAddress.countrySelectLabel'), options: countries.map((c) => ({ label: c.name, value: c.code })), value: state.countryCode?.value, onValueChange: (value) => setField('countryCode', value), errors: state.countryCode?.errors, required: true }), addressId && (_jsx(EntityCustomFields, { id: addressId, entityName: "address", hideButton: true, initialValues: address && 'customFields' in address
|
|
73
|
+
? { customFields: address.customFields }
|
|
74
|
+
: { customFields: {} }, onChange: (cf) => {
|
|
75
|
+
setField('customFields', cf);
|
|
76
|
+
}, additionalData: {}, withoutBorder: true }))] }));
|
|
77
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Button, CardIcons, CustomCard, useTranslation } from '@deenruv/react-ui-devkit';
|
|
3
|
+
import { Address } from "./Address";
|
|
4
|
+
import { PlusCircle } from 'lucide-react';
|
|
5
|
+
import { AddressDialog } from "./AddressDialog";
|
|
6
|
+
export const AddressesCard = ({ addresses, customerId, onActionCompleted }) => {
|
|
7
|
+
const { t } = useTranslation('customers');
|
|
8
|
+
return (_jsx(CustomCard, { title: t('addresses.header'), icon: _jsx(CardIcons.address, {}), color: "green", bottomRight: customerId && (_jsx(AddressDialog, { customerId: customerId, onActionCompleted: onActionCompleted, children: _jsxs(Button, { variant: "secondary", className: "flex items-center gap-2", children: [_jsx(PlusCircle, {}), t('addresses.addBtn')] }) })), children: _jsx("div", { className: "flex gap-4", children: addresses?.length ? (addresses?.map((a) => _jsx(Address, { onActionCompleted: onActionCompleted, address: a, customerId: customerId }))) : (_jsx("p", { className: "w-full text-center", children: t(customerId ? 'addresses.empty' : 'addresses.createCustomerFirst') })) }) }));
|
|
9
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useDetailView } from '@deenruv/react-ui-devkit';
|
|
3
|
+
import { VerifiedCard } from "./VerifiedCard";
|
|
4
|
+
import { CustomerGroupsCard } from "./CustomerGroupsCard";
|
|
5
|
+
const CUSTOMER_FORM_KEYS = ['CreateCustomerInput'];
|
|
6
|
+
export const CustomerDetailSidebar = () => {
|
|
7
|
+
const { id, entity } = useDetailView('customers-detail-view', ...CUSTOMER_FORM_KEYS);
|
|
8
|
+
return (_jsx("main", { className: "min-h-96", children: _jsxs("div", { className: "flex flex-col gap-3", children: [id && _jsx(VerifiedCard, { verified: !!entity?.user?.verified }), _jsx(CustomerGroupsCard, { customerId: id, groups: entity?.groups })] }) }));
|
|
9
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useCallback, useEffect, useState } from 'react';
|
|
3
|
+
import { EntityCustomFields, useSettings, useDetailView, DetailViewMarker, } from '@deenruv/react-ui-devkit';
|
|
4
|
+
import { PersonalDataCard } from "./PersonalDataCard";
|
|
5
|
+
import { AddressesCard } from "./AddressesCard";
|
|
6
|
+
const CUSTOMER_FORM_KEYS = [
|
|
7
|
+
'CreateCustomerInput',
|
|
8
|
+
'title',
|
|
9
|
+
'phoneNumber',
|
|
10
|
+
'firstName',
|
|
11
|
+
'lastName',
|
|
12
|
+
'emailAddress',
|
|
13
|
+
'customFields',
|
|
14
|
+
];
|
|
15
|
+
export const CustomerDetailView = () => {
|
|
16
|
+
const [addresses, setAddresses] = useState([]);
|
|
17
|
+
const contentLng = useSettings((p) => p.translationsLanguage);
|
|
18
|
+
const { form, entity, id, fetchEntity } = useDetailView('customers-detail-view', ...CUSTOMER_FORM_KEYS);
|
|
19
|
+
const { base: { setField, state }, } = form;
|
|
20
|
+
const handleFetchEntity = useCallback(async () => {
|
|
21
|
+
const res = await fetchEntity();
|
|
22
|
+
if (!res)
|
|
23
|
+
return;
|
|
24
|
+
setField('title', res.title);
|
|
25
|
+
setField('phoneNumber', res.phoneNumber);
|
|
26
|
+
setField('firstName', res.firstName);
|
|
27
|
+
setField('lastName', res.lastName);
|
|
28
|
+
setField('emailAddress', res.emailAddress);
|
|
29
|
+
if ('customFields' in res)
|
|
30
|
+
setField('customFields', res.customFields);
|
|
31
|
+
setAddresses(res.addresses);
|
|
32
|
+
}, []);
|
|
33
|
+
useEffect(() => {
|
|
34
|
+
(async () => {
|
|
35
|
+
await handleFetchEntity();
|
|
36
|
+
})();
|
|
37
|
+
}, [contentLng]);
|
|
38
|
+
return (_jsx("main", { className: "min-h-96", children: _jsxs("div", { className: "flex flex-col gap-3", children: [_jsx(PersonalDataCard, { setField: setField, state: state }), _jsx(DetailViewMarker, { position: 'customers-detail-view' }), _jsx(EntityCustomFields, { entityName: "customer", id: id, hideButton: true, additionalData: {}, initialValues: entity && 'customFields' in entity ? { customFields: entity.customFields } : { customFields: {} }, onChange: (cf) => {
|
|
39
|
+
setField('customFields', cf);
|
|
40
|
+
} }), id && _jsx(AddressesCard, { addresses: addresses, customerId: id, onActionCompleted: handleFetchEntity })] }) }));
|
|
41
|
+
};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useCallback, useMemo, useState } from 'react';
|
|
3
|
+
import { CardIcons, CustomCard, MultipleSelector, useMutation, useQuery, useTranslation, } from '@deenruv/react-ui-devkit';
|
|
4
|
+
import { typedGql, scalars, $ } from '@deenruv/admin-types';
|
|
5
|
+
import { toast } from 'sonner';
|
|
6
|
+
const CustomerGroupsQuery = typedGql('query', { scalars })({
|
|
7
|
+
customerGroups: [{}, { items: { id: true, name: true } }],
|
|
8
|
+
});
|
|
9
|
+
const AddCustomerToGroupMutation = typedGql('mutation', { scalars })({
|
|
10
|
+
addCustomersToGroup: [
|
|
11
|
+
{ customerGroupId: $('groupId', 'ID!'), customerIds: $('customerIds', '[ID!]!') },
|
|
12
|
+
{ id: true },
|
|
13
|
+
],
|
|
14
|
+
});
|
|
15
|
+
const RemoveCustomerFromGroupMutation = typedGql('mutation', { scalars })({
|
|
16
|
+
removeCustomersFromGroup: [
|
|
17
|
+
{ customerGroupId: $('groupId', 'ID!'), customerIds: $('customerIds', '[ID!]!') },
|
|
18
|
+
{ id: true },
|
|
19
|
+
],
|
|
20
|
+
});
|
|
21
|
+
const mapToOptions = (groups) => groups.map((g) => ({ value: g.id, label: g.name }));
|
|
22
|
+
export const CustomerGroupsCard = ({ groups, customerId }) => {
|
|
23
|
+
const { t } = useTranslation('customers');
|
|
24
|
+
const { data } = useQuery(CustomerGroupsQuery);
|
|
25
|
+
const [addToGroup] = useMutation(AddCustomerToGroupMutation);
|
|
26
|
+
const [removeFromGroup] = useMutation(RemoveCustomerFromGroupMutation);
|
|
27
|
+
const [value, setValue] = useState(mapToOptions(groups || []));
|
|
28
|
+
const options = useMemo(() => mapToOptions(data?.customerGroups.items || []), [data]);
|
|
29
|
+
const handleChange = useCallback((newValue) => {
|
|
30
|
+
if (!customerId)
|
|
31
|
+
return;
|
|
32
|
+
const added = newValue.find((item) => !value.includes(item));
|
|
33
|
+
const removed = value.find((item) => !newValue.includes(item));
|
|
34
|
+
if (added)
|
|
35
|
+
addToGroup({ customerIds: [customerId], groupId: added.value }).then(() => {
|
|
36
|
+
setValue((prev) => [...prev, added]);
|
|
37
|
+
toast.success(t('customerGroups.toastAdded'));
|
|
38
|
+
});
|
|
39
|
+
else if (removed)
|
|
40
|
+
removeFromGroup({ customerIds: [customerId], groupId: removed.value }).then(() => {
|
|
41
|
+
setValue((prev) => prev.filter((i) => i.value !== removed.value));
|
|
42
|
+
toast.success(t('customerGroups.toastRemoved'));
|
|
43
|
+
});
|
|
44
|
+
}, [value]);
|
|
45
|
+
return (_jsx(CustomCard, { title: t('customerGroups.header'), icon: _jsx(CardIcons.users, {}), color: "gray", children: _jsx("div", { className: "flex flex-col gap-4", children: customerId ? (_jsx("div", { className: "flex gap-2", children: _jsx(MultipleSelector, { options: options, value: value, placeholder: t('customerGroups.placeholder'), onChange: handleChange, hideClearAllButton: true, className: "h-24" }) })) : (_jsx("p", { children: t('customerGroups.createCustomerFirst') })) }) }));
|
|
46
|
+
};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useCallback, useEffect } from 'react';
|
|
3
|
+
import { CardIcons, CustomCard, HistorySelector, useDetailView, useLazyQuery, useMutation, useSettings, useTranslation, } from '@deenruv/react-ui-devkit';
|
|
4
|
+
import { History } from "../../../components";
|
|
5
|
+
import { typedGql, scalars, $ } from '@deenruv/admin-types';
|
|
6
|
+
import { toast } from 'sonner';
|
|
7
|
+
const CUSTOMER_FORM_KEYS = ['CreateCustomerInput'];
|
|
8
|
+
const CustomerGroupsQuery = typedGql('query', { scalars })({
|
|
9
|
+
customer: [{ id: $('id', 'ID!') }, { history: [{}, HistorySelector] }],
|
|
10
|
+
});
|
|
11
|
+
const AddNoteToCustomerMutation = typedGql('mutation', { scalars })({
|
|
12
|
+
addNoteToCustomer: [
|
|
13
|
+
{
|
|
14
|
+
input: $('input', 'AddNoteToCustomerInput!'),
|
|
15
|
+
},
|
|
16
|
+
{ id: true },
|
|
17
|
+
],
|
|
18
|
+
});
|
|
19
|
+
const EditCustomerNoteMutation = typedGql('mutation', { scalars })({
|
|
20
|
+
updateCustomerNote: [
|
|
21
|
+
{
|
|
22
|
+
input: $('input', 'UpdateCustomerNoteInput!'),
|
|
23
|
+
},
|
|
24
|
+
{ id: true },
|
|
25
|
+
],
|
|
26
|
+
});
|
|
27
|
+
const DeleteStockLocationMutation = typedGql('mutation', { scalars })({
|
|
28
|
+
deleteCustomerNote: [
|
|
29
|
+
{
|
|
30
|
+
id: $('id', 'ID!'),
|
|
31
|
+
},
|
|
32
|
+
{ message: true, result: true },
|
|
33
|
+
],
|
|
34
|
+
});
|
|
35
|
+
export const HistoryTab = () => {
|
|
36
|
+
const { t } = useTranslation('customers');
|
|
37
|
+
const [getHistory, { data, loading }] = useLazyQuery(CustomerGroupsQuery);
|
|
38
|
+
const contentLng = useSettings((p) => p.translationsLanguage);
|
|
39
|
+
const { id, setLoading } = useDetailView('customers-detail-view', ...CUSTOMER_FORM_KEYS);
|
|
40
|
+
useEffect(() => {
|
|
41
|
+
setLoading(loading);
|
|
42
|
+
}, [loading]);
|
|
43
|
+
useEffect(() => {
|
|
44
|
+
if (id)
|
|
45
|
+
getHistory({ id });
|
|
46
|
+
}, [id, contentLng]);
|
|
47
|
+
const [edit] = useMutation(EditCustomerNoteMutation);
|
|
48
|
+
const [add] = useMutation(AddNoteToCustomerMutation);
|
|
49
|
+
const [remove] = useMutation(DeleteStockLocationMutation);
|
|
50
|
+
const handle = useCallback((method) => {
|
|
51
|
+
method
|
|
52
|
+
.then(() => {
|
|
53
|
+
toast.success(t('history.toastSuccess'));
|
|
54
|
+
if (id)
|
|
55
|
+
getHistory({ id });
|
|
56
|
+
})
|
|
57
|
+
.catch(() => {
|
|
58
|
+
toast.error(t('history.toastError'));
|
|
59
|
+
});
|
|
60
|
+
}, [getHistory]);
|
|
61
|
+
return (_jsx(CustomCard, { title: t('history.header'), icon: _jsx(CardIcons.history, {}), color: "indigo", children: _jsx("div", { className: "flex flex-col gap-4", children: _jsx(History, { data: data?.customer?.history.items.reverse(), onNoteAdd: (input) => handle(add({ input })), onNoteDelete: (id) => handle(remove({ id })), onNoteEdit: (input) => handle(edit({ input: { note: input.note || '', noteId: input.noteId } }).then(() => {
|
|
62
|
+
if (id)
|
|
63
|
+
getHistory({ id });
|
|
64
|
+
})) }) }) }));
|
|
65
|
+
};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useCallback, useEffect } from 'react';
|
|
3
|
+
import { CustomerDetailOrderSelector, DetailList, OrderStateBadge, Routes, TableLabel, apiClient, deepMerge, useDetailView, useSettings, useTranslation, } from '@deenruv/react-ui-devkit';
|
|
4
|
+
import { Permission, SortOrder } from '@deenruv/admin-types';
|
|
5
|
+
const CUSTOMER_FORM_KEYS = ['CreateCustomerInput'];
|
|
6
|
+
export const OrdersTab = () => {
|
|
7
|
+
const { t } = useTranslation('table');
|
|
8
|
+
const contentLng = useSettings((p) => p.translationsLanguage);
|
|
9
|
+
const { id, fetchEntity } = useDetailView('customers-detail-view', ...CUSTOMER_FORM_KEYS);
|
|
10
|
+
useEffect(() => {
|
|
11
|
+
fetchEntity();
|
|
12
|
+
}, [contentLng]);
|
|
13
|
+
const fetch = useCallback(async ({ page, perPage, filter, filterOperator, sort }, customFieldsSelector, additionalSelector) => {
|
|
14
|
+
const selector = deepMerge(CustomerDetailOrderSelector, additionalSelector ?? {});
|
|
15
|
+
const response = await apiClient('query')({
|
|
16
|
+
customer: [
|
|
17
|
+
{ id: id },
|
|
18
|
+
{
|
|
19
|
+
orders: [
|
|
20
|
+
{
|
|
21
|
+
options: {
|
|
22
|
+
take: perPage,
|
|
23
|
+
skip: (page - 1) * perPage,
|
|
24
|
+
filterOperator: filterOperator,
|
|
25
|
+
sort: sort ? { [sort.key]: sort.sortDir } : { createdAt: SortOrder.DESC },
|
|
26
|
+
...(filter && { filter }),
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
{ items: selector, totalItems: true },
|
|
30
|
+
],
|
|
31
|
+
},
|
|
32
|
+
],
|
|
33
|
+
});
|
|
34
|
+
return response['customer'].orders;
|
|
35
|
+
}, [id]);
|
|
36
|
+
if (!id)
|
|
37
|
+
return null;
|
|
38
|
+
return (_jsx(DetailList, { detailLinkColumn: "id", filterFields: [{ key: 'id', operator: 'IDOperators' }], searchFields: ['code'], hideColumns: ['customFields', 'user', 'title'], entityName: 'Order', route: Routes['orders'], tableId: "orders-list-view", fetch: fetch, noCreateButton: true, createPermissions: [Permission.CreateOrder], deletePermissions: [Permission.DeleteOrder], additionalColumns: [
|
|
39
|
+
{
|
|
40
|
+
accessorKey: 'state',
|
|
41
|
+
header: () => _jsx(TableLabel, { children: t('columns.state') }),
|
|
42
|
+
accessorFn: (order) => order?.state,
|
|
43
|
+
cell: ({ row }) => _jsx(OrderStateBadge, { state: row.original.state }),
|
|
44
|
+
},
|
|
45
|
+
] }));
|
|
46
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useTranslation, CardIcons, CustomCard, Input } from '@deenruv/react-ui-devkit';
|
|
3
|
+
export const PersonalDataCard = ({ setField, state }) => {
|
|
4
|
+
const { t } = useTranslation('customers');
|
|
5
|
+
return (_jsx(CustomCard, { title: t('personalData.header'), icon: _jsx(CardIcons.basic, {}), color: "blue", children: _jsxs("div", { className: "flex flex-col gap-4", children: [_jsx("div", { className: "flex w-1/4 gap-3", children: _jsx(Input, { label: t('personalData.title'), value: state.title?.value, onChange: (e) => setField('title', e.target.value) }) }), _jsxs("div", { className: "flex items-start gap-3", children: [_jsx(Input, { label: t('personalData.firstName'), value: state.firstName?.value, onChange: (e) => setField('firstName', e.target.value), errors: state.firstName?.errors, required: true }), _jsx(Input, { label: t('personalData.lastName'), value: state.lastName?.value, onChange: (e) => setField('lastName', e.target.value), errors: state.lastName?.errors, required: true })] }), _jsxs("div", { className: "flex items-start gap-3", children: [_jsx(Input, { label: t('personalData.emailAddress'), value: state.emailAddress?.value, onChange: (e) => setField('emailAddress', e.target.value), errors: state.emailAddress?.errors, required: true }), _jsx(Input, { label: t('personalData.phoneNumber'), value: state.phoneNumber?.value, onChange: (e) => setField('phoneNumber', e.target.value) })] })] }) }));
|
|
6
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useTranslation, Badge, CardIcons, CustomCard } from '@deenruv/react-ui-devkit';
|
|
3
|
+
export const VerifiedCard = ({ verified }) => {
|
|
4
|
+
const { t } = useTranslation('customers');
|
|
5
|
+
return (_jsx(CustomCard, { title: t('verified.header'), icon: _jsx(CardIcons.permissions, {}), color: "gray", children: _jsx("div", { className: "flex gap-2", children: verified ? _jsx(Badge, { children: t('verified.true') }) : _jsx(Badge, { children: t('verified.false') }) }) }));
|
|
6
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { DashboardWidgets, useWidgetsStore, DropdownMenu, DropdownMenuTrigger, DropdownMenuContent, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuGroup, Button, DropdownMenuCheckboxItem, useTranslation, } from '@deenruv/react-ui-devkit';
|
|
3
|
+
export const Dashboard = () => {
|
|
4
|
+
const { t } = useTranslation('common');
|
|
5
|
+
const { widgets, setShowWidget } = useWidgetsStore((state) => ({
|
|
6
|
+
widgets: state.widgets,
|
|
7
|
+
setShowWidget: state.setShowWidget,
|
|
8
|
+
}));
|
|
9
|
+
return (_jsxs("div", { className: "px-4 pb-4 pt-2 md:px-8 md:py-4", children: [_jsx("div", { className: "mb-4 flex justify-end", children: !!widgets.length && (_jsxs(DropdownMenu, { children: [_jsx(DropdownMenuTrigger, { asChild: true, children: _jsx(Button, { variant: "outline", children: t('widgets.add') }) }), _jsxs(DropdownMenuContent, { className: "w-42", children: [_jsx(DropdownMenuLabel, { children: t('widgets.title') }), _jsx(DropdownMenuSeparator, {}), _jsx(DropdownMenuGroup, { children: widgets.map((widget) => (_jsx(DropdownMenuCheckboxItem, { checked: widget.visible, onCheckedChange: (checked) => setShowWidget(widget.id, checked), children: widget.name }, widget.id))) })] })] })) }), _jsx(DashboardWidgets, {})] }));
|
|
10
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './Dashboard.js';
|