summaryrefslogtreecommitdiff
path: root/src/lib/shipment/components/Shipments.jsx
blob: eb14c77f77d6755364786cef851c74dd4d368844 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
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 ImageNext from 'next/image'
import { useRouter } from 'next/router'
import { useQuery } from 'react-query'
import _ from 'lodash-contrib'
import Spinner from '@/core/components/elements/Spinner/Spinner'
import Manifest from '@/lib/treckingAwb/component/Manifest'
import { useState } from 'react'

const { listShipments } = require('../api/listShipment')

const Shipments = () => {
  const router = useRouter()
  const { q = '', page = 1 } = router.query

  const limit = 15

  const query = {
    name: q,
    offset: (page - 1) * limit,
    limit
  }

  const queryString = _.toQuery(query)

  const { data: shipments } = useQuery('shipments', () => listShipments({ query: queryString }))
  const [ idAWB, setIdAWB ] = useState(null)

  const closePopup = () => {
    setIdAWB(null)
  }

  const handleSubmit = async () => {}
  return (
    <>
      <MobileView>
        <div className='p-4 flex flex-col gap-y-4'>
          <div className='flex justify-between gap-x-1'>
            <div className='flex justify-between items-center gap-x-2 p-2 bg-white border border-gray-200 rounded-lg shadow'>
              <div>
                <ImageNext src='/images/BOX(1).svg' width={15} height={20} />
              </div>
              <h1 className='text-xs'>Pending</h1>
              <h1 className='text-xs'>99 {'>'}</h1>
            </div>
            <div className='flex justify-between items-center gap-x-2 p-2 bg-white border border-gray-200 rounded-lg shadow'>
              <div>
                <ImageNext src='/images/BOX_DELIVER_(1).svg' width={15} height={20} />
              </div>
              <h1 className='text-xs'>Pengiriman</h1>
              <h1 className='text-xs'>99 {'>'}</h1>
            </div>
            <div className='flex justify-between items-center gap-x-2 p-2 bg-white border border-gray-200 rounded-lg shadow'>
              <div>
                <ImageNext src='/images/open-box(1).svg' width={16} height={20} />
              </div>
              <h1 className='text-xs'>Selesai</h1>
              <h1 className='text-xs'>99 {'>'}</h1>
            </div>
          </div>

          <form className='flex gap-x-3' onSubmit={handleSubmit}>
            <input
              type='text'
              className='form-input'
              placeholder='Cari Pengiriman...'
              value=''
              onChange={(e) => setInputQuery(e.target.value)}
            />
            <button className='btn-light bg-transparent px-3' type='submit'>
              <MagnifyingGlassIcon className='w-6' />
            </button>
          </form>
        </div>
      </MobileView>
      <DesktopView>
        <div className='container mx-auto flex py-10'>
          <div className='w-3/12 pr-4'>
            <Menu />
          </div>
          <div className='w-9/12'>
            <div className='p-4 bg-white border border-gray_r-6 rounded mb-2'>
              <h1 className='text-title-sm font-semibold'>Pengiriman</h1>
              <div
                class='flex items-center p-4 mb-4 text-sm text-yellow-800 rounded-lg bg-yellow-50'
                role='alert'
              >
                <svg
                  class='flex-shrink-0 inline w-4 h-4 mr-3'
                  aria-hidden='true'
                  fill='currentColor'
                  viewBox='0 0 20 20'
                >
                  <path d='M10 .5a9.5 9.5 0 1 0 9.5 9.5A9.51 9.51 0 0 0 10 .5ZM9.5 4a1.5 1.5 0 1 1 0 3 1.5 1.5 0 0 1 0-3ZM12 15H8a1 1 0 0 1 0-2h1v-3H8a1 1 0 0 1 0-2h2a1 1 0 0 1 1 1v4h1a1 1 0 0 1 0 2Z' />
                </svg>
                <div>
                  <span class='font-medium'>Warning alert!</span> Change a few things up and try
                  submitting again.
                </div>
              </div>
              <div className='flex justify-between gap-x-5'>
                <div class='max-w-sm p-6 bg-white border border-gray-200 rounded-lg shadow min-w-[268px]'>
                  <h2 class='mb-2 text-lg font-bold tracking-tight'>Pending</h2>
                  <div className='bg-red-100 border border-red-200 rounded-sm p-2 w-20 h-[39px] mb-2'>
                    <div>
                      <ImageNext
                        src='/images/BOX(1).svg'
                        width={25}
                        height={20}
                        style={{ stroke: 'red' }}
                      />
                    </div>
                  </div>
                  <h1 className='text-xl font-bold'>
                    {shipments?.summary?.pendingCount} <span className='text-sm'>Pesanan</span>
                  </h1>
                </div>
                <div class='max-w-sm p-6 bg-white border border-gray-200 rounded-lg shadow min-w-[268px]'>
                  <h5 class='mb-2 text-lg font-bold tracking-tight'>Pengiriman</h5>
                  <div className='bg-yellow-100 border border-yellow-200 rounded-sm p-1 w-20 mb-2'>
                    <div>
                      <ImageNext src='/images/BOX_DELIVER_(1).svg' width={30} height={20} />
                    </div>
                  </div>
                  <h1 className='text-xl font-bold'>
                    {shipments?.summary?.shipmentCount} <span className='text-sm'>Pesanan</span>
                  </h1>
                </div>
                <div class='max-w-sm p-6 bg-white border border-gray-200 rounded-lg shadow min-w-[268px]'>
                  <h5 class='mb-2 text-lg font-bold tracking-tight'>Pesanan Tiba</h5>
                  <div className='bg-green-100 border border-green-200 rounded-sm p-1 w-20 mb-2'>
                    <div>
                      <ImageNext
                        src='/images/open-box(1).svg'
                        width={30}
                        height={20}
                        className='stroke-orange-600'
                      />
                    </div>
                  </div>
                  <h1 className='text-xl font-bold'>
                    {shipments?.summary?.completedCount} <span className='text-sm'>Pesanan</span>
                  </h1>
                </div>
              </div>
            </div>
            <div className='p-4 bg-white border border-gray_r-6 rounded'>
              <div className='flex mb-6 items-center justify-between'>
                <h1 className='text-title-sm font-semibold'>Detail Pengiriman</h1>
                <form className='flex gap-x-2' onSubmit={handleSubmit}>
                  <input
                    type='text'
                    className='form-input'
                    placeholder='Cari Pengiriman...'
                    value=''
                    onChange={(e) => setInputQuery(e.target.value)}
                  />
                  <button className='btn-light bg-transparent px-3' type='submit'>
                    <MagnifyingGlassIcon className='w-6' />
                  </button>
                </form>
              </div>
              <table className='table-data'>
                <thead>
                  <tr>
                    <th>Tanggal</th>
                    <th>No. Resi</th>
                    <th>No. Pengiriman</th>
                    <th>Sales Order</th>
                    <th>Purchase Order</th>
                    <th>Expedisi</th>
                    <th>Status</th>
                  </tr>
                </thead>
                <tbody>
                  {!shipments && (
                    <tr>
                      <td colSpan={7}>
                        <div className='flex justify-center my-2'>
                          <Spinner className='w-6 text-gray_r-12/50 fill-gray_r-12' />
                        </div>
                      </td>
                    </tr>
                  )}
                  {shipments && shipments?.pickings?.length == 0 && (
                    <tr>
                      <td colSpan={7}>Tidak ada transaksi</td>
                    </tr>
                  )}
                  {shipments?.pickings.map((shipment) => (
                    <tr key={shipment.id}>
                      <td>{shipment.date || '-'}</td>
                      <td>{shipment.trackingNumber || '-'}</td>
                      <td>{shipment.name || '-'}</td>
                      <td>{shipment.saleOrder.name || '-'}</td>
                      <td>{shipment.saleOrder.clientOrderRef || '-'}</td>
                      <td>{shipment.carrierName || '-'}</td>
                      <td>
                        <button onClick={() => setIdAWB(shipment.id) }className='bg-red-600 border border-red-600 rounded-md text-sm text-white p-1 w-20'>
                          Lacak
                        </button>
                      </td>
                    </tr>
                  ))}
                </tbody>
              </table>
            </div>
          </div>
        </div>
          <Manifest idAWB={idAWB} closePopup={closePopup}/>
      </DesktopView>
    </>
  )
}

export default Shipments