design review: funciton review

This commit is contained in:
Arman committed 2025-03-11 11:47:16 +01:00
1 parent 72a36494b5
commit 682ac55ae4
12 files changed
+976 -10

No files matched your search

@@ -1,14 +1,198 @@
<script lang="ts">
import { Container } from '$lib/layout';
import type { PageData } from './$types';
import { ProxyRulesPage } from '$lib/pages/domains';
import { Dependencies } from '$lib/constants';
import { base } from '$app/paths';
import { page } from '$app/stores';
import { EmptySearch, PaginationWithLimit } from '$lib/components/index.js';
import { Button } from '$lib/elements/forms';
import Link from '$lib/elements/link.svelte';
import Container from '$lib/layout/container.svelte';
import { protocol } from '$routes/(console)/store.js';
import type { Models } from '@appwrite.io/console';
import {
IconDotsHorizontal,
IconExternalLink,
IconPlus,
IconRefresh,
IconTrash
} from '@appwrite.io/pink-icons-svelte';
import {
ActionMenu,
Card,
Empty,
Icon,
Layout,
Popover,
Table
} from '@appwrite.io/pink-svelte';
import DeleteDomainModal from './deleteDomainModal.svelte';
import RetryDomainModal from './retryDomainModal.svelte';
import SearchQuery from '$lib/components/searchQuery.svelte';
import { app } from '$lib/stores/app';
import { Click, trackEvent } from '$lib/actions/analytics';
import CreateAppwriteDomainModal from './createAppwriteDomainModal.svelte';
export let data: PageData;
export let data;
let showDelete = false;
let showRetry = false;
let selectedDomain: Models.ProxyRule = null;
let showAppwriteDomainModal = false;
</script>
<Container>
<ProxyRulesPage rules={data.rules} dependency={Dependencies.FUNCTION_DOMAINS}>
<svelte:fragment slot="heading">Domains</svelte:fragment>
</ProxyRulesPage>
<Layout.Stack direction="row" justifyContent="space-between">
<SearchQuery search={data.search} placeholder="Search domain" />
<Popover padding="none" let:toggle placement="bottom-end">
<Button
on:click={(event) => {
toggle(event);
trackEvent(Click.DomainCreateClick, {
source: 'functions_domain_overview'
});
}}>
<Icon icon={IconPlus} size="s" />
Add domain
</Button>
<svelte:fragment slot="tooltip">
<ActionMenu.Root>
<ActionMenu.Item.Anchor
href={`${base}/project-${$page.params.project}/functions/function-${$page.params.function}/domains/add-domain`}>
Custom domain
</ActionMenu.Item.Anchor>
<ActionMenu.Item.Button on:click={() => (showAppwriteDomainModal = true)}>
Appwrite domain
</ActionMenu.Item.Button>
</ActionMenu.Root>
</svelte:fragment>
</Popover>
</Layout.Stack>
{#if data.domains.total}
<Table.Root>
<svelte:fragment slot="header">
<Table.Header.Cell width="200px">Domain</Table.Header.Cell>
<Table.Header.Cell>Redirect to</Table.Header.Cell>
<Table.Header.Cell>Production branch</Table.Header.Cell>
<Table.Header.Cell />
</svelte:fragment>
{#each data.domains.rules as domain}
<Table.Row>
<Table.Cell>
<Link external href={`${$protocol}${domain.domain}`} variant="quiet">
<Layout.Stack direction="row" alignItems="center" gap="xs">
{domain.domain}
<Icon icon={IconExternalLink} size="s" />
</Layout.Stack>
</Link>
</Table.Cell>
<Table.Cell>
{domain?.redirectUrl || 'No redirect'}
{domain?.redirectStatusCode ? `(${domain.redirectStatusCode})` : ''}
</Table.Cell>
<Table.Cell>
{domain.deploymentVcsProviderBranch || '-'}
</Table.Cell>
<Table.Cell>
<Layout.Stack direction="row" justifyContent="flex-end">
<Popover let:toggle placement="bottom-start" padding="none">
<Button
text
icon
on:click={(e) => {
e.preventDefault();
toggle(e);
}}>
<Icon icon={IconDotsHorizontal} size="s" />
</Button>
<svelte:fragment slot="tooltip" let:toggle>
<ActionMenu.Root>
{#if domain.status !== 'verified'}
<ActionMenu.Item.Button
leadingIcon={IconRefresh}
on:click={(e) => {
e.preventDefault();
selectedDomain = domain;
showRetry = true;
toggle(e);
}}>
Retry
</ActionMenu.Item.Button>
{/if}
<ActionMenu.Item.Button
status="danger"
leadingIcon={IconTrash}
on:click={(e) => {
e.preventDefault();
selectedDomain = domain;
showDelete = true;
toggle(e);
trackEvent(Click.DomainDeleteClick, {
source: 'functions_domain_overview'
});
}}>
Delete
</ActionMenu.Item.Button>
</ActionMenu.Root>
</svelte:fragment>
</Popover>
</Layout.Stack>
</Table.Cell>
</Table.Row>
{/each}
</Table.Root>
<PaginationWithLimit
name="Domains"
limit={data.limit}
offset={data.offset}
total={data.domains.total} />
{:else if data?.search}
<EmptySearch hidePages bind:search={data.search} target="domains" hidePagination>
<svelte:fragment slot="actions">
<Button
secondary
on:click={() => {
data.search = '';
}}>Clear search</Button>
</svelte:fragment>
</EmptySearch>
{:else}
<Card.Base padding="none">
<Empty
src={$app.themeInUse === 'dark'
? `${base}/images/domains/empty-domain-dark.svg`
: `${base}/images/domains/empty-domain-light.svg`}
title="Use a custom domain for your function"
description="Make your function easier to access and integrate by assigning it a custom domain.">
<svelte:fragment slot="actions">
<Button
external
href="#/"
text
event="empty_documentation"
size="s"
ariaLabel="add domain">Documentation</Button>
<Button
secondary
href={`${base}/project-${$page.params.project}/functions/function-${$page.params.function}/domains/add-domain`}
size="s">
Add domain
</Button>
</svelte:fragment>
</Empty>
</Card.Base>
{/if}
</Container>
{#if showDelete}
<DeleteDomainModal bind:show={showDelete} {selectedDomain} />
{/if}
{#if showRetry}
<RetryDomainModal bind:show={showRetry} {selectedDomain} />
{/if}
{#if showAppwriteDomainModal}
<CreateAppwriteDomainModal bind:show={showAppwriteDomainModal} />
{/if}
@@ -22,7 +22,11 @@ export const load: PageLoad = async ({ depends, params, url, route }) => {
queries.set(parsedQueries);
return {
rules: await sdk.forProject.proxy.listRules(
offset,
limit,
query,
search,
domains: await sdk.forProject.proxy.listRules(
[
Query.equal('type', [RuleType.DEPLOYMENT, RuleType.REDIRECT]),
Query.equal('deploymentResourceType', DeploymentResourceType.FUNCTION),
@@ -0,0 +1,296 @@
<script lang="ts">
import { base } from '$app/paths';
import { page } from '$app/stores';
import { Button, Form, InputSelect } from '$lib/elements/forms';
import { Wizard } from '$lib/layout';
import { addNotification } from '$lib/stores/notifications';
import { sdk } from '$lib/stores/sdk';
import { Fieldset, Layout, Tooltip, Icon, Alert } from '@appwrite.io/pink-svelte';
import { goto, invalidate } from '$app/navigation';
import { Dependencies } from '$lib/constants';
import { sortBranches } from '$lib/stores/vcs';
import { organization } from '$lib/stores/organization';
import { consoleVariables } from '$routes/(console)/store';
import InputDomain from '$lib/elements/forms/inputDomain.svelte';
import { IconInfo } from '@appwrite.io/pink-icons-svelte';
import { LabelCard } from '$lib/components';
import { writable } from 'svelte/store';
import { isCloud } from '$lib/system';
import { onMount } from 'svelte';
import { StatusCode } from '@appwrite.io/console';
import ConnectRepoModal from '../../(modals)/connectRepoModal.svelte';
const backPage = `${base}/project-${$page.params.project}/functions/function-${$page.params.function}/domains`;
export let data;
let formComponent: Form;
let isSubmitting = writable(false);
let showConnectRepo = false;
let behaviour: 'REDIRECT' | 'CREATE' = 'CREATE';
let domain = '';
let redirect: string = null;
let statusCode: number = null;
let branch = null;
const redirectOptions = data.domains.rules
.filter((d) => !d.domain.endsWith($consoleVariables._APP_DOMAIN_TARGET))
.map((domain) => ({
label: domain.domain,
value: domain.domain
}));
const statusCodeOptions = [
{
label: '301 Moved permanently',
value: 301
},
{
label: '302 Found',
value: 302
},
{
label: '303 See other',
value: 303
},
{
label: '307 Temporary redirect',
value: 307
},
{
label: '308 Permanent redirect',
value: 308
}
];
onMount(() => {
if (
$page.url.searchParams.has('connectRepo') &&
$page.url.searchParams.get('connectRepo') === 'true'
) {
showConnectRepo = true;
}
});
async function addDomain() {
const isAppwriteDomain = domain.endsWith($consoleVariables._APP_DOMAIN_TARGET);
const isNewDomain = data.domains.rules.findIndex((rule) => rule.domain === domain) === -1;
const isSubDomain = domain.split('.').length >= 2;
try {
if (behaviour === 'CREATE') {
if (isCloud && !isAppwriteDomain) {
//Redirect if subdomain so user can choose how to proceed
if (isSubDomain) {
goto(
`${base}/project-${$page.params.project}/functions/function-${$page.params.function}/domains/add-domain/verify?domain=${domain}`
);
}
//Create domain if it's a new domain
else if (isNewDomain) {
const domainData = await sdk.forConsole.domains.create(
$organization.$id,
domain
);
await sdk.forProject.proxy.createFunctionRule(
domain,
$page.params.function,
branch
);
goto(
`${base}/project-${$page.params.project}/functions/function-${$page.params.function}/domains/add-domain/verify-${domainData.$id}}`
);
}
}
//if selfhosted or appwrite domain create function rule
else {
await sdk.forProject.proxy.createFunctionRule(
domain,
$page.params.function,
branch
);
addNotification({
type: 'success',
message: 'Domain added successfully'
});
await goto(backPage);
await invalidate(Dependencies.FUNCTION_DOMAINS);
}
} else if (behaviour === 'REDIRECT') {
if (isCloud && !isAppwriteDomain) {
//Redirect if subdomain so user can choose how to proceed
if (isSubDomain) {
goto(
`${base}/project-${$page.params.project}/functions/function-${$page.params.function}/domains/add-domain/verify?domain=${domain}?redirect=${redirect}?statusCode=${statusCode}`
);
}
//Create domain if it's a new domain
else if (isNewDomain) {
const domainData = await sdk.forConsole.domains.create(
$organization.$id,
domain
);
const sc = Object.values(StatusCode).find(
(code) => parseInt(code) === statusCode
);
await sdk.forProject.proxy.createRedirectRule(domain, redirect, sc);
goto(
`${base}/project-${$page.params.project}/functions/function-${$page.params.function}/domains/add-domain/verify-${domainData.$id}}`
);
}
}
}
} catch (error) {
addNotification({
type: 'error',
message: error.message
});
}
}
</script>
<Wizard title="Add custom domain" href={backPage} column columnSize="s">
<Form bind:this={formComponent} onSubmit={addDomain} bind:isSubmitting>
<Layout.Stack gap="xxl">
<Fieldset legend="Details">
<!-- <Input.ComboBox
label="Domain"
id="domain"
name="domain"
bind:value={domain}
options={data.domains.rules.map((domain) => ({
label: domain.domain,
value: domain.domain
}))}
required
placeholder="appwrite.example.com" /> -->
<InputDomain
label="Domain"
id="domain"
bind:value={domain}
required
placeholder="appwrite.example.com" />
</Fieldset>
<Layout.Grid columns={2} columnsXS={1}>
<LabelCard
value="CREATE"
bind:group={behaviour}
title="Connect to active deployment">
Connect this domain to your active deployment and configure the linked Git
branch as needed.
</LabelCard>
<LabelCard
value="REDIRECT"
bind:group={behaviour}
title="Redirect to another domain">
Automatically forward traffic from this domain to another URL of your choice.
</LabelCard>
</Layout.Grid>
{#if behaviour === 'CREATE'}
<Fieldset legend="Configuration">
<Layout.Stack gap="xl">
{#if data.branches?.total}
{@const sortedBranches = sortBranches(data.branches.branches)}
{@const options = sortedBranches.map((branch) => ({
label: branch.name,
value: branch.name
}))}
<InputSelect
{options}
label="Production branch"
id="branch"
required
bind:value={branch}
placeholder="Select branch" />
{:else}
<InputSelect
disabled
options={[{ label: 'main', value: 'main' }]}
label="Production branch"
id="branch"
required
value="main"
placeholder="Select branch" />
<Alert.Inline
title=" There is no repository connected to your function">
<Layout.Stack>
<p>
The domain will be connected to your active deployment.
Connect your Git repository to link a production branch.
</p>
<div>
<Button compact on:click={() => (showConnectRepo = true)}>
Connect repository
</Button>
</div>
</Layout.Stack>
</Alert.Inline>
{/if}
</Layout.Stack>
</Fieldset>
<!-- {:else if data.function.installationId || data.installations?.total}
<PinkCard.Base padding="none" border="dashed">
<Empty
type="secondary"
title="Connect Git repository"
description="Link a repository to associate your domain with an active deployment.">
<svelte:fragment slot="actions">
<Button secondary on:click={() => (showConnectRepo = true)}>
<Icon icon={IconGithub} size="s" slot="start" />
Connect Git repository
</Button>
</svelte:fragment>
</Empty>
</PinkCard.Base>
{:else}
<ConnectGit callbackState={{ newInstallation: 'true' }} />
{/if} -->
{:else if behaviour === 'REDIRECT'}
<Fieldset legend="Configuration">
<Layout.Stack gap="xl">
<InputSelect
label="Redirect to"
id="redirect"
placeholder="Select domain"
options={redirectOptions}
bind:value={redirect}
required>
<Tooltip slot="info">
<Icon icon={IconInfo} size="s" />
<span slot="tooltip">
Redirect this domain. Domains added to your project will be
listed here.
</span>
</Tooltip>
</InputSelect>
<InputSelect
options={statusCodeOptions}
label="Status code"
id="code"
required
bind:value={statusCode}
placeholder="Select status code" />
</Layout.Stack>
</Fieldset>
{/if}
</Layout.Stack>
</Form>
<svelte:fragment slot="footer">
<Button secondary href={backPage}>Cancel</Button>
<Button on:click={() => formComponent.triggerSubmit()} bind:disabled={$isSubmitting}>
Add
</Button>
</svelte:fragment>
</Wizard>
{#if showConnectRepo}
<ConnectRepoModal
bind:show={showConnectRepo}
func={data.function}
callbackState={{ connectRepo: 'true' }} />
{/if}
@@ -0,0 +1,28 @@
import { Query } from '@appwrite.io/console';
import { sdk } from '$lib/stores/sdk';
import { RuleTrigger, RuleType } from '$lib/stores/sdk';
export const load = async ({ parent }) => {
const { site } = await parent();
const [domains, installations] = await Promise.all([
sdk.forProject.proxy.listRules([
Query.equal('type', RuleType.DEPLOYMENT),
Query.equal('trigger', RuleTrigger.MANUAL)
]),
sdk.forProject.vcs.listInstallations()
]);
return {
site,
domains,
installations,
branches:
site?.installationId && site?.providerRepositoryId
? await sdk.forProject.vcs.listRepositoryBranches(
site.installationId,
site.providerRepositoryId
)
: undefined
};
};
@@ -0,0 +1,182 @@
<script lang="ts">
import {
Badge,
Divider,
Fieldset,
Icon,
InteractiveText,
Layout,
Table,
Tabs,
Typography
} from '@appwrite.io/pink-svelte';
import { Card } from '$lib/components';
import { Button } from '$lib/elements/forms';
import { Wizard } from '$lib/layout';
import { addNotification } from '$lib/stores/notifications';
import { sdk } from '$lib/stores/sdk';
import { base } from '$app/paths';
import { page } from '$app/stores';
import { IconInfo } from '@appwrite.io/pink-icons-svelte';
import { Link } from '$lib/elements';
import { consoleVariables } from '$routes/(console)/store';
const backPage = `${base}/project-${$page.params.project}/sites/site-${$page.params.site}/domains`;
let nameservers = $consoleVariables?._APP_DOMAINS_NAMESERVERS
? $consoleVariables?._APP_DOMAINS_NAMESERVERS.split(',')
: ['ns1.appwrite.io', 'ns2.appwrite.io'];
export let data;
async function verifyStatus() {
try {
await sdk.forProject.proxy.updateRuleVerification(data.domain.$id);
console.log(data.domain);
} catch (error) {
addNotification({
type: 'error',
message: error.message
});
}
}
let selectedTab: 'cname' | 'nameserver' = 'cname';
$: isVerified = data.domain?.nameservers?.toLocaleLowerCase() === 'appwrite';
</script>
<Wizard title="Add custom domain" href={backPage} column columnSize="s" hideFooter>
{#if isVerified}
<Card radius="s">
<Layout.Stack gap="s" direction="row" alignItems="center">
<Typography.Text variant="l-500">{data.domain.domain}</Typography.Text>
<Badge variant="secondary" type="success" content="Verified" />
</Layout.Stack>
</Card>
{:else}
<Fieldset legend="Verification">
<Layout.Stack gap="xl">
<div>
<Tabs.Root variant="secondary" let:root>
<Tabs.Item.Button
{root}
on:click={() => (selectedTab = 'cname')}
active={selectedTab === 'cname'}>
CNAME
</Tabs.Item.Button>
<Tabs.Item.Button
{root}
on:click={() => (selectedTab = 'nameserver')}
active={selectedTab === 'nameserver'}>
Nameservers
</Tabs.Item.Button>
</Tabs.Root>
<Divider />
</div>
{#if selectedTab === 'cname'}
<Layout.Stack gap="s">
<Layout.Stack gap="s" direction="row" alignItems="center">
<Typography.Text variant="l-500" color="--fgcolor-neutral-primary"
>{data.domain?.domain}</Typography.Text>
{#if isVerified}
<Badge variant="secondary" type="success" content="Verified" />
{:else}
<Badge
variant="secondary"
type="warning"
size="xs"
content="Pending verification" />
{/if}
</Layout.Stack>
<Typography.Text variant="m-400">
Add the following record on your DNS provider. Note that DNS changes may
take time to propagate fully.
</Typography.Text>
</Layout.Stack>
<Table.Root>
<svelte:fragment slot="header">
<Table.Header.Cell>Type</Table.Header.Cell>
<Table.Header.Cell>Name</Table.Header.Cell>
<Table.Header.Cell>Value</Table.Header.Cell>
</svelte:fragment>
<Table.Row>
<Table.Cell>CNAME</Table.Cell>
<Table.Cell>{data.domain?.domain}</Table.Cell>
<Table.Cell>
<InteractiveText
variant="copy"
isVisible
text={globalThis?.location?.origin}>
{globalThis?.location?.origin}</InteractiveText>
</Table.Cell>
</Table.Row>
</Table.Root>
<Layout.Stack gap="s" direction="row" alignItems="center">
<Icon icon={IconInfo} size="s" color="--fgcolor-neutral-secondary" />
<Typography.Text variant="m-400" color="--fgcolor-neutral-secondary">
A list of all domain providers and their DNS setting is available <Link
variant="muted"
external
href="https://appwrite.io/docs/advanced/platform/custom-domains"
>here</Link
>.
</Typography.Text>
</Layout.Stack>
<Divider />
<Layout.Stack direction="row" justifyContent="flex-end">
<Button on:click={verifyStatus}>Verify</Button>
</Layout.Stack>
{:else}
<Layout.Stack gap="s">
<Layout.Stack gap="s" direction="row" alignItems="center">
<Typography.Text variant="l-500" color="--fgcolor-neutral-primary"
>{data.domain?.domain}</Typography.Text>
<Badge
variant="secondary"
type="warning"
size="xs"
content="Pending verification" />
</Layout.Stack>
<Typography.Text variant="m-400">
Add the following nameservers on your DNS provider. Note that DNS
changes may take time to propagate fully.
</Typography.Text>
</Layout.Stack>
<Table.Root>
<svelte:fragment slot="header">
<Table.Header.Cell>Type</Table.Header.Cell>
<Table.Header.Cell>Value</Table.Header.Cell>
</svelte:fragment>
{#each nameservers as nameserver}
<Table.Row>
<Table.Cell>NS</Table.Cell>
<Table.Cell>
<InteractiveText variant="copy" isVisible text={nameserver}>
{nameserver}</InteractiveText>
</Table.Cell>
</Table.Row>
{/each}
</Table.Root>
<!-- <Layout.Stack gap="s" direction="row" alignItems="center">
<Icon icon={IconInfo} size="s" color="--fgcolor-neutral-secondary" />
<Typography.Text variant="m-400" color="--fgcolor-neutral-secondary">
A list of all domain providers and their DNS setting is available <Link
variant="muted"
href="https://appwrite.io/docs/advanced/platform/custom-domains"
>here</Link
>.
</Typography.Text>
</Layout.Stack> -->
<Divider />
<Layout.Stack direction="row" justifyContent="flex-end">
<Button on:click={verifyStatus}>Verify</Button>
</Layout.Stack>
{/if}
</Layout.Stack>
</Fieldset>
{/if}
</Wizard>
@@ -0,0 +1,16 @@
import { sdk } from '$lib/stores/sdk';
import { isCloud } from '$lib/system';
export const load = async ({ params }) => {
if (isCloud) {
// if (params?.id) {
// return {
// domain: await sdk.forConsole.domains.get(params.id)
// };
// }
} else {
return {
domain: undefined
};
}
};
@@ -0,0 +1,104 @@
<script lang="ts">
import { Modal } from '$lib/components';
import { Button, InputText } from '$lib/elements/forms';
import { sdk } from '$lib/stores/sdk';
import { addNotification } from '$lib/stores/notifications';
import { invalidate } from '$app/navigation';
import { Submit, trackEvent, trackError } from '$lib/actions/analytics';
import { Dependencies } from '$lib/constants';
import { consoleVariables } from '$routes/(console)/store';
import { page } from '$app/stores';
import { Layout, Status, Typography } from '@appwrite.io/pink-svelte';
import { ConsoleResourceType, ID } from '@appwrite.io/console';
import { debounce } from '$lib/helpers/debounce';
export let show = false;
let baseDomain = ID.unique();
let domain = baseDomain;
let domainStatus: 'complete' | 'failed' | 'pending' = 'complete';
let error = null;
async function onSubmit() {
try {
await sdk.forProject.proxy.createFunctionRule(
`${domain}.${$consoleVariables._APP_DOMAIN_TARGET}`,
$page.params.function
);
await invalidate(Dependencies.FUNCTION_DOMAINS);
show = false;
addNotification({
type: 'success',
message: 'Appwrite domain has been added'
});
trackEvent(Submit.DomainCreate);
} catch (e) {
error = e;
trackError(e, Submit.DomainCreate);
}
}
function setDomainLabel(status: typeof domainStatus) {
switch (status) {
case 'complete':
return 'Domain is available';
case 'failed':
return 'Domain is not available';
case 'pending':
return 'Checking domain availability';
}
}
const checkDomain = debounce(async (value: string) => {
if (!value) {
domainStatus = 'failed';
return;
}
try {
await sdk.forConsole.console.getResource(
`${value}.${$consoleVariables._APP_DOMAIN_TARGET}`,
ConsoleResourceType.Rules
);
domainStatus = 'complete';
baseDomain = domain;
} catch {
domainStatus = 'failed';
} finally {
baseDomain = domain;
}
}, 500);
$: if (domain !== baseDomain) {
domainStatus = 'pending';
checkDomain(domain);
}
$: if (!show) {
error = null;
}
</script>
<Modal title="Add Appwrite domain" bind:show {onSubmit} bind:error>
<span slot="description">
Get an auto-generated domain to quickly access your project. You can customize its prefix.
</span>
<Layout.Stack>
<Layout.Stack gap="s">
<InputText id="domain" placeholder="my-domain" bind:value={domain}>
<svelte:fragment slot="end">
<Typography.Text variant="m-400" color="--fgcolor-neutral-tertiary">
.{$consoleVariables._APP_DOMAIN_TARGET}
</Typography.Text>
</svelte:fragment>
</InputText>
<Status status={domainStatus} label={setDomainLabel(domainStatus)}></Status>
</Layout.Stack>
</Layout.Stack>
<svelte:fragment slot="footer">
<Button text on:click={() => (show = false)}>Cancel</Button>
<Button submit>Add</Button>
</svelte:fragment>
</Modal>
@@ -0,0 +1,54 @@
<script lang="ts">
import { Button, InputCheckbox } from '$lib/elements/forms';
import { sdk } from '$lib/stores/sdk';
import { addNotification } from '$lib/stores/notifications';
import { invalidate } from '$app/navigation';
import type { Models } from '@appwrite.io/console';
import { Submit, trackEvent, trackError } from '$lib/actions/analytics';
import { Dependencies } from '$lib/constants';
import { Confirm } from '$lib/components';
import { Typography } from '@appwrite.io/pink-svelte';
export let show = false;
export let selectedDomain: Models.ProxyRule;
let confirm = false;
let error = '';
async function deleteDomain() {
try {
await sdk.forProject.proxy.deleteRule(selectedDomain.$id);
await invalidate(Dependencies.FUNCTION_DOMAINS);
show = false;
addNotification({
type: 'success',
message: `Domain has been deleted`
});
trackEvent(Submit.DomainDelete);
} catch (e) {
error = e.message;
trackError(e, Submit.DomainDelete);
}
}
</script>
<Confirm title="Delete domain" bind:open={show} onSubmit={deleteDomain} bind:error>
{#if selectedDomain}
<Typography.Text variant="m-400">
Are you sure you want to delete this domain? You will no longer be able to execute your
function by visiting:
</Typography.Text>
<Typography.Text variant="m-500">
{selectedDomain.domain}
</Typography.Text>
{/if}
<InputCheckbox
required
bind:checked={confirm}
id="confirm"
label="I understand and confirm"
size="s" />
<svelte:fragment slot="footer">
<Button text on:click={() => (show = false)}>Cancel</Button>
<Button secondary submit disabled={!confirm}>Delete</Button>
</svelte:fragment>
</Confirm>
@@ -0,0 +1,52 @@
<script lang="ts">
import { Copy } from '$lib/components';
import { Link } from '$lib/elements';
import type { Domain } from '$lib/sdk/domains';
import { IconInfo } from '@appwrite.io/pink-icons-svelte';
import { Badge, Layout, Typography, Table, Fieldset, Icon } from '@appwrite.io/pink-svelte';
export let domain: Domain;
</script>
<Fieldset legend="Verification">
<Layout.Stack gap="xl">
<Layout.Stack gap="xl">
<Layout.Stack gap="s">
<Layout.Stack gap="s" direction="row" alignItems="center">
<Typography.Text variant="l-500">{domain?.domain}</Typography.Text>
<Badge variant="secondary" type="warning" content="Pending verification" />
</Layout.Stack>
<Typography.Text variant="m-400">
Add the following nameservers on your DNS provider. Note that DNS changes may
take time to propagate fully.
</Typography.Text>
</Layout.Stack>
<Table.Root>
<svelte:fragment slot="header">
<Table.Header.Cell>Type</Table.Header.Cell>
<Table.Header.Cell>Name</Table.Header.Cell>
<Table.Header.Cell>Value</Table.Header.Cell>
</svelte:fragment>
<Table.Row>
<Table.Cell>CNAME</Table.Cell>
<Table.Cell>{domain?.domain}</Table.Cell>
<Table.Cell>
<Copy value={globalThis?.location?.origin}
>{globalThis?.location?.origin}</Copy>
</Table.Cell>
</Table.Row>
</Table.Root>
<Layout.Stack gap="s" direction="row" alignItems="center">
<Icon icon={IconInfo} size="s" color="--fgcolor-neutral-secondary" />
<Typography.Text variant="m-400" color="--fgcolor-neutral-secondary">
A list of all domain providers and their DNS setting is available <Link
variant="muted"
href="#">here</Link
>.
</Typography.Text>
</Layout.Stack>
</Layout.Stack>
<slot />
</Layout.Stack>
</Fieldset>
@@ -0,0 +1,46 @@
<script lang="ts">
import { Modal } from '$lib/components';
import { Button } from '$lib/elements/forms';
import { sdk } from '$lib/stores/sdk';
import { addNotification } from '$lib/stores/notifications';
import { invalidate } from '$app/navigation';
import type { Models } from '@appwrite.io/console';
import { Submit, trackEvent, trackError } from '$lib/actions/analytics';
import { Dependencies } from '$lib/constants';
import RecordsCard from './recordsCard.svelte';
export let show = false;
export let selectedDomain: Models.ProxyRule;
let error = null;
async function retryDomain() {
try {
await sdk.forProject.proxy.updateRuleVerification(selectedDomain.$id);
await invalidate(Dependencies.SITES_DOMAINS);
show = false;
addNotification({
type: 'success',
message: `${selectedDomain.domain} has been deleted`
});
trackEvent(Submit.DomainDelete);
} catch (e) {
error = e;
trackError(e, Submit.DomainDelete);
}
}
$: if (!show) {
error = null;
}
</script>
<Modal title="Retry verification" bind:show onSubmit={retryDomain} bind:error>
{#if selectedDomain}
<RecordsCard domain={selectedDomain} />
{/if}
<svelte:fragment slot="footer">
<Button text on:click={() => (show = false)}>Cancel</Button>
<Button submit>Retry</Button>
</svelte:fragment>
</Modal>
@@ -26,7 +26,7 @@
import { IconGithub } from '@appwrite.io/pink-icons-svelte';
import { ConnectGit } from '$lib/components/git';
import { isValueOfStringEnum } from '$lib/helpers/types';
import ConnectRepoModal from './connectRepoModal.svelte';
import ConnectRepoModal from '../(modals)/connectRepoModal.svelte';
export let func: Models.Function;
export let installations: Models.InstallationList;