Files
classroomio/apps/dashboard/src/lib/components/Org/VerifyEmail/VerifyEmailModal.svelte
T

90 lines
2.4 KiB
Svelte
Raw Normal View History

2024-03-22 06:30:24 +01:00
<script>
import Modal from '$lib/components/Modal/index.svelte';
import PrimaryButton from '$lib/components/PrimaryButton/index.svelte';
import { snackbar } from '$lib/components/Snackbar/store';
import { profile } from '$lib/utils/store/user';
import {
triggerSendEmail,
NOTIFICATION_NAME
} from '$lib/utils/services/notification/notification';
import { currentOrg } from '$lib/utils/store/org';
2024-04-19 05:45:48 +01:00
import { t } from '$lib/utils/functions/translations';
2024-03-22 06:30:24 +01:00
const WAIT_SEC = 120;
const WAIT_TIME = WAIT_SEC * 1000;
let open = false;
2024-03-22 06:30:24 +01:00
let loading = false;
let isSent = false;
let interval;
let countDown = WAIT_SEC;
2024-11-06 21:28:55 +01:00
const sendVerificationCode = async () => {
if (isSent) return;
2024-03-22 06:30:24 +01:00
loading = true;
try {
triggerSendEmail(NOTIFICATION_NAME.VERIFY_EMAIL, {
to: $profile.email,
profileId: $profile.id,
2024-05-09 09:15:08 +01:00
fullname: $profile.fullname,
2024-03-22 06:30:24 +01:00
orgSiteName: $currentOrg.siteName
});
isSent = true;
} catch (error) {
2024-04-19 05:45:48 +01:00
snackbar.error('verify_email_modal.snackbar.error');
2024-03-22 06:30:24 +01:00
} finally {
loading = false;
}
interval = setInterval(() => {
countDown = countDown - 1;
}, 1000);
setTimeout(() => {
isSent = false;
clearInterval(interval);
}, WAIT_TIME);
};
$: open = Boolean(!$profile.is_email_verified && !!$currentOrg.id);
2024-11-06 21:28:55 +01:00
$: open && sendVerificationCode();
2024-03-22 06:30:24 +01:00
</script>
<Modal {open} isCloseable={false} width="w-4/5" maxWidth="w-[500px]" containerClass="p-4">
2024-03-22 06:30:24 +01:00
<div class="flex flex-col items-center space-y-6 text-center">
<img src="/verify-email.svg" alt="email verification" />
2024-04-19 05:45:48 +01:00
<p class="font-bold text-xl">{$t('verify_email_modal.heading')}</p>
<p class="text-sm w-[70%] text-gray-700 dark:text-gray-200">
2024-04-19 05:45:48 +01:00
{$t('verify_email_modal.sent_verification')}
{$profile.email}
{$t('verify_email_modal.to_confirm')}
2024-03-22 06:30:24 +01:00
</p>
<div class="flex items-center flex-col">
<PrimaryButton
isDisabled={loading || isSent}
className="font-normal"
2024-11-06 21:28:55 +01:00
onClick={sendVerificationCode}
2024-03-22 06:30:24 +01:00
>
{#if loading}
2024-04-19 05:45:48 +01:00
{$t('verify_email_modal.loading')}
2024-03-22 06:30:24 +01:00
{:else}
2024-04-19 05:45:48 +01:00
{$t('verify_email_modal.resend')}
2024-03-22 06:30:24 +01:00
{/if}
</PrimaryButton>
{#if isSent}
2024-04-19 05:45:48 +01:00
<p class="text-xs text-gray-700">
{$t('verify_email_modal.resend_in')}
{countDown}
{$t('verify_email_modal.seconds')}
</p>
2024-03-22 06:30:24 +01:00
{/if}
</div>
</div>
</Modal>