summaryrefslogtreecommitdiff
path: root/src/lib/auth/components/Menu.jsx
blob: d99917d0f223b6f662d52f4eeccebe93d7859fb9 (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
import Link from '@/core/components/elements/Link/Link';
import { useRouter } from 'next/router';
import ImageNext from 'next/image';
import whatsappUrl from '@/core/utils/whatsappUrl';
import { deleteAuth } from '@/core/utils/auth';
import useAuth from '@/core/hooks/useAuth';
const Menu = () => {
  const router = useRouter();
  const auth = useAuth();

  const routeStartWith = (route) => router.pathname.startsWith(route);

  const logout = async () => {
    deleteAuth().then(() => {
      router.push('/login');
    });
  };

  return (
    <div className='grid grid-cols-1 bg-white border border-gray_r-6 rounded py-2 px-4 sticky top-48'>
      <div className='mt-4 mb-1 font-medium'>Menu</div>
      <LinkItem href='/my/quotations' active={routeStartWith('/my/quotations')}>
        <div className='flex gap-x-3 items-center'>
          <ImageNext
            src='/images/icon/icon_daftar_quotation.svg'
            width={18}
            height={20}
          />
          <p>Daftar Quotation</p>
        </div>
      </LinkItem>
      <LinkItem
        href='/my/transactions'
        active={routeStartWith('/my/transactions')}
      >
        <div className='flex gap-x-3 items-center'>
          <ImageNext
            src='/images/icon/icon_daftar_transaksi.svg'
            width={18}
            height={20}
          />
          <p>Daftar Transaksi</p>
        </div>
      </LinkItem>
      <LinkItem href='/my/shipments' active={routeStartWith('/my/shipments')}>
        <div className='flex gap-x-3 items-center'>
          <ImageNext
            src='/images/icon/icon_pengiriman.svg'
            width={18}
            height={20}
          />
          <p>Daftar Pengiriman</p>
        </div>
      </LinkItem>
      <LinkItem href='/my/invoices' active={routeStartWith('/my/invoices')}>
        <div className='flex gap-x-3 items-center'>
          <ImageNext
            src='/images/icon/icon_invoice.svg'
            width={18}
            height={20}
          />
          <p>Invoice & Faktur Pajak</p>
        </div>
      </LinkItem>
      {auth &&
        auth.partnerTempo &&
        (auth.partnerTempo ||
          auth.tempoProgres === 'review') && (
          <LinkItem href='/my/tempo' active={routeStartWith('/my/tempo')}>
            <div className='flex gap-x-3 items-center'>
              <ImageNext
                src='/images/icon/icon_tempo.svg'
                width={18}
                height={20}
              />
              <p>Pembayaran Tempo</p>
            </div>
          </LinkItem>
        )}
      <LinkItem href='/my/wishlist' active={routeStartWith('/my/wishlist')}>
        <div className='flex gap-x-3 items-center'>
          <ImageNext
            src='/images/icon/icon_wishlist.svg'
            width={18}
            height={20}
          />
          <p>Wishlist</p>
        </div>
      </LinkItem>
      <div className='mt-4 mb-1 font-medium'>Pusat Bantuan</div>

      <LinkItem
        href={whatsappUrl('', '', '')}
        rel='noopener noreferrer'
        target='_blank'
      >
        <div className='flex gap-x-3 items-center'>
          <ImageNext
            src='/images/icon/icon_layanan_pelanggan.svg'
            width={18}
            height={20}
          />
          <p>Layanan Pelanggan</p>
        </div>
      </LinkItem>
      <div className='mt-4 mb-1 font-medium'>Pengaturan Akun</div>
      <LinkItem href='/my/address' active={routeStartWith('/my/address')}>
        <div className='flex gap-x-3 items-center'>
          <ImageNext
            src='/images/icon/icon_daftar_alamat.svg'
            width={18}
            height={20}
          />
          <p>Daftar Alamat</p>
        </div>
      </LinkItem>
      <LinkItem href='/my/profile' active={routeStartWith('/my/profile')}>
        <div className='flex gap-x-3 items-center'>
          <ImageNext
            src='/images/icon/icon_profile.svg'
            width={18}
            height={20}
          />
          <p>Profil Saya</p>
        </div>
      </LinkItem>
      <button
        type='button'
        onClick={logout}
        className='text-gray_r-12/80 p-2 text-left'
      >
        <div className='flex gap-x-3 items-center'>
          <ImageNext
            src='/images/icon/icon_logout.svg'
            width={18}
            height={20}
          />
          <p>Keluar Akun</p>
        </div>
      </button>
    </div>
  );
};

const LinkItem = ({ children, ...props }) => (
  <Link
    {...props}
    className={`!text-gray_r-12/80 !font-normal p-2 rounded ${
      props.active == true ? 'bg-gray_r-3' : ''
    }`}
  >
    {children}
  </Link>
);

export default Menu;