feat: simplify WhatsApp share text generation by removing unnecessary variables and logic
This commit is contained in:
parent
a07cb4bb45
commit
cff231097a
@ -20,8 +20,6 @@ function generateShareLink(cuttingId: number): string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function generateWhatsappText(cutting: Cutting): string {
|
function generateWhatsappText(cutting: Cutting): string {
|
||||||
const result = cutting.cutting_results?.[0];
|
|
||||||
const items = cutting.cutting_materials ?? [];
|
|
||||||
const shareLink = generateShareLink(cutting.id);
|
const shareLink = generateShareLink(cutting.id);
|
||||||
|
|
||||||
let text = `*Cutting #${cutting.id}*\n`;
|
let text = `*Cutting #${cutting.id}*\n`;
|
||||||
@ -33,25 +31,12 @@ function generateWhatsappText(cutting: Cutting): string {
|
|||||||
text += `Deskripsi: ${cutting.description}\n`;
|
text += `Deskripsi: ${cutting.description}\n`;
|
||||||
}
|
}
|
||||||
|
|
||||||
const productNames = new Set<string>();
|
if (cutting.product_name) {
|
||||||
(cutting.cutting_results ?? []).forEach((r) => {
|
text += `\nNama Produk: ${cutting.product_name}\n`;
|
||||||
if (r.product_name) {
|
|
||||||
productNames.add(r.product_name);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
if (productNames.size > 0) {
|
|
||||||
text += `\nNama Produk: ${Array.from(productNames).join(', ')}\n`;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const totalUsage = items.reduce(
|
if (cutting.cutting_result) {
|
||||||
(sum, item) => sum + Number(item.material_usage),
|
text += `Total Hasil Cutting: ${formatNumber(cutting.cutting_result)} pcs\n`;
|
||||||
0,
|
|
||||||
);
|
|
||||||
text += `Total Pemakaian: ${formatNumber(totalUsage)}\n`;
|
|
||||||
|
|
||||||
if (result?.cutting_result) {
|
|
||||||
text += `Total Hasil Cutting: ${formatNumber(result.cutting_result)} pcs\n`;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
text += `\nLihat detail lengkap:\n${shareLink}`;
|
text += `\nLihat detail lengkap:\n${shareLink}`;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user