summaryrefslogtreecommitdiff
path: root/src/pages/my/address/index.js
blob: cac6e8f6a6b075ed1d95a52cbb34c31c70fac6fb (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
import { useEffect, useState } from "react";
import AppBar from "../../../components/AppBar";
import Layout from "../../../components/Layout";
import Link from "../../../components/Link";
import WithAuth from "../../../components/WithAuth";
import apiOdoo from "../../../helpers/apiOdoo";
import { useAuth } from "../../../helpers/auth";

export default function Address() {
  const [auth] = useAuth();
  const [addresses, setAddresses] = useState(null);

  useEffect(() => {
    const getAddress = async () => {
      if (auth) {
        const dataAddress = await apiOdoo('GET', `/api/v1/user/${auth.id}/address`);
        setAddresses(dataAddress);
      }
    };
    getAddress();
  }, [auth]);

  return (
    <WithAuth>
      <Layout>
        <AppBar title="Daftar Alamat" />
        
        <div className="text-right mt-4 px-4">
          <Link href="/my/address/create">Tambah Alamat</Link>
        </div>

        <div className="grid gap-y-4 p-4">
        { addresses && addresses.map((address, index) => (
          <div className="p-4 rounded-md border border-gray_r-7" key={index}>
            <p className="font-medium">{ address.name }</p>
            <p className="mt-3 text-gray_r-11">{ address.mobile }</p>
            <p className="mt-1 text-gray_r-11 leading-6">{ address.street } { address.street2 }</p>
            <button className="btn-light mt-3 w-full">Ubah Alamat</button>
          </div>
        )) }
        </div>
      </Layout>
    </WithAuth>
  )
}