summaryrefslogtreecommitdiff
path: root/src/lib/pengajuan-tempo/component/FinishTempo.jsx
blob: 2b6f69d04cd3f920db0728708f569ee993852b75 (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
import Link from 'next/link';
import Image from '~/components/ui/image';
import whatsappUrl from '@/core/utils/whatsappUrl';
import { useEffect, useState } from 'react';
import odooApi from '@/core/api/odooApi';
import useDevice from '@/core/hooks/useDevice';
import useAuth from '@/core/hooks/useAuth';
import axios from 'axios';
import { toast } from 'react-hot-toast';
import { ChevronRightIcon, ChevronLeftIcon } from '@heroicons/react/24/outline';

const FinishTempo = ({ query }) => {
  const [data, setData] = useState();
  const [transactionData, setTransactionData] = useState();
  const { isDesktop, isMobile } = useDevice();
  const auth = useAuth();
  const so_order = query?.order_id?.replaceAll('-', '/');
  useEffect(() => {
    const fetchData = async () => {
      const fetchedData = await odooApi(
        'GET',
        `/api/v1/sale_order_number?sale_number=${so_order}`
      );
      setData(fetchedData[0]);
    };
    fetchData();
  }, [query]);

  // Kirim email ketika komponen ini dimount atau sesuai kondisi
  const sendEmail = async () => {
    try {
      const send = await axios.post(
        `${process.env.NEXT_PUBLIC_SELF_HOST}/api/shop/finish-checkout?orderName=${query?.order_id}`,
        {}
      );
      if (send.status === 200) {
        toast.success('Berhasil mengirim rincian pesanan');
      } else {
        toast.error('Gagal mengirimkan rincian pesanan');
      }
    } catch (error) {
      console.error(error);
      toast.error('Gagal mengirimkan rincian pesanan');
    }
  };

  return (
    <div className='container flex flex-col items-center gap-4'>
      <div
        className={`flex ${
          isMobile ? 'w-full' : 'w-2/3'
        } justify-center items-center`}
      >
        <h1
          className={`text-red-500 text-center font-semibold ${
            isMobile ? 'text-lg' : 'text-3xl'
          }`}
        >
          {query?.status == 'switch-account'
            ? 'Form Pengajuan Tempo kamu gagal dilakukan'
            : 'Form Pengajuan Tempo kamu Telah Berhasil Didaftarkan Mohon menunggu hingga Proses Selesai'}
        </h1>
      </div>
      <Image
        src='/images/REGISTRASI-TEMPO.svg'
        alt='Checkout Pesanan'
        width={isMobile ? 300 : 450}
        height={isMobile ? 300 : 450}
      />

      <div
        className={`mt-2 text-center opacity-75 leading-6  p-4 md:p-0 ${
          isMobile ? 'w-full text-sm' : 'w-4/5 text-base'
        }`}
      >
        {query?.status == 'switch-account'
          ? 'Terima kasih atas minat anda untuk mendaftar Tempo, namun sayangnya akun anda bukan merupakan akun bisnis. Segera ubah akun anda menjadi Bisnis untuk menggunakan fitur ini'
          : 'Mohon menunggu untuk verifikasi dokumen dan kelengkapan data yang telah anda berikan. Proses approval pembayaran tempo kamu berhasil atau tidak akan diinfokan melalui email perusahaan / email yang mendaftar'}
      </div>
      <Link
        href={
          query?.status == 'switch-account'
            ? `/profil`
            : `/my/quotations/${data?.id}`
        }
        className='btn-solid-red rounded-md text-base flex flex-row'
      >
        {query?.status == 'switch-account'
          ? 'Ubah Akun'
          : 'Lihat Status Pendaftaran'}{' '}
        <ChevronRightIcon className='w-5' />
      </Link>
    </div>
  );
};

export default FinishTempo;