forked from verdnatura/salix-front
perf: optimize get packing type function
This commit is contained in:
parent
4bde0dffa7
commit
1daa8be635
|
@ -152,17 +152,20 @@ const setShippedColor = (date) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const getItemPackagingType = (ticketSales) => {
|
const getItemPackagingType = (ticketSales) => {
|
||||||
if (!ticketSales || ticketSales.length === 0) return '-';
|
if (!ticketSales?.length) return '-';
|
||||||
|
|
||||||
const packagingTypes = ticketSales
|
const packagingTypes = ticketSales.reduce((types, sale) => {
|
||||||
.map((sale) => sale.item?.itemPackingTypeFk)
|
const { itemPackingTypeFk } = sale.item;
|
||||||
.filter((type) => type !== undefined && type !== null);
|
if (
|
||||||
|
!types.includes(itemPackingTypeFk) &&
|
||||||
|
(itemPackingTypeFk === 'H' || itemPackingTypeFk === 'V')
|
||||||
|
) {
|
||||||
|
types.push(itemPackingTypeFk);
|
||||||
|
}
|
||||||
|
return types;
|
||||||
|
}, []);
|
||||||
|
|
||||||
const uniquePackagingTypes = [...new Set(packagingTypes)];
|
return dashIfEmpty(packagingTypes.join(', ') || '-');
|
||||||
|
|
||||||
return dashIfEmpty(
|
|
||||||
uniquePackagingTypes.length > 0 ? uniquePackagingTypes.join(', ') : '-'
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue