diff --git a/src/figma-make/components/pages/list-daily-checklist/detail/DetailDailyChecklistContent.tsx b/src/figma-make/components/pages/list-daily-checklist/detail/DetailDailyChecklistContent.tsx index d927d312..9af93ee8 100644 --- a/src/figma-make/components/pages/list-daily-checklist/detail/DetailDailyChecklistContent.tsx +++ b/src/figma-make/components/pages/list-daily-checklist/detail/DetailDailyChecklistContent.tsx @@ -556,27 +556,68 @@ export function DetailDailyChecklistContent() { }); }; - const shareHandler = async () => { - setIsGeneratingImage(true); - - const htmlBlob = await htmlToImage.toBlob(document.body); - const imgFile = new File( - [htmlBlob!], - `daily-checklist-${header?.date}-${header?.kandang_name}-${header?.category}.png`, - { - type: 'image/png', - } + const isMobileDevice = () => { + return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test( + navigator.userAgent ); + }; + + const getStatusMessage = () => { + switch (header?.status) { + case 'DRAFT': + return 'Checklist harian perlu disubmit'; + case 'SUBMITTED': + return 'Checklist harian menunggu persetujuan'; + case 'APPROVED': + return 'Checklist harian telah disetujui'; + case 'REJECTED': + return 'Checklist harian telah ditolak'; + default: + return ''; + } + }; + + const shareHandler = async () => { + const isMobile = isMobileDevice(); + + if (isMobile) { + setIsGeneratingImage(true); + } + + const baseTitle = `Daily Checklist - ${formatDate(header?.date || '')} - ${header?.kandang_name} - ${header?.category}`; + const statusMsg = getStatusMessage(); + const statusInfo = `\nStatus: ${header?.status}${statusMsg ? ` - ${statusMsg}` : ''}`; + const urlMessage = `\n\nView full checklist: ${window.location.href}`; + const fullMessage = baseTitle + statusInfo + urlMessage; + + let shareData: ShareData; + + if (isMobile) { + const htmlBlob = await htmlToImage.toBlob(document.body); + const imgFile = new File( + [htmlBlob!], + `daily-checklist-${header?.date}-${header?.kandang_name}-${header?.category}.png`, + { + type: 'image/png', + } + ); + + shareData = { + files: [imgFile], + title: baseTitle, + text: fullMessage, + url: window.location.href, + }; + } else { + shareData = { + title: baseTitle, + text: fullMessage, + url: window.location.href, + }; + } setIsGeneratingImage(false); - const shareData = { - files: [imgFile], - title: `Daily Checklist - ${formatDate(header?.date || '')} - ${header?.kandang_name} - ${header?.category}`, - text: `Daily Checklist - ${formatDate(header?.date || '')} - ${header?.kandang_name} - ${header?.category}`, - url: window.location.href, - }; - try { if (!navigator.canShare(shareData)) { toast.error( @@ -592,6 +633,25 @@ export function DetailDailyChecklistContent() { } }; + const shareToWhatsAppHandler = async () => { + const isMobile = isMobileDevice(); + setIsGeneratingImage(true); + + const statusMsg = getStatusMessage(); + const category = header?.category || ''; + const message = encodeURIComponent( + `Daily Checklist\n\nTanggal: ${formatDate(header?.date || '')}\nKandang: ${header?.kandang_name}\nKategori: ${CATEGORY_LABELS[category] || category}\nProgress: ${header?.progress_percent}%\nStatus: ${header?.status}${statusMsg ? ` - ${statusMsg}` : ''}\n\nLihat detail lengkap: ${window.location.href}` + ); + + setIsGeneratingImage(false); + + const whatsappUrl = isMobile + ? `https://wa.me/?text=${message}` + : `https://web.whatsapp.com/send?text=${message}`; + + window.open(whatsappUrl, '_blank'); + }; + if (loading) { return (