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 {
|
||||
const result = cutting.cutting_results?.[0];
|
||||
const items = cutting.cutting_materials ?? [];
|
||||
const shareLink = generateShareLink(cutting.id);
|
||||
|
||||
let text = `*Cutting #${cutting.id}*\n`;
|
||||
@ -33,25 +31,12 @@ function generateWhatsappText(cutting: Cutting): string {
|
||||
text += `Deskripsi: ${cutting.description}\n`;
|
||||
}
|
||||
|
||||
const productNames = new Set<string>();
|
||||
(cutting.cutting_results ?? []).forEach((r) => {
|
||||
if (r.product_name) {
|
||||
productNames.add(r.product_name);
|
||||
}
|
||||
});
|
||||
|
||||
if (productNames.size > 0) {
|
||||
text += `\nNama Produk: ${Array.from(productNames).join(', ')}\n`;
|
||||
if (cutting.product_name) {
|
||||
text += `\nNama Produk: ${cutting.product_name}\n`;
|
||||
}
|
||||
|
||||
const totalUsage = items.reduce(
|
||||
(sum, item) => sum + Number(item.material_usage),
|
||||
0,
|
||||
);
|
||||
text += `Total Pemakaian: ${formatNumber(totalUsage)}\n`;
|
||||
|
||||
if (result?.cutting_result) {
|
||||
text += `Total Hasil Cutting: ${formatNumber(result.cutting_result)} pcs\n`;
|
||||
if (cutting.cutting_result) {
|
||||
text += `Total Hasil Cutting: ${formatNumber(cutting.cutting_result)} pcs\n`;
|
||||
}
|
||||
|
||||
text += `\nLihat detail lengkap:\n${shareLink}`;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user