|
| 1 | +<script lang="ts"> |
| 2 | + import { base } from '$app/paths'; |
| 3 | + import { goto } from '$app/navigation'; |
| 4 | + import { Button } from '$lib/elements/forms'; |
| 5 | + import { HeaderAlert } from '$lib/layout'; |
| 6 | + import { Typography } from '@appwrite.io/pink-svelte'; |
| 7 | + import { hideNotification, shouldShowNotification } from '$lib/helpers/notifications'; |
| 8 | + import { user } from '$lib/stores/user'; |
| 9 | + import { wizard } from '$lib/stores/wizard'; |
| 10 | + import { page } from '$app/state'; |
| 11 | +
|
| 12 | + const { emailBannerClosed, onEmailBannerClose } = $props<{ |
| 13 | + emailBannerClosed: boolean; |
| 14 | + onEmailBannerClose: (closed: boolean) => void; |
| 15 | + }>(); |
| 16 | +
|
| 17 | + const isOnOnboarding = $derived(() => page.route?.id?.includes('/(console)/onboarding')); |
| 18 | +
|
| 19 | + const hasUser = $derived(!!$user); |
| 20 | + const needsEmailVerification = $derived(hasUser && !$user.emailVerification); |
| 21 | + const shouldShowNotificationBanner = $derived.by(() => |
| 22 | + shouldShowNotification('email-verification-banner') |
| 23 | + ); |
| 24 | + const wizardNotActive = $derived(!$wizard.show && !$wizard.cover); |
| 25 | + const bannerNotClosed = $derived(!emailBannerClosed); |
| 26 | + const notOnOnboarding = $derived(!isOnOnboarding); |
| 27 | +
|
| 28 | + const shouldShowEmailBanner = $derived( |
| 29 | + hasUser && |
| 30 | + needsEmailVerification && |
| 31 | + shouldShowNotificationBanner && |
| 32 | + wizardNotActive && |
| 33 | + bannerNotClosed && |
| 34 | + notOnOnboarding |
| 35 | + ); |
| 36 | +
|
| 37 | + function navigateToAccount() { |
| 38 | + goto(`${base}/account`); |
| 39 | + } |
| 40 | +
|
| 41 | + function handleDismiss() { |
| 42 | + onEmailBannerClose(true); |
| 43 | + hideNotification('email-verification-banner', { coolOffPeriod: 24 * 365 * 100 }); |
| 44 | + } |
| 45 | +</script> |
| 46 | + |
| 47 | +{#if shouldShowEmailBanner} |
| 48 | + <HeaderAlert |
| 49 | + type="warning" |
| 50 | + title="Your email address needs to be verified" |
| 51 | + dismissible |
| 52 | + on:dismiss={handleDismiss}> |
| 53 | + <svelte:fragment> |
| 54 | + To avoid losing access to your projects, make sure <Typography.Text |
| 55 | + variant="m-500" |
| 56 | + style="display:inline">{$user.email}</Typography.Text> is valid and up to date. Email |
| 57 | + verification will be required soon. |
| 58 | + </svelte:fragment> |
| 59 | + <svelte:fragment slot="buttons"> |
| 60 | + <Button secondary size="s" on:click={navigateToAccount}>Update email address</Button> |
| 61 | + </svelte:fragment> |
| 62 | + </HeaderAlert> |
| 63 | +{/if} |
0 commit comments