@deenruv/admin-dashboard 1.0.17-dev.4 → 1.0.17-dev.40

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.
Files changed (87) hide show
  1. package/dist/DeenruvAdminPanel.js +30 -41
  2. package/dist/access/access-context.js +10 -0
  3. package/dist/access/admin-router.js +60 -0
  4. package/dist/access/built-in-route-permissions.js +44 -0
  5. package/dist/access/built-in-routes.js +301 -0
  6. package/dist/access/channel-selection.js +11 -0
  7. package/dist/access/index.js +6 -0
  8. package/dist/access/navigation.js +33 -0
  9. package/dist/access/permission-access.js +9 -0
  10. package/dist/access/permission-routes.js +3 -0
  11. package/dist/access/types.js +1 -0
  12. package/dist/components/BrandLogo.js +5 -5
  13. package/dist/components/GlobalSearch.js +32 -57
  14. package/dist/components/Menu/AccountMenu.js +58 -0
  15. package/dist/components/Menu/Breadcrumbs.js +23 -0
  16. package/dist/components/Menu/ChannelSwitcher.js +8 -1
  17. package/dist/components/Menu/Navigation.js +79 -257
  18. package/dist/components/Menu/NavigationFooter.js +16 -7
  19. package/dist/components/Menu/SidebarContent.js +9 -0
  20. package/dist/components/Menu/SidebarState.js +93 -0
  21. package/dist/components/Menu/TopbarOverflow.js +11 -0
  22. package/dist/components/Menu/index.js +68 -56
  23. package/dist/components/storefrontAction/StorefrontAction.js +9 -0
  24. package/dist/components/storefrontAction/StorefrontAction.logic.js +27 -0
  25. package/dist/components/storefrontAction/index.js +2 -0
  26. package/dist/graphql/scalars.js +4 -0
  27. package/dist/index.css +65 -0
  28. package/dist/locales/en/admins.json +62 -0
  29. package/dist/locales/en/collections.json +14 -0
  30. package/dist/locales/en/common.json +55 -27
  31. package/dist/locales/en/orders.json +9 -1
  32. package/dist/locales/en/products.json +15 -0
  33. package/dist/locales/pl/admins.json +62 -0
  34. package/dist/locales/pl/collections.json +14 -0
  35. package/dist/locales/pl/common.json +56 -28
  36. package/dist/locales/pl/orders.json +9 -1
  37. package/dist/locales/pl/products.json +15 -0
  38. package/dist/pages/Root.js +76 -35
  39. package/dist/pages/admins/Detail.js +1 -1
  40. package/dist/pages/admins/List.js +8 -3
  41. package/dist/pages/admins/Provision.js +173 -0
  42. package/dist/pages/admins/Provision.logic.js +53 -0
  43. package/dist/pages/admins/index.js +1 -0
  44. package/dist/pages/assets/List.js +3 -3
  45. package/dist/pages/channels/Detail.js +1 -1
  46. package/dist/pages/collections/Detail.js +9 -1
  47. package/dist/pages/collections/List.js +87 -20
  48. package/dist/pages/collections/_components/ContentsCard.js +1 -1
  49. package/dist/pages/collections/_components/collectionStorefrontAction/CollectionStorefrontAction.js +41 -0
  50. package/dist/pages/collections/_components/collectionStorefrontAction/CollectionStorefrontAction.logic.js +44 -0
  51. package/dist/pages/collections/_components/collectionStorefrontAction/index.js +2 -0
  52. package/dist/pages/countries/Detail.js +6 -1
  53. package/dist/pages/countries/List.js +1 -1
  54. package/dist/pages/dashboard/Dashboard.js +2 -2
  55. package/dist/pages/facets/Detail.js +6 -1
  56. package/dist/pages/facets/List.js +1 -1
  57. package/dist/pages/facets/_components/FacetDetailView.js +3 -2
  58. package/dist/pages/orders/_components/CancelAndRefundDialog.js +80 -19
  59. package/dist/pages/orders/_components/OrderLineImage.logic.js +4 -0
  60. package/dist/pages/orders/_components/Payments.js +39 -23
  61. package/dist/pages/orders/_components/ProductsCard.js +2 -3
  62. package/dist/pages/orders/_components/ProductsTable.js +13 -25
  63. package/dist/pages/orders/_components/TopActions.js +14 -8
  64. package/dist/pages/payment-methods/Detail.js +6 -1
  65. package/dist/pages/payment-methods/List.js +1 -1
  66. package/dist/pages/product-variants/List.js +7 -6
  67. package/dist/pages/products/Detail.js +9 -17
  68. package/dist/pages/products/List.js +3 -2
  69. package/dist/pages/products/ProductInitialVariantFormConfig.js +17 -0
  70. package/dist/pages/products/_components/Variant.js +13 -7
  71. package/dist/pages/products/_components/productStorefrontAction/ProductStorefrontAction.js +42 -0
  72. package/dist/pages/products/_components/productStorefrontAction/ProductStorefrontAction.logic.js +39 -0
  73. package/dist/pages/products/_components/productStorefrontAction/index.js +2 -0
  74. package/dist/pages/roles/Detail.js +1 -1
  75. package/dist/pages/sellers/Detail.js +1 -1
  76. package/dist/pages/shipping-methods/Detail.js +6 -1
  77. package/dist/pages/shipping-methods/List.js +1 -1
  78. package/dist/pages/status/_components/Jobs.js +2 -2
  79. package/dist/pages/stock-locations/Detail.js +1 -1
  80. package/dist/pages/tax-categories/Detail.js +3 -3
  81. package/dist/pages/tax-categories/List.js +1 -1
  82. package/dist/pages/tax-rates/Detail.js +6 -1
  83. package/dist/pages/tax-rates/List.js +1 -1
  84. package/dist/pages/zones/Detail.js +6 -1
  85. package/dist/pages/zones/List.js +1 -1
  86. package/dist/version.js +1 -1
  87. package/package.json +5 -5
@@ -1,6 +1,8 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import { Routes, apiClient, DetailList, deepMerge, ListBadge, ListLocations, useTranslation, TableLabel, } from '@deenruv/react-ui-devkit';
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Button, Routes, apiClient, DetailList, deepMerge, ListBadge, ListLocations, useTranslation, TableLabel, useServer, } from '@deenruv/react-ui-devkit';
3
3
  import { Permission, SortOrder } from '@deenruv/admin-types';
