Skip to content

Commit

Permalink
#1051 [BACKOFFICE] [Bugs] Product Templates - Categories - Product at…
Browse files Browse the repository at this point in the history
…tributes tab issues (#1058)
  • Loading branch information
nashtech-tuannguyenhuu1 authored Sep 23, 2024
1 parent ccd40b4 commit 357d2ea
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
4 changes: 2 additions & 2 deletions backoffice/modules/catalog/models/FormProductTemplate.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export type ProductAttributeOfTemplate = {
ProductAttributeId?: number;
productAttributeId?: number;
displayOrder?: number;
};
export type productAttribute = {
Expand All @@ -14,7 +14,7 @@ export type ProductAttributeTemplate = {

export type FromProductTemplate = {
name?: string;
ProductAttributeTemplates?: ProductAttributeOfTemplate[];
productAttributeTemplates?: ProductAttributeOfTemplate[];
};

export type ProductTemplate = {
Expand Down
18 changes: 9 additions & 9 deletions backoffice/pages/catalog/product-templates/[id]/edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ const ProductTemplateEdit: NextPage = () => {
let att = [];
for (const element of data.productAttributeTemplates) {
let attribute: ProductAttributeOfTemplate = {
ProductAttributeId: element.productAttribute.id,
productAttributeId: element.productAttribute.id,
displayOrder: element.displayOrder,
};
attributes.push(attribute);
att.push(element.productAttribute.name);
setSelectedAtts(att);
setValue('ProductAttributeTemplates', attributes);
setValue('productAttributeTemplates', attributes);
}
});
setLoading(false);
Expand All @@ -60,17 +60,17 @@ const ProductTemplateEdit: NextPage = () => {
const onAddAttributeList = (event: React.MouseEvent<HTMLElement>) => {
event.preventDefault();
let attributeName = (document.getElementById('attribute') as HTMLSelectElement).value;
let atts = getValues('ProductAttributeTemplates') || [];
let atts = getValues('productAttributeTemplates') || [];
if (selectedAtts.indexOf(attributeName) === -1) {
setSelectedAtts([...selectedAtts, attributeName]);
let att = productAtts.find((attribute) => attribute.name === attributeName);
if (att) {
let newAttr: ProductAttributeOfTemplate = {
ProductAttributeId: att.id,
productAttributeId: att.id,
displayOrder: 0,
};
atts.push(newAttr);
setValue('ProductAttributeTemplates', atts);
setValue('productAttributeTemplates', atts);
}
} else {
toast.info(`${attributeName} is selected`);
Expand All @@ -80,7 +80,7 @@ const ProductTemplateEdit: NextPage = () => {
const handleSubmitEditProductTemplate = async (event: FromProductTemplate) => {
let fromProductTemplate: FromProductTemplate = {
name: event.name,
ProductAttributeTemplates: getValues('ProductAttributeTemplates'),
productAttributeTemplates: getValues('productAttributeTemplates') || [],
};

const response = await updateProductTemplate(+id, fromProductTemplate);
Expand All @@ -92,15 +92,15 @@ const ProductTemplateEdit: NextPage = () => {

const onDelete = (event: React.MouseEvent<HTMLElement>, attName: string) => {
event.preventDefault();
let atts = getValues('ProductAttributeTemplates') || [];
let atts = getValues('productAttributeTemplates') || [];
const attribute = productTemplate?.productAttributeTemplates?.find(
(attribute) => attribute?.productAttribute?.name === attName
);
let filter = selectedAtts.filter((item) => item !== attName);
let attFilter = atts.filter(
(att) => att.ProductAttributeId !== attribute?.productAttribute?.id
(att) => att.productAttributeId !== attribute?.productAttribute?.id
);
setValue('ProductAttributeTemplates', attFilter);
setValue('productAttributeTemplates', attFilter);
setSelectedAtts(filter);
};

Expand Down
14 changes: 7 additions & 7 deletions backoffice/pages/catalog/product-templates/create.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,17 @@ const ProductTemplateCreate = () => {
if (attName === '0') {
toast.info('No attribute has been selected yet');
} else {
let attributes = getValues('ProductAttributeTemplates') || [];
let attributes = getValues('productAttributeTemplates') || [];
if (selectedAttributes.indexOf(attName) === -1) {
setSelectedAttributes([...selectedAttributes, attName]);
let attribute = productAttributes.find((attribute) => attribute.name === attName);
if (attribute) {
let newAttr: ProductAttributeOfTemplate = {
ProductAttributeId: attribute.id,
productAttributeId: attribute.id,
displayOrder: 0,
};
attributes.push(newAttr);
setValue('ProductAttributeTemplates', attributes);
setValue('productAttributeTemplates', attributes);
}
} else {
toast.info(`${attName} is selected`);
Expand All @@ -61,18 +61,18 @@ const ProductTemplateCreate = () => {
};
const onDeleteSelectedAttribute = (event: React.MouseEvent<HTMLElement>, attName: string) => {
event.preventDefault();
let attributes = getValues('ProductAttributeTemplates') || [];
let attributes = getValues('productAttributeTemplates') || [];
const attribute = productAttributes.find((attribute) => attribute.name === attName);
let filter = selectedAttributes.filter((item) => item !== attName);
let attFilter = attributes.filter((_att) => _att.ProductAttributeId !== attribute?.id);
let attFilter = attributes.filter((_att) => _att.productAttributeId !== attribute?.id);
setSelectedAttributes(filter);
setValue('ProductAttributeTemplates', attFilter);
setValue('productAttributeTemplates', attFilter);
};
const handleSubmitProductTemplate = async (event: FromProductTemplate) => {
setValue('name', event.name);
let fromProductTemplate: FromProductTemplate = {
name: event.name,
ProductAttributeTemplates: getValues('ProductAttributeTemplates'),
productAttributeTemplates: getValues('productAttributeTemplates') || [],
};
let response = await createProductTemplate(fromProductTemplate);

Expand Down

0 comments on commit 357d2ea

Please sign in to comment.