|
3 | 3 | import {contactDetail} from "$lib/api/ContactApi.js";
|
4 | 4 | import {alertError} from "$lib/alert.js";
|
5 | 5 | import {onMount} from "svelte";
|
| 6 | + import {addressList} from "$lib/api/AddressApi.js"; |
6 | 7 |
|
7 | 8 | const token = localStorage.getItem('token');
|
8 | 9 | const {id} = page.params;
|
|
15 | 16 | phone: ''
|
16 | 17 | })
|
17 | 18 |
|
| 19 | + let addresses = $state([]); |
| 20 | +
|
| 21 | + async function fetchAddresses() { |
| 22 | + const response = await addressList(token, id); |
| 23 | + const responseBody = await response.json(); |
| 24 | + console.log(responseBody); |
| 25 | +
|
| 26 | + if (response.status === 200) { |
| 27 | + addresses = responseBody.data; |
| 28 | + } else { |
| 29 | + await alertError(responseBody.errors); |
| 30 | + } |
| 31 | + } |
| 32 | +
|
18 | 33 | async function fetchContact() {
|
19 | 34 | const response = await contactDetail(token, id);
|
20 | 35 | const responseBody = await response.json();
|
|
29 | 44 |
|
30 | 45 | onMount(async () => {
|
31 | 46 | await fetchContact();
|
| 47 | + await fetchAddresses(); |
32 | 48 | })
|
33 | 49 | </script>
|
34 | 50 |
|
|
108 | 124 | </a>
|
109 | 125 | </div>
|
110 | 126 |
|
111 |
| - <!-- Address Card 1 --> |
112 |
| - <div class="bg-gray-700 bg-opacity-50 p-5 rounded-lg shadow-md border border-gray-600 card-hover"> |
113 |
| - <div class="flex items-center mb-3"> |
114 |
| - <div class="w-10 h-10 bg-blue-500 rounded-full flex items-center justify-center mr-3 shadow-md"> |
115 |
| - <i class="fas fa-home text-white"></i> |
| 127 | + {#each addresses as address (address.id)} |
| 128 | + <div class="bg-gray-700 bg-opacity-50 p-5 rounded-lg shadow-md border border-gray-600 card-hover"> |
| 129 | + <div class="flex items-center mb-3"> |
| 130 | + <div class="w-10 h-10 bg-blue-500 rounded-full flex items-center justify-center mr-3 shadow-md"> |
| 131 | + <i class="fas fa-home text-white"></i> |
| 132 | + </div> |
| 133 | + <h4 class="text-lg font-semibold text-white">Address</h4> |
116 | 134 | </div>
|
117 |
| - <h4 class="text-lg font-semibold text-white">Home Address</h4> |
118 |
| - </div> |
119 |
| - <div class="space-y-3 text-gray-300 ml-2 mb-4"> |
120 |
| - <p class="flex items-center"> |
121 |
| - <i class="fas fa-road text-gray-500 w-6"></i> |
122 |
| - <span class="font-medium w-24">Street:</span> |
123 |
| - <span>123 Main St</span> |
124 |
| - </p> |
125 |
| - <p class="flex items-center"> |
126 |
| - <i class="fas fa-city text-gray-500 w-6"></i> |
127 |
| - <span class="font-medium w-24">City:</span> |
128 |
| - <span>New York</span> |
129 |
| - </p> |
130 |
| - <p class="flex items-center"> |
131 |
| - <i class="fas fa-map text-gray-500 w-6"></i> |
132 |
| - <span class="font-medium w-24">Province:</span> |
133 |
| - <span>NY</span> |
134 |
| - </p> |
135 |
| - <p class="flex items-center"> |
136 |
| - <i class="fas fa-flag text-gray-500 w-6"></i> |
137 |
| - <span class="font-medium w-24">Country:</span> |
138 |
| - <span>USA</span> |
139 |
| - </p> |
140 |
| - <p class="flex items-center"> |
141 |
| - <i class="fas fa-mailbox text-gray-500 w-6"></i> |
142 |
| - <span class="font-medium w-24">Postal Code:</span> |
143 |
| - <span>10001</span> |
144 |
| - </p> |
145 |
| - </div> |
146 |
| - <div class="flex justify-end space-x-3"> |
147 |
| - <a href="edit_address.html" |
148 |
| - class="px-4 py-2 bg-gradient text-white rounded-lg hover:opacity-90 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2 focus:ring-offset-gray-800 transition-all duration-200 font-medium shadow-md flex items-center"> |
149 |
| - <i class="fas fa-edit mr-2"></i> Edit |
150 |
| - </a> |
151 |
| - <button class="px-4 py-2 bg-gradient-to-r from-red-600 to-red-500 text-white rounded-lg hover:opacity-90 focus:outline-none focus:ring-2 focus:ring-red-500 focus:ring-offset-2 focus:ring-offset-gray-800 transition-all duration-200 font-medium shadow-md flex items-center"> |
152 |
| - <i class="fas fa-trash-alt mr-2"></i> Delete |
153 |
| - </button> |
154 |
| - </div> |
155 |
| - </div> |
156 |
| - |
157 |
| - <!-- Address Card 2 --> |
158 |
| - <div class="bg-gray-700 bg-opacity-50 p-5 rounded-lg shadow-md border border-gray-600 card-hover"> |
159 |
| - <div class="flex items-center mb-3"> |
160 |
| - <div class="w-10 h-10 bg-purple-500 rounded-full flex items-center justify-center mr-3 shadow-md"> |
161 |
| - <i class="fas fa-building text-white"></i> |
| 135 | + <div class="space-y-3 text-gray-300 ml-2 mb-4"> |
| 136 | + <p class="flex items-center"> |
| 137 | + <i class="fas fa-road text-gray-500 w-6"></i> |
| 138 | + <span class="font-medium w-24">Street:</span> |
| 139 | + <span>{address.street}</span> |
| 140 | + </p> |
| 141 | + <p class="flex items-center"> |
| 142 | + <i class="fas fa-city text-gray-500 w-6"></i> |
| 143 | + <span class="font-medium w-24">City:</span> |
| 144 | + <span>{address.city}</span> |
| 145 | + </p> |
| 146 | + <p class="flex items-center"> |
| 147 | + <i class="fas fa-map text-gray-500 w-6"></i> |
| 148 | + <span class="font-medium w-24">Province:</span> |
| 149 | + <span>{address.province}</span> |
| 150 | + </p> |
| 151 | + <p class="flex items-center"> |
| 152 | + <i class="fas fa-flag text-gray-500 w-6"></i> |
| 153 | + <span class="font-medium w-24">Country:</span> |
| 154 | + <span>{address.country}</span> |
| 155 | + </p> |
| 156 | + <p class="flex items-center"> |
| 157 | + <i class="fas fa-mailbox text-gray-500 w-6"></i> |
| 158 | + <span class="font-medium w-24">Postal Code:</span> |
| 159 | + <span>{address.postal_code}</span> |
| 160 | + </p> |
| 161 | + </div> |
| 162 | + <div class="flex justify-end space-x-3"> |
| 163 | + <a href="/dashboard/contacts/{contact.id}/addresses/{address.id}/edit" |
| 164 | + class="px-4 py-2 bg-gradient text-white rounded-lg hover:opacity-90 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2 focus:ring-offset-gray-800 transition-all duration-200 font-medium shadow-md flex items-center"> |
| 165 | + <i class="fas fa-edit mr-2"></i> Edit |
| 166 | + </a> |
| 167 | + <button class="px-4 py-2 bg-gradient-to-r from-red-600 to-red-500 text-white rounded-lg hover:opacity-90 focus:outline-none focus:ring-2 focus:ring-red-500 focus:ring-offset-2 focus:ring-offset-gray-800 transition-all duration-200 font-medium shadow-md flex items-center"> |
| 168 | + <i class="fas fa-trash-alt mr-2"></i> Delete |
| 169 | + </button> |
162 | 170 | </div>
|
163 |
| - <h4 class="text-lg font-semibold text-white">Work Address</h4> |
164 |
| - </div> |
165 |
| - <div class="space-y-3 text-gray-300 ml-2 mb-4"> |
166 |
| - <p class="flex items-center"> |
167 |
| - <i class="fas fa-road text-gray-500 w-6"></i> |
168 |
| - <span class="font-medium w-24">Street:</span> |
169 |
| - <span>456 Oak Ave</span> |
170 |
| - </p> |
171 |
| - <p class="flex items-center"> |
172 |
| - <i class="fas fa-city text-gray-500 w-6"></i> |
173 |
| - <span class="font-medium w-24">City:</span> |
174 |
| - <span>San Francisco</span> |
175 |
| - </p> |
176 |
| - <p class="flex items-center"> |
177 |
| - <i class="fas fa-map text-gray-500 w-6"></i> |
178 |
| - <span class="font-medium w-24">Province:</span> |
179 |
| - <span>CA</span> |
180 |
| - </p> |
181 |
| - <p class="flex items-center"> |
182 |
| - <i class="fas fa-flag text-gray-500 w-6"></i> |
183 |
| - <span class="font-medium w-24">Country:</span> |
184 |
| - <span>USA</span> |
185 |
| - </p> |
186 |
| - <p class="flex items-center"> |
187 |
| - <i class="fas fa-mailbox text-gray-500 w-6"></i> |
188 |
| - <span class="font-medium w-24">Postal Code:</span> |
189 |
| - <span>94102</span> |
190 |
| - </p> |
191 |
| - </div> |
192 |
| - <div class="flex justify-end space-x-3"> |
193 |
| - <a href="edit_address.html" |
194 |
| - class="px-4 py-2 bg-gradient text-white rounded-lg hover:opacity-90 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2 focus:ring-offset-gray-800 transition-all duration-200 font-medium shadow-md flex items-center"> |
195 |
| - <i class="fas fa-edit mr-2"></i> Edit |
196 |
| - </a> |
197 |
| - <button class="px-4 py-2 bg-gradient-to-r from-red-600 to-red-500 text-white rounded-lg hover:opacity-90 focus:outline-none focus:ring-2 focus:ring-red-500 focus:ring-offset-2 focus:ring-offset-gray-800 transition-all duration-200 font-medium shadow-md flex items-center"> |
198 |
| - <i class="fas fa-trash-alt mr-2"></i> Delete |
199 |
| - </button> |
200 | 171 | </div>
|
201 |
| - </div> |
| 172 | + {/each} |
| 173 | + |
202 | 174 | </div>
|
203 | 175 | </div>
|
204 | 176 |
|
|
0 commit comments