import odooApi from '@/core/api/odooApi'; import BottomPopup from '@/core/components/elements/Popup/BottomPopup'; import LogoSpinner from '@/core/components/elements/Spinner/LogoSpinner'; import { getAuth } from '@/core/utils/auth'; import { useEffect, useState } from 'react'; import { toast } from 'react-hot-toast'; import ImageNext from 'next/image'; import { list } from 'postcss'; const Manifest = ({ idAWB, closePopup }) => { const [manifests, setManifests] = useState(null); const [isLoading, setIsLoading] = useState(false); console.log('manifests', manifests); const formatCustomDate = (date) => { const months = [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec', ]; const parts = date.split(' '); // Pisahkan tanggal dan waktu const [datePart, timePart] = parts; const [yyyy, mm, dd] = datePart.split('-'); const [hh, min] = timePart.split(':'); const monthAbbreviation = months[parseInt(mm, 10) - 1]; return `${dd} ${monthAbbreviation} ${hh}:${min}`; }; const getManifest = async () => { setIsLoading(true); const auth = getAuth(); let list; if (auth) { list = await odooApi( 'GET', `/api/v1/partner/${auth.partnerId}/stock-picking/${idAWB}/tracking` ); } else { list = await odooApi('GET', `/api/v1/stock-picking/${idAWB}/tracking`); } setManifests(list); setIsLoading(false); }; useEffect(() => { if (idAWB) { getManifest(); } else { setManifests(null); } }, [idAWB]); const [copied, setCopied] = useState(false); const handleCopyClick = () => { const textToCopy = manifests?.waybillNumber; navigator.clipboard.writeText(textToCopy); setCopied(true); toast.success('No Resi Berhasil di Copy'); setTimeout(() => setCopied(false), 2000); // Reset copied state after 2 seconds }; return ( <> {isLoading && ( Mohon Tunggu )} {!isLoading && ( Status Pesanan {manifests?.status === 'completed' && ( Pesanan Tiba )} {manifests?.status === 'shipment' && ( Sedang Dikirim )} {manifests?.status === 'pending' && ( Pending )} Estimasi tiba pada{' '} ({manifests?.eta}) Dikirim Menggunakan{' '} {manifests?.deliveryOrder.carrier} {manifests?.waybillNumber && ( No. Resi {manifests?.waybillNumber} handleCopyClick()} > )} {manifests?.manifests?.map((manifest, index) => ( <> {manifests.delivered == true && index == 0 ? ( ) : ( )} {manifests.delivered != true && ( )} {formatCustomDate(manifest.datetime)} {manifests.delivered == true && index == 0 && ( Sudah Sampai )} {manifest.description} > ))} )} > ); }; export default Manifest;
Pesanan Tiba
Sedang Dikirim
Pending
Sudah Sampai
{manifest.description}