change create product

This commit is contained in:
hamid zarghami
2025-10-25 16:22:24 +03:30
parent f9122d2661
commit 40fb5a6c15
+8 -8
View File
@@ -9,8 +9,8 @@ import { CloseCircle } from 'iconsax-react';
interface AttributeSelectorProps { interface AttributeSelectorProps {
attribute: CategoryAttributeType; attribute: CategoryAttributeType;
selectedValues: number[]; selectedValues: string[];
onChange: (attributeId: number, values: number[]) => void; onChange: (attributeId: number, values: string[]) => void;
} }
interface TextNumberInputProps { interface TextNumberInputProps {
@@ -20,7 +20,7 @@ interface TextNumberInputProps {
} }
const AttributeSelector: FC<AttributeSelectorProps> = ({ attribute, selectedValues, onChange }) => { const AttributeSelector: FC<AttributeSelectorProps> = ({ attribute, selectedValues, onChange }) => {
const handleValueChange = (valueId: number, checked: boolean) => { const handleValueChange = (valueId: string, checked: boolean) => {
if (attribute.multiple) { if (attribute.multiple) {
// چند انتخابی - checkbox // چند انتخابی - checkbox
const newValues = checked const newValues = checked
@@ -46,7 +46,7 @@ const AttributeSelector: FC<AttributeSelectorProps> = ({ attribute, selectedValu
<div className="space-y-2"> <div className="space-y-2">
{attribute.values.map((value) => { {attribute.values.map((value) => {
const isChecked = selectedValues.includes(value._id); const isChecked = selectedValues.includes(value.text);
return ( return (
<label key={value._id} className="flex items-center space-x-2 cursor-pointer"> <label key={value._id} className="flex items-center space-x-2 cursor-pointer">
@@ -54,7 +54,7 @@ const AttributeSelector: FC<AttributeSelectorProps> = ({ attribute, selectedValu
type={attribute.multiple ? "checkbox" : "radio"} type={attribute.multiple ? "checkbox" : "radio"}
name={`attribute-${attribute._id}`} name={`attribute-${attribute._id}`}
checked={isChecked} checked={isChecked}
onChange={(e) => handleValueChange(value._id, e.target.checked)} onChange={(e) => handleValueChange(value.text, e.target.checked)}
className={`w-4 h-4 text-blue-600 bg-gray-100 border-gray-300 rounded focus:ring-blue-500 focus:ring-2 ${attribute.multiple ? 'rounded' : 'rounded-full' className={`w-4 h-4 text-blue-600 bg-gray-100 border-gray-300 rounded focus:ring-blue-500 focus:ring-2 ${attribute.multiple ? 'rounded' : 'rounded-full'
}`} }`}
/> />
@@ -126,7 +126,7 @@ interface Step2FormProps {
interface AttributeWithValue { interface AttributeWithValue {
id: number; id: number;
values: number[] | string[]; values: string[];
} }
// کامپوننت مدیریت تگ‌ها // کامپوننت مدیریت تگ‌ها
@@ -270,7 +270,7 @@ const Step2Form: FC<Step2FormProps> = ({ onSubmit, loading, onPrevious, category
const { data: categoryAttributesData } = useGetCategoryAttributes(categoryId || ''); const { data: categoryAttributesData } = useGetCategoryAttributes(categoryId || '');
const handleAttributeChange = (attributeId: number, values: number[]) => { const handleAttributeChange = (attributeId: number, values: string[]) => {
setFormData(prev => ({ setFormData(prev => ({
...prev, ...prev,
attributes: prev.attributes.filter(attr => attr.id !== attributeId).concat({ attributes: prev.attributes.filter(attr => attr.id !== attributeId).concat({
@@ -323,7 +323,7 @@ const Step2Form: FC<Step2FormProps> = ({ onSubmit, loading, onPrevious, category
<AttributeSelector <AttributeSelector
key={attribute._id} key={attribute._id}
attribute={attribute} attribute={attribute}
selectedValues={selectedValues as number[]} selectedValues={selectedValues as string[]}
onChange={handleAttributeChange} onChange={handleAttributeChange}
/> />
); );