@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,80 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useParams } from 'react-router-dom';
|
|
3
|
+
import { useTranslation, useValidators, createDeenruvForm, DetailView, useMutation } from '@deenruv/react-ui-devkit';
|
|
4
|
+
import { $, Permission, scalars, typedGql } from '@deenruv/admin-types';
|
|
5
|
+
import { PromotionDetailView } from "./_components/PromotionDetailView";
|
|
6
|
+
import { PromotionDetailSidebar } from "./_components/PromotionDetailSidebar";
|
|
7
|
+
const EditPromotionMutation = typedGql('mutation', { scalars })({
|
|
8
|
+
updatePromotion: [{ input: $('input', 'UpdatePromotionInput!') }, { '...on Promotion': { id: true } }],
|
|
9
|
+
});
|
|
10
|
+
const CreatePromotionMutation = typedGql('mutation', { scalars })({
|
|
11
|
+
createPromotion: [{ input: $('input', 'CreatePromotionInput!') }, { '...on Promotion': { id: true } }],
|
|
12
|
+
});
|
|
13
|
+
const DeletePromotionMutation = typedGql('mutation', { scalars })({
|
|
14
|
+
deletePromotion: [{ id: $('id', 'ID!') }, { result: true }],
|
|
15
|
+
});
|
|
16
|
+
export const PromotionsDetailPage = () => {
|
|
17
|
+
const { id } = useParams();
|
|
18
|
+
const { t } = useTranslation('common');
|
|
19
|
+
const [update] = useMutation(EditPromotionMutation);
|
|
20
|
+
const [create] = useMutation(CreatePromotionMutation);
|
|
21
|
+
const [remove] = useMutation(DeletePromotionMutation);
|
|
22
|
+
const { translationsValidator, configurableOperationArrayValidator } = useValidators();
|
|
23
|
+
return (_jsx("div", { className: "relative flex flex-col gap-y-4", children: _jsx(DetailView, { id: id, locationId: "promotions-detail-view", main: {
|
|
24
|
+
name: 'promotion',
|
|
25
|
+
label: 'Promotion',
|
|
26
|
+
component: _jsx(PromotionDetailView, {}),
|
|
27
|
+
sidebar: _jsx(PromotionDetailSidebar, {}),
|
|
28
|
+
form: createDeenruvForm({
|
|
29
|
+
key: 'CreatePromotionInput',
|
|
30
|
+
keys: [
|
|
31
|
+
'translations',
|
|
32
|
+
'enabled',
|
|
33
|
+
'startsAt',
|
|
34
|
+
'endsAt',
|
|
35
|
+
'couponCode',
|
|
36
|
+
'perCustomerUsageLimit',
|
|
37
|
+
'usageLimit',
|
|
38
|
+
'conditions',
|
|
39
|
+
'actions',
|
|
40
|
+
'translations',
|
|
41
|
+
'customFields',
|
|
42
|
+
],
|
|
43
|
+
config: {
|
|
44
|
+
translations: translationsValidator,
|
|
45
|
+
actions: configurableOperationArrayValidator(t('validation.actionsCode'), t('validation.actionsArgs')),
|
|
46
|
+
conditions: configurableOperationArrayValidator(t('validation.conditionsCode'), t('validation.conditionsArgs')),
|
|
47
|
+
},
|
|
48
|
+
onSubmitted: (data) => {
|
|
49
|
+
if (!data.translations || !data.actions || !data.conditions)
|
|
50
|
+
throw new Error('Fill required fields.');
|
|
51
|
+
const input = {
|
|
52
|
+
translations: data.translations?.validatedValue,
|
|
53
|
+
enabled: data.enabled?.validatedValue || false,
|
|
54
|
+
actions: data.actions?.validatedValue,
|
|
55
|
+
conditions: data.conditions?.validatedValue?.map((el) => ({
|
|
56
|
+
...el,
|
|
57
|
+
arguments: el.arguments.map((arg) => ({ ...arg, value: arg.value.toString() })),
|
|
58
|
+
})),
|
|
59
|
+
couponCode: data.couponCode?.validatedValue,
|
|
60
|
+
endsAt: data.endsAt?.validatedValue,
|
|
61
|
+
startsAt: data.startsAt?.validatedValue,
|
|
62
|
+
perCustomerUsageLimit: data.perCustomerUsageLimit?.validatedValue,
|
|
63
|
+
usageLimit: data.usageLimit?.validatedValue,
|
|
64
|
+
...(data.customFields?.validatedValue ? { customFields: data.customFields?.validatedValue } : {}),
|
|
65
|
+
};
|
|
66
|
+
return id ? update({ input: { id, ...input } }) : create({ input });
|
|
67
|
+
},
|
|
68
|
+
onDeleted: () => {
|
|
69
|
+
if (id)
|
|
70
|
+
return remove({ id });
|
|
71
|
+
else
|
|
72
|
+
throw new Error('No id');
|
|
73
|
+
},
|
|
74
|
+
}),
|
|
75
|
+
}, permissions: {
|
|
76
|
+
create: Permission.CreatePromotion,
|
|
77
|
+
edit: Permission.UpdatePromotion,
|
|
78
|
+
delete: Permission.DeletePromotion,
|
|
79
|
+
} }) }));
|
|
80
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Permission, SortOrder } from '@deenruv/admin-types';
|
|
3
|
+
import { apiClient, deepMerge, DetailList, EntityChannelManagementBulkAction, ListLocations, Routes, } from '@deenruv/react-ui-devkit';
|
|
4
|
+
const tableId = 'promotions-list-view';
|
|
5
|
+
const { selector } = ListLocations[tableId];
|
|
6
|
+
const fetch = async ({ page, perPage, filter, filterOperator, sort }, additionalSelector) => {
|
|
7
|
+
const response = await apiClient('query')({
|
|
8
|
+
['promotions']: [
|
|
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['promotions'];
|
|
22
|
+
};
|
|
23
|
+
const onRemove = async (items) => {
|
|
24
|
+
try {
|
|
25
|
+
const ids = items.map((item) => item.id);
|
|
26
|
+
const { deletePromotions } = await apiClient('mutation')({
|
|
27
|
+
deletePromotions: [{ ids }, { message: true, result: true }],
|
|
28
|
+
});
|
|
29
|
+
return !!deletePromotions.length;
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
return error;
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
export const PromotionsListPage = () => (_jsx(DetailList, { filterFields: [
|
|
36
|
+
{ key: 'name', operator: 'StringOperators' },
|
|
37
|
+
{ key: 'enabled', operator: 'BooleanOperators' },
|
|
38
|
+
], additionalBulkActions: [...EntityChannelManagementBulkAction(tableId)], searchFields: ['name'], entityName: 'Promotion', route: Routes['promotions'], tableId: tableId, fetch: fetch, onRemove: onRemove, detailLinkColumn: "id", createPermissions: [Permission.CreatePromotion], deletePermissions: [Permission.DeletePromotion] }));
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuTrigger, Button, useQuery, Separator, ErrorMessage, ArgumentFieldsComponent, CustomCard, CardIcons, useTranslation, PromotionConditionAndActionSelector, } from '@deenruv/react-ui-devkit';
|
|
3
|
+
import { typedGql, scalars } from '@deenruv/admin-types';
|
|
4
|
+
import { useCallback, useMemo } from 'react';
|
|
5
|
+
import { X } from 'lucide-react';
|
|
6
|
+
export const ActionsQuery = typedGql('query', { scalars })({
|
|
7
|
+
promotionActions: PromotionConditionAndActionSelector,
|
|
8
|
+
});
|
|
9
|
+
export const ActionsCard = ({ value, onChange, errors }) => {
|
|
10
|
+
const { t } = useTranslation('promotions');
|
|
11
|
+
const { data } = useQuery(ActionsQuery);
|
|
12
|
+
const availableActions = useMemo(() => {
|
|
13
|
+
return data?.promotionActions.filter((a) => !value?.some((v) => v.code === a.code)) || [];
|
|
14
|
+
}, [data, value]);
|
|
15
|
+
const handleActionsValueChange = useCallback((index, code, args) => {
|
|
16
|
+
const correspondingAction = data?.promotionActions.find((h) => h.code === code);
|
|
17
|
+
if (correspondingAction && value) {
|
|
18
|
+
const newFiltersValue = [...value];
|
|
19
|
+
newFiltersValue[index] = {
|
|
20
|
+
code: correspondingAction.code,
|
|
21
|
+
arguments: args ||
|
|
22
|
+
correspondingAction.args.map((a) => ({
|
|
23
|
+
name: a.name,
|
|
24
|
+
value: 'false',
|
|
25
|
+
})),
|
|
26
|
+
};
|
|
27
|
+
onChange('actions', newFiltersValue);
|
|
28
|
+
}
|
|
29
|
+
}, [data, onChange, value]);
|
|
30
|
+
const removeAction = useCallback((code) => {
|
|
31
|
+
if (value) {
|
|
32
|
+
let newValue = [...value];
|
|
33
|
+
newValue = newValue.filter((v) => v.code !== code);
|
|
34
|
+
onChange('actions', newValue);
|
|
35
|
+
}
|
|
36
|
+
}, [onChange, value, data]);
|
|
37
|
+
const addAction = useCallback((action) => {
|
|
38
|
+
const newValue = [
|
|
39
|
+
...(value || []),
|
|
40
|
+
{
|
|
41
|
+
code: action.code,
|
|
42
|
+
arguments: action.args.map((a) => ({ name: a.name, value: a.type === 'boolean' ? 'false' : a.defaultValue })),
|
|
43
|
+
},
|
|
44
|
+
];
|
|
45
|
+
onChange('actions', newValue);
|
|
46
|
+
}, [onChange, value, data]);
|
|
47
|
+
return (_jsx(CustomCard, { title: t('actions.header'), color: "red", icon: _jsx(CardIcons.action, {}), upperRight: _jsx(ErrorMessage, { errors: errors }), bottomRight: _jsxs(DropdownMenu, { children: [_jsx(DropdownMenuTrigger, { asChild: true, children: _jsx(Button, { disabled: !availableActions.length, children: t(`actions.add`) }) }), _jsxs(DropdownMenuContent, { children: [_jsx(DropdownMenuLabel, { children: t(`actions.header`) }), _jsx(DropdownMenuSeparator, {}), availableActions.map((action) => {
|
|
48
|
+
const translated = t(`actions.codes.${action.code}`);
|
|
49
|
+
return (_jsx(DropdownMenuItem, { onClick: () => addAction(action), children: translated !== `actions.codes.${action.code}` ? translated : action.description }, action.code));
|
|
50
|
+
})] })] }), children: _jsx("div", { className: "flex flex-1 flex-col gap-y-4", children: !value?.length ? (_jsx("p", { children: t('actions.emptyState') })) : (value?.map((action, index) => {
|
|
51
|
+
const translated = t(`actions.codes.${action.code}`);
|
|
52
|
+
const available = availableActions.find((a) => a.code === action.code);
|
|
53
|
+
return (_jsxs("div", { className: "flex flex-col gap-4", children: [_jsx("div", { className: "flex items-center gap-3", children: action?.code && (_jsxs(_Fragment, { children: [_jsx(Button, { variant: 'destructive', size: 'sm', className: "h-auto p-1", onClick: (e) => {
|
|
54
|
+
e.preventDefault();
|
|
55
|
+
removeAction(action.code);
|
|
56
|
+
}, children: _jsx(X, { size: 16 }) }), _jsx("h5", { children: translated !== `actions.codes.${action.code}`
|
|
57
|
+
? translated
|
|
58
|
+
: available?.description || action.code })] })) }), _jsx(ArgumentFieldsComponent, { actions: data?.promotionActions, args: action.arguments, setArg: (argument, data) => {
|
|
59
|
+
const newArgs = action.arguments.map((arg) => {
|
|
60
|
+
if (arg.name === argument.name)
|
|
61
|
+
return { ...arg, value: data.value };
|
|
62
|
+
return arg;
|
|
63
|
+
});
|
|
64
|
+
handleActionsValueChange(index, action.code, newArgs);
|
|
65
|
+
} }), _jsx(Separator, { className: "my-4" })] }, index));
|
|
66
|
+
})) }) }));
|
|
67
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useTranslation, Input, Label, CustomCard, CardIcons, RichTextEditor } from '@deenruv/react-ui-devkit';
|
|
3
|
+
export const BasicFieldsCard = ({ currentTranslationValue, onChange, errors }) => {
|
|
4
|
+
const { t } = useTranslation('promotions');
|
|
5
|
+
return (_jsx(CustomCard, { title: t('basicInfo.header'), color: "blue", icon: _jsx(CardIcons.basic, {}), children: _jsxs("div", { className: "flex flex-1 flex-col gap-y-4", children: [_jsx("div", { className: "flex gap-3", children: _jsx(Input, { label: t('basicInfo.name'), placeholder: t('basicInfo.name'), value: currentTranslationValue?.name ?? undefined, onChange: (e) => onChange('name', e.target.value), errors: errors }) }), _jsxs("div", { className: "flex basis-full flex-col", children: [_jsx(Label, { className: "mb-2", children: t('basicInfo.description') }), _jsx(RichTextEditor, { content: currentTranslationValue?.description ?? undefined, onContentChanged: (value) => onChange('description', value) })] })] }) }));
|
|
6
|
+
};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuTrigger, Button, useQuery, Separator, ErrorMessage, ArgumentFieldsComponent, CustomCard, CardIcons, useTranslation, PromotionConditionAndActionSelector, } from '@deenruv/react-ui-devkit';
|
|
3
|
+
import { typedGql, scalars } from '@deenruv/admin-types';
|
|
4
|
+
import { useCallback, useMemo } from 'react';
|
|
5
|
+
import { X } from 'lucide-react';
|
|
6
|
+
export const ConditionsQuery = typedGql('query', { scalars })({
|
|
7
|
+
promotionConditions: PromotionConditionAndActionSelector,
|
|
8
|
+
});
|
|
9
|
+
export const ConditionsCard = ({ value, onChange, errors }) => {
|
|
10
|
+
const { t } = useTranslation('promotions');
|
|
11
|
+
const { data } = useQuery(ConditionsQuery);
|
|
12
|
+
const availableConditions = useMemo(() => {
|
|
13
|
+
return data?.promotionConditions.filter((c) => !value?.some((v) => v.code === c.code)) || [];
|
|
14
|
+
}, [data, value]);
|
|
15
|
+
const handleConditionsValueChange = useCallback((index, code, args) => {
|
|
16
|
+
const correspondingCondition = data?.promotionConditions.find((h) => h.code === code);
|
|
17
|
+
if (correspondingCondition && value) {
|
|
18
|
+
const newFiltersValue = [...value];
|
|
19
|
+
newFiltersValue[index] = {
|
|
20
|
+
code: correspondingCondition.code,
|
|
21
|
+
arguments: args ||
|
|
22
|
+
correspondingCondition.args.map((a) => ({
|
|
23
|
+
name: a.name,
|
|
24
|
+
value: 'false',
|
|
25
|
+
})),
|
|
26
|
+
};
|
|
27
|
+
onChange('conditions', newFiltersValue);
|
|
28
|
+
}
|
|
29
|
+
}, [data, onChange, value]);
|
|
30
|
+
const removeCondition = useCallback((code) => {
|
|
31
|
+
if (value) {
|
|
32
|
+
let newValue = [...value];
|
|
33
|
+
newValue = newValue.filter((v) => v.code !== code);
|
|
34
|
+
onChange('conditions', newValue);
|
|
35
|
+
}
|
|
36
|
+
}, [onChange, value, data]);
|
|
37
|
+
const addCondition = useCallback((condition) => {
|
|
38
|
+
const newValue = [
|
|
39
|
+
...(value || []),
|
|
40
|
+
{
|
|
41
|
+
code: condition.code,
|
|
42
|
+
arguments: condition.args.map((a) => ({
|
|
43
|
+
name: a.name,
|
|
44
|
+
value: a.type === 'boolean' ? 'false' : a.defaultValue,
|
|
45
|
+
})),
|
|
46
|
+
},
|
|
47
|
+
];
|
|
48
|
+
onChange('conditions', newValue);
|
|
49
|
+
}, [onChange, value, data]);
|
|
50
|
+
return (_jsx(CustomCard, { title: t('conditions.header'), color: "yellow", icon: _jsx(CardIcons.check, {}), upperRight: _jsx(ErrorMessage, { errors: errors }), bottomRight: _jsxs(DropdownMenu, { children: [_jsx(DropdownMenuTrigger, { asChild: true, children: _jsx(Button, { disabled: !availableConditions.length, children: t(`conditions.add`) }) }), _jsxs(DropdownMenuContent, { children: [_jsx(DropdownMenuLabel, { children: t(`conditions.header`) }), _jsx(DropdownMenuSeparator, {}), availableConditions.map((condition) => {
|
|
51
|
+
const translated = t(`conditions.codes.${condition.code}`);
|
|
52
|
+
return (_jsx(DropdownMenuItem, { onClick: () => addCondition(condition), children: translated !== `conditions.codes.${condition.code}` ? translated : condition.description }, condition.code));
|
|
53
|
+
})] })] }), children: _jsx("div", { className: "flex flex-1 flex-col gap-y-4", children: !value?.length ? (_jsx("p", { children: t('conditions.emptyState') })) : (value?.map((condition, index) => {
|
|
54
|
+
const translated = t(`conditions.codes.${condition.code}`);
|
|
55
|
+
const available = availableConditions.find((c) => c.code === condition.code);
|
|
56
|
+
return (_jsxs("div", { className: "flex flex-col gap-4", children: [_jsx("div", { className: "flex items-center gap-3", children: condition?.code && (_jsxs(_Fragment, { children: [_jsx(Button, { variant: 'destructive', size: 'sm', className: "h-auto p-1", onClick: (e) => {
|
|
57
|
+
e.preventDefault();
|
|
58
|
+
removeCondition(condition.code);
|
|
59
|
+
}, children: _jsx(X, { size: 16 }) }), _jsx("h5", { children: translated !== `conditions.codes.${condition.code}`
|
|
60
|
+
? translated
|
|
61
|
+
: available?.description || condition.code })] })) }), _jsx(ArgumentFieldsComponent, { actions: data?.promotionConditions, args: condition.arguments, setArg: (argument, data) => {
|
|
62
|
+
const newArgs = condition.arguments.map((arg) => {
|
|
63
|
+
if (arg.name === argument.name)
|
|
64
|
+
return { ...arg, value: data.value };
|
|
65
|
+
return arg;
|
|
66
|
+
});
|
|
67
|
+
handleConditionsValueChange(index, condition.code, newArgs);
|
|
68
|
+
} }), _jsx(Separator, { className: "my-4" })] }, index));
|
|
69
|
+
})) }) }));
|
|
70
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Label, apiClient, SimpleSelect } from '@deenruv/react-ui-devkit';
|
|
3
|
+
import { useCallback, useEffect, useMemo, useState } from 'react';
|
|
4
|
+
export const CustomerGroupsSelector = ({ label, value, onChange }) => {
|
|
5
|
+
const [options, setOptions] = useState([]);
|
|
6
|
+
const valueParsed = useMemo(() => (value?.startsWith('"') ? JSON.parse(value) : value), [value]);
|
|
7
|
+
const fetchCustomerGroups = useCallback(async () => {
|
|
8
|
+
const response = await apiClient('query')({
|
|
9
|
+
customerGroups: [
|
|
10
|
+
{},
|
|
11
|
+
{
|
|
12
|
+
items: {
|
|
13
|
+
name: true,
|
|
14
|
+
id: true,
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
],
|
|
18
|
+
});
|
|
19
|
+
setOptions(response.customerGroups.items?.map((v) => ({ label: v.name, value: v.id })));
|
|
20
|
+
}, []);
|
|
21
|
+
useEffect(() => {
|
|
22
|
+
fetchCustomerGroups();
|
|
23
|
+
}, [fetchCustomerGroups]);
|
|
24
|
+
return (_jsxs("div", { className: "flex basis-full flex-col gap-2", children: [_jsx(Label, { children: label }), _jsx(SimpleSelect, { options: options, value: valueParsed, onValueChange: (e) => onChange(e) })] }));
|
|
25
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useTranslation, Label, Switch, CustomCard, CardIcons } from '@deenruv/react-ui-devkit';
|
|
3
|
+
export const EnabledCard = ({ onEnabledChange, enabledValue }) => {
|
|
4
|
+
const { t } = useTranslation('products');
|
|
5
|
+
return (_jsx(CustomCard, { title: t('details.basicInfo'), icon: _jsx(CardIcons.default, {}), color: "teal", children: _jsxs("div", { className: "flex items-center space-x-2", children: [_jsx(Switch, { id: "product-enabled", checked: enabledValue, onCheckedChange: onEnabledChange }), _jsx(Label, { htmlFor: "product-enabled", children: t('enabled') })] }) }));
|
|
6
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Input, CustomCard, CardIcons, useTranslation, DateTimePicker } from '@deenruv/react-ui-devkit';
|
|
3
|
+
export const OptionsCard = ({ startsAt, endsAt, couponCode, perCustomerUsageLimit, usageLimit, setField, }) => {
|
|
4
|
+
const { t } = useTranslation('promotions');
|
|
5
|
+
return (_jsx(CustomCard, { title: t('options.header'), color: "orange", icon: _jsx(CardIcons.options, {}), children: _jsxs("div", { className: "flex flex-1 flex-col gap-y-4", children: [_jsxs("div", { className: "flex gap-3", children: [_jsx(DateTimePicker, { value: startsAt ? new Date(startsAt) : undefined, onChange: (date) => setField('startsAt', date ? date.toISOString() : ''), min: new Date(), max: endsAt ? new Date(endsAt) : undefined }), _jsx(DateTimePicker, { value: endsAt ? new Date(endsAt) : undefined, onChange: (date) => setField('endsAt', date ? date.toISOString() : ''), min: startsAt ? new Date(startsAt) : undefined, max: new Date(new Date().getFullYear() + 10, 11, 31) })] }), _jsxs("div", { className: "flex gap-3", children: [_jsx(Input, { label: t('options.couponCode'), placeholder: t('options.couponCode'), value: couponCode, onChange: (e) => setField('couponCode', e.target.value) }), _jsx(Input, { label: t('options.usageLimit'), placeholder: t('options.usageLimit'), value: usageLimit, type: "number", onChange: (e) => setField('usageLimit', +e.target.value) }), _jsx(Input, { label: t('options.perCustomerUsageLimit'), placeholder: t('options.perCustomerUsageLimit'), value: perCustomerUsageLimit, type: "number", onChange: (e) => setField('perCustomerUsageLimit', +e.target.value) })] })] }) }));
|
|
6
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { EnabledCard } from "./EnabledCard";
|
|
3
|
+
import { PromotionQuery } from "./PromotionDetailView";
|
|
4
|
+
import { useDetailView, useQuery } from '@deenruv/react-ui-devkit';
|
|
5
|
+
import { useEffect } from 'react';
|
|
6
|
+
export const PromotionDetailSidebar = () => {
|
|
7
|
+
const { id, form } = useDetailView('promotions-detail-view', 'CreatePromotionInput', 'enabled');
|
|
8
|
+
const { base: { state, setField }, } = form;
|
|
9
|
+
const { data } = id ? useQuery(PromotionQuery, { initialVariables: { id } }) : { data: undefined };
|
|
10
|
+
useEffect(() => {
|
|
11
|
+
if (data)
|
|
12
|
+
setField('enabled', data.promotion.enabled);
|
|
13
|
+
}, [data]);
|
|
14
|
+
return (_jsx("div", { className: "flex w-full flex-col gap-4", children: _jsx(EnabledCard, { enabledValue: state.enabled?.value, onEnabledChange: (e) => setField('enabled', e) }) }));
|
|
15
|
+
};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useDetailView, useSettings, DetailViewMarker, PromotionDetailSelector, setInArrayBy, EntityCustomFields, PromotionConditionAndActionSelector, } from '@deenruv/react-ui-devkit';
|
|
3
|
+
import { useCallback, useEffect, useMemo } from 'react';
|
|
4
|
+
import { BasicFieldsCard } from "./BasicFieldsCard";
|
|
5
|
+
import { OptionsCard } from "./OptionsCard";
|
|
6
|
+
import { ConditionsCard } from "./ConditionsCard";
|
|
7
|
+
import { ActionsCard } from "./ActionsCard";
|
|
8
|
+
import { typedGql, scalars, $ } from '@deenruv/admin-types';
|
|
9
|
+
export const ConditionsQuery = typedGql('query', { scalars })({
|
|
10
|
+
promotionConditions: PromotionConditionAndActionSelector,
|
|
11
|
+
});
|
|
12
|
+
const PROMOTION_FORM_KEYS = [
|
|
13
|
+
'CreatePromotionInput',
|
|
14
|
+
'enabled',
|
|
15
|
+
'startsAt',
|
|
16
|
+
'endsAt',
|
|
17
|
+
'couponCode',
|
|
18
|
+
'perCustomerUsageLimit',
|
|
19
|
+
'usageLimit',
|
|
20
|
+
'conditions',
|
|
21
|
+
'actions',
|
|
22
|
+
'translations',
|
|
23
|
+
'customFields',
|
|
24
|
+
];
|
|
25
|
+
export const PromotionQuery = typedGql('query', { scalars })({
|
|
26
|
+
promotion: [{ id: $('id', 'ID!') }, PromotionDetailSelector],
|
|
27
|
+
});
|
|
28
|
+
export const PromotionDetailView = () => {
|
|
29
|
+
const contentLng = useSettings((p) => p.translationsLanguage);
|
|
30
|
+
const { form, entity, fetchEntity, id } = useDetailView('promotions-detail-view', ...PROMOTION_FORM_KEYS);
|
|
31
|
+
const { base: { setField, state }, } = form;
|
|
32
|
+
// const { data } = useQuery(ConditionsQuery);
|
|
33
|
+
// const availableConditions = useMemo(() => {
|
|
34
|
+
// return data?.promotionConditions.filter((c) => !state.conditions?.value?.some((v) => v.code === c.code)) || [];
|
|
35
|
+
// }, [data, state.conditions?.value]);
|
|
36
|
+
useEffect(() => {
|
|
37
|
+
(async () => {
|
|
38
|
+
const res = await fetchEntity();
|
|
39
|
+
if (!res)
|
|
40
|
+
return;
|
|
41
|
+
setField('translations', res.translations);
|
|
42
|
+
setField('endsAt', res.endsAt);
|
|
43
|
+
setField('startsAt', res.startsAt);
|
|
44
|
+
setField('couponCode', res.couponCode);
|
|
45
|
+
setField('usageLimit', res.usageLimit);
|
|
46
|
+
setField('perCustomerUsageLimit', res.perCustomerUsageLimit);
|
|
47
|
+
setField('conditions', res.conditions.map((c) => ({ code: c.code, arguments: c.args })));
|
|
48
|
+
setField('actions', res.actions.map((a) => ({ code: a.code, arguments: a.args })));
|
|
49
|
+
})();
|
|
50
|
+
}, [contentLng]);
|
|
51
|
+
const translations = useMemo(() => state?.translations?.value || [], [state?.translations?.value]);
|
|
52
|
+
const currentTranslationValue = useMemo(() => translations.find((v) => v.languageCode === contentLng), [translations, contentLng]);
|
|
53
|
+
const setTranslationField = useCallback((field, e) => {
|
|
54
|
+
setField('translations', setInArrayBy(translations, (t) => t.languageCode !== contentLng, {
|
|
55
|
+
[field]: e,
|
|
56
|
+
languageCode: contentLng,
|
|
57
|
+
}));
|
|
58
|
+
}, [contentLng, translations]);
|
|
59
|
+
return (_jsx("div", { children: _jsxs("form", { className: "flex flex-col gap-4", children: [_jsx(BasicFieldsCard, { currentTranslationValue: currentTranslationValue ?? undefined, onChange: setTranslationField, errors: state.translations?.errors }), _jsx(OptionsCard, { endsAt: state.endsAt?.value, startsAt: state.startsAt?.value, couponCode: state.couponCode?.value ?? undefined, usageLimit: state.usageLimit?.value ?? undefined, perCustomerUsageLimit: state.perCustomerUsageLimit?.value ?? undefined, setField: setField }), _jsx(DetailViewMarker, { position: 'promotions-detail-view' }), _jsx(EntityCustomFields, { entityName: "promotion", id: id, hideButton: true, onChange: (customFields, translations) => {
|
|
60
|
+
setField('customFields', customFields);
|
|
61
|
+
if (translations)
|
|
62
|
+
setField('translations', translations);
|
|
63
|
+
}, initialValues: entity && 'customFields' in entity
|
|
64
|
+
? { customFields: entity.customFields, translations: entity.translations }
|
|
65
|
+
: { customFields: {} } }), _jsx(ConditionsCard, { value: state.conditions?.value, onChange: setField, errors: state.conditions?.errors }), _jsx(ActionsCard, { value: state.actions?.value, onChange: setField, errors: state.actions?.errors })] }) }));
|
|
66
|
+
};
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useCallback } from 'react';
|
|
3
|
+
import { useParams } from 'react-router-dom';
|
|
4
|
+
import { useValidators, DetailView, createDeenruvForm, getMutation, useMutation, useTranslation, } from '@deenruv/react-ui-devkit';
|
|
5
|
+
import { Permission } from '@deenruv/admin-types';
|
|
6
|
+
import { RoleDetailView } from "./_components/RoleDetailView.js";
|
|
7
|
+
const CreateRoleMutation = getMutation('createRole');
|
|
8
|
+
const EditRoleMutation = getMutation('updateRole');
|
|
9
|
+
const DeleteRoleMutation = getMutation('deleteRole');
|
|
10
|
+
export const RolesDetailPage = () => {
|
|
11
|
+
const { id } = useParams();
|
|
12
|
+
const [update] = useMutation(EditRoleMutation);
|
|
13
|
+
const [create] = useMutation(CreateRoleMutation);
|
|
14
|
+
const [remove] = useMutation(DeleteRoleMutation);
|
|
15
|
+
const { t } = useTranslation('roles');
|
|
16
|
+
const { nameValidator } = useValidators();
|
|
17
|
+
const onSubmitHandler = useCallback((data) => {
|
|
18
|
+
if (!data.code?.validatedValue) {
|
|
19
|
+
throw new Error('Name is required.');
|
|
20
|
+
}
|
|
21
|
+
const inputData = {
|
|
22
|
+
code: data.code.validatedValue,
|
|
23
|
+
channelIds: data.channelIds?.validatedValue,
|
|
24
|
+
description: data.description?.validatedValue,
|
|
25
|
+
permissions: data.permissions?.validatedValue,
|
|
26
|
+
};
|
|
27
|
+
if (id) {
|
|
28
|
+
return update({
|
|
29
|
+
input: {
|
|
30
|
+
id,
|
|
31
|
+
...inputData,
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
return create({
|
|
37
|
+
input: inputData,
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
}, [id, update, create]);
|
|
41
|
+
const onDeleteHandler = useCallback(() => {
|
|
42
|
+
if (!id) {
|
|
43
|
+
throw new Error('Could not find the id.');
|
|
44
|
+
}
|
|
45
|
+
return remove({ input: { id } });
|
|
46
|
+
}, [remove, id]);
|
|
47
|
+
return (_jsx("div", { className: "relative flex flex-col gap-y-4", children: _jsx(DetailView, { id: id, locationId: "roles-detail-view", main: {
|
|
48
|
+
name: 'role',
|
|
49
|
+
label: 'Role',
|
|
50
|
+
component: _jsx(RoleDetailView, {}),
|
|
51
|
+
form: createDeenruvForm({
|
|
52
|
+
key: 'CreateRoleInput',
|
|
53
|
+
keys: ['code', 'description', 'channelIds', 'permissions'],
|
|
54
|
+
config: {
|
|
55
|
+
code: {
|
|
56
|
+
validate: (v) => (!v || v === '' ? [t('validation.codeRequired')] : undefined),
|
|
57
|
+
},
|
|
58
|
+
permissions: {
|
|
59
|
+
// initialValue: DEFAULT_VALUES.permissions,
|
|
60
|
+
validate: (v) => (!v || !v.length ? [t('validation.permissionsRequired')] : undefined),
|
|
61
|
+
},
|
|
62
|
+
description: nameValidator,
|
|
63
|
+
},
|
|
64
|
+
onSubmitted: onSubmitHandler,
|
|
65
|
+
onDeleted: onDeleteHandler,
|
|
66
|
+
}),
|
|
67
|
+
}, permissions: {
|
|
68
|
+
create: Permission.CreateAdministrator,
|
|
69
|
+
delete: Permission.DeleteAdministrator,
|
|
70
|
+
edit: Permission.UpdateAdministrator,
|
|
71
|
+
} }) }));
|
|
72
|
+
};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { useCallback } from 'react';
|
|
3
|
+
import { apiClient, DetailList, deepMerge, DEFAULT_CHANNEL_CODE, ListBadge, ListLocations, useTranslation, Routes, TableLabel, EntityChannelManagementBulkAction, } from '@deenruv/react-ui-devkit';
|
|
4
|
+
import { Permission, SortOrder } from '@deenruv/admin-types';
|
|
5
|
+
const tableId = 'roles-list-view';
|
|
6
|
+
const { selector } = ListLocations[tableId];
|
|
7
|
+
const DEFAULT_ROLE_CODES = ['__customer_role__', '__super_admin_role__'];
|
|
8
|
+
const isDefaultRole = (row) => DEFAULT_ROLE_CODES.includes(row.original.code);
|
|
9
|
+
const fetch = async ({ page, perPage, filter, filterOperator, sort }, additionalSelector) => {
|
|
10
|
+
const response = await apiClient('query')({
|
|
11
|
+
roles: [
|
|
12
|
+
{
|
|
13
|
+
options: {
|
|
14
|
+
take: perPage,
|
|
15
|
+
skip: (page - 1) * perPage,
|
|
16
|
+
filterOperator: filterOperator,
|
|
17
|
+
sort: sort ? { [sort.key]: sort.sortDir } : { createdAt: SortOrder.DESC },
|
|
18
|
+
...(filter && { filter }),
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
{ items: deepMerge(selector, additionalSelector ?? {}), totalItems: true },
|
|
22
|
+
],
|
|
23
|
+
});
|
|
24
|
+
return response.roles;
|
|
25
|
+
};
|
|
26
|
+
const onRemove = async (items) => {
|
|
27
|
+
try {
|
|
28
|
+
const ids = items.map((item) => item.id);
|
|
29
|
+
const { deleteRoles } = await apiClient('mutation')({
|
|
30
|
+
deleteRoles: [{ ids }, { message: true, result: true }],
|
|
31
|
+
});
|
|
32
|
+
return !!deleteRoles.length;
|
|
33
|
+
}
|
|
34
|
+
catch (error) {
|
|
35
|
+
return error;
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
export const RolesListPage = () => {
|
|
39
|
+
const { t } = useTranslation('roles');
|
|
40
|
+
const renderElements = useCallback((elements) => {
|
|
41
|
+
const LIMIT_TO = 3;
|
|
42
|
+
const elementsRemain = elements.length - LIMIT_TO;
|
|
43
|
+
const renderedElements = elements
|
|
44
|
+
.filter((_e, i) => i + 1 <= LIMIT_TO)
|
|
45
|
+
.map((e) => _jsx(ListBadge, { children: e }, e));
|
|
46
|
+
return (_jsxs(_Fragment, { children: [renderedElements, elementsRemain > 0 && _jsxs(ListBadge, { children: ["+", elementsRemain] }, 'plus')] }));
|
|
47
|
+
}, []);
|
|
48
|
+
return (_jsx(DetailList, { filterFields: [
|
|
49
|
+
{ key: 'id', operator: 'IDOperators' },
|
|
50
|
+
{ key: 'description', operator: 'StringOperators' },
|
|
51
|
+
{ key: 'code', operator: 'StringOperators' },
|
|
52
|
+
], detailLinkColumn: "description", searchFields: ['code', 'description'], hideColumns: ['customFields', 'translations', 'collections', 'variantList'], additionalBulkActions: [...EntityChannelManagementBulkAction(tableId)], additionalColumns: [
|
|
53
|
+
{
|
|
54
|
+
accessorKey: 'permissions',
|
|
55
|
+
enableSorting: false,
|
|
56
|
+
enableColumnFilter: false,
|
|
57
|
+
header: () => _jsx(TableLabel, { children: t('table.permissions') }),
|
|
58
|
+
cell: ({ row }) => (_jsx("div", { className: "flex gap-1", children: isDefaultRole(row) ? (_jsx("p", { className: "flex w-full items-center justify-center py-2 text-[12px] font-medium text-gray-500", children: t('table.defaultRoleInfo') })) : (renderElements(row.original.permissions)) })),
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
accessorKey: 'channels',
|
|
62
|
+
enableSorting: false,
|
|
63
|
+
enableColumnFilter: false,
|
|
64
|
+
header: () => _jsx(TableLabel, { children: t('table.channels') }),
|
|
65
|
+
cell: ({ row }) => (_jsx("div", { className: "flex gap-1", children: isDefaultRole(row)
|
|
66
|
+
? ''
|
|
67
|
+
: row.original.channels.map((ch) => (_jsx(ListBadge, { children: ch.code === DEFAULT_CHANNEL_CODE ? t('defaultChannel') : ch.code }, ch.code))) })),
|
|
68
|
+
},
|
|
69
|
+
], entityName: 'Role', route: Routes['roles'], tableId: "roles-list-view", fetch: fetch, onRemove: onRemove, createPermissions: [Permission.CreateAdministrator], deletePermissions: [Permission.DeleteAdministrator] }));
|
|
70
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useTranslation, ErrorMessage, CustomCard, CardIcons } from '@deenruv/react-ui-devkit';
|
|
3
|
+
import { PermissionsTable } from "./PermissionsTable";
|
|
4
|
+
export const PermissionsCard = ({ currentPermissions, onPermissionsChange, errors, }) => {
|
|
5
|
+
const { t } = useTranslation('roles');
|
|
6
|
+
return (_jsx(CustomCard, { title: t('details.permissions.title'), icon: _jsx(CardIcons.permissions, {}), color: "teal", upperRight: _jsx(ErrorMessage, { errors: errors }), children: _jsx(PermissionsTable, { currentPermissions: currentPermissions, onPermissionsChange: onPermissionsChange }) }));
|
|
7
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useCallback, useEffect, useState } from 'react';
|
|
3
|
+
import { useTranslation, cn, Table, TableBody, TableCell, TableRow, useServer } from '@deenruv/react-ui-devkit';
|
|
4
|
+
import { CircleCheckBig } from 'lucide-react';
|
|
5
|
+
import permissionsJson from "../../../locales/en/permissions.json";
|
|
6
|
+
export const PermissionsTable = ({ currentPermissions, onPermissionsChange }) => {
|
|
7
|
+
const { t } = useTranslation('permissions');
|
|
8
|
+
const [groupedPermissions, setGroupedPermissions] = useState();
|
|
9
|
+
const { serverConfig } = useServer();
|
|
10
|
+
const groupPermissions = useCallback((allPermissions) => {
|
|
11
|
+
const permissionGroups = {};
|
|
12
|
+
allPermissions?.forEach((permission) => {
|
|
13
|
+
const match = permission.match(/(Create|Read|Update|Delete)(.*)/);
|
|
14
|
+
if (match) {
|
|
15
|
+
const resource = match[2];
|
|
16
|
+
if (!permissionGroups[resource]) {
|
|
17
|
+
permissionGroups[resource] = [];
|
|
18
|
+
}
|
|
19
|
+
permissionGroups[resource].push(permission);
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
setGroupedPermissions(permissionGroups);
|
|
23
|
+
}, []);
|
|
24
|
+
useEffect(() => {
|
|
25
|
+
if (serverConfig)
|
|
26
|
+
groupPermissions(serverConfig.permissions.map((p) => p.name));
|
|
27
|
+
}, [serverConfig]);
|
|
28
|
+
const handlePermissionsChange = useCallback((permission) => {
|
|
29
|
+
if (!onPermissionsChange)
|
|
30
|
+
return;
|
|
31
|
+
const isPresent = currentPermissions?.includes(permission);
|
|
32
|
+
const permissions = currentPermissions ? [...currentPermissions] : [];
|
|
33
|
+
if (isPresent) {
|
|
34
|
+
onPermissionsChange(permissions?.filter((p) => p !== permission));
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
onPermissionsChange([...permissions, permission]);
|
|
38
|
+
}
|
|
39
|
+
}, [currentPermissions, onPermissionsChange]);
|
|
40
|
+
return (_jsx(Table, { children: _jsx(TableBody, { children: groupedPermissions &&
|
|
41
|
+
Object.entries(groupedPermissions).map(([key, values]) => (_jsxs(TableRow, { children: [_jsx(TableCell, { className: "dark:bg-secondary bg-slate-50 px-4 py-2", colSpan: values.length + 1, children: _jsxs("div", { className: "flex flex-col gap-1", children: [_jsx("p", { className: "text-base font-semibold", children: t(`${key}.title`) }), _jsx("p", { className: "text-xs", children: t(`${key}.description`) })] }) }), values.map((v) => (_jsx(TableCell, { className: cn('py-4', onPermissionsChange && 'cursor-pointer'), onClick: () => handlePermissionsChange(v), children: _jsxs("div", { className: cn('flex items-center gap-2 text-gray-400', currentPermissions?.includes(v) && 'font-medium text-green-600'), children: [_jsx(CircleCheckBig, { size: 18, strokeWidth: 2.5 }), _jsx("p", { children: v })] }) }, v)))] }, key))) }) }));
|
|
42
|
+
};
|