Skip to content

Commit f9f5192

Browse files
committed
feat: add confirmation modal for lead conversion with handling functions
1 parent f832a10 commit f9f5192

File tree

1 file changed

+74
-14
lines changed

1 file changed

+74
-14
lines changed

src/routes/(app)/app/leads/[lead_id]/+page.svelte

Lines changed: 74 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@
4747
let toastMessage = '';
4848
let toastType = 'success';
4949
50+
// Confirmation modal state
51+
let showConfirmModal = false;
52+
5053
// Function to get the full name of a lead
5154
function getFullName(lead) {
5255
return `${lead.firstName} ${lead.lastName}`.trim();
@@ -126,6 +129,23 @@
126129
showToast = true;
127130
}
128131
}
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+
}
129149
130150
const enhanceConvertForm = () => {
131151
isConverting = true;
@@ -179,6 +199,44 @@
179199
}
180200
</script>
181201
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+
182240
<!-- Toast -->
183241
{#if showToast}
184242
<div class="fixed top-4 right-4 z-50 max-w-md" transition:fly={{ y: -20, duration: 300 }}>
@@ -311,21 +369,23 @@
311369
<!-- Action Buttons -->
312370
<div class="flex flex-col gap-3">
313371
{#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 -->
328374
</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>
329389
{/if}
330390
<a
331391
href="/app/leads/{lead.id}/edit"

0 commit comments

Comments
 (0)