@vendure/dashboard 3.6.0-minor-202511061555 → 3.6.0-minor-202512161454
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/dist/plugin/constants.js +2 -2
- package/dist/vite/constants.js +1 -0
- package/dist/vite/utils/compiler.d.ts +1 -0
- package/dist/vite/utils/compiler.js +5 -4
- package/dist/vite/utils/get-dashboard-paths.d.ts +5 -0
- package/dist/vite/utils/get-dashboard-paths.js +20 -0
- package/dist/vite/vite-plugin-dashboard-metadata.js +2 -1
- package/dist/vite/vite-plugin-tailwind-source.js +2 -15
- package/dist/vite/vite-plugin-translations.d.ts +10 -1
- package/dist/vite/vite-plugin-translations.js +156 -45
- package/dist/vite/vite-plugin-vendure-dashboard.d.ts +12 -0
- package/dist/vite/vite-plugin-vendure-dashboard.js +1 -0
- package/lingui.config.js +1 -0
- package/package.json +7 -7
- package/src/app/routeTree.gen.ts +1221 -0
- package/src/app/routes/_authenticated/_administrators/administrators.tsx +9 -12
- package/src/app/routes/_authenticated/_administrators/administrators_.$id.tsx +9 -12
- package/src/app/routes/_authenticated/_assets/assets_.$id.tsx +6 -9
- package/src/app/routes/_authenticated/_channels/channels.tsx +9 -12
- package/src/app/routes/_authenticated/_channels/channels_.$id.tsx +9 -12
- package/src/app/routes/_authenticated/_collections/collections.tsx +9 -12
- package/src/app/routes/_authenticated/_collections/collections_.$id.tsx +9 -12
- package/src/app/routes/_authenticated/_countries/countries.tsx +9 -12
- package/src/app/routes/_authenticated/_countries/countries_.$id.tsx +9 -12
- package/src/app/routes/_authenticated/_customer-groups/customer-groups.tsx +9 -12
- package/src/app/routes/_authenticated/_customer-groups/customer-groups_.$id.tsx +9 -12
- package/src/app/routes/_authenticated/_customers/components/customer-history/index.ts +0 -1
- package/src/app/routes/_authenticated/_customers/customers.tsx +9 -12
- package/src/app/routes/_authenticated/_customers/customers_.$id.tsx +9 -12
- package/src/app/routes/_authenticated/_facets/facets.tsx +9 -12
- package/src/app/routes/_authenticated/_facets/facets_.$facetId.values_.$id.tsx +9 -12
- package/src/app/routes/_authenticated/_facets/facets_.$id.tsx +9 -12
- package/src/app/routes/_authenticated/_global-settings/global-settings.tsx +10 -13
- package/src/app/routes/_authenticated/_orders/components/add-surcharge-form.tsx +139 -0
- package/src/app/routes/_authenticated/_orders/components/edit-order-table.tsx +3 -0
- package/src/app/routes/_authenticated/_orders/components/fulfill-order-dialog.tsx +3 -1
- package/src/app/routes/_authenticated/_orders/components/order-address.tsx +3 -3
- package/src/app/routes/_authenticated/_orders/components/order-detail-shared.tsx +41 -41
- package/src/app/routes/_authenticated/_orders/components/order-history/order-history-utils.tsx +1 -1
- package/src/app/routes/_authenticated/_orders/components/order-modification-summary.tsx +49 -11
- package/src/app/routes/_authenticated/_orders/components/order-table.tsx +4 -1
- package/src/app/routes/_authenticated/_orders/components/use-transition-order-to-state.tsx +2 -3
- package/src/app/routes/_authenticated/_orders/orders.tsx +3 -3
- package/src/app/routes/_authenticated/_orders/orders_.$id_.modify.tsx +12 -3
- package/src/app/routes/_authenticated/_orders/orders_.draft.$id.tsx +27 -30
- package/src/app/routes/_authenticated/_orders/utils/use-modify-order.ts +23 -0
- package/src/app/routes/_authenticated/_payment-methods/payment-methods.tsx +9 -12
- package/src/app/routes/_authenticated/_payment-methods/payment-methods_.$id.tsx +9 -12
- package/src/app/routes/_authenticated/_product-variants/components/add-currency-dropdown.tsx +3 -3
- package/src/app/routes/_authenticated/_product-variants/components/add-stock-location-dropdown.tsx +2 -2
- package/src/app/routes/_authenticated/_product-variants/product-variants.graphql.ts +1 -0
- package/src/app/routes/_authenticated/_product-variants/product-variants_.$id.tsx +10 -12
- package/src/app/routes/_authenticated/_products/products.graphql.ts +1 -0
- package/src/app/routes/_authenticated/_products/products.tsx +15 -18
- package/src/app/routes/_authenticated/_products/products_.$id.tsx +9 -12
- package/src/app/routes/_authenticated/_products/products_.$productId.option-groups.$id.tsx +9 -12
- package/src/app/routes/_authenticated/_products/products_.$productId.option-groups.$productOptionGroupId.options_.$id.tsx +9 -12
- package/src/app/routes/_authenticated/_profile/profile.tsx +3 -3
- package/src/app/routes/_authenticated/_promotions/promotions.tsx +9 -12
- package/src/app/routes/_authenticated/_promotions/promotions_.$id.tsx +9 -12
- package/src/app/routes/_authenticated/_roles/roles.tsx +9 -12
- package/src/app/routes/_authenticated/_roles/roles_.$id.tsx +9 -12
- package/src/app/routes/_authenticated/_sellers/sellers.tsx +9 -12
- package/src/app/routes/_authenticated/_sellers/sellers_.$id.tsx +9 -12
- package/src/app/routes/_authenticated/_shipping-methods/shipping-methods.tsx +11 -12
- package/src/app/routes/_authenticated/_shipping-methods/shipping-methods_.$id.tsx +19 -20
- package/src/app/routes/_authenticated/_stock-locations/stock-locations.tsx +9 -12
- package/src/app/routes/_authenticated/_stock-locations/stock-locations_.$id.tsx +9 -12
- package/src/app/routes/_authenticated/_system/healthchecks.tsx +2 -3
- package/src/app/routes/_authenticated/_system/job-queue.tsx +3 -3
- package/src/app/routes/_authenticated/_tax-categories/tax-categories.tsx +9 -12
- package/src/app/routes/_authenticated/_tax-categories/tax-categories_.$id.tsx +9 -12
- package/src/app/routes/_authenticated/_tax-rates/tax-rates.tsx +9 -12
- package/src/app/routes/_authenticated/_tax-rates/tax-rates_.$id.tsx +9 -12
- package/src/app/routes/_authenticated/_zones/components/zone-bulk-actions.tsx +49 -1
- package/src/app/routes/_authenticated/_zones/components/zone-countries-table.tsx +34 -16
- package/src/app/routes/_authenticated/_zones/zones.tsx +9 -12
- package/src/app/routes/_authenticated/_zones/zones_.$id.tsx +9 -12
- package/src/app/routes/_authenticated/index.tsx +5 -3
- package/src/i18n/locales/bg.po +3436 -0
- package/src/lib/components/data-input/datetime-input.tsx +1 -1
- package/src/lib/components/data-input/default-relation-input.tsx +1 -1
- package/src/lib/components/data-input/relation-selector.tsx +1 -1
- package/src/lib/components/data-input/string-list-input.tsx +188 -26
- package/src/lib/components/data-input/struct-form-input.tsx +175 -174
- package/src/lib/components/data-table/column-header-wrapper.tsx +1 -1
- package/src/lib/components/data-table/data-table-filter-badge.tsx +2 -2
- package/src/lib/components/data-table/data-table.tsx +1 -1
- package/src/lib/components/data-table/use-generated-columns.tsx +1 -1
- package/src/lib/components/layout/channel-switcher.tsx +6 -2
- package/src/lib/components/layout/content-language-selector.tsx +6 -7
- package/src/lib/components/layout/dev-mode-indicator.tsx +7 -3
- package/src/lib/components/layout/language-dialog.tsx +26 -13
- package/src/lib/components/layout/manage-languages-dialog.tsx +10 -29
- package/src/lib/components/layout/nav-item-wrapper.tsx +1 -1
- package/src/lib/components/shared/asset/asset-gallery.tsx +8 -3
- package/src/lib/components/shared/configurable-operation-multi-selector.tsx +14 -16
- package/src/lib/components/shared/custom-fields-form.tsx +14 -9
- package/src/lib/components/shared/language-selector.tsx +14 -6
- package/src/lib/components/shared/multi-select.tsx +1 -1
- package/src/lib/components/shared/navigation-confirmation.tsx +1 -1
- package/src/lib/components/shared/table-cell/order-table-cell-components.tsx +4 -4
- package/src/lib/components/ui/carousel.tsx +2 -2
- package/src/lib/components/ui/chart.tsx +1 -1
- package/src/lib/components/ui/context-menu.tsx +1 -1
- package/src/lib/components/ui/drawer.tsx +1 -1
- package/src/lib/components/ui/grid-layout.tsx +1 -1
- package/src/lib/components/ui/input-group.tsx +1 -0
- package/src/lib/components/ui/input-otp.tsx +1 -1
- package/src/lib/components/ui/menubar.tsx +1 -1
- package/src/lib/components/ui/navigation-menu.tsx +1 -1
- package/src/lib/components/ui/progress.tsx +1 -1
- package/src/lib/components/ui/radio-group.tsx +1 -1
- package/src/lib/components/ui/resizable.tsx +1 -1
- package/src/lib/components/ui/select.tsx +1 -1
- package/src/lib/components/ui/slider.tsx +1 -1
- package/src/lib/components/ui/toggle-group.tsx +2 -2
- package/src/lib/components/ui/toggle.tsx +1 -1
- package/src/lib/framework/component-registry/component-registry.tsx +2 -6
- package/src/lib/framework/document-introspection/add-custom-fields.spec.ts +907 -1
- package/src/lib/framework/document-introspection/add-custom-fields.ts +248 -119
- package/src/lib/framework/extension-api/display-component-extensions.tsx +4 -3
- package/src/lib/framework/extension-api/logic/detail-forms.ts +0 -13
- package/src/lib/framework/extension-api/logic/navigation.ts +1 -1
- package/src/lib/framework/extension-api/types/data-table.ts +4 -2
- package/src/lib/framework/extension-api/types/layout.ts +34 -1
- package/src/lib/framework/extension-api/types/navigation.ts +7 -2
- package/src/lib/framework/form-engine/use-generated-form.tsx +7 -1
- package/src/lib/framework/history-entry/history-entry.tsx +1 -1
- package/src/lib/framework/layout-engine/action-bar-item-wrapper.tsx +185 -0
- package/src/lib/framework/layout-engine/dev-mode-button.tsx +15 -13
- package/src/lib/framework/layout-engine/location-wrapper.tsx +3 -1
- package/src/lib/framework/layout-engine/page-layout.spec.tsx +138 -0
- package/src/lib/framework/layout-engine/page-layout.tsx +294 -69
- package/src/lib/framework/nav-menu/nav-menu-extensions.ts +1 -1
- package/src/lib/framework/page/detail-page-route-loader.tsx +1 -1
- package/src/lib/framework/page/page-api.ts +1 -1
- package/src/lib/framework/page/use-detail-page.ts +4 -2
- package/src/lib/framework/page/use-extended-router.tsx +20 -16
- package/src/lib/framework/registry/registry-types.ts +2 -1
- package/src/lib/graphql/api.ts +3 -8
- package/src/lib/graphql/graphql-env.d.ts +29 -10
- package/src/lib/hooks/use-permissions.ts +3 -3
- package/src/lib/hooks/use-sorted-languages.ts +41 -0
- package/src/lib/index.ts +1 -0
- package/src/lib/lib/load-i18n-messages.ts +4 -1
- package/src/lib/providers/channel-provider.tsx +11 -7
- package/src/lib/utils/config-utils.ts +19 -0
- package/src/lib/virtual.d.ts +3 -0
- package/LICENSE.md +0 -42
- package/src/app/routes/_authenticated/_facets/components/edit-facet-value.tsx +0 -129
- /package/src/{app/routes/_authenticated/_global-settings → lib}/utils/global-languages.ts +0 -0
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { Permission } from '@vendure/common/lib/generated-types';
|
|
2
|
-
|
|
3
1
|
import { useAuth } from './use-auth.js';
|
|
4
2
|
import { useChannel } from './use-channel.js';
|
|
5
3
|
|
|
@@ -33,7 +31,9 @@ export function usePermissions() {
|
|
|
33
31
|
if (!selectedChannel) {
|
|
34
32
|
return false;
|
|
35
33
|
}
|
|
36
|
-
return permissions.some(permission =>
|
|
34
|
+
return permissions.some(permission =>
|
|
35
|
+
selectedChannel.permissions.includes(permission as (typeof selectedChannel.permissions)[number]),
|
|
36
|
+
);
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
return { hasPermissions };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
|
|
3
|
+
import { useLocalFormat } from './use-local-format.js';
|
|
4
|
+
|
|
5
|
+
export interface SortedLanguage {
|
|
6
|
+
code: string;
|
|
7
|
+
label: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @description
|
|
12
|
+
* This hook takes an array of language codes and returns a sorted array of language objects
|
|
13
|
+
* with code and localized label, sorted alphabetically by the label.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* const sortedLanguages = useSortedLanguages(['en', 'fr', 'de']);
|
|
18
|
+
* // Returns: [{ code: 'de', label: 'German' }, { code: 'en', label: 'English' }, { code: 'fr', label: 'French' }]
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* @param availableLanguages - Array of language codes to sort
|
|
22
|
+
* @returns Sorted array of language objects with code and label
|
|
23
|
+
*
|
|
24
|
+
* @docsCategory hooks
|
|
25
|
+
* @docsPage useSortedLanguages
|
|
26
|
+
* @docsWeight 0
|
|
27
|
+
*/
|
|
28
|
+
export function useSortedLanguages(availableLanguages?: string[] | null): SortedLanguage[] {
|
|
29
|
+
const { formatLanguageName } = useLocalFormat();
|
|
30
|
+
|
|
31
|
+
return useMemo(
|
|
32
|
+
() =>
|
|
33
|
+
(availableLanguages ?? [])
|
|
34
|
+
.map(code => ({
|
|
35
|
+
code,
|
|
36
|
+
label: formatLanguageName(code),
|
|
37
|
+
}))
|
|
38
|
+
.sort((a, b) => a.label.localeCompare(b.label)),
|
|
39
|
+
[availableLanguages, formatLanguageName],
|
|
40
|
+
);
|
|
41
|
+
}
|
package/src/lib/index.ts
CHANGED
|
@@ -247,6 +247,7 @@ export * from './framework/form-engine/utils.js';
|
|
|
247
247
|
export * from './framework/form-engine/value-transformers.js';
|
|
248
248
|
export * from './framework/history-entry/history-entry-extensions.js';
|
|
249
249
|
export * from './framework/history-entry/history-entry.js';
|
|
250
|
+
export * from './framework/layout-engine/action-bar-item-wrapper.js';
|
|
250
251
|
export * from './framework/layout-engine/dev-mode-button.js';
|
|
251
252
|
export * from './framework/layout-engine/layout-extensions.js';
|
|
252
253
|
export * from './framework/layout-engine/location-wrapper.js';
|
|
@@ -12,6 +12,9 @@ export async function loadI18nMessages(locale: string): Promise<Messages> {
|
|
|
12
12
|
} else {
|
|
13
13
|
// In dev mode we allow the dynamic import behaviour
|
|
14
14
|
const { messages } = await import(`../../i18n/locales/${locale}.po`);
|
|
15
|
-
|
|
15
|
+
const pluginTranslations = await import('virtual:plugin-translations');
|
|
16
|
+
const safeLocale = locale.replace(/-/g, '_');
|
|
17
|
+
const pluginTranslationsForLocale = pluginTranslations.default[safeLocale] ?? {};
|
|
18
|
+
return { ...messages, ...pluginTranslationsForLocale };
|
|
16
19
|
}
|
|
17
20
|
}
|
|
@@ -147,6 +147,7 @@ export function ChannelProvider({ children }: Readonly<{ children: React.ReactNo
|
|
|
147
147
|
defaultCurrencyCode: fullChannelData?.defaultCurrencyCode || 'USD',
|
|
148
148
|
pricesIncludeTax: fullChannelData?.pricesIncludeTax || false,
|
|
149
149
|
availableLanguageCodes: fullChannelData?.availableLanguageCodes || ['en'],
|
|
150
|
+
availableCurrencyCodes: fullChannelData?.availableCurrencyCodes || ['USD'],
|
|
150
151
|
};
|
|
151
152
|
});
|
|
152
153
|
}
|
|
@@ -198,13 +199,16 @@ export function ChannelProvider({ children }: Readonly<{ children: React.ReactNo
|
|
|
198
199
|
});
|
|
199
200
|
};
|
|
200
201
|
|
|
201
|
-
const contextValue: ChannelContext =
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
202
|
+
const contextValue: ChannelContext = React.useMemo(
|
|
203
|
+
() => ({
|
|
204
|
+
channels,
|
|
205
|
+
activeChannel: selectedChannel,
|
|
206
|
+
isLoading,
|
|
207
|
+
setActiveChannel: setSelectedChannel,
|
|
208
|
+
refreshChannels,
|
|
209
|
+
}),
|
|
210
|
+
[channels, selectedChannel, isLoading, setSelectedChannel, refreshChannels],
|
|
211
|
+
);
|
|
208
212
|
|
|
209
213
|
return <ChannelContext.Provider value={contextValue}>{children}</ChannelContext.Provider>;
|
|
210
214
|
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { uiConfig } from 'virtual:vendure-ui-config';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Returns the base URL for API requests based on the configuration.
|
|
5
|
+
* Respects the 'auto' setting to derive the URL from the current location.
|
|
6
|
+
*
|
|
7
|
+
* @returns {string} The constructed API base URL, e.g. https://api.example.test:3070
|
|
8
|
+
*/
|
|
9
|
+
export function getApiBaseUrl(): string {
|
|
10
|
+
const schemeAndHost =
|
|
11
|
+
uiConfig.api.host !== 'auto'
|
|
12
|
+
? uiConfig.api.host
|
|
13
|
+
: `${globalThis.location.protocol}//${globalThis.location.hostname}`;
|
|
14
|
+
|
|
15
|
+
const locationPortPart = globalThis.location.port ? `:${globalThis.location.port}` : '';
|
|
16
|
+
const portPart = uiConfig.api.port === 'auto' ? locationPortPart : `:${uiConfig.api.port}`;
|
|
17
|
+
|
|
18
|
+
return schemeAndHost + portPart;
|
|
19
|
+
}
|
package/src/lib/virtual.d.ts
CHANGED
|
@@ -5,6 +5,9 @@ declare module 'virtual:admin-api-schema' {
|
|
|
5
5
|
declare module 'virtual:dashboard-extensions' {
|
|
6
6
|
export const runDashboardExtensions: () => Promise<void>;
|
|
7
7
|
}
|
|
8
|
+
declare module 'virtual:plugin-translations' {
|
|
9
|
+
export default translations = Record<string, any>;
|
|
10
|
+
}
|
|
8
11
|
|
|
9
12
|
declare module 'virtual:vendure-ui-config' {
|
|
10
13
|
import { LanguageCode } from '@vendure/core';
|
package/LICENSE.md
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
# License
|
|
2
|
-
Copyright (C) Vendure GmbH
|
|
3
|
-
|
|
4
|
-
This software is available under two different licenses:
|
|
5
|
-
* GNU General Public License version 3 (GPLv3) as Vendure Community Edition
|
|
6
|
-
* Vendure Commercial License (VCL)
|
|
7
|
-
|
|
8
|
-
The default Vendure license, without a valid Vendure Commercial License agreement, is the Open-Source GPLv3 license.
|
|
9
|
-
|
|
10
|
-
## GNU General Public License version 3 (GPLv3)
|
|
11
|
-
|
|
12
|
-
If you decide to choose the GPLv3 license, you must comply with the following terms:
|
|
13
|
-
|
|
14
|
-
This program is free software: you can redistribute it and/or modify
|
|
15
|
-
it under the terms of the GNU General Public License as published by
|
|
16
|
-
the Free Software Foundation, either version 3 of the License, or
|
|
17
|
-
(at your option) any later version.
|
|
18
|
-
|
|
19
|
-
This program is distributed in the hope that it will be useful,
|
|
20
|
-
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
21
|
-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
22
|
-
GNU General Public License for more details.
|
|
23
|
-
|
|
24
|
-
You should have received a copy of the GNU General Public License
|
|
25
|
-
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
26
|
-
|
|
27
|
-
Additional permission under GNU GPL version 3 section 7:
|
|
28
|
-
|
|
29
|
-
An additional exception under section 7 of the GPL is included in the plugin-exception.txt file,
|
|
30
|
-
which allows you to distribute Vendure plugins (i.e. extensions) under a different license.
|
|
31
|
-
|
|
32
|
-
## Vendure Commercial License (VCL)
|
|
33
|
-
|
|
34
|
-
Alternatively, commercial and supported versions of the program - also known as
|
|
35
|
-
Commercial Distributions - must be used in accordance with the terms and conditions
|
|
36
|
-
contained in a separate written agreement between you and Vendure GmbH.
|
|
37
|
-
For more information about the Vendure Commercial License (VCL) please contact contact@vendure.io.
|
|
38
|
-
|
|
39
|
-
Please see also:
|
|
40
|
-
|
|
41
|
-
- [Licensing FAQ - license-faq.md](license/license-faq.md)
|
|
42
|
-
- [GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 - gpl-3.0.txt](license/gpl-3.0.txt)
|
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
import { usePaginatedList } from '@/vdb/components/shared/paginated-list-data-table.js';
|
|
2
|
-
import { Button } from '@/vdb/components/ui/button.js';
|
|
3
|
-
import { Form, FormControl, FormItem, FormLabel, FormMessage } from '@/vdb/components/ui/form.js';
|
|
4
|
-
import { Input } from '@/vdb/components/ui/input.js';
|
|
5
|
-
import { api } from '@/vdb/graphql/api.js';
|
|
6
|
-
import { graphql } from '@/vdb/graphql/graphql.js';
|
|
7
|
-
import { useUserSettings } from '@/vdb/hooks/use-user-settings.js';
|
|
8
|
-
import { Trans } from '@lingui/react/macro';
|
|
9
|
-
import { useMutation, useQuery } from '@tanstack/react-query';
|
|
10
|
-
import { useForm } from 'react-hook-form';
|
|
11
|
-
|
|
12
|
-
const facetValuesDocument = graphql(`
|
|
13
|
-
query FacetValue($options: FacetValueListOptions) {
|
|
14
|
-
facetValues(options: $options) {
|
|
15
|
-
items {
|
|
16
|
-
id
|
|
17
|
-
name
|
|
18
|
-
code
|
|
19
|
-
customFields
|
|
20
|
-
translations {
|
|
21
|
-
id
|
|
22
|
-
languageCode
|
|
23
|
-
name
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
`);
|
|
29
|
-
|
|
30
|
-
const updateFacetValueDocument = graphql(`
|
|
31
|
-
mutation UpdateFacetValue($input: [UpdateFacetValueInput!]!) {
|
|
32
|
-
updateFacetValues(input: $input) {
|
|
33
|
-
id
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
`);
|
|
37
|
-
|
|
38
|
-
export interface EditFacetValueProps {
|
|
39
|
-
facetValueId: string;
|
|
40
|
-
onSuccess?: () => void;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export function EditFacetValue({ facetValueId, onSuccess }: Readonly<EditFacetValueProps>) {
|
|
44
|
-
const {
|
|
45
|
-
settings: { contentLanguage },
|
|
46
|
-
} = useUserSettings();
|
|
47
|
-
const { refetchPaginatedList } = usePaginatedList();
|
|
48
|
-
const { data: facetValues } = useQuery({
|
|
49
|
-
queryKey: ['facetValues', facetValueId],
|
|
50
|
-
queryFn: () => api.query(facetValuesDocument, { options: { filter: { id: { eq: facetValueId } } } }),
|
|
51
|
-
});
|
|
52
|
-
const { mutate: updateFacetValue } = useMutation({
|
|
53
|
-
mutationFn: api.mutate(updateFacetValueDocument),
|
|
54
|
-
onSuccess: () => {
|
|
55
|
-
refetchPaginatedList();
|
|
56
|
-
onSuccess?.();
|
|
57
|
-
},
|
|
58
|
-
});
|
|
59
|
-
const facetValue = facetValues?.facetValues.items[0];
|
|
60
|
-
|
|
61
|
-
const form = useForm({
|
|
62
|
-
values: {
|
|
63
|
-
name: facetValue?.name ?? '',
|
|
64
|
-
code: facetValue?.code ?? '',
|
|
65
|
-
},
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
if (!facetValue) {
|
|
69
|
-
return <div>Facet value not found</div>;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
const handleSave = (values: { name: string; code: string }) => {
|
|
73
|
-
const translations = facetValue.translations.map(translation => {
|
|
74
|
-
if (translation.languageCode === contentLanguage) {
|
|
75
|
-
return {
|
|
76
|
-
id: translation.id,
|
|
77
|
-
languageCode: translation.languageCode,
|
|
78
|
-
name: values.name,
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
return translation;
|
|
82
|
-
});
|
|
83
|
-
updateFacetValue({
|
|
84
|
-
input: [
|
|
85
|
-
{
|
|
86
|
-
id: facetValue.id,
|
|
87
|
-
translations,
|
|
88
|
-
code: values.code,
|
|
89
|
-
},
|
|
90
|
-
],
|
|
91
|
-
});
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
return (
|
|
95
|
-
<div className="grid gap-4">
|
|
96
|
-
<div className="space-y-2">
|
|
97
|
-
<h4 className="font-medium leading-none">Edit Facet Value</h4>
|
|
98
|
-
<p className="text-sm text-muted-foreground">Update the name and code of this facet value.</p>
|
|
99
|
-
</div>
|
|
100
|
-
<Form {...form}>
|
|
101
|
-
<form onSubmit={form.handleSubmit(handleSave)} className="grid gap-2">
|
|
102
|
-
<FormItem>
|
|
103
|
-
<FormLabel>
|
|
104
|
-
<Trans>Name</Trans>
|
|
105
|
-
</FormLabel>
|
|
106
|
-
<FormControl>
|
|
107
|
-
<Input placeholder="" {...form.register('name')} />
|
|
108
|
-
</FormControl>
|
|
109
|
-
<FormMessage />
|
|
110
|
-
</FormItem>
|
|
111
|
-
<FormItem>
|
|
112
|
-
<FormLabel>
|
|
113
|
-
<Trans>Code</Trans>
|
|
114
|
-
</FormLabel>
|
|
115
|
-
<FormControl>
|
|
116
|
-
<Input placeholder="" {...form.register('code')} />
|
|
117
|
-
</FormControl>
|
|
118
|
-
<FormMessage />
|
|
119
|
-
</FormItem>
|
|
120
|
-
<div className="flex justify-end">
|
|
121
|
-
<Button type="submit" size="sm">
|
|
122
|
-
<Trans>Save changes</Trans>
|
|
123
|
-
</Button>
|
|
124
|
-
</div>
|
|
125
|
-
</form>
|
|
126
|
-
</Form>
|
|
127
|
-
</div>
|
|
128
|
-
);
|
|
129
|
-
}
|
|
File without changes
|