4
+ import { UserPlus } from 'lucide-react';
5
+ import { useNavigate } from 'react-router';
4
6
  const tableId = 'admins-list-view';
5
7
  const { selector } = ListLocations[tableId];
6
8
  const fetch = async ({ page, perPage, filter, filterOperator, sort }, additionalSelector) => {
@@ -40,6 +42,9 @@ const onRemove = async (items) => {
40
42
  };
41
43
  export const AdminsListPage = () => {
42
44
  const { t } = useTranslation('admins');
45
+ const navigate = useNavigate();
46
+ const userPermissions = useServer(({ userPermissions }) => userPermissions);
47
+ const canCreateAdministrators = userPermissions.includes(Permission.CreateAdministrator);
43
48
  return (_jsx(DetailList, { filterFields: [
44
49
  { key: 'firstName', operator: 'StringOperators' },
45
50
  { key: 'emailAddress', operator: 'StringOperators' },
@@ -52,5 +57,5 @@ export const AdminsListPage = () => {
52
57
  header: () => _jsx(TableLabel, { children: t('table.role') }),
53
58
  cell: ({ row }) => (_jsx("div", { className: "flex gap-1", children: row.original.user.roles.map((r) => (_jsx(ListBadge, { children: r.description }, r.description))) })),
54
59
  },
55
- ], entityName: 'Administrator', route: Routes['admins'], tableId: tableId, fetch: fetch, onRemove: onRemove, createPermissions: [Permission.CreateAdministrator], deletePermissions: [Permission.DeleteAdministrator] }));
60
+ ], entityName: 'Administrator', route: Routes['admins'], tableId: tableId, fetch: fetch, onRemove: onRemove, createPermissions: [Permission.CreateAdministrator], deletePermissions: [Permission.DeleteAdministrator], additionalButtons: canCreateAdministrators ? (_jsxs(Button, { variant: "outline", className: "flex items-center gap-2", onClick: () => navigate(Routes.admins.provision), children: [_jsx(UserPlus, { size: 16 }), t('provision.action')] })) : null }));
56
61
  };
