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
|
import AppBar from "../../../components/AppBar";
import Layout from "../../../components/Layout";
import WithAuth from "../../../components/WithAuth";
import apiOdoo from "../../../helpers/apiOdoo";
import ReactSelect from "react-select";
import { useEffect, useState } from "react";
export default function CreateAddress() {
// Master Data
const [cities, setCities] = useState([]);
const [districts, setDistricts] = useState([]);
const [subDistricts, setSubDistricts] = useState([]);
// Input Data
const [city, setCity] = useState(null);
const [district, setDistrict] = useState(null);
const [subDistrict, setSubDistrict] = useState(null);
const [formValue, setFormValue] = useState({});
useEffect(() => {
if (cities.length == 0) {
const loadCities = async () => {
let dataCities = await apiOdoo('GET', '/api/v1/city');
setCities(dataCities);
};
loadCities();
}
}, [cities]);
useEffect(() => {
setDistrict(null);
if (city) {
const loadDistricts = async () => {
let dataDistricts = await apiOdoo('GET', `/api/v1/district?city_id=${city.id}`);
setDistricts(dataDistricts);
};
loadDistricts();
}
}, [city]);
useEffect(() => {
setSubDistrict(null);
if (district) {
const loadSubDistricts = async () => {
let dataSubDistricts = await apiOdoo('GET', `/api/v1/sub_district?district_id=${district.id}`);
console.log(dataSubDistricts);
setSubDistricts(dataSubDistricts);
};
loadSubDistricts();
}
}, [district]);
const handleChange = (e) => {
setFormValue({
...formValue,
[e.target.name]: e.target.value
});
};
return (
<WithAuth>
<Layout>
<AppBar title="Tambah Alamat" />
<form className="px-4">
<label className="form-label mt-4 mb-2">Label Alamat</label>
<input
type="text"
className="form-input"
placeholder="Invoice Address"
name="name"
/>
<label className="form-label mt-4 mb-2">Nama Kontak</label>
<input
type="text"
className="form-input"
placeholder="John Doe"
name="name"
/>
<label className="form-label mt-4 mb-2">Email <span className="text-gray_r-11">(opsional)</span></label>
<input
type="text"
className="form-input"
placeholder="johndoe@gmail.com"
name="name"
/>
<label className="form-label mt-4 mb-2">No. Handphone</label>
<input
type="tel"
className="form-input"
placeholder="08xxxxxxxx"
name="mobile"
/>
<label className="form-label mt-4 mb-2">Alamat</label>
<input
type="text"
className="form-input"
placeholder="Jl. Bandengan Utara"
name="street"
/>
<label className="form-label mt-4 mb-2">Kota</label>
<ReactSelect
placeholder="Pilih kota..."
classNamePrefix="form-select"
classNames={{ control: (state) => state.menuIsOpen || state.isFocused ? '!border-yellow_r-9' : '' }}
options={cities}
getOptionLabel={e => e.name}
getOptionValue={e => e.id}
onChange={(value) => setCity(value)}
value={city}
/>
<label className="form-label mt-4 mb-2">Kecamatan <span className="text-gray_r-11">(opsional)</span></label>
<ReactSelect
placeholder="Pilih Kecamatan..."
classNamePrefix="form-select"
classNames={{ control: (state) => state.menuIsOpen || state.isFocused ? '!border-yellow_r-9' : '' }}
options={districts}
getOptionLabel={e => e.name}
getOptionValue={e => e.id}
onChange={(value) => setDistrict(value)}
value={district}
isDisabled={!city}
/>
<label className="form-label mt-4 mb-2">Kelurahan <span className="text-gray_r-11">(opsional)</span></label>
<ReactSelect
placeholder="Pilih Kelurahan..."
classNamePrefix="form-select"
classNames={{ control: (state) => state.menuIsOpen || state.isFocused ? '!border-yellow_r-9' : '' }}
options={subDistricts}
getOptionLabel={e => e.name}
getOptionValue={e => e.id}
onChange={(value) => setSubDistrict(value)}
value={subDistrict}
isDisabled={!district}
/>
<label className="form-label mt-4 mb-2">Kode Pos</label>
<input
type="number"
className="form-input"
placeholder="10100"
name="zip"
/>
<button
type="button"
className="btn-yellow float-right mt-6 w-full"
>
Simpan
</button>
</form>
</Layout>
</WithAuth>
);
}
|