| 1 | const useCreateAddress = async (details) => { |
| 2 | |
| 3 | let url = 'create' |
| 4 | if (details.addressId) url = 'update' |
| 5 | |
| 6 | const response = await fetch(`/api/address/${url}`, { |
| 7 | method: 'POST', |
| 8 | headers: {'Content-Type': 'application/json'}, |
| 9 | body: JSON.stringify({ |
| 10 | addressId: details.addressId, |
| 11 | name: details.name, |
| 12 | address: details.address, |
| 13 | zipcode: details.zipcode, |
| 14 | city: details.city, |
| 15 | country: details.country, |
| 16 | }) |
| 17 | }) |
| 18 | |
| 19 | const data = await response.json(); |
| 20 | |
| 21 | return data |
| 22 | } |
| 23 | |
| 24 | export default useCreateAddress; |