@@ -0,0 +1,173 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useEffect, useMemo, useState } from 'react';
3
+ import { useNavigate } from 'react-router';
4
+ import { ArrowLeft, BadgeCheck, ShieldCheck, UserPlus } from 'lucide-react';
5
+ import { toast } from 'sonner';
6
+ import { apiClient, Badge, Button, Card, CardContent, CardDescription, CardHeader, CardTitle, Checkbox, DEFAULT_CHANNEL_CODE, Input, Label, MultipleSelector, PageBlock, Routes, Separator, useServer, useTranslation, } from '@deenruv/react-ui-devkit';
7
+ import { PermissionsTable } from "../roles/_components/PermissionsTable";
8
+ import { getSelectedAssignablePermissions, normalizeRoleCode, SHOP_MANAGER_ROLE_PERMISSIONS, validateAdminProvisionForm, } from './Provision.logic';
9
+ const roleProvisionSelector = {
10
+ id: true,
11
+ code: true,
12
+ description: true,
13
+ permissions: true,
14
+ channels: {
15
+ id: true,
16
+ code: true,
17
+ },
18
+ };
19
+ const findRoleByCode = async (code) => {
20
+ const response = await apiClient('query')({
21
+ roles: [
22
+ {
23
+ options: {
24
+ take: 1,
25
+ filter: {
26
+ code: {
27
+ eq: code,
28
+ },
29
+ },
30
+ },
31
+ },
32
+ { items: roleProvisionSelector },
33
+ ],
34
+ });
35
+ return response.roles.items[0];
36
+ };
37
+ export const AdminsProvisionPage = () => {
38
+ const { t } = useTranslation('admins');
39
+ const { t: tRoles } = useTranslation('roles');
40
+ const navigate = useNavigate();
41
+ const { channels, serverConfig } = useServer();
42
+ const [firstName, setFirstName] = useState('');
43
+ const [lastName, setLastName] = useState('');
44
+ const [emailAddress, setEmailAddress] = useState('');
45
+ const [password, setPassword] = useState('');
46
+ const [roleCode, setRoleCode] = useState('shop-manager');
47
+ const [roleDescription, setRoleDescription] = useState(t('provision.presets.shopManager.roleDescription'));
48
+ const [channelIds, setChannelIds] = useState([]);
49
+ const [permissions, setPermissions] = useState(SHOP_MANAGER_ROLE_PERMISSIONS);
50
+ const [reuseExistingRole, setReuseExistingRole] = useState(false);
51
+ const [errors, setErrors] = useState({});
52
+ const [submitting, setSubmitting] = useState(false);
53
+ const channelOptions = useMemo(() => channels.map((channel) => ({
54
+ value: channel.id,
55
+ label: channel.code === DEFAULT_CHANNEL_CODE ? tRoles('defaultChannel') : channel.code,
56
+ })), [channels, tRoles]);
57
+ const currentChannelOptions = useMemo(() => channelIds.map((id) => channelOptions.find((option) => option.value === id) || { value: id, label: id }), [channelIds, channelOptions]);
58
+ const assignablePermissions = useMemo(() => {
59
+ if (!serverConfig?.permissions)
60
+ return undefined;
61
+ return new Set(serverConfig.permissions
62
+ .filter((permission) => permission.assignable)
63
+ .map((permission) => permission.name));
64
+ }, [serverConfig]);
65
+ const selectedAssignablePermissions = useMemo(() => getSelectedAssignablePermissions(permissions, assignablePermissions), [assignablePermissions, permissions]);
66
+ useEffect(() => {
67
+ if (!channelIds.length && channels.length) {
68
+ setChannelIds(channels.map((channel) => channel.id));
69
+ }
70
+ }, [channelIds.length, channels]);
71
+ useEffect(() => {
72
+ setRoleDescription(t('provision.presets.shopManager.roleDescription'));
73
+ }, [t]);
74
+ const applyShopManagerPreset = () => {
75
+ setRoleCode('shop-manager');
76
+ setRoleDescription(t('provision.presets.shopManager.roleDescription'));
77
+ setPermissions(SHOP_MANAGER_ROLE_PERMISSIONS);
78
+ };
79
+ const validateForm = () => {
80
+ const result = validateAdminProvisionForm({
81
+ firstName,
82
+ lastName,
83
+ emailAddress,
84
+ password,
85
+ roleCode,
86
+ channelIds,
87
+ permissions,
88
+ reuseExistingRole,
89
+ }, {
90
+ firstNameRequired: t('validation.firstNameRequired'),
91
+ lastNameRequired: t('validation.lastNameRequired'),
92
+ emailRequired: t('provision.validation.emailRequired'),
93
+ emailInvalid: t('provision.validation.emailInvalid'),
94
+ passwordRequired: t('validation.passwordRequired'),
95
+ roleCodeRequired: t('provision.validation.roleCodeRequired'),
96
+ channelsRequired: t('provision.validation.channelsRequired'),
97
+ permissionsRequired: t('provision.validation.permissionsRequired'),
98
+ }, assignablePermissions);
99
+ setErrors(result.errors);
100
+ return result.valid;
101
+ };
102
+ const createRole = async () => {
103
+ const response = await apiClient('mutation')({
104
+ createRole: [
105
+ {
106
+ input: {
107
+ code: normalizeRoleCode(roleCode),
108
+ description: roleDescription.trim() || normalizeRoleCode(roleCode),
109
+ channelIds,
110
+ permissions: selectedAssignablePermissions,
111
+ },
112
+ },
113
+ roleProvisionSelector,
114
+ ],
115
+ });
116
+ return response.createRole;
117
+ };
118
+ const createAdministrator = async (roleId) => {
119
+ const response = await apiClient('mutation')({
120
+ createAdministrator: [
121
+ {
122
+ input: {
123
+ firstName: firstName.trim(),
124
+ lastName: lastName.trim(),
125
+ emailAddress: emailAddress.trim(),
126
+ password,
127
+ roleIds: [roleId],
128
+ },
129
+ },
130
+ {
131
+ id: true,
132
+ emailAddress: true,
133
+ },
134
+ ],
135
+ });
136
+ return response.createAdministrator;
137
+ };
138
+ const handleSubmit = async () => {
139
+ if (!validateForm())
140
+ return;
141
+ setSubmitting(true);
142
+ const normalizedRoleCode = normalizeRoleCode(roleCode);
143
+ try {
144
+ const existingRole = await findRoleByCode(normalizedRoleCode);
145
+ let roleId = existingRole?.id;
146
+ if (reuseExistingRole) {
147
+ if (!roleId) {
148
+ setErrors({ roleCode: t('provision.validation.roleNotFound') });
149
+ toast.error(t('provision.toasts.roleNotFound'));
150
+ return;
151
+ }
152
+ }
153
+ else {
154
+ if (existingRole) {
155
+ setErrors({ roleCode: t('provision.validation.roleCodeExists') });
156
+ toast.error(t('provision.toasts.roleCodeExists'));
157
+ return;
158
+ }
159
+ roleId = (await createRole()).id;
160
+ }
161
+ const administrator = await createAdministrator(roleId);
162
+ toast.success(t('provision.toasts.success'));
163
+ navigate(Routes.admins.to(administrator.id));
164
+ }
165
+ catch (error) {
166
+ toast.error(error instanceof Error ? error.message : t('provision.toasts.error'));
167
+ }
168
+ finally {
169
+ setSubmitting(false);
170
+ }
171
+ };
172
+ return (_jsx(PageBlock, { children: _jsxs("div", { className: "flex flex-col gap-6", children: [_jsxs("div", { className: "flex flex-col gap-4 lg:flex-row lg:items-center lg:justify-between", children: [_jsxs("div", { className: "flex items-start gap-3", children: [_jsx(Button, { variant: "secondary", size: "icon", className: "mt-1", onClick: () => navigate(Routes.admins.list), children: _jsx(ArrowLeft, { className: "size-4" }) }), _jsxs("div", { children: [_jsx("h1", { className: "text-3xl font-bold tracking-tight", children: t('provision.title') }), _jsx("p", { className: "mt-1 max-w-3xl text-sm text-muted-foreground", children: t('provision.description') })] })] }), _jsxs(Button, { className: "gap-2", disabled: submitting, onClick: handleSubmit, children: [_jsx(UserPlus, { className: "size-4" }), submitting ? t('provision.submitting') : t('provision.submit')] })] }), _jsxs("div", { className: "grid gap-4 xl:grid-cols-[minmax(0,1fr)_380px]", children: [_jsxs("div", { className: "flex flex-col gap-4", children: [_jsxs(Card, { children: [_jsxs(CardHeader, { children: [_jsx(CardTitle, { children: t('provision.admin.title') }), _jsx(CardDescription, { children: t('provision.admin.description') })] }), _jsx(CardContent, { children: _jsxs("div", { className: "grid gap-4 md:grid-cols-2", children: [_jsx(Input, { label: t('details.basic.firstName'), value: firstName, onChange: (event) => setFirstName(event.target.value), errors: errors.firstName ? [errors.firstName] : undefined, required: true }), _jsx(Input, { label: t('details.basic.lastName'), value: lastName, onChange: (event) => setLastName(event.target.value), errors: errors.lastName ? [errors.lastName] : undefined, required: true }), _jsx(Input, { label: t('details.basic.emailAddress'), type: "email", value: emailAddress, onChange: (event) => setEmailAddress(event.target.value), errors: errors.emailAddress ? [errors.emailAddress] : undefined, required: true }), _jsx(Input, { label: t('details.basic.password'), type: "password", value: password, onChange: (event) => setPassword(event.target.value), errors: errors.password ? [errors.password] : undefined, required: true })] }) })] }), _jsxs(Card, { children: [_jsxs(CardHeader, { children: [_jsx(CardTitle, { children: t('provision.role.title') }), _jsx(CardDescription, { children: t('provision.role.description') })] }), _jsxs(CardContent, { className: "flex flex-col gap-4", children: [_jsxs("div", { className: "grid gap-4 md:grid-cols-2", children: [_jsx(Input, { label: t('provision.role.code'), value: roleCode, onChange: (event) => setRoleCode(event.target.value), onBlur: () => setRoleCode(normalizeRoleCode(roleCode)), errors: errors.roleCode ? [errors.roleCode] : undefined, required: true }), _jsx(Input, { label: t('provision.role.descriptionLabel'), value: roleDescription, onChange: (event) => setRoleDescription(event.target.value), required: !reuseExistingRole, disabled: reuseExistingRole })] }), _jsxs("label", { className: "flex items-start gap-3 border border-border/70 bg-muted/30 p-3 text-sm", children: [_jsx(Checkbox, { checked: reuseExistingRole, onCheckedChange: (checked) => setReuseExistingRole(checked === true) }), _jsxs("span", { className: "flex flex-col gap-1", children: [_jsx("span", { className: "font-medium", children: t('provision.role.reuseExisting') }), _jsx("span", { className: "text-muted-foreground", children: t('provision.role.reuseExistingHint') })] })] }), !reuseExistingRole && (_jsxs("div", { className: "flex flex-col gap-2", children: [_jsx(Label, { children: t('provision.role.channels') }), _jsx(MultipleSelector, { options: channelOptions, value: currentChannelOptions, placeholder: t('provision.role.channelsPlaceholder'), onChange: (options) => setChannelIds(options.map((option) => option.value)), hideClearAllButton: true }), errors.channelIds && _jsx("p", { className: "text-xs text-destructive", children: errors.channelIds })] }))] })] }), _jsxs(Card, { children: [_jsxs(CardHeader, { children: [_jsx(CardTitle, { children: t('provision.permissions.title') }), _jsx(CardDescription, { children: t('provision.permissions.description') })] }), _jsx(CardContent, { children: reuseExistingRole ? (_jsx("div", { className: "border border-dashed border-border p-4 text-sm text-muted-foreground", children: t('provision.permissions.reuseExisting') })) : (_jsxs("div", { className: "flex flex-col gap-3", children: [errors.permissions && _jsx("p", { className: "text-xs text-destructive", children: errors.permissions }), _jsx(PermissionsTable, { currentPermissions: selectedAssignablePermissions, onPermissionsChange: setPermissions })] })) })] })] }), _jsxs("div", { className: "flex flex-col gap-4", children: [_jsxs(Card, { children: [_jsxs(CardHeader, { children: [_jsxs(CardTitle, { className: "flex items-center gap-2", children: [_jsx(ShieldCheck, { className: "size-5 text-primary" }), t('provision.presets.title')] }), _jsx(CardDescription, { children: t('provision.presets.description') })] }), _jsxs(CardContent, { className: "flex flex-col gap-3", children: [_jsx("button", { type: "button", className: "border border-primary/40 bg-primary/10 p-4 text-left transition-colors hover:bg-primary/15", onClick: applyShopManagerPreset, children: _jsxs("div", { className: "flex items-start justify-between gap-3", children: [_jsxs("div", { children: [_jsx("p", { className: "font-medium", children: t('provision.presets.shopManager.title') }), _jsx("p", { className: "mt-1 text-sm text-muted-foreground", children: t('provision.presets.shopManager.description') })] }), _jsx(Badge, { variant: "secondary", children: t('provision.presets.defaultBadge') })] }) }), _jsx(Separator, {}), _jsxs("div", { className: "flex items-start gap-3 text-sm", children: [_jsx(BadgeCheck, { className: "mt-0.5 size-4 text-green-600" }), _jsx("p", { className: "text-muted-foreground", children: t('provision.presets.backendNote') })] })] })] }), _jsxs(Card, { children: [_jsxs(CardHeader, { children: [_jsx(CardTitle, { children: t('provision.summary.title') }), _jsx(CardDescription, { children: t('provision.summary.description') })] }), _jsxs(CardContent, { className: "flex flex-col gap-3 text-sm", children: [_jsxs("div", { className: "flex items-center justify-between gap-4", children: [_jsx("span", { className: "text-muted-foreground", children: t('provision.summary.role') }), _jsx(Badge, { variant: "outline", children: normalizeRoleCode(roleCode) || '-' })] }), _jsxs("div", { className: "flex items-center justify-between gap-4", children: [_jsx("span", { className: "text-muted-foreground", children: t('provision.summary.channels') }), _jsx("span", { className: "font-medium", children: reuseExistingRole ? '-' : channelIds.length })] }), _jsxs("div", { className: "flex items-center justify-between gap-4", children: [_jsx("span", { className: "text-muted-foreground", children: t('provision.summary.permissions') }), _jsx("span", { className: "font-medium", children: reuseExistingRole ? '-' : selectedAssignablePermissions.length })] }), _jsxs("div", { className: "flex items-center justify-between gap-4", children: [_jsx("span", { className: "text-muted-foreground", children: t('provision.summary.mode') }), _jsx("span", { className: "font-medium", children: reuseExistingRole ? t('provision.summary.reuse') : t('provision.summary.create') })] })] })] })] })] })] }) }));
173
+ };
@@ -0,0 +1,53 @@
1
+ import { Permission } from '@deenruv/admin-types';
2
+ export const SHOP_MANAGER_ROLE_PERMISSIONS = [
3
+ Permission.ReadOrder,
4
+ Permission.UpdateOrder,
5
+ Permission.ReadCustomer,
6
+ Permission.UpdateCustomer,
7
+ Permission.ReadProduct,
8
+ Permission.ReadCatalog,
9
+ Permission.ReadAsset,
10
+ Permission.ReadCollection,
11
+ Permission.ReadFacet,
12
+ Permission.ReadPaymentMethod,
13
+ Permission.ReadShippingMethod,
14
+ Permission.ReadCountry,
15
+ Permission.ReadStockLocation,
16
+ ];
17
+ export const normalizeRoleCode = (value) => value.trim().toLowerCase().replace(/\s+/g, '-');
18
+ export const getSelectedAssignablePermissions = (permissions, assignablePermissions) => {
19
+ if (!assignablePermissions)
20
+ return permissions;
21
+ return permissions.filter((permission) => assignablePermissions.has(permission));
22
+ };
23
+ export const validateAdminProvisionForm = (values, messages, assignablePermissions) => {
24
+ const errors = {};
25
+ const normalizedRoleCode = normalizeRoleCode(values.roleCode);
26
+ const selectedAssignablePermissions = getSelectedAssignablePermissions(values.permissions, assignablePermissions);
27
+ if (!values.firstName.trim())
28
+ errors.firstName = messages.firstNameRequired;
29
+ if (!values.lastName.trim())
30
+ errors.lastName = messages.lastNameRequired;
31
+ if (!values.emailAddress.trim())
32
+ errors.emailAddress = messages.emailRequired;
33
+ if (values.emailAddress.trim() && !values.emailAddress.includes('@')) {
34
+ errors.emailAddress = messages.emailInvalid;
35
+ }
36
+ if (!values.password.trim())
37
+ errors.password = messages.passwordRequired;
38
+ if (!normalizedRoleCode)
39
+ errors.roleCode = messages.roleCodeRequired;
40
+ if (!values.reuseExistingRole) {
41
+ if (!values.channelIds.length)
42
+ errors.channelIds = messages.channelsRequired;
43
+ if (!selectedAssignablePermissions.length) {
44
+ errors.permissions = messages.permissionsRequired;
45
+ }
46
+ }
47
+ return {
48
+ errors,
49
+ normalizedRoleCode,
50
+ selectedAssignablePermissions,
51
+ valid: Object.keys(errors).length === 0,
52
+ };
53
+ };
@@ -1,2 +1,3 @@
1
1
  export * from './Detail.js';
