From fd0e97e0a4a9b6d625c7c0605d415955b9b25597 Mon Sep 17 00:00:00 2001 From: "HATEC\\SPVDEV001" Date: Fri, 8 Sep 2023 14:16:44 +0700 Subject: cr - traking web awb --- src/lib/shipment/components/Shipments.jsx | 240 +++++++++++++++++++---------- src/lib/treckingAwb/component/Manifest.jsx | 16 +- 2 files changed, 174 insertions(+), 82 deletions(-) (limited to 'src') diff --git a/src/lib/shipment/components/Shipments.jsx b/src/lib/shipment/components/Shipments.jsx index 8b369a11..129e2496 100644 --- a/src/lib/shipment/components/Shipments.jsx +++ b/src/lib/shipment/components/Shipments.jsx @@ -5,7 +5,7 @@ import { EllipsisVerticalIcon, MagnifyingGlassIcon } from '@heroicons/react/24/o import ImageNext from 'next/image' import { useRouter } from 'next/router' import { useQuery } from 'react-query' -import _ from 'lodash-contrib' +import _, { forEach } from 'lodash-contrib' import Spinner from '@/core/components/elements/Spinner/Spinner' import Manifest from '@/lib/treckingAwb/component/Manifest' import { useState } from 'react' @@ -18,19 +18,24 @@ const { listShipments } = require('../api/listShipment') const Shipments = () => { const router = useRouter() const { q = '', page = 1 } = router.query + const [paramStatus, setParamStatus] = useState(null) const limit = 15 const query = { q: q, + status: paramStatus, offset: (page - 1) * limit, limit } const [inputQuery, setInputQuery] = useState(q) const queryString = _.toQuery(query) - const { data: shipments } = useQuery('shipments', () => listShipments({ query: queryString })) + const { data: shipments } = useQuery('shipments' + queryString, () => + listShipments({ query: queryString }) + ) const [idAWB, setIdAWB] = useState(null) + console.log('ini shipmnets', shipments) const pageCount = Math.ceil(shipments?.pickingTotal / limit) let pageQuery = _.omit(query, ['limit', 'offset', 'context']) @@ -45,41 +50,25 @@ const Shipments = () => { e.preventDefault() router.push(`${router.pathname}?q=${inputQuery}`) } + + const filterStatus = async (status) => { + if (status === paramStatus) { + setParamStatus(null) + } else { + setParamStatus(status) + } + } return ( <>
-
-
- -
-

Pending

-

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

-
-
-
- -
-

Pengiriman

-

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

-
-
-
- -
-

Selesai

-

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

-
+
@@ -108,14 +97,19 @@ const Shipments = () => {

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

- {shipment?.delivered && ( + {shipment?.status === 'completed' && (

Pesanan Tiba

)} - {!shipment?.delivered && ( + {shipment?.status === 'shipment' && ( +
+

Sedang Dikirim

+
+ )} + {shipment?.status === 'pending' && (
-

Sedang Dikirim

+

Pending

)}
@@ -187,49 +181,12 @@ const Shipments = () => {
-
-

Pending

-
-
- -
-
-

- {shipments?.summary?.pendingCount} Pesanan -

-
-
-
Pengiriman
-
-
- -
-
-

- {shipments?.summary?.shipmentCount} Pesanan -

-
-
-
Pesanan Tiba
-
-
- -
-
-

- {shipments?.summary?.completedCount} Pesanan -

-
+
@@ -310,4 +267,131 @@ const Shipments = () => { ) } +const CardStatus = ({ device, paramStatus, shipments, filterStatus }) => { + const status = [`pending`, `shipment`, `completed`] + + return ( + <> + {status.map((value) => { + const statusData = getStatusLabel(device, value, shipments) + if (device === 'desktop') { + return ( +
filterStatus(value)} + > +

{statusData.label}

+ {statusData.image} +

+ {statusData.shipCount} Pesanan +

+
+ ) + } else { + return ( +
filterStatus(value)} + > + {statusData.image} +

{statusData.label}

+

+ {' '} + {statusData.shipCount} {'>'} +

+
+ ) + } + })} + + ) +} + +const getStatusLabel = (device, status, shipments) => { + let images = null + switch (status) { + case 'pending': + if (device === 'desktop') { + images = ( +
+
+ +
+
+ ) + } else { + images = ( +
+ +
+ ) + } + return { + label: 'Pending', + shipCount: shipments?.summary?.pendingCount, + image: images + } + case 'shipment': + if (device === 'desktop') { + images = ( +
+
+ +
+
+ ) + } else { + images = ( +
+ +
+ ) + } + return { + label: 'Pengiriman', + shipCount: shipments?.summary?.shipmentCount, + image: images + } + case 'completed': + if (device === 'desktop') { + images = ( +
+
+ +
+
+ ) + } else { + images = ( +
+ +
+ ) + } + return { + label: 'Pesanan Tiba', + shipCount: shipments?.summary?.completedCount, + image: images + } + default: + return 'Status Tidak Dikenal' + } +} + export default Shipments diff --git a/src/lib/treckingAwb/component/Manifest.jsx b/src/lib/treckingAwb/component/Manifest.jsx index 185a9d55..cf2fa4ed 100644 --- a/src/lib/treckingAwb/component/Manifest.jsx +++ b/src/lib/treckingAwb/component/Manifest.jsx @@ -5,6 +5,7 @@ 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) @@ -84,14 +85,19 @@ const Manifest = ({ idAWB, closePopup }) => { >

Status Pesanan

- {manifests?.delivered && ( + {manifests?.status === 'completed' && (

Pesanan Tiba

)} - {!manifests?.delivered && ( + {manifests?.status === 'shipment' && ( +
+

Sedang Dikirim

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

Sedang Dikirim

+

Pending

)}
@@ -152,7 +158,9 @@ const Manifest = ({ idAWB, closePopup }) => { )} {manifests.delivered != true && (
)} -- cgit v1.2.3