|
47 | 47 | let toastMessage = ''; |
48 | 48 | let toastType = 'success'; |
49 | 49 |
|
| 50 | + // Confirmation modal state |
| 51 | + let showConfirmModal = false; |
| 52 | +
|
50 | 53 | // Function to get the full name of a lead |
51 | 54 | function getFullName(lead) { |
52 | 55 | return `${lead.firstName} ${lead.lastName}`.trim(); |
|
126 | 129 | showToast = true; |
127 | 130 | } |
128 | 131 | } |
| 132 | +
|
| 133 | + // Function to show confirmation modal |
| 134 | + function showConvertConfirmation() { |
| 135 | + showConfirmModal = true; |
| 136 | + } |
| 137 | +
|
| 138 | + // Function to hide confirmation modal |
| 139 | + function hideConvertConfirmation() { |
| 140 | + showConfirmModal = false; |
| 141 | + } |
| 142 | +
|
| 143 | + // Function to handle confirmed conversion |
| 144 | + function confirmConversion() { |
| 145 | + showConfirmModal = false; |
| 146 | + // Submit the form programmatically |
| 147 | + document.getElementById('convertForm').requestSubmit(); |
| 148 | + } |
129 | 149 | |
130 | 150 | const enhanceConvertForm = () => { |
131 | 151 | isConverting = true; |
|
179 | 199 | } |
180 | 200 | </script> |
181 | 201 |
|
| 202 | +<!-- Confirmation Modal --> |
| 203 | +{#if showConfirmModal} |
| 204 | + <div class="fixed inset-0 z-50 flex items-center justify-center p-4 bg-black bg-opacity-50" transition:fly={{ duration: 200 }}> |
| 205 | + <div class="bg-white dark:bg-gray-800 rounded-2xl border border-gray-200 dark:border-gray-700 shadow-xl max-w-md w-full p-6" transition:fly={{ y: 20, duration: 300 }}> |
| 206 | + <div class="flex items-center gap-4 mb-4"> |
| 207 | + <div class="w-12 h-12 bg-blue-100 dark:bg-blue-900 rounded-xl flex items-center justify-center"> |
| 208 | + <CheckCircle class="w-6 h-6 text-blue-600 dark:text-blue-400" /> |
| 209 | + </div> |
| 210 | + <div> |
| 211 | + <h3 class="text-lg font-bold text-gray-900 dark:text-gray-100">Convert Lead</h3> |
| 212 | + <p class="text-sm text-gray-600 dark:text-gray-400">This action cannot be undone</p> |
| 213 | + </div> |
| 214 | + </div> |
| 215 | + |
| 216 | + <p class="text-sm text-gray-700 dark:text-gray-300 mb-6"> |
| 217 | + Are you sure you want to convert <strong>{getFullName(lead)}</strong> into an account and contact? |
| 218 | + This will create new records and mark the lead as converted. |
| 219 | + </p> |
| 220 | + |
| 221 | + <div class="flex gap-3 justify-end"> |
| 222 | + <button |
| 223 | + onclick={hideConvertConfirmation} |
| 224 | + class="px-4 py-2 text-sm font-medium text-gray-700 dark:text-gray-300 bg-white dark:bg-gray-700 border border-gray-300 dark:border-gray-600 rounded-xl hover:bg-gray-50 dark:hover:bg-gray-600 transition-colors" |
| 225 | + > |
| 226 | + Cancel |
| 227 | + </button> |
| 228 | + <button |
| 229 | + onclick={confirmConversion} |
| 230 | + class="inline-flex items-center gap-2 px-4 py-2 bg-blue-600 dark:bg-blue-700 text-white text-sm font-semibold rounded-xl hover:bg-blue-700 dark:hover:bg-blue-800 transition-colors" |
| 231 | + > |
| 232 | + <CheckCircle class="w-4 h-4" /> |
| 233 | + Yes, Convert Lead |
| 234 | + </button> |
| 235 | + </div> |
| 236 | + </div> |
| 237 | + </div> |
| 238 | +{/if} |
| 239 | +
|
182 | 240 | <!-- Toast --> |
183 | 241 | {#if showToast} |
184 | 242 | <div class="fixed top-4 right-4 z-50 max-w-md" transition:fly={{ y: -20, duration: 300 }}> |
|
311 | 369 | <!-- Action Buttons --> |
312 | 370 | <div class="flex flex-col gap-3"> |
313 | 371 | {#if lead.status !== 'CONVERTED'} |
314 | | - <form method="POST" action="?/convert" use:enhance={enhanceConvertForm}> |
315 | | - <button |
316 | | - type="submit" |
317 | | - disabled={isConverting} |
318 | | - class="inline-flex items-center gap-2 px-6 py-3 bg-gradient-to-r from-blue-600 to-blue-700 dark:from-blue-700 dark:to-blue-800 text-white text-sm font-semibold rounded-xl hover:from-blue-700 hover:to-blue-800 dark:hover:from-blue-800 dark:hover:to-blue-900 disabled:opacity-50 disabled:cursor-not-allowed transition-all shadow-lg hover:shadow-xl" |
319 | | - > |
320 | | - {#if isConverting} |
321 | | - <Loader2 class="w-4 h-4 animate-spin" /> |
322 | | - Converting... |
323 | | - {:else} |
324 | | - <CheckCircle class="w-4 h-4" /> |
325 | | - Convert Lead |
326 | | - {/if} |
327 | | - </button> |
| 372 | + <form id="convertForm" method="POST" action="?/convert" use:enhance={enhanceConvertForm}> |
| 373 | + <!-- Hidden form - will be submitted via JavaScript --> |
328 | 374 | </form> |
| 375 | + <button |
| 376 | + type="button" |
| 377 | + onclick={showConvertConfirmation} |
| 378 | + disabled={isConverting} |
| 379 | + class="inline-flex items-center gap-2 px-6 py-3 bg-gradient-to-r from-blue-600 to-blue-700 dark:from-blue-700 dark:to-blue-800 text-white text-sm font-semibold rounded-xl hover:from-blue-700 hover:to-blue-800 dark:hover:from-blue-800 dark:hover:to-blue-900 disabled:opacity-50 disabled:cursor-not-allowed transition-all shadow-lg hover:shadow-xl" |
| 380 | + > |
| 381 | + {#if isConverting} |
| 382 | + <Loader2 class="w-4 h-4 animate-spin" /> |
| 383 | + Converting... |
| 384 | + {:else} |
| 385 | + <CheckCircle class="w-4 h-4" /> |
| 386 | + Convert Lead |
| 387 | + {/if} |
| 388 | + </button> |
329 | 389 | {/if} |
330 | 390 | <a |
331 | 391 | href="/app/leads/{lead.id}/edit" |
|
0 commit comments