2
2
  export * from './List.js';
3
+ export * from './Provision.js';
@@ -1,6 +1,6 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { apiClient, DetailList, deepMerge, ListLocations, createDialogFromComponent, Badge, ImageWithPreview, useTranslation, TableLabel, } from '@deenruv/react-ui-devkit';
3
- import { Permission, SortOrder } from '@deenruv/admin-types';
3
+ import { DeletionResult, Permission, SortOrder } from '@deenruv/admin-types';
4
4
  import { UploadAssetDialog } from "./_components/UploadAssetDialog.js";
5
5
  import { EditAssetDialog } from "./_components/EditAssetDialog.js";
6
6
  const tableId = 'assets-list-view';
@@ -28,7 +28,7 @@ const onRemove = async (items) => {
28
28
  const { deleteAssets } = await apiClient('mutation')({
29
29
  deleteAssets: [{ input: { assetIds: ids } }, { message: true, result: true }],
30
30
  });
31
- return !!deleteAssets.result.length;
31
+ return deleteAssets.result === DeletionResult.DELETED;
32
32
  }
33
33
  catch (error) {
34
34
  return error;
@@ -78,5 +78,5 @@ export const AssetsListPage = () => {
78
78
  return (_jsx("div", { className: "flex flex-wrap gap-1", children: tags.length ? (tags.map((tag, index) => (_jsx(Badge, { variant: "secondary", className: "text-xs", children: tag.value }, index)))) : (_jsx(Badge, { variant: "secondary", className: "text-xs", children: "No Tags" })) }));
79
79
  },
80
80
  },
