feat: loading state and fixes

This commit is contained in:
Arman committed 2023-04-28 17:26:06 +02:00
1 parent c72fdc1b31
commit b9cb7024af
7 files changed
+66 -27

No files matched your search

@@ -63,6 +63,7 @@
async function openEmail(type: string) {
emailOpen = type;
$emailTemplate = await loadEmailTemplate(projectId, type, 'en-us');
$baseEmailTemplate = { ...$emailTemplate };
}
async function openSms(type: string) {
@@ -1,9 +1,7 @@
import { sdk } from '$lib/stores/sdk';
import type { PageLoad } from './$types';
import type { Models } from '@appwrite.io/console';
export const load: PageLoad = async () => {
const codes: Models.LocaleCodeList = await sdk.forProject.locale.listCodes();
export const load = async () => {
const codes = await sdk.forProject.locale.listCodes();
return {
localeCodes: codes.localeCodes
};
@@ -64,15 +64,18 @@
label="Sender Email"
placeholder="Enter sender email" />
<InputEmail id="replyTo" label="Reply to" placeholder="DoNotReply" />
<li>
<p class="text">
Click to copy the variables you can use in the fields below. For more information,
<button class="link" on:click={() => (openVariablesDescription = true)}>
click here
</button>.
</p>
</li>
{#if $$slots.default}
<li>
<p class="text">
Click to copy the variables you can use in the fields below. For more
information,
<a class="link" href="#">click here</a>.
</p>
<div class="common-section u-flex u-gap-24">
<slot />
</div>
</li>
{/if}
<InputText
bind:value={$emailTemplate.subject}
id="subject"
@@ -5,19 +5,40 @@
import { loadEmailTemplate } from './+page.svelte';
import { emailTemplate } from './strote';
import { page } from '$app/stores';
import { Id } from '$lib/components';
export let localeCodes: Models.LocaleCode[];
const projectId = $page.params.project;
let locale = 'en-us';
let loading = false;
async function onLocaleChange() {
let template = await loadEmailTemplate(projectId, 'verification', locale);
emailTemplate.set(template);
loading = true;
try {
const template = await loadEmailTemplate(projectId, 'verification', locale);
emailTemplate.set(template);
} catch (error) {
console.log(error);
} finally {
loading = false;
}
}
</script>
<div class="box common-section">
<LocaleOptions {localeCodes} on:select={onLocaleChange} bind:value={locale} />
<EmailTemplate />
{#if loading}
<div
class="u-width-full-100 u-flex u-flex-vertical u-main-center u-cross-center u-gap-16 u-margin-block-start-32">
<div class="loader" />
<p class="text">Loading template...</p>
</div>
{/if}
<div class:u-opacity-0={loading} style={loading ? 'pointer-events: none' : ''}>
<EmailTemplate>
<Id value={'{{name}}'}>{'{{name}}'}</Id>
<Id value={'{{project}}'}>{'{{project}}'}</Id>
</EmailTemplate>
</div>
</div>
@@ -7,12 +7,14 @@
let search: string = 'English';
$: options = localeCodes
.map((code) => ({
label: code.name,
value: code.code
}))
.filter((option) => option.label?.toLowerCase().startsWith(search?.toLowerCase()));
$: options =
localeCodes
?.map((code) => ({
label: code.name,
value: code.code
}))
?.filter((option) => option.label?.toLowerCase().startsWith(search?.toLowerCase())) ??
[];
</script>
<div class="u-flex u-main-space-between">
@@ -5,7 +5,7 @@ export const emailTemplate = writable<Models.EmailTemplate>({
type: null,
locale: null,
message: null,
senderName: null,
senderName: '',
senderEmail: null,
replyTo: null,
subject: null
@@ -1,6 +1,13 @@
<script lang="ts">
import { CardGrid, Heading } from '$lib/components';
import { Button, Form, FormList, InputText, InputSwitch } from '$lib/elements/forms';
import {
Button,
Form,
FormList,
InputText,
InputSwitch,
InputChoice
} from '$lib/elements/forms';
import { Container } from '$lib/layout';
import { project } from '../../store';
import { onMount } from 'svelte/internal';
@@ -76,11 +83,14 @@
</p>
<svelte:fragment slot="aside">
<FormList>
<InputSwitch id="enabled" bind:value={enabled} label="Custom SMTP Server" />
<p class="text">
<InputChoice
type="switchbox"
id="enabled"
bind:value={enabled}
label="Custom SMTP Server">
Enabling this option allows customizing email templates and prevents emails
from being labeled as spam.
</p>
</InputChoice>
{#if enabled}
<InputText
@@ -114,6 +124,10 @@
bind:value={password}
required
placeholder="Enter password" />
<InputChoice id="tls" label="TLS Secure Protocol">
Enable if TLS is supported on your SMTP server.
</InputChoice>
{/if}
</FormList>
</svelte:fragment>