refactor: optimize RowShareAction component by replacing grouping logic with a Set for product names, simplifying the shareable output format
This commit is contained in:
parent
c222be62d3
commit
7c15a39bbd
@ -37,26 +37,17 @@ const whatsappText = computed(() => {
|
||||
}
|
||||
|
||||
if (c.results?.length) {
|
||||
const groups: Record<string, { name: string; items: typeof c.results }> = {};
|
||||
const productNames = new Set<string>();
|
||||
|
||||
c.results.forEach((result) => {
|
||||
const productName = result.product_variant?.product?.name ?? 'Produk Tidak Diketahui';
|
||||
|
||||
if (!groups[productName]) {
|
||||
groups[productName] = { name: productName, items: [] };
|
||||
}
|
||||
|
||||
groups[productName].items.push(result);
|
||||
productNames.add(productName);
|
||||
});
|
||||
|
||||
text += `\n*Hasil Produk:*\n`;
|
||||
|
||||
Object.values(groups).forEach((group, index) => {
|
||||
text += `${index + 1}. ${group.name}\n`;
|
||||
|
||||
group.items.forEach((item) => {
|
||||
text += ` - ${item.product_variant?.name ?? '-'}\n`;
|
||||
});
|
||||
Array.from(productNames).forEach((name, index) => {
|
||||
text += `${index + 1}. ${name}\n`;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user