81
- ], createPermissions: [Permission.CreateChannel], deletePermissions: [Permission.DeleteChannel] }));
81
+ ], createPermissions: [Permission.CreateAsset, Permission.CreateCatalog], deletePermissions: [Permission.DeleteAsset, Permission.DeleteCatalog] }));
82
82
  };
@@ -112,7 +112,7 @@ export const ChannelsDetailPage = () => {
112
112
  if (!id) {
113
113
  throw new Error('Could not find the id.');
114
114
  }
115
- return remove({ input: { id } });
115
+ return remove({ id });
116
116
  }, [remove, id]);
117
117
  return (_jsx("div", { className: "relative flex flex-col gap-y-4", children: _jsx(DetailView, { id: id, locationId: "channels-detail-view", main: {
118
118
  name: 'channel',
@@ -3,6 +3,8 @@ import { useCallback } from 'react';
3
3
  import { useParams } from 'react-router';
4
4
  import { useValidators, DetailView, createDeenruvForm, getMutation, useMutation, useSettings, } from '@deenruv/react-ui-devkit';
5
5
  import { CollectionsDetailView } from "./_components/CollectionDetailView.js";
6
+ import { CollectionStorefrontAction } from "./_components/collectionStorefrontAction";
7
+ import { Permission } from '@deenruv/admin-types';
6
8
  const CreateCollectionMutation = getMutation('createCollection');
7
9
  const EditCollectionMutation = getMutation('updateCollection');
8
10
  const DeleteCollectionMutation = getMutation('deleteCollection');
@@ -46,7 +48,7 @@ export const CollectionsDetailPage = () => {
46
48
  if (!id) {
47
49
  throw new Error('Could not find the id.');
48
50
  }
49
- return remove({ input: { id } });
51
+ return remove({ id });
50
52
  }, [remove, id]);
51
53
  return (_jsx("div", { className: "relative flex flex-col gap-y-4", children: _jsx(DetailView, { id: id, locationId: "collections-detail-view", main: {
52
54
  name: 'collection',
@@ -73,5 +75,11 @@ export const CollectionsDetailPage = () => {
73
75
  onSubmitted: onSubmitHandler,
74
76
  onDeleted: onDeleteHandler,
75
77
  }),
78
+ }, topActions: {
79
+ inline: [_jsx(CollectionStorefrontAction, {}, "collection-storefront-action")],
80
+ }, permissions: {
81
+ create: [Permission.CreateCollection, Permission.CreateCatalog],
82
+ edit: [Permission.UpdateCollection, Permission.UpdateCatalog],
83
+ delete: [Permission.DeleteCollection, Permission.DeleteCatalog],
76
84
  } }) }));
77
85
  };
@@ -1,39 +1,108 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { ArrowDownSquareIcon, ArrowUpSquareIcon, Folder, FolderOpen, XSquareIcon } from 'lucide-react';
2
+ import { ArrowDownSquareIcon, ArrowRight, ArrowUpSquareIcon, CornerDownRight, Folder, FolderOpen } from 'lucide-react';
3
3
  import { Permission, SortOrder } from '@deenruv/admin-types';
4
4
  import { CollectionProductVariantsDrawer } from './_components/CollectionProductVariantsDrawer.js';
5
- import { DrawerTrigger, Routes, apiClient, ListBadge, DetailList, deepMerge, ListLocations, EntityChannelManagementBulkAction, EntityFacetManagementBulkAction, } from '@deenruv/react-ui-devkit';
6
- import { ArrowRight } from 'lucide-react';
5
+ import { Button, DrawerTrigger, Routes, apiClient, ListBadge, DetailList, deepMerge, ListLocations, EntityChannelManagementBulkAction, EntityFacetManagementBulkAction, useDetailList, useTranslation, } from '@deenruv/react-ui-devkit';
6
+ import { useNavigate } from 'react-router';
7
7
  const tableId = 'collections-list-view';
8
8
  const { selector } = ListLocations[tableId];
9
+ const COLLECTION_TREE_FETCH_LIMIT = 1000;
10
+ const hasActiveFilter = (filter) => {
11
+ if (!filter) {
12
+ return false;
13
+ }
14
+ return Object.values(filter).some((value) => {
15
+ if (value === null || value === undefined || value === '') {
16
+ return false;
17
+ }
18
+ if (Array.isArray(value)) {
19
+ return value.length > 0;
20
+ }
21
+ if (typeof value === 'object') {
22
+ return Object.values(value).some((operatorValue) => operatorValue !== null && operatorValue !== undefined && operatorValue !== '');
23
+ }
24
+ return true;
25
+ });
26
+ };
27
+ const buildCollectionTree = (items) => {
28
+ const itemsById = new Map();
29
+ items.forEach((item) => {
30
+ itemsById.set(item.id, { ...item, children: [] });
31
+ });
32
+ const roots = [];
33
+ itemsById.forEach((item) => {
34
+ const parent = item.parentId ? itemsById.get(item.parentId) : undefined;
35
+ if (parent && parent.id !== item.id) {
36
+ parent.children?.push(item);
37
+ }
38
+ else {
39
+ roots.push(item);
40
+ }
41
+ });
42
+ return roots;
43
+ };
44
+ const withoutNestedChildren = (items) => {
45
+ return items.map((item) => ({ ...item, children: [] }));
46
+ };
47
+ const CollectionNameHeader = () => {
48
+ const { sortButton } = useDetailList();
49
+ const { t } = useTranslation('table');
50
+ return sortButton('name', t('columns.name'));
51
+ };
9
52
  const fetch = async ({ page, perPage, filter, filterOperator, sort }, additionalSelector) => {
53
+ const isFiltered = hasActiveFilter(filter);
10
54
  const response = await apiClient('query')({
11
55
  ['collections']: [
12
56
  {
13
57
  options: {
14
- take: perPage,
15
- skip: (page - 1) * perPage,
58
+ take: isFiltered ? perPage : COLLECTION_TREE_FETCH_LIMIT,
59
+ skip: isFiltered ? (page - 1) * perPage : 0,
16
60
  filterOperator: filterOperator,
17
- sort: sort ? { [sort.key]: sort.sortDir } : { createdAt: SortOrder.DESC },
61
+ sort: sort ? { [sort.key]: sort.sortDir } : { position: SortOrder.ASC },
18
62
  ...(filter && { filter }),
19
- topLevelOnly: true,
63
+ ...(!isFiltered && { topLevelOnly: false }),
20
64
  },
21
65
  },
22
66
  { items: deepMerge(selector, additionalSelector ?? {}), totalItems: true },
23
67
  ],
24
68
  });
25
- return response['collections'];
69
+ const collections = response['collections'];
70
+ const items = collections.items;
71
+ if (isFiltered) {
72
+ return {
73
+ ...collections,
74
+ items: withoutNestedChildren(items),
75
+ };
76
+ }
77
+ const rootCollections = buildCollectionTree(items);
78
+ const pageStart = (page - 1) * perPage;
79
+ return {
80
+ ...collections,
81
+ items: rootCollections.slice(pageStart, pageStart + perPage),
82
+ totalItems: rootCollections.length,
83
+ };
84
+ };
85
+ const onRemove = async (items) => {
86
+ const ids = items.map((item) => item.id);
87
+ const { deleteCollections } = await apiClient('mutation')({
88
+ deleteCollections: [{ ids }, { message: true, result: true }],
89
+ });
90
+ return !!deleteCollections.length;
26
91
  };
27
92
  export const CollectionsListPage = () => {
28
- return (_jsx(DetailList, { filterFields: [], detailLinkColumn: "id", searchFields: ['name', 'code'], hideColumns: ['translations', 'breadcrumbs', 'description'], getSubRows: (row) => row.children, additionalColumns: [
93
+ const navigate = useNavigate();
94
+ return (_jsx(DetailList, { filterFields: [], detailLinkColumn: "id", searchFields: ['name', 'code'], hideColumns: ['translations', 'breadcrumbs', 'description', 'children'], getSubRows: (row) => row.children, additionalColumns: [
29
95
  {
30
- accessorKey: 'children',
31
- header: 'Children',
32
- cell: ({ row, getValue }) => {
33
- const value = getValue();
96
+ accessorKey: 'name',
97
+ header: () => _jsx(CollectionNameHeader, {}),
98
+ cell: ({ row }) => {
34
99
  const isExpanded = row.getIsExpanded();
35
- return (_jsx("div", { style: { paddingLeft: `${row.depth * 2}rem` }, children: _jsx(ListBadge, { onClick: row.getToggleExpandedHandler(),
36
- style: { cursor: 'pointer' }, children: isExpanded ? (_jsx(FolderOpen, { size: 16 })) : value?.length > 0 ? (_jsx(Folder, { size: 16 })) : (_jsx(XSquareIcon, { size: 16 })) }) }));
100
+ const canExpand = row.getCanExpand();
101
+ return (_jsxs("div", { className: "flex items-center gap-2", style: { paddingLeft: `${row.depth * 1.5}rem` }, children: [canExpand ? (_jsx(Button, { type: "button", variant: "ghost", size: "icon", className: "size-7 shrink-0 text-stone-700 hover:text-stone-950", onClick: row.getToggleExpandedHandler(), "aria-expanded": isExpanded, "aria-label": `${isExpanded ? 'Collapse' : 'Expand'} ${row.original.name}`, children: isExpanded ? _jsx(FolderOpen, { size: 16 }) : _jsx(Folder, { size: 16 }) })) : (_jsx("span", { className: "flex size-7 shrink-0 items-center justify-center text-stone-400", "aria-hidden": "true", children: row.depth > 0 && _jsx(CornerDownRight, { size: 14 }) })), _jsxs(Button, { type: "button", variant: "outline", className: "h-7 min-w-0 justify-start gap-1 px-2 text-left", title: row.original.name, onClick: () => {
102
+ navigate(Routes.collections.to(row.original.id), {
103
+ viewTransition: true,
104
+ });
105
+ }, children: [_jsx("span", { className: "truncate", children: row.original.name }), _jsx(ArrowRight, { className: "shrink-0 pl-1", size: 16 })] })] }));
37
106
  },
38
107
  },
39
108
  {
@@ -50,7 +119,7 @@ export const CollectionsListPage = () => {
50
119
  {
51
120
  icon: _jsx(FolderOpen, { size: 16 }),
52
121
  label: 'Przenieś zaznaczone kolekcje',
53
- onClick: async ({ table, data, refetch }) => {
122
+ onClick: async ({ table }) => {
54
123
  const selectedRows = table.getSelectedRowModel().flatRows.map((row) => row);
55
124
  if (selectedRows.length === 0) {
56
125
  return { error: 'Nie zaznaczono żadnej kolekcji' };
@@ -118,7 +187,7 @@ export const CollectionsListPage = () => {
118
187
  {
119
188
  icon: _jsx(FolderOpen, { size: 16 }),
120
189
  label: 'Przenieś kolekcje',
121
- onClick: async ({ row, refetch }) => {
190
+ onClick: async () => {
122
191
  try {
123
192
  // const result = await createDialogFromComponent(MoveCollectionsToCollections, [row]);
124
193
  }
@@ -128,7 +197,5 @@ export const CollectionsListPage = () => {
128
197
  return { success: '' };
129
198
  },
130
199
  },
131
- ], entityName: 'Collection', route: Routes['collections'], tableId: tableId, fetch: fetch, onRemove: async () => {
132
- return true;
133
- }, createPermissions: [Permission.CreateCollection], deletePermissions: [Permission.DeleteCollection] }));
200
+ ], entityName: 'Collection', route: Routes['collections'], tableId: tableId, fetch: fetch, onRemove: onRemove, createPermissions: [Permission.CreateCollection, Permission.CreateCatalog], deletePermissions: [Permission.DeleteCollection, Permission.DeleteCatalog] }));
134
201
  };
@@ -31,7 +31,7 @@ export const ContentsCard = ({ collectionId }) => {
31
31
  totalItems: 0,
32
32
  });
33
33
  }, [collectionId]);
34
- return (_jsx(CustomCard, { title: t('details.contents.title'), color: "green", icon: _jsx(CardIcons.group, {}), children: _jsx(DetailList, { noPaddings: true, detailLinkColumn: "id", filterFields: [{ key: 'id', operator: 'IDOperators' }], searchFields: ['code', 'name'], hideColumns: ['customFields', 'product', 'updatedAt', 'createdAt'], entityName: 'Product', route: Routes['products'], tableId: "products-list-view", fetch: fetch, noCreateButton: true, createPermissions: [Permission.CreateProduct], deletePermissions: [Permission.DeleteProduct], additionalColumns: [
34
+ return (_jsx(CustomCard, { title: t('details.contents.title'), color: "green", icon: _jsx(CardIcons.group, {}), children: _jsx(DetailList, { noPaddings: true, detailLinkColumn: "id", filterFields: [{ key: 'id', operator: 'IDOperators' }], searchFields: ['code', 'name'], hideColumns: ['customFields', 'product', 'updatedAt', 'createdAt'], entityName: 'Product', route: Routes['products'], tableId: "products-list-view", fetch: fetch, noCreateButton: true, createPermissions: [Permission.CreateProduct, Permission.CreateCatalog], deletePermissions: [Permission.DeleteProduct, Permission.DeleteCatalog], additionalColumns: [
35
35
  {
36
36
  accessorKey: 'product',
37
37
  enableSorting: false,
@@ -0,0 +1,41 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useDetailView, useGlobalStore, useSettings, useTranslation } from '@deenruv/react-ui-devkit';
3
+ import { StorefrontAction } from "../../../../components/storefrontAction";
4
+ import { getCollectionStorefrontActionState, } from './CollectionStorefrontAction.logic';
5
+ const COLLECTION_STOREFRONT_FORM_KEYS = ['CreateCollectionInput', 'translations', 'isPrivate'];
6
+ export const CollectionStorefrontAction = () => {
7
+ const { t } = useTranslation('collections');
8
+ const selectedChannelCode = useSettings((state) => state.selectedChannel?.code);
9
+ const languageCode = useSettings((state) => state.translationsLanguage);
10
+ const resolveStorefrontEntityUrl = useGlobalStore((state) => state.ui?.resolveStorefrontEntityUrl);
11
+ const { entity, form, id, loading } = useDetailView('collections-detail-view', ...COLLECTION_STOREFRONT_FORM_KEYS);
12
+ const formTranslations = form.base.watch('translations');
13
+ const formIsPrivate = form.base.watch('isPrivate');
14
+ if (!id || loading || !entity || !resolveStorefrontEntityUrl)
15
+ return null;
16
+ const state = getCollectionStorefrontActionState({
17
+ collection: entity,
18
+ selectedChannelCode,
19
+ languageCode,
20
+ formTranslations,
21
+ formIsPrivate,
22
+ resolveStorefrontEntityUrl,
23
+ });
24
+ const label = t('storefrontAction.label');
25
+ if (state.kind === 'hidden')
26
+ return null;
27
+ const disabledTooltips = {
28
+ collectionPrivate: t('storefrontAction.disabled.collectionPrivate'),
29
+ missingChannel: t('storefrontAction.disabled.missingChannel'),
30
+ missingSlug: t('storefrontAction.disabled.missingSlug'),
31
+ unsavedPrivate: t('storefrontAction.disabled.unsavedPrivate'),
32
+ unsavedSlug: t('storefrontAction.disabled.unsavedSlug'),
33
+ resolverFailed: t('storefrontAction.disabled.resolverFailed'),
34
+ resolverEmpty: t('storefrontAction.disabled.resolverEmpty'),
35
+ urlNotAbsolute: t('storefrontAction.disabled.urlNotAbsolute'),
36
+ unsupportedProtocol: t('storefrontAction.disabled.unsupportedProtocol'),
37
+ };
38
+ return (_jsx(StorefrontAction, { label: label, state: state.kind === 'ready'
39
+ ? { kind: 'ready', url: state.url }
40
+ : { kind: 'disabled', tooltip: disabledTooltips[state.reason] } }));
41
+ };
@@ -0,0 +1,44 @@
1
+ import { getStorefrontEntityUrlState, } from '../../../../components/storefrontAction/StorefrontAction.logic';
2
+ const getFormSlug = (formTranslations, languageCode) => {
3
+ if (!Array.isArray(formTranslations))
4
+ return undefined;
5
+ const translation = formTranslations.find((value) => typeof value === 'object' && value !== null && 'languageCode' in value && value.languageCode === languageCode);
6
+ return typeof translation?.slug === 'string' ? translation.slug : undefined;
7
+ };
8
+ export const normalizeCollectionBreadcrumbs = (collection, persistedSlug) => {
9
+ const ancestors = collection.breadcrumbs
10
+ .slice(1)
11
+ .filter(({ id }) => id !== collection.id)
12
+ .map(({ id, slug }) => ({ id, slug }));
13
+ return [...ancestors, { id: collection.id, slug: persistedSlug }];
14
+ };
15
+ export const getCollectionStorefrontActionState = ({ collection, selectedChannelCode, languageCode, formTranslations, formIsPrivate, resolveStorefrontEntityUrl, }) => {
16
+ if (!selectedChannelCode)
17
+ return { kind: 'disabled', reason: 'missingChannel' };
18
+ const persistedTranslation = languageCode
19
+ ? collection.translations.find((translation) => translation.languageCode === languageCode)
20
+ : undefined;
21
+ if (!languageCode || typeof persistedTranslation?.slug !== 'string' || !persistedTranslation.slug.trim()) {
22
+ return { kind: 'disabled', reason: 'missingSlug' };
23
+ }
24
+ const context = {
25
+ entityType: 'collection',
26
+ entityId: collection.id,
27
+ slug: persistedTranslation.slug,
28
+ channelCode: selectedChannelCode,
29
+ languageCode,
30
+ breadcrumbs: normalizeCollectionBreadcrumbs(collection, persistedTranslation.slug),
31
+ };
32
+ const urlState = getStorefrontEntityUrlState(context, resolveStorefrontEntityUrl);
33
+ if (urlState.kind === 'hidden')
34
+ return urlState;
35
+ if (collection.isPrivate)
36
+ return { kind: 'disabled', reason: 'collectionPrivate' };
37
+ if (formIsPrivate !== collection.isPrivate) {
38
+ return { kind: 'disabled', reason: 'unsavedPrivate' };
39
+ }
40
+ if (getFormSlug(formTranslations, languageCode) !== persistedTranslation.slug) {
41
+ return { kind: 'disabled', reason: 'unsavedSlug' };
42
+ }
43
+ return urlState.kind === 'ready' ? { ...urlState, context } : urlState;
44
+ };
@@ -0,0 +1,2 @@
1
+ export * from './CollectionStorefrontAction';
2
+ export * from './CollectionStorefrontAction.logic';
@@ -3,6 +3,7 @@ import { useParams } from 'react-router';
3
3
  import { useValidators, DetailView, createDeenruvForm, getMutation, useMutation, useTranslation, } from '@deenruv/react-ui-devkit';
4
4
  import { CountryDetailView } from "./_components/CountryDetailView.js";
5
5
  import { useCallback } from 'react';
6
+ import { Permission } from '@deenruv/admin-types';
6
7
  const CreateCountryMutation = getMutation('createCountry');
7
8
  const EditCountryMutation = getMutation('updateCountry');
8
9
  const DeleteCountryMutation = getMutation('deleteCountry');
@@ -34,7 +35,7 @@ export const CountriesDetailPage = () => {
34
35
  if (!id) {
35
36
  throw new Error('Could not find the id.');
36
37
  }
37
- return remove({ input: { id } });
38
+ return remove({ id });
38
39
  }, [remove, id]);
39
40
  return (_jsx("div", { className: "relative flex flex-col gap-y-4", children: _jsx(DetailView, { id: id, locationId: "countries-detail-view", main: {
40
41
  name: 'country',
@@ -53,5 +54,9 @@ export const CountriesDetailPage = () => {
53
54
  onSubmitted: onSubmitHandler,
54
55
  onDeleted: onDeleteHandler,
55
56
  }),
57
+ }, permissions: {
58
+ create: [Permission.CreateCountry, Permission.CreateSettings],
59
+ edit: [Permission.UpdateCountry, Permission.UpdateSettings],
60
+ delete: [Permission.DeleteCountry, Permission.DeleteSettings],
56
61
  } }) }));
57
62
  };
@@ -43,5 +43,5 @@ export const CountriesListPage = () => {
43
43
  { key: 'name', operator: 'StringOperators' },
44
44
  { key: 'enabled', operator: 'BooleanOperators' },
45
45
  { key: 'code', operator: 'StringOperators' },
46
- ], detailLinkColumn: "id", searchFields: ['name', 'code'], hideColumns: ['customFields', 'translations'], entityName: 'Country', route: Routes['countries'], tableId: tableId, fetch: fetch, onRemove: onRemove, createPermissions: [Permission.CreateCountry], deletePermissions: [Permission.DeleteCountry] }));
46
+ ], detailLinkColumn: "id", searchFields: ['name', 'code'], hideColumns: ['customFields', 'translations'], entityName: 'Country', route: Routes['countries'], tableId: tableId, fetch: fetch, onRemove: onRemove, createPermissions: [Permission.CreateCountry, Permission.CreateSettings], deletePermissions: [Permission.DeleteCountry, Permission.DeleteSettings] }));
47
47
  };