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'; import InformationSection from './InformationSection'; import Link from 'next/link'; // function capitalizeFirstLetter(str) { // return str.charAt(0).toUpperCase() + str.slice(1); // } function capitalizeWords(str) { if (!str || typeof str !== 'string') { return ''; } return str .split(' ') .map((word) => capitalizeFirstLetter(word)) .join(' '); } function capitalizeFirstLetter(word) { return word.charAt(0).toUpperCase() + word.slice(1).toLowerCase(); } function mappingLiveTracking(kurir, resi){ let url = null switch (kurir){ case('grab'): url = 'https://express.grab.com/track/orders?ids='+resi break; default: url = false } return url } const Manifest = ({ idAWB, closePopup }) => { const [manifests, setManifests] = useState(null); const [isLoading, setIsLoading] = useState(false); 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 isLiveTracking = mappingLiveTracking(manifests?.deliveryOrder?.carrier.toLowerCase(), manifests?.waybillNumber) return ( <> {isLoading && (
Mohon Tunggu
)} {!isLoading && (

Status Pesanan

{manifests?.status === 'completed' && (

Pesanan Tiba

)} {manifests?.status === 'shipment' && (

Sedang Dikirim

)} {manifests?.status === 'cancelled' && (

Di Batalkan

)} {manifests?.status === 'on_hold' && (

Ditunda Sementara

)} {manifests?.status === 'pending' && (

Pending

)}

{manifests?.isDelay && ( )}
    {manifests?.manifests?.map((manifest, index) => { const isFirst = index === 0; const isDelivered = manifests.delivered === true; const isBiteship = manifests.isBiteship === true; const statusTitle = isDelivered && isFirst && !isBiteship ? 'Pesanan sampai' : isBiteship ? capitalizeWords(manifest.status) : ''; return (
  1. {/* Kolom 1: Tanggal + Jam */}
    {formatCustomDate(manifest.datetime)}
    {/* Kolom 2: Bullet/Poin */}
    {/* Kolom 3: Status dan Deskripsi */}

    {manifests?.deliveryOrder.carrier != 'Self Pick Up' ? capitalizeWords(manifest.status) : ''}

  2. ); })}
{ isLiveTracking && manifests?.status === 'shipment' && ( Live Tracking ) }
{/* Barang */}
{Array.isArray(manifests?.products) && manifests.products.length > 0 ? (
{manifests.products.map((product, idx) => (
{/* Gambar Produk */} {product.name} {/* Info Produk */}
{product.name} {product.code}
))}
) : ( )}
)} ); }; export default Manifest;