|
| 1 | +<script> |
| 2 | + import { X, Mail, Loader2 } from 'lucide-svelte'; |
| 3 | + import { portalStore } from '../stores/portal.svelte.js'; |
| 4 | + import { portalAuthStore } from '../stores/portalAuth.svelte.js'; |
| 5 | + import { t } from '../stores/i18n.svelte.js'; |
| 6 | +
|
| 7 | + let email = $state(''); |
| 8 | + let authState = $state({}); |
| 9 | +
|
| 10 | + // Subscribe to auth store |
| 11 | + portalAuthStore.subscribe(value => { |
| 12 | + authState = value; |
| 13 | + }); |
| 14 | +
|
| 15 | + function closeModal() { |
| 16 | + portalStore.showLoginDialog = false; |
| 17 | + email = ''; |
| 18 | + portalAuthStore.clearError(); |
| 19 | + portalAuthStore.resetEmailSent(); |
| 20 | + } |
| 21 | +
|
| 22 | + async function handleSubmit(e) { |
| 23 | + e.preventDefault(); |
| 24 | + if (!email.trim()) return; |
| 25 | +
|
| 26 | + const result = await portalAuthStore.requestMagicLink(portalStore.slug, email.trim()); |
| 27 | + if (result.success) { |
| 28 | + // Email sent - the store will update emailSent state |
| 29 | + } |
| 30 | + } |
| 31 | +
|
| 32 | + function handleBackdropClick(e) { |
| 33 | + if (e.target === e.currentTarget) { |
| 34 | + closeModal(); |
| 35 | + } |
| 36 | + } |
| 37 | +
|
| 38 | + function handleKeydown(e) { |
| 39 | + if (e.key === 'Escape') { |
| 40 | + closeModal(); |
| 41 | + } |
| 42 | + } |
| 43 | +</script> |
| 44 | + |
| 45 | +<svelte:window onkeydown={handleKeydown} /> |
| 46 | + |
| 47 | +{#if portalStore.showLoginDialog} |
| 48 | + <!-- Modal Backdrop --> |
| 49 | + <div |
| 50 | + class="fixed inset-0 z-50 flex items-center justify-center bg-black/50 backdrop-blur-sm p-4" |
| 51 | + onclick={handleBackdropClick} |
| 52 | + > |
| 53 | + <!-- Modal Content --> |
| 54 | + <div |
| 55 | + class="relative w-full max-w-md rounded-xl shadow-2xl overflow-hidden" |
| 56 | + style="background-color: var(--ds-surface-card);" |
| 57 | + > |
| 58 | + <!-- Close Button --> |
| 59 | + <button |
| 60 | + onclick={closeModal} |
| 61 | + class="absolute top-4 right-4 p-2 rounded-full transition-colors" |
| 62 | + style="color: var(--ds-text-subtle);" |
| 63 | + aria-label="Close" |
| 64 | + > |
| 65 | + <X class="w-5 h-5" /> |
| 66 | + </button> |
| 67 | + |
| 68 | + <div class="p-8"> |
| 69 | + {#if authState.emailSent} |
| 70 | + <!-- Email Sent Confirmation --> |
| 71 | + <div class="text-center"> |
| 72 | + <div class="w-16 h-16 mx-auto mb-6 rounded-full flex items-center justify-center" style="background-color: var(--ds-background-success-subtle);"> |
| 73 | + <Mail class="w-8 h-8" style="color: var(--ds-icon-success);" /> |
| 74 | + </div> |
| 75 | + <h2 class="text-2xl font-bold mb-3" style="color: var(--ds-text);"> |
| 76 | + {t('portal.checkYourEmail') || 'Check your email'} |
| 77 | + </h2> |
| 78 | + <p class="mb-6" style="color: var(--ds-text-subtle);"> |
| 79 | + {t('portal.magicLinkSent') || "We've sent a sign-in link to your email. Click the link to access your portal account."} |
| 80 | + </p> |
| 81 | + <p class="text-sm mb-6" style="color: var(--ds-text-subtlest);"> |
| 82 | + {t('portal.linkExpiresIn') || 'The link expires in 15 minutes.'} |
| 83 | + </p> |
| 84 | + <button |
| 85 | + onclick={() => { portalAuthStore.resetEmailSent(); email = ''; }} |
| 86 | + class="text-sm font-medium transition-colors" |
| 87 | + style="color: var(--ds-link);" |
| 88 | + > |
| 89 | + {t('portal.useAnotherEmail') || 'Use a different email'} |
| 90 | + </button> |
| 91 | + </div> |
| 92 | + {:else} |
| 93 | + <!-- Login Form --> |
| 94 | + <div class="text-center mb-8"> |
| 95 | + <h2 class="text-2xl font-bold mb-2" style="color: var(--ds-text);"> |
| 96 | + {t('portal.signInTitle') || 'Sign in to your account'} |
| 97 | + </h2> |
| 98 | + <p style="color: var(--ds-text-subtle);"> |
| 99 | + {t('portal.signInDescription') || 'Enter your email to receive a sign-in link'} |
| 100 | + </p> |
| 101 | + </div> |
| 102 | + |
| 103 | + <form onsubmit={handleSubmit} class="space-y-6"> |
| 104 | + <div> |
| 105 | + <label for="email" class="block text-sm font-medium mb-2" style="color: var(--ds-text);"> |
| 106 | + {t('common.email') || 'Email'} |
| 107 | + </label> |
| 108 | + <div class="relative"> |
| 109 | + <Mail class="absolute left-3 top-1/2 -translate-y-1/2 w-5 h-5" style="color: var(--ds-text-subtle);" /> |
| 110 | + <input |
| 111 | + id="email" |
| 112 | + type="email" |
| 113 | + bind:value={email} |
| 114 | + placeholder={t('portal.enterEmail') || 'Enter your email address'} |
| 115 | + required |
| 116 | + class="w-full pl-10 pr-4 py-3 rounded-lg border transition-colors focus:outline-none focus:ring-2" |
| 117 | + style=" |
| 118 | + background-color: var(--ds-background-input); |
| 119 | + border-color: var(--ds-border-input); |
| 120 | + color: var(--ds-text); |
| 121 | + " |
| 122 | + disabled={authState.loading} |
| 123 | + /> |
| 124 | + </div> |
| 125 | + </div> |
| 126 | + |
| 127 | + {#if authState.error} |
| 128 | + <div class="p-3 rounded-lg text-sm" style="background-color: var(--ds-background-danger-subtle); color: var(--ds-text-danger);"> |
| 129 | + {authState.error} |
| 130 | + </div> |
| 131 | + {/if} |
| 132 | + |
| 133 | + <button |
| 134 | + type="submit" |
| 135 | + disabled={authState.loading || !email.trim()} |
| 136 | + class="w-full py-3 px-4 rounded-lg font-medium transition-colors flex items-center justify-center gap-2 disabled:opacity-50 disabled:cursor-not-allowed" |
| 137 | + style="background-color: var(--ds-background-brand-bold); color: var(--ds-text-inverse);" |
| 138 | + > |
| 139 | + {#if authState.loading} |
| 140 | + <Loader2 class="w-5 h-5 animate-spin" /> |
| 141 | + {t('common.sending') || 'Sending...'} |
| 142 | + {:else} |
| 143 | + <Mail class="w-5 h-5" /> |
| 144 | + {t('portal.sendMagicLink') || 'Send sign-in link'} |
| 145 | + {/if} |
| 146 | + </button> |
| 147 | + </form> |
| 148 | + |
| 149 | + <p class="mt-6 text-center text-sm" style="color: var(--ds-text-subtlest);"> |
| 150 | + {t('portal.noAccountNeeded') || "You don't need to create an account. Just enter your email and we'll send you a sign-in link."} |
| 151 | + </p> |
| 152 | + {/if} |
| 153 | + </div> |
| 154 | + </div> |
| 155 | + </div> |
| 156 | +{/if} |
0 commit comments