summaryrefslogtreecommitdiff
path: root/src/lib/treckingAwb/component/Manifest.jsx
blob: fa998bd368819710f46c9b4f139ce95023687504 (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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
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';

function capitalizeFirstLetter(str) {
  return str.charAt(0).toUpperCase() + str.slice(1);
}

function capitalizeWords(str) {
  return str
    .split(' ')
    .map((word) => capitalizeFirstLetter(word))
    .join(' ');
}

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);
  };
  console.log(manifests);
  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 (
    <>
      {isLoading && (
        <BottomPopup active={true} close=''>
          <div className='leading-7 text-gray_r-12/80 flex justify-center'>
            Mohon Tunggu
          </div>
          <div className='container flex justify-center my-4'>
            <LogoSpinner width={48} height={48} />
          </div>
        </BottomPopup>
      )}
      {!isLoading && (
        <BottomPopup
          key={manifests?.waybillNumber}
          title='Lacak Pengiriman'
          active={idAWB}
          close={closePopup}
        >
          <div className='flex justify-between items-center mb-5'>
            <h1 className='text-body-1'>Status Pesanan</h1>
            {manifests?.status === 'completed' && (
              <div className='bg-green-100 p-2 rounded '>
                <p className='text-green-600 text-sm'>Pesanan Tiba</p>
              </div>
            )}
            {manifests?.status === 'shipment' && (
              <div className='bg-yellow-100 p-2 rounded '>
                <p className='text-yellow-600 text-sm'>Sedang Dikirim</p>
              </div>
            )}
            {manifests?.status === 'cancelled' && (
              <div className='bg-red-800 p-2 rounded '>
                <p className='text-white text-sm'>Di Batalkan</p>
              </div>
            )}
            {manifests?.status === 'on_hold' && (
              <div className='bg-red-800 p-2 rounded '>
                <p className='text-white text-sm'>Ditunda Sementara </p>
              </div>
            )}
            {manifests?.status === 'pending' && (
              <div className='bg-red-100 p-2 rounded '>
                <p className='text-red-600 text-sm'>Pending</p>
              </div>
            )}
          </div>

          <div className=''>
            <div className='grid gap-y-2 text-sm'>
              <div className='grid grid-cols-[150px_auto]'>
                <span className='font-semibold'>Nomor Resi</span>
                <div className='flex gap-x-3'>
                  <span className='font-semibold'>
                    : {manifests?.waybillNumber}{' '}
                  </span>
                  <button
                    className={`${copied ? 'text-gray-400' : 'text-red-600 '}`}
                    onClick={() => handleCopyClick()}
                  >
                    <svg
                      aria-hidden='true'
                      fill='none'
                      stroke='currentColor'
                      stroke-width='1.5'
                      viewBox='0 0 24 24'
                      className='w-5 h-6'
                    >
                      <path
                        d='M15.75 17.25v3.375c0 .621-.504 1.125-1.125 1.125h-9.75a1.125 1.125 0 01-1.125-1.125V7.875c0-.621.504-1.125 1.125-1.125H6.75a9.06 9.06 0 011.5.124m7.5 10.376h3.375c.621 0 1.125-.504 1.125-1.125V11.25c0-4.46-3.243-8.161-7.5-8.876a9.06 9.06 0 00-1.5-.124H9.375c-.621 0-1.125.504-1.125 1.125v3.5m7.5 10.375H9.375a1.125 1.125 0 01-1.125-1.125v-9.25m12 6.625v-1.875a3.375 3.375 0 00-3.375-3.375h-1.5a1.125 1.125 0 01-1.125-1.125v-1.5a3.375 3.375 0 00-3.375-3.375H9.75'
                        stroke-linecap='round'
                        stroke-linejoin='round'
                      ></path>
                    </svg>
                  </button>
                </div>
              </div>
              <div className='grid grid-cols-[150px_auto]'>
                <span>Kurir</span>
                <span className='font-semibold'>
                  {' '}
                  : {manifests?.deliveryOrder.carrier}
                </span>
              </div>
              <div className='grid grid-cols-[150px_auto]'>
                <span>Jenis Service</span>
                <span className='font-semibold'>
                  {' '}
                  : {manifests?.deliveryOrder.service}
                </span>
              </div>
              <div className='grid grid-cols-[150px_auto]'>
                <span>Tanggal Dikirim</span>
                <span className='font-semibold'> : {manifests?.deliveredDate}</span>
              </div>
              <div className='grid grid-cols-[150px_auto]'>
                <span>Estimasi Tiba</span>
                <span className='font-semibold'>
                  :{' '}
                  <span className='text-red-600 font-semibold'>
                    {manifests?.eta}
                  </span>
                </span>
              </div>
            </div>
          </div>
          <hr className='mt-4' />
          {manifests?.isDelay && (
            <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>Pesanan anda mungkin mengalami keterlambatan tiba</div>
            </div>
          )}
          <div className='pt-4'>
            <ol className='relative'>
              {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 (
                  <li className='grid grid-cols-[80px_20px_1fr] gap-2 mb-6 items-start' key={index}>
                    {/* Kolom 1: Tanggal + Jam */}
                    <div className='text-sm text-gray-400 whitespace-nowrap'>
                      {formatCustomDate(manifest.datetime)}
                    </div>

                    {/* Kolom 2: Bullet/Poin */}
                    <div className='relative flex items-start justify-center pt-1'>
                      <div
                        className={`w-3 h-3 rounded-full border ${
                          index === 0 && manifests.delivered
                            ? 'bg-green-600 border-green-600'
                            : 'bg-gray-400 border-white'
                        }`}
                      />
                    </div>

                    {/* Kolom 3: Status dan Deskripsi */}
                    <div>
                      <p className='text-sm font-semibold text-green-600'>
                        {manifests?.deliveryOrder.carrier != 'Self Pick Up' ? capitalizeWords(manifest.status) : ''}
                      </p>
                      <p
                        className='text-xs text-gray-600'
                        dangerouslySetInnerHTML={{
                          __html: manifest.description,
                        }}
                      />
                    </div>
                  </li>
                );
              })}
            </ol>
          </div>
        </BottomPopup>
      )}
    </>
  );
};

export default Manifest;