Skip to content

The complete open source platform to run your entire marketplace. Storefront, vendor panel, admin console, and integrations in one enterprise-grade platform you own.

refactor(admin): misc cleanup - remove lodash debounce, fix marketplace translations, remove product additional attributes section

vholik99c3a541cdac
diff --git a/bun.lock b/bun.lock
index 1fd7f3b1f..f951a9eea 100644
--- a/bun.lock
+++ b/bun.lock
@@ -247,6 +247,7 @@
"@types/react": "^18.3.2",
"@types/react-dom": "^18.2.25",
"cors": "^2.8.5",
+ "multer": "^2.0.2",
"prop-types": "^15.8.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
@@ -349,6 +350,7 @@
"@mercurjs/vendor": "workspace:*",
"@tanstack/react-query": "5.64.2",
"@tanstack/react-table": "8.20.5",
+ "algoliasearch": "^5.40.0",
"jsonwebtoken": "9.0.2",
"react-hook-form": "7.49.1",
"react-i18next": "13.5.0",
@@ -393,8 +395,8 @@
"@medusajs/dashboard": "^2.13.0",
"@medusajs/icons": "2.13.0",
"@medusajs/ui": "4.1.1",
- "@mercurjs/client": "2.0.0-canary.6",
- "@mercurjs/dashboard-shared": "2.0.0-canary.6",
+ "@mercurjs/client": "2.0.0-canary.24",
+ "@mercurjs/dashboard-shared": "2.0.0-canary.24",
"@radix-ui/react-dialog": "1.1.4",
"@radix-ui/react-dismissable-layer": "1.1.4",
"@tanstack/react-query": "5.64.2",
@@ -444,6 +446,34 @@
"@acme/api": ["@acme/api@workspace:apps/api"],
+ "@algolia/abtesting": ["@algolia/[email protected]", "", { "dependencies": { "@algolia/client-common": "5.49.1", "@algolia/requester-browser-xhr": "5.49.1", "@algolia/requester-fetch": "5.49.1", "@algolia/requester-node-http": "5.49.1" } }, "sha512-2yuIC48rUuHGhU1U5qJ9kJHaxYpJ0jpDHJVI5ekOxSMYXlH4+HP+pA31G820lsAznfmu2nzDV7n5RO44zIY1zw=="],
+
+ "@algolia/client-abtesting": ["@algolia/[email protected]", "", { "dependencies": { "@algolia/client-common": "5.49.1", "@algolia/requester-browser-xhr": "5.49.1", "@algolia/requester-fetch": "5.49.1", "@algolia/requester-node-http": "5.49.1" } }, "sha512-h6M7HzPin+45/l09q0r2dYmocSSt2MMGOOk5c4O5K/bBBlEwf1BKfN6z+iX4b8WXcQQhf7rgQwC52kBZJt/ZZw=="],
+
+ "@algolia/client-analytics": ["@algolia/[email protected]", "", { "dependencies": { "@algolia/client-common": "5.49.1", "@algolia/requester-browser-xhr": "5.49.1", "@algolia/requester-fetch": "5.49.1", "@algolia/requester-node-http": "5.49.1" } }, "sha512-048T9/Z8OeLmTk8h76QUqaNFp7Rq2VgS2Zm6Y2tNMYGQ1uNuzePY/udB5l5krlXll7ZGflyCjFvRiOtlPZpE9g=="],
+
+ "@algolia/client-common": ["@algolia/[email protected]", "", {}, "sha512-vp5/a9ikqvf3mn9QvHN8PRekn8hW34aV9eX+O0J5mKPZXeA6Pd5OQEh2ZWf7gJY6yyfTlLp5LMFzQUAU+Fpqpg=="],
+
+ "@algolia/client-insights": ["@algolia/[email protected]", "", { "dependencies": { "@algolia/client-common": "5.49.1", "@algolia/requester-browser-xhr": "5.49.1", "@algolia/requester-fetch": "5.49.1", "@algolia/requester-node-http": "5.49.1" } }, "sha512-B6N7PgkvYrul3bntTz/l6uXnhQ2bvP+M7NqTcayh681tSqPaA5cJCUBp/vrP7vpPRpej4Eeyx2qz5p0tE/2N2g=="],
+
+ "@algolia/client-personalization": ["@algolia/[email protected]", "", { "dependencies": { "@algolia/client-common": "5.49.1", "@algolia/requester-browser-xhr": "5.49.1", "@algolia/requester-fetch": "5.49.1", "@algolia/requester-node-http": "5.49.1" } }, "sha512-v+4DN+lkYfBd01Hbnb9ZrCHe7l+mvihyx218INRX/kaCXROIWUDIT1cs3urQxfE7kXBFnLsqYeOflQALv/gA5w=="],
+
+ "@algolia/client-query-suggestions": ["@algolia/[email protected]", "", { "dependencies": { "@algolia/client-common": "5.49.1", "@algolia/requester-browser-xhr": "5.49.1", "@algolia/requester-fetch": "5.49.1", "@algolia/requester-node-http": "5.49.1" } }, "sha512-Un11cab6ZCv0W+Jiak8UktGIqoa4+gSNgEZNfG8m8eTsXGqwIEr370H3Rqwj87zeNSlFpH2BslMXJ/cLNS1qtg=="],
+
+ "@algolia/client-search": ["@algolia/[email protected]", "", { "dependencies": { "@algolia/client-common": "5.49.1", "@algolia/requester-browser-xhr": "5.49.1", "@algolia/requester-fetch": "5.49.1", "@algolia/requester-node-http": "5.49.1" } }, "sha512-Nt9hri7nbOo0RipAsGjIssHkpLMHHN/P7QqENywAq5TLsoYDzUyJGny8FEiD/9KJUxtGH8blGpMedilI6kK3rA=="],
+
+ "@algolia/ingestion": ["@algolia/[email protected]", "", { "dependencies": { "@algolia/client-common": "5.49.1", "@algolia/requester-browser-xhr": "5.49.1", "@algolia/requester-fetch": "5.49.1", "@algolia/requester-node-http": "5.49.1" } }, "sha512-b5hUXwDqje0Y4CpU6VL481DXgPgxpTD5sYMnfQTHKgUispGnaCLCm2/T9WbJo1YNUbX3iHtYDArp804eD6CmRQ=="],
+
+ "@algolia/monitoring": ["@algolia/[email protected]", "", { "dependencies": { "@algolia/client-common": "5.49.1", "@algolia/requester-browser-xhr": "5.49.1", "@algolia/requester-fetch": "5.49.1", "@algolia/requester-node-http": "5.49.1" } }, "sha512-bvrXwZ0WsL3rN6Q4m4QqxsXFCo6WAew7sAdrpMQMK4Efn4/W920r9ptOuckejOSSvyLr9pAWgC5rsHhR2FYuYw=="],
+
+ "@algolia/recommend": ["@algolia/[email protected]", "", { "dependencies": { "@algolia/client-common": "5.49.1", "@algolia/requester-browser-xhr": "5.49.1", "@algolia/requester-fetch": "5.49.1", "@algolia/requester-node-http": "5.49.1" } }, "sha512-h2yz3AGeGkQwNgbLmoe3bxYs8fac4An1CprKTypYyTU/k3Q+9FbIvJ8aS1DoBKaTjSRZVoyQS7SZQio6GaHbZw=="],
+
+ "@algolia/requester-browser-xhr": ["@algolia/[email protected]", "", { "dependencies": { "@algolia/client-common": "5.49.1" } }, "sha512-2UPyRuUR/qpqSqH8mxFV5uBZWEpxhGPHLlx9Xf6OVxr79XO2ctzZQAhsmTZ6X22x+N8MBWpB9UEky7YU2HGFgA=="],
+
+ "@algolia/requester-fetch": ["@algolia/[email protected]", "", { "dependencies": { "@algolia/client-common": "5.49.1" } }, "sha512-N+xlE4lN+wpuT+4vhNEwPVlrfN+DWAZmSX9SYhbz986Oq8AMsqdntOqUyiOXVxYsQtfLwmiej24vbvJGYv1Qtw=="],
+
+ "@algolia/requester-node-http": ["@algolia/[email protected]", "", { "dependencies": { "@algolia/client-common": "5.49.1" } }, "sha512-zA5bkUOB5PPtTr182DJmajCiizHp0rCJQ0Chf96zNFvkdESKYlDeYA3tQ7r2oyHbu/8DiohAQ5PZ85edctzbXA=="],
+
"@alloc/quick-lru": ["@alloc/[email protected]", "", {}, "sha512-UrcABB+4bUrFABwbluTIBErXwvbsU/V7TZWfmbgJfbkwiBuziS9gxdODUyuiecfdGQ85jglMW6juS3+z5TsKLw=="],
"@antfu/ni": ["@antfu/[email protected]", "", { "dependencies": { "ansis": "^4.2.0", "fzf": "^0.5.2", "package-manager-detector": "^1.5.0", "tinyexec": "^1.0.1", "tinyglobby": "^0.2.15" }, "bin": { "na": "bin/na.mjs", "nd": "bin/nd.mjs", "ni": "bin/ni.mjs", "nr": "bin/nr.mjs", "nci": "bin/nci.mjs", "nlx": "bin/nlx.mjs", "nun": "bin/nun.mjs", "nup": "bin/nup.mjs" } }, "sha512-I6SOlwJ0MN73ECYcr7VJHpqSseyd7bpshx6JAaD0zNowS4kSWzFsqg8ikQT7DnCLiD4AZ+FaQJQ8WAk0Qi89Vw=="],
@@ -1882,6 +1912,8 @@
"ajv-formats": ["[email protected]", "", { "dependencies": { "ajv": "^8.0.0" } }, "sha512-8iUql50EUR+uUcdRQ3HDqa6EVyo3docL8g5WJ3FNcWmu62IbkGUue/pEyLBW8VGKKucTPgqeks4fIU1DA4yowQ=="],
+ "algoliasearch": ["[email protected]", "", { "dependencies": { "@algolia/abtesting": "1.15.1", "@algolia/client-abtesting": "5.49.1", "@algolia/client-analytics": "5.49.1", "@algolia/client-common": "5.49.1", "@algolia/client-insights": "5.49.1", "@algolia/client-personalization": "5.49.1", "@algolia/client-query-suggestions": "5.49.1", "@algolia/client-search": "5.49.1", "@algolia/ingestion": "1.49.1", "@algolia/monitoring": "1.49.1", "@algolia/recommend": "5.49.1", "@algolia/requester-browser-xhr": "5.49.1", "@algolia/requester-fetch": "5.49.1", "@algolia/requester-node-http": "5.49.1" } }, "sha512-X3Pp2aRQhg4xUC6PQtkubn5NpRKuUPQ9FPDQlx36SmpFwwH2N0/tw4c+NXV3nw3PsgeUs+BuWGP0gjz3TvENLQ=="],
+
"ansi-align": ["[email protected]", "", { "dependencies": { "string-width": "^4.1.0" } }, "sha512-IOfwwBF5iczOjp/WeY4YxyjqAFMQoZufdQWDd19SEExbVLNXqvpzSJ/M7Za4/sCPmQ0+GRquoA7bGcINcxew6w=="],
"ansi-escapes": ["[email protected]", "", { "dependencies": { "environment": "^1.0.0" } }, "sha512-BvU8nYgGQBxcmMuEeUEmNTvrMVjJNSH7RgW24vXexN4Ven6qCvy4TntnvlnwnMLTVlcRQQdbRY8NKnaIoeWDNg=="],
diff --git a/packages/admin/src/hooks/api/sellers.tsx b/packages/admin/src/hooks/api/sellers.tsx
index 1699cd0fa..6f33e235a 100644
--- a/packages/admin/src/hooks/api/sellers.tsx
+++ b/packages/admin/src/hooks/api/sellers.tsx
@@ -2,27 +2,24 @@ import {
ClientError,
InferClientInput,
InferClientOutput,
-} from "@mercurjs/client"
+} from "@mercurjs/client";
import {
QueryKey,
UseMutationOptions,
UseQueryOptions,
useMutation,
useQuery,
-} from "@tanstack/react-query"
-import { sdk } from "../../lib/client"
-import { queryClient } from "../../lib/query-client"
-import { queryKeysFactory } from "../../lib/query-key-factory"
+} from "@tanstack/react-query";
+import { sdk } from "../../lib/client";
+import { queryClient } from "../../lib/query-client";
+import { queryKeysFactory } from "../../lib/query-key-factory";
-const SELLERS_QUERY_KEY = "sellers" as const
-export const sellersQueryKeys = queryKeysFactory(SELLERS_QUERY_KEY)
+const SELLERS_QUERY_KEY = "sellers" as const;
+export const sellersQueryKeys = queryKeysFactory(SELLERS_QUERY_KEY);
export const useSeller = (
id: string,
- query?: Omit<
- InferClientInput<typeof sdk.admin.sellers.$id.query>,
- "$id"
- >,
+ query?: Omit<InferClientInput<typeof sdk.admin.sellers.$id.query>, "$id">,
options?: Omit<
UseQueryOptions<
InferClientOutput<typeof sdk.admin.sellers.$id.query>,
@@ -31,16 +28,16 @@ export const useSeller = (
QueryKey
>,
"queryKey" | "queryFn"
- >
+ >,
) => {
const { data, ...rest } = useQuery({
queryFn: () => sdk.admin.sellers.$id.query({ $id: id, ...query }),
queryKey: sellersQueryKeys.detail(id),
...options,
- })
+ });
- return { ...data, ...rest }
-}
+ return { ...data, ...rest };
+};
export const useSellers = (
query?: InferClientInput<typeof sdk.admin.sellers.query>,
@@ -52,27 +49,27 @@ export const useSellers = (
QueryKey
>,
"queryKey" | "queryFn"
- >
+ >,
) => {
const { data, ...rest } = useQuery({
- queryFn: () => sdk.admin.sellers.query({ ...query }),
+ queryFn: () =>
+ sdk.admin.sellers.query({
+ ...query,
+ }),
queryKey: sellersQueryKeys.list(query),
...options,
- })
+ });
- return { ...data, ...rest }
-}
+ return { ...data, ...rest };
+};
export const useUpdateSeller = (
id: string,
options?: UseMutationOptions<
InferClientOutput<typeof sdk.admin.sellers.$id.mutate>,
ClientError,
- Omit<
- InferClientInput<typeof sdk.admin.sellers.$id.mutate>,
- "$id"
- >
- >
+ Omit<InferClientInput<typeof sdk.admin.sellers.$id.mutate>, "$id">
+ >,
) => {
return useMutation({
mutationFn: (payload) =>
@@ -80,13 +77,13 @@ export const useUpdateSeller = (
onSuccess: (data, variables, context) => {
queryClient.invalidateQueries({
queryKey: sellersQueryKeys.detail(id),
- })
+ });
queryClient.invalidateQueries({
queryKey: sellersQueryKeys.lists(),
- })
+ });
- options?.onSuccess?.(data, variables, context)
+ options?.onSuccess?.(data, variables, context);
},
...options,
- })
-}
+ });
+};
diff --git a/packages/admin/src/hooks/use-debounced-search.tsx b/packages/admin/src/hooks/use-debounced-search.tsx
index 213234b4c..bbafadeb0 100644
--- a/packages/admin/src/hooks/use-debounced-search.tsx
+++ b/packages/admin/src/hooks/use-debounced-search.tsx
@@ -1,5 +1,4 @@
-import debounce from "lodash/debounce"
-import { useCallback, useEffect, useState } from "react"
+import { useCallback, useEffect, useRef, useState } from "react"
/**
* Hook for debouncing search input
@@ -8,17 +7,17 @@ import { useCallback, useEffect, useState } from "react"
export const useDebouncedSearch = () => {
const [searchValue, onSearchValueChange] = useState("")
const [debouncedQuery, setDebouncedQuery] = useState("")
+ const timerRef = useRef<ReturnType<typeof setTimeout>>()
- // eslint-disable-next-line react-hooks/exhaustive-deps
- const debouncedUpdate = useCallback(
- debounce((query: string) => setDebouncedQuery(query), 300),
- []
- )
+ const debouncedUpdate = useCallback((query: string) => {
+ clearTimeout(timerRef.current)
+ timerRef.current = setTimeout(() => setDebouncedQuery(query), 300)
+ }, [])
useEffect(() => {
debouncedUpdate(searchValue)
- return () => debouncedUpdate.cancel()
+ return () => clearTimeout(timerRef.current)
}, [searchValue, debouncedUpdate])
return {
diff --git a/packages/admin/src/i18n/translations/en.json b/packages/admin/src/i18n/translations/en.json
index 6bdce7d8f..e9cdbb10e 100644
--- a/packages/admin/src/i18n/translations/en.json
+++ b/packages/admin/src/i18n/translations/en.json
@@ -2467,7 +2467,10 @@
},
"marketplace": {
"domain": "Marketplace",
- "manageMarketplaceDetails": "Manage your marketplace's details"
+ "manageMarketplaceDetails": "Manage your marketplace's details",
+ "edit": {
+ "header": "Edit Marketplace"
+ }
},
"store": {
"domain": "Store",
diff --git a/packages/admin/src/lib/client/client.ts b/packages/admin/src/lib/client/client.ts
index 363d361e4..96d568a1b 100644
--- a/packages/admin/src/lib/client/client.ts
+++ b/packages/admin/src/lib/client/client.ts
@@ -4,7 +4,7 @@ import config from 'virtual:mercur/config'
export const backendUrl = config.backendUrl ?? 'http://localhost:9000'
-export const sdk: InferClient<Routes> = createClient<Routes>({
+export const sdk: InferClient<Routes> = createClient({
baseUrl: backendUrl,
fetchOptions: {
credentials: 'include',
diff --git a/packages/admin/src/pages/marketplace/marketplace-edit/marketplace-edit.tsx b/packages/admin/src/pages/marketplace/marketplace-edit/marketplace-edit.tsx
index 56da444a1..787aab165 100644
--- a/packages/admin/src/pages/marketplace/marketplace-edit/marketplace-edit.tsx
+++ b/packages/admin/src/pages/marketplace/marketplace-edit/marketplace-edit.tsx
@@ -17,7 +17,7 @@ export const MarketplaceEdit = () => {
return (
<RouteDrawer data-testid="store-edit">
<RouteDrawer.Header data-testid="store-edit-header">
- <Heading data-testid="store-edit-heading">{t("store.edit.header")}</Heading>
+ <Heading data-testid="store-edit-heading">{t("marketplace.edit.header")}</Heading>
</RouteDrawer.Header>
{ready && <EditMarketplaceForm store={store} />}
</RouteDrawer>
diff --git a/packages/admin/src/pages/products/product-detail/components/product-additional-attribute-section/components/attribute-select.tsx b/packages/admin/src/pages/products/product-detail/components/product-additional-attribute-section/components/attribute-select.tsx
deleted file mode 100644
index d0050ba64..000000000
--- a/packages/admin/src/pages/products/product-detail/components/product-additional-attribute-section/components/attribute-select.tsx
+++ /dev/null
@@ -1,53 +0,0 @@
-import { Select } from '@medusajs/ui';
-
-export const AttributeSelect = ({
- values,
- field,
- 'data-testid': dataTestId
-}: {
- values: any[];
- field: any;
- 'data-testid'?: string;
-}) => {
- const handleChange = (value: string) => {
- field.onChange({
- target: {
- name: field.name,
- value: value
- }
- });
- };
-
- return (
- <div data-testid={dataTestId ? `${dataTestId}-wrapper` : undefined}>
- <Select
- onValueChange={value => handleChange(value)}
- value={field.value}
- data-testid={dataTestId}
- >
- <Select.Trigger
- className="bg-ui-bg-base"
- data-testid={dataTestId ? `${dataTestId}-trigger` : undefined}
- >
- <Select.Value
- placeholder="Select value"
- data-testid={dataTestId ? `${dataTestId}-value` : undefined}
- />
- </Select.Trigger>
- <Select.Content data-testid={dataTestId ? `${dataTestId}-content` : undefined}>
- {values
- ?.filter(v => v && v.attribute_id)
- .map(({ id, attribute_id, value }) => (
- <Select.Item
- key={`select-option-${attribute_id}-${id}`}
- value={value}
- data-testid={dataTestId ? `${dataTestId}-option-${id}` : undefined}
- >
- {value}
- </Select.Item>
- ))}
- </Select.Content>
- </Select>
- </div>
- );
-};
diff --git a/packages/admin/src/pages/products/product-detail/components/product-additional-attribute-section/components/form-components.tsx b/packages/admin/src/pages/products/product-detail/components/product-additional-attribute-section/components/form-components.tsx
deleted file mode 100644
index 6cd6e3387..000000000
--- a/packages/admin/src/pages/products/product-detail/components/product-additional-attribute-section/components/form-components.tsx
+++ /dev/null
@@ -1,63 +0,0 @@
-import { Input, Switch, Textarea } from "@medusajs/ui";
-import { AttributeSelect } from "./attribute-select";
-
-export const FormComponents = ({
- attribute,
- field,
- "data-testid": dataTestId,
-}: {
- attribute: any;
- field: any;
- "data-testid"?: string;
-}) => {
- const { ui_component, possible_values } = attribute;
-
- if (ui_component === "select")
- return <AttributeSelect values={possible_values} field={field} data-testid={dataTestId} />;
-
- if (ui_component === "toggle")
- return (
- <div data-testid={dataTestId ? `${dataTestId}-switch-wrapper` : undefined}>
- <Switch
- name={field.name}
- onCheckedChange={(value) => {
- field.onChange({
- target: {
- name: field.name,
- value: value,
- },
- });
- }}
- checked={field.value === "true" || field.value === true}
- data-testid={dataTestId}
- />
- </div>
- );
-
- if (ui_component === "text_area")
- return (
- <div data-testid={dataTestId ? `${dataTestId}-textarea-wrapper` : undefined}>
- <Textarea {...field} rows={4} data-testid={dataTestId} />
- </div>
- );
-
- if (ui_component === "unit")
- return (
- <div data-testid={dataTestId ? `${dataTestId}-input-wrapper` : undefined}>
- <Input type="number" {...field} data-testid={dataTestId} />
- </div>
- );
-
- if (ui_component === "text")
- return (
- <div data-testid={dataTestId ? `${dataTestId}-input-wrapper` : undefined}>
- <Input {...field} data-testid={dataTestId} />
- </div>
- );
-
- return (
- <div data-testid={dataTestId ? `${dataTestId}-input-wrapper` : undefined}>
- <Input {...field} data-testid={dataTestId} />
- </div>
- );
-};
diff --git a/packages/admin/src/pages/products/product-detail/components/product-additional-attribute-section/index.ts b/packages/admin/src/pages/products/product-detail/components/product-additional-attribute-section/index.ts
deleted file mode 100644
index 00c5d62b7..000000000
--- a/packages/admin/src/pages/products/product-detail/components/product-additional-attribute-section/index.ts
+++ /dev/null
@@ -1 +0,0 @@
-export * from "./product-additional-attribute-section";
diff --git a/packages/admin/src/pages/products/product-detail/components/product-additional-attribute-section/product-additional-attribute-section.tsx b/packages/admin/src/pages/products/product-detail/components/product-additional-attribute-section/product-additional-attribute-section.tsx
deleted file mode 100644
index 3488e36df..000000000
--- a/packages/admin/src/pages/products/product-detail/components/product-additional-attribute-section/product-additional-attribute-section.tsx
+++ /dev/null
@@ -1,247 +0,0 @@
-import { useEffect, useState } from "react";
-
-import { InformationCircleSolid, PencilSquare } from "@medusajs/icons";
-import {
- Button,
- Container,
- Heading,
- Label,
- Tooltip,
- toast,
-} from "@medusajs/ui";
-import { Drawer } from "@medusajs/ui";
-
-import { FormProvider, useForm } from "react-hook-form";
-import { useTranslation } from "react-i18next";
-import { useParams } from "react-router-dom";
-
-import { ActionMenu } from "../../../../../components/common/action-menu";
-import { SectionRow } from "../../../../../components/common/section";
-import {
- useProduct,
- useProductAttributes,
- useUpdateProduct,
-} from "../../../../../hooks/api";
-import { FormComponents } from "./components/form-components";
-
-export const ProductAdditionalAttributeSection = () => {
- const { t } = useTranslation();
- const { id } = useParams();
- const [open, setOpen] = useState(false);
- const { product, isLoading: isProductLoading } = useProduct(id!, {
- fields: "attribute_values.*,attribute_values.attribute.*",
- });
-
- const { data, isLoading } = useProductAttributes(id!);
-
- const attributes = data?.attributes || [];
-
- const { mutate: updateProduct } = useUpdateProduct(id!);
-
- const form = useForm<any>({
- defaultValues: {},
- });
-
- // Reset form when product data is loaded
- useEffect(() => {
- if (product?.attribute_values) {
- const defaultValues = product.attribute_values.reduce(
- (acc: any, curr: any) => {
- if (curr) {
- acc[curr.attribute_id] = curr.value;
- }
- return acc;
- },
- {},
- );
- form.reset(defaultValues);
- }
- }, [product?.attribute_values, form]);
-
- const onSubmit = (data: any) => {
- const formattedData = Object.keys(data).map((key) => {
- const attribute = attributes.find(
- (a: any) => a.id === key && a.ui_component === "select",
- );
- const value = attribute?.possible_values?.find(
- (pv: any) => pv.id === data[key],
- )?.value;
-
- return (
- value && {
- [key]: value,
- }
- );
- });
- const payload = {
- ...data,
- ...Object.assign({}, ...formattedData.filter(Boolean)),
- };
-
- const values = Object.keys(payload).reduce(
- (acc: Array<Record<string, string>>, key) => {
- acc.push({ attribute_id: key, value: payload[key] });
- return acc;
- },
- [],
- );
-
- updateProduct(
- {
- additional_data: { values },
- },
- {
- onSuccess: () => {
- toast.success("Product updated successfully");
- setOpen(false);
- },
- },
- );
- };
-
- if (isLoading || isProductLoading) return <div>Loading...</div>;
-
- return (
- <>
- <div>
- <Container
- className="divide-y p-0"
- data-testid="product-additional-attributes-section"
- >
- <div
- className="flex items-center justify-between px-6 py-4"
- data-testid="product-additional-attributes-header"
- >
- <Heading
- level="h2"
- data-testid="product-additional-attributes-title"
- >
- {t("products.additionalAttributes")}
- </Heading>
- <ActionMenu
- groups={[
- {
- actions: [
- {
- label: t("actions.edit"),
- onClick: () => setOpen(true),
- icon: <PencilSquare />,
- },
- ],
- },
- ]}
- data-testid="product-additional-attributes-action-menu"
- />
- </div>
-
- {product?.attribute_values?.map(
- (attribute: any) =>
- attribute && (
- <SectionRow
- key={attribute.id}
- title={attribute.attribute.name}
- value={attribute.value}
- data-testid={`product-additional-attribute-row-${attribute.attribute.name}`}
- />
- ),
- )}
- </Container>
- </div>
- <Drawer
- open={open}
- onOpenChange={setOpen}
- data-testid="product-additional-attributes-drawer"
- >
- <Drawer.Content data-testid="product-additional-attributes-drawer-content">
- <Drawer.Header data-testid="product-additional-attributes-drawer-header">
- <Heading
- level="h2"
- data-testid="product-additional-attributes-drawer-title"
- >
- {t("products.additionalAttributes")}
- </Heading>
- </Drawer.Header>
- <Drawer.Body
- className="m-4 max-h-[calc(86vh)] overflow-y-auto py-2"
- data-testid="product-additional-attributes-drawer-body"
- >
- <FormProvider {...form}>
- <form
- id="product-additional-attributes-form"
- onSubmit={form.handleSubmit(onSubmit)}
- className="p-0"
- data-testid="product-additional-attributes-form"
- >
- {attributes.map((a: any) => (
- <div
- key={`form-field-${a.handle}-${a.id}`}
- className="-mx-4 mb-4"
- data-testid={`product-additional-attribute-field-${a.id}`}
- >
- <Label
- className="mb-2 flex items-center gap-x-2"
- data-testid={`product-additional-attribute-label-${a.id}`}
- >
- {a.name}
- {a.description && (
- <Tooltip
- content={a.description}
- data-testid={`product-additional-attribute-tooltip-${a.id}`}
- >
- <InformationCircleSolid />
- </Tooltip>
- )}
- </Label>
- <div
- data-testid={`product-additional-attribute-input-${a.id}`}
- >
- <FormComponents
- attribute={a}
- field={{
- name: a.id,
- value: form.watch(a.id),
- defaultValue: form.getValues(a.id),
- onChange: (e: any) => {
- form.setValue(a.id, e.target.value);
- },
- }}
- data-testid={`product-additional-attribute-input-${a.id}-component`}
- />
- </div>
- </div>
- ))}
- </form>
- </FormProvider>
- </Drawer.Body>
- <Drawer.Footer data-testid="product-additional-attributes-drawer-footer">
- <div
- className="flex items-center justify-end gap-x-2"
- data-testid="product-additional-attributes-form-actions"
- >
- <Drawer.Close
- asChild
- data-testid="product-additional-attributes-cancel-button-wrapper"
- >
- <Button
- variant="secondary"
- size="small"
- data-testid="product-additional-attributes-cancel-button"
- >
- {t("actions.cancel")}
- </Button>
- </Drawer.Close>
- <Button
- size="small"
- type="submit"
- form="product-additional-attributes-form"
- data-testid="product-additional-attributes-save-button"
- >
- {t("actions.save")}
- </Button>
- </div>
- </Drawer.Footer>
- </Drawer.Content>
- </Drawer>
- </>
- );
-};
diff --git a/packages/admin/src/pages/products/product-detail/product-detail.tsx b/packages/admin/src/pages/products/product-detail/product-detail.tsx
index d2b662ae8..f7f930054 100644
--- a/packages/admin/src/pages/products/product-detail/product-detail.tsx
+++ b/packages/admin/src/pages/products/product-detail/product-detail.tsx
@@ -4,7 +4,6 @@ import { TwoColumnPageSkeleton } from "../../../components/common/skeleton";
import { TwoColumnPage } from "../../../components/layout/pages";
import { useProduct } from "../../../hooks/api/products";
-import { ProductAdditionalAttributeSection } from "./components/product-additional-attribute-section";
import { ProductAttributeSection } from "./components/product-attribute-section";
import { ProductGeneralSection } from "./components/product-general-section";
import { ProductMediaSection } from "./components/product-media-section";
@@ -58,7 +57,6 @@ export const ProductDetail = () => {
<ProductShippingProfileSection product={product} />
<ProductOrganizationSection product={product} />
<ProductAttributeSection product={product} />
- <ProductAdditionalAttributeSection />
</TwoColumnPage.Sidebar>
</TwoColumnPage>
</div>
diff --git a/packages/vendor/src/lib/client/client.ts b/packages/vendor/src/lib/client/client.ts
index 363d361e4..96d568a1b 100644
--- a/packages/vendor/src/lib/client/client.ts
+++ b/packages/vendor/src/lib/client/client.ts
@@ -4,7 +4,7 @@ import config from 'virtual:mercur/config'
export const backendUrl = config.backendUrl ?? 'http://localhost:9000'
-export const sdk: InferClient<Routes> = createClient<Routes>({
+export const sdk: InferClient<Routes> = createClient({
baseUrl: backendUrl,
fetchOptions: {
credentials: 'include',