From 1e48d12340ac0ec258078fc5def871d52ee0971a Mon Sep 17 00:00:00 2001 From: hamid zarghami Date: Sun, 26 Oct 2025 11:24:14 +0330 Subject: [PATCH] fix attibute edit --- src/pages/products/Update.tsx | 6 +-- src/pages/products/components/Step2Form.tsx | 55 +++++++++++++++++++-- 2 files changed, 53 insertions(+), 8 deletions(-) diff --git a/src/pages/products/Update.tsx b/src/pages/products/Update.tsx index 400f345..43a51fb 100644 --- a/src/pages/products/Update.tsx +++ b/src/pages/products/Update.tsx @@ -42,10 +42,7 @@ const UpdateProduct: FC = () => { seoTitle: product.seoTitle || '', source: product.source, isFake: product.isFake, - attributes: product.specifications?.map(spec => ({ - id: 0, // This might need to be adjusted based on API - values: spec.values.map(() => 0) // This might need to be adjusted based on API - })) || [], + attributes: [], description: product.description, metaDescription: product.metaDescription, tags: product.tags, @@ -164,6 +161,7 @@ const UpdateProduct: FC = () => { loading={updateProductAttributeMutation.isPending} onPrevious={handlePreviousStep} categoryId={productData.category} + specifications={productDetails?.results?.product?.specifications} initialData={{ attributes: productData.attributes, description: productData.description, diff --git a/src/pages/products/components/Step2Form.tsx b/src/pages/products/components/Step2Form.tsx index 603b1e8..bf504fa 100644 --- a/src/pages/products/components/Step2Form.tsx +++ b/src/pages/products/components/Step2Form.tsx @@ -1,4 +1,4 @@ -import { type FC, useState } from 'react'; +import { type FC, useState, useEffect } from 'react'; import Button from '../../../components/Button'; import Input from '../../../components/Input'; import Textarea from '../../../components/Textarea'; @@ -46,7 +46,8 @@ const AttributeSelector: FC = ({ attribute, selectedValu
{attribute.values.map((value) => { - const isChecked = selectedValues.includes(value.text); + const valueIdStr = String(value._id); + const isChecked = selectedValues.includes(valueIdStr) || selectedValues.includes(value.text); return (