From 60f0b9d33335719b15f60f4b99bd80a48b7da346 Mon Sep 17 00:00:00 2001 From: "HATEC\\SPVDEV001" Date: Mon, 28 Aug 2023 16:55:26 +0700 Subject: add icon menu sidebar, add pagination --- src/lib/treckingAwb/component/Manifest.jsx | 217 +++++++++++++++++++++-------- 1 file changed, 161 insertions(+), 56 deletions(-) (limited to 'src/lib/treckingAwb/component') diff --git a/src/lib/treckingAwb/component/Manifest.jsx b/src/lib/treckingAwb/component/Manifest.jsx index b8ad78c4..185a9d55 100644 --- a/src/lib/treckingAwb/component/Manifest.jsx +++ b/src/lib/treckingAwb/component/Manifest.jsx @@ -1,70 +1,175 @@ +import odooApi from '@/core/api/odooApi' import BottomPopup from '@/core/components/elements/Popup/BottomPopup' -import { useState } from 'react' +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' const Manifest = ({ idAWB, closePopup }) => { - console.log('ini adalah', idAWB) - const airway = { - waybillNumber: '1234', - deliveryOrder: { - name: 'name', - carrier: 'carrier' - }, - manifests: [ - { - datetime: '12/12/2023', - description: 'ini descripsi' - } + 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() + const list = await odooApi( + 'GET', + `/api/v1/partner/${auth.partnerId}/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 ( <> - -
-
-
No Pengiriman
-
{airway?.deliveryOrder?.name}
+ {isLoading && ( + +
Mohon Tunggu
+
+
-
-
Kurir
-
{airway?.deliveryOrder?.carrier}
+ + )} + {!isLoading && ( + +
+

Status Pesanan

+ {manifests?.delivered && ( +
+

Pesanan Tiba

+
+ )} + {!manifests?.delivered && ( +
+

Sedang Dikirim

+
+ )}
-
-
No Resi
-
{airway?.waybillNumber}
+
+

+ Estimasi tiba pada ({manifests?.eta}) +

+

+ Dikirim Menggunakan{' '} + {manifests?.deliveryOrder.carrier} +

+ {manifests?.waybillNumber && ( +
+

No. Resi

+
+

{manifests?.waybillNumber}

+ +
+
+ )}
-
+
+
+
    + {manifests?.manifests?.map((manifest, index) => ( + <> +
  1. + {manifests.delivered == true && index == 0 ? ( +
    + +
    + ) : ( +
    + )} + {manifests.delivered != true && ( +
    + )} -
    -
    Status Pengiriman
    -
      - {airway?.manifests?.map((manifest, index) => ( -
    1. -
      - -

      - {manifest.description} -

      -
    2. - ))} - {(!airway?.manifests || airway?.manifests?.length == 0) && ( -
      Belum ada pengiriman
      - )} -
    -
    - + + {manifests.delivered == true && index == 0 && ( +

    Sudah Sampai

    + )} +

    {manifest.description}

    +
  2. + + ))} +
+
+
+ )} ) } -- cgit v1.2.3