mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-20 13:32:00 +00:00
feat: add share to whatsapp after submitting daily checklist
This commit is contained in:
@@ -53,7 +53,6 @@ import { useRouter, useSearchParams, usePathname } from 'next/navigation';
|
||||
import { Icon } from '@iconify/react';
|
||||
import { DailyChecklistKandangApi } from '@/services/api/daily-checklist/kandang';
|
||||
|
||||
// Static categories
|
||||
const CATEGORIES = [
|
||||
{ value: 'pullet_open', label: 'Pullet Open' },
|
||||
{ value: 'pullet_close', label: 'Pullet Close' },
|
||||
@@ -62,6 +61,14 @@ const CATEGORIES = [
|
||||
{ value: 'empty_kandang', label: 'Kandang Kosong' },
|
||||
];
|
||||
|
||||
const CATEGORY_LABELS: { [key: string]: string } = {
|
||||
pullet_open: 'Pullet Open',
|
||||
pullet_close: 'Pullet Close',
|
||||
produksi_open: 'Produksi Open',
|
||||
produksi_close: 'Produksi Close',
|
||||
empty_kandang: 'Kandang Kosong',
|
||||
};
|
||||
|
||||
const TIME_TYPE_ORDER = ['Umum', 'Pagi', 'Siang', 'Sore', 'Malam'];
|
||||
const TIME_TYPE_LABELS: { [key: string]: string } = {
|
||||
Umum: 'Umum',
|
||||
@@ -246,7 +253,6 @@ export function DailyChecklistContent() {
|
||||
}
|
||||
}, [selectedCategory]);
|
||||
|
||||
// Format date for display
|
||||
const formatDateForDisplay = (dateStr: string) => {
|
||||
if (!dateStr) return 'Pilih tanggal';
|
||||
const [year, month, day] = dateStr.split('-');
|
||||
@@ -259,6 +265,36 @@ export function DailyChecklistContent() {
|
||||
});
|
||||
};
|
||||
|
||||
const formatDate = (dateString: string) => {
|
||||
const date = new Date(dateString);
|
||||
return date.toLocaleDateString('id-ID', {
|
||||
day: '2-digit',
|
||||
month: 'long',
|
||||
year: 'numeric',
|
||||
});
|
||||
};
|
||||
|
||||
const isMobileDevice = () => {
|
||||
return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
|
||||
navigator.userAgent
|
||||
);
|
||||
};
|
||||
|
||||
const getStatusMessage = () => {
|
||||
switch (checklistStatus) {
|
||||
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 '';
|
||||
}
|
||||
};
|
||||
|
||||
// Fetch master data on mount
|
||||
useEffect(() => {
|
||||
setInitialLoading(false);
|
||||
@@ -842,7 +878,43 @@ export function DailyChecklistContent() {
|
||||
}
|
||||
|
||||
setChecklistStatus('SUBMITTED');
|
||||
toast.success('Checklist berhasil disubmit untuk approval');
|
||||
|
||||
const shareToWhatsApp = () => {
|
||||
const kandangName = kandangOptions.find(
|
||||
(k) => String(k.value) === kandangId
|
||||
)?.label || kandangId;
|
||||
const statusMsg = getStatusMessage();
|
||||
const category = selectedCategory || '';
|
||||
const message = encodeURIComponent(
|
||||
`Daily Checklist\n\nTanggal: ${formatDate(date)}\nKandang: ${kandangName}\nKategori: ${CATEGORY_LABELS[category] || category}\nStatus: SUBMITTED${statusMsg ? ` - ${statusMsg}` : ''}\n\nLihat detail lengkap: ${window.location.href}`
|
||||
);
|
||||
|
||||
const isMobile = isMobileDevice();
|
||||
const whatsappUrl = isMobile
|
||||
? `https://wa.me/?text=${message}`
|
||||
: `https://web.whatsapp.com/send?text=${message}`;
|
||||
|
||||
window.open(whatsappUrl, '_blank');
|
||||
};
|
||||
|
||||
toast.success('Checklist berhasil disubmit untuk approval', {
|
||||
action: {
|
||||
label: 'Bagikan ke WhatsApp',
|
||||
onClick: shareToWhatsApp,
|
||||
},
|
||||
description: (
|
||||
<button
|
||||
onClick={() =>
|
||||
router.push(
|
||||
`/daily-checklist/list-daily-checklist/detail/?checklistId=${dailyChecklistId}`
|
||||
)
|
||||
}
|
||||
className='text-blue-600 hover:text-blue-800 underline font-medium'
|
||||
>
|
||||
Lihat Detail
|
||||
</button>
|
||||
),
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Error submitting:', error);
|
||||
toast.error('Terjadi kesalahan');
|
||||
|
||||
Reference in New Issue
Block a user