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/auth/components/Menu.jsx | 49 +++++-- src/lib/shipment/components/Shipments.jsx | 122 ++++++++++++++-- src/lib/treckingAwb/api/getManifest.js | 9 ++ src/lib/treckingAwb/component/Manifest.jsx | 217 +++++++++++++++++++++-------- 4 files changed, 318 insertions(+), 79 deletions(-) (limited to 'src/lib') diff --git a/src/lib/auth/components/Menu.jsx b/src/lib/auth/components/Menu.jsx index e54992be..939a0d5f 100644 --- a/src/lib/auth/components/Menu.jsx +++ b/src/lib/auth/components/Menu.jsx @@ -1,5 +1,6 @@ import Link from '@/core/components/elements/Link/Link' import { useRouter } from 'next/router' +import ImageNext from 'next/image' const Menu = () => { const router = useRouter() @@ -10,33 +11,61 @@ const Menu = () => {
Menu
- Daftar Quotation +
+ +

Daftar Quotation

+
- Daftar Transaksi +
+ +

Daftar Transaksi

+
- Daftar Pengiriman +
+ +

Daftar Pengiriman

+
- Invoice & Faktur Pajak +
+ +

Invoice & Faktur Pajak

+
- Wishlist +
+ +

Wishlist

+
-
Pusat Bantuan
- Layanan Pelanggan + +
+ +

Layanan Pelanggan

+
+
Pengaturan Akun
- Daftar Alamat +
+ +

Daftar Alamat

+
- Profil Saya +
+ +

Profil Saya

+
) diff --git a/src/lib/shipment/components/Shipments.jsx b/src/lib/shipment/components/Shipments.jsx index eb14c77f..d62afcb7 100644 --- a/src/lib/shipment/components/Shipments.jsx +++ b/src/lib/shipment/components/Shipments.jsx @@ -1,7 +1,7 @@ import DesktopView from '@/core/components/views/DesktopView' import MobileView from '@/core/components/views/MobileView' import Menu from '@/lib/auth/components/Menu' -import { MagnifyingGlassIcon } from '@heroicons/react/24/outline' +import { EllipsisVerticalIcon, MagnifyingGlassIcon } from '@heroicons/react/24/outline' import ImageNext from 'next/image' import { useRouter } from 'next/router' import { useQuery } from 'react-query' @@ -9,6 +9,9 @@ import _ from 'lodash-contrib' import Spinner from '@/core/components/elements/Spinner/Spinner' import Manifest from '@/lib/treckingAwb/component/Manifest' import { useState } from 'react' +import Pagination from '@/core/components/elements/Pagination/Pagination' +import Link from 'next/link' +import TransactionStatusBadge from '@/lib/transaction/components/TransactionStatusBadge' const { listShipments } = require('../api/listShipment') @@ -19,21 +22,30 @@ const Shipments = () => { const limit = 15 const query = { - name: q, + q: q, offset: (page - 1) * limit, limit } - + console.log('ini query', query) + const [inputQuery, setInputQuery] = useState(q) const queryString = _.toQuery(query) const { data: shipments } = useQuery('shipments', () => listShipments({ query: queryString })) - const [ idAWB, setIdAWB ] = useState(null) + const [idAWB, setIdAWB] = useState(null) + + const pageCount = Math.ceil(shipments?.pickingTotal / limit) + let pageQuery = _.omit(query, ['limit', 'offset', 'context']) + pageQuery = _.pickBy(pageQuery, _.identity) + pageQuery = _.toQuery(pageQuery) const closePopup = () => { setIdAWB(null) } - const handleSubmit = async () => {} + const handleSubmit = async (e) => { + e.preventDefault() + router.push(`${router.pathname}?q=${inputQuery}`) + } return ( <> @@ -44,21 +56,30 @@ const Shipments = () => {

Pending

-

99 {'>'}

+

+ {' '} + {shipments?.summary?.pendingCount} {'>'} +

- +

Pengiriman

-

99 {'>'}

+

+ {' '} + {shipments?.summary?.shipmentCount} {'>'} +

Selesai

-

99 {'>'}

+

+ {' '} + {shipments?.summary?.shipmentCount} {'>'} +

@@ -67,14 +88,80 @@ const Shipments = () => { type='text' className='form-input' placeholder='Cari Pengiriman...' - value='' + value={inputQuery} onChange={(e) => setInputQuery(e.target.value)} /> + + {shipments?.pickings.map((shipment) => ( +
+
+
+

+ Kurir :{' '} + + {shipment.carrierName || '-'} + +

+

No. Resi : {shipment.trackingNumber || '-'}

+
+
+ {shipment?.delivered && ( +
+

Pesanan Tiba

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

Sedang Dikirim

+
+ )} +
+
+
+
+
+ No. Transaksi + +

{shipment.saleOrder.name}

+ + {shipment.date} +
+
+ +
+
+
+ +
+ ))} + + + +
@@ -155,7 +242,7 @@ const Shipments = () => { type='text' className='form-input' placeholder='Cari Pengiriman...' - value='' + value={inputQuery} onChange={(e) => setInputQuery(e.target.value)} /> @@ -207,10 +297,16 @@ const Shipments = () => { ))} +
- +
) diff --git a/src/lib/treckingAwb/api/getManifest.js b/src/lib/treckingAwb/api/getManifest.js index e69de29b..7d78a5f2 100644 --- a/src/lib/treckingAwb/api/getManifest.js +++ b/src/lib/treckingAwb/api/getManifest.js @@ -0,0 +1,9 @@ +const { default: odooApi } = require("@/core/api/odooApi") +const { getAuth } = require("@/core/utils/auth") + +export const getManifest = async ({id}) => { + const auth = getAuth() + const manifest = await odooApi('GET', `/api/v1/partner/${auth.partnerId}/stock-picking/${id}/tracking`) + + return manifest +} \ No newline at end of file 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