feat: more work on domains

This commit is contained in:
Arman committed 2025-02-20 17:04:23 +01:00
1 parent fba9be0ae4
commit cd55074172
8 files changed
+203 -14

No files matched your search

@@ -29,10 +29,7 @@
}
</script>
<!-- TODO: fix copy -->
<Confirm onSubmit={deleteDomain} title="Delete domain" bind:open={show} bind:error>
<p data-private>Are you sure you want to delete <b>{selectedDomain?.domain}</b>?</p>
<p>
You will no longer be able to access any projects or services associated with this domain.
</p>
<p>Your site will no longer be available at this domain. This action is irreversible.</p>
</Confirm>
@@ -4,7 +4,7 @@ import { Dependencies } from '$lib/constants';
import { sdk } from '$lib/stores/sdk';
export const load = async ({ depends, params }) => {
depends(Dependencies.SITE);
depends(Dependencies.DOMAIN);
return {
domain: await sdk.forConsole.domains.get(params.domain),
@@ -4,7 +4,6 @@
import { addNotification } from '$lib/stores/notifications';
import { Submit, trackError, trackEvent } from '$lib/actions/analytics';
import { Skeleton, Table } from '@appwrite.io/pink-svelte';
import { onMount } from 'svelte';
import { capitalize } from '$lib/helpers/string';
export let show = false;
@@ -1,11 +1,9 @@
<script lang="ts">
import { Button } from '$lib/elements/forms';
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 { Confirm } from '$lib/components';
import { Typography } from '@appwrite.io/pink-svelte';
export let show = false;
export let selectedCertificate;
@@ -14,8 +12,8 @@
async function deleteCertificate() {
try {
await invalidate(Dependencies.DOMAIN);
//TODO: add method
await invalidate(Dependencies.DOMAIN);
show = false;
addNotification({
type: 'success',
@@ -30,5 +28,5 @@
</script>
<Confirm title="Delete certificate" bind:open={show} onSubmit={deleteCertificate} bind:error>
Are you sure you want to delete SSL certificate? This action is irreversible.
Are you sure you want to delete this SSL certificate? This action is irreversible.
</Confirm>
@@ -68,7 +68,7 @@
}
];
let name: string;
let type: RecordType;
let type: RecordType = 'A';
let value: string;
let ttl = 3600;
let priority: number;
@@ -99,9 +99,10 @@
<Layout.Stack gap="l">
<InputText id="name" label="Name" placeholder="subdomain" bind:value={name} />
<Layout.Stack gap="xs">
<InputSelect {options} bind:value={type} id="type" label="Type" />
<InputSelect {options} bind:value={type} id="type" label="Type" required />
<Layout.Stack direction="row" gap="xs">
<Icon icon={IconInfo} />
{options.find((option) => option.value === type)?.helper}
</Layout.Stack>
</Layout.Stack>
@@ -109,7 +110,8 @@
<Tooltip slot="info">
<Icon icon={IconInfo} />
<span slot="tooltip">
{options.find((option) => option.value === type)?.helper}
Enter the target or destination for this DNS record (e.g., IP address, hostname,
or other required data)
</span>
</Tooltip>
</InputText>
@@ -0,0 +1,35 @@
<script lang="ts">
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 { page } from '$app/stores';
export let show = false;
export let selectedRecord: Models.DnsRecord;
let error = '';
async function deleteDomain() {
try {
await sdk.forConsole.domains.deleteRecord($page.params.domain, selectedRecord.$id);
await invalidate(Dependencies.DOMAINS);
show = false;
addNotification({
type: 'success',
message: 'Record has been deleted'
});
trackEvent(Submit.DomainDelete);
} catch (e) {
error = e.message;
trackError(e, Submit.DomainDelete);
}
}
</script>
<Confirm onSubmit={deleteDomain} title="Delete domain" bind:open={show} bind:error>
<p>Are you sure you want to delete this record? This action is irreversible.</p>
</Confirm>
@@ -0,0 +1,152 @@
<script lang="ts">
import {
Button,
InputNumber,
InputSelect,
InputText,
InputTextarea
} from '$lib/elements/forms';
import { Modal } from '$lib/components';
import { Icon, Layout, Tooltip } from '@appwrite.io/pink-svelte';
import { IconInfo } from '@appwrite.io/pink-icons-svelte';
import { addNotification } from '$lib/stores/notifications';
import { Submit, trackError, trackEvent } from '$lib/actions/analytics';
type RecordType = 'A' | 'AAAA' | 'CNAME' | 'MX' | 'TXT' | 'NS' | 'SRV' | 'CAA' | 'PTR';
export let show = false;
const options = [
{
value: 'A',
label: 'A ',
helper: 'A records map a domain to an IPv4 address, allowing browsers to find your website by translating the domain name to an IP address.'
},
{
value: 'AAAA',
label: 'AAAA ',
helper: 'AAAA records map a domain to an IPv6 address, providing the same function as A records but for IPv6-enabled devices.'
},
{
value: 'CNAME',
label: 'CNAME',
helper: 'CNAME records alias one domain name to another, allowing you to point subdomains or other domain names to an existing domain.'
},
{
value: 'MX',
label: 'MX ',
helper: 'MX records specify mail servers responsible for receiving emails for a domain, helping route email traffic to the correct mail server.'
},
{
value: 'TXT',
label: 'TXT',
helper: 'TXT records store arbitrary text data in DNS, commonly used for verification purposes, such as domain ownership or email security settings.'
},
{
value: 'NS',
label: 'NS',
helper: "NS records define the authoritative DNS servers for a domain, directing queries to the servers that manage the domain's DNS settings."
},
{
value: 'SRV',
label: 'SRV',
helper: 'SRV records specify the location (hostname and port number) of servers for specific services, directing traffic to particular servers based on service types.'
},
{
value: 'CAA',
label: 'CAA',
helper: 'CAA records specify which certificate authorities are allowed to issue SSL certificates for your domain, helping to prevent unauthorized certificate issuance.'
},
{
value: 'HTTPS',
label: 'HTTPS',
helper: 'HTTPS records define which service or endpoint handles secure HTTPS traffic for your domain, typically used in SSL/TLS configurations.'
},
{
value: 'ALIAS',
label: 'ALIAS',
helper: 'ALIAS records are similar to CNAMEs but can be used for the root domain, allowing you to point your domain to another domain or server.'
}
];
let name: string;
let type: RecordType;
let value: string;
let ttl = 3600;
let priority: number;
let comment: string;
let error = '';
async function handleSubmit() {
try {
//TODO: create DNS record
show = false;
addNotification({
type: 'success',
message: `Record has been created`
});
trackEvent(Submit.RecordCreate);
} catch (e) {
error = e.message;
trackError(e, Submit.RecordCreate);
}
}
</script>
<Modal title="Create DNS record" bind:show bind:error onSubmit={handleSubmit}>
<span slot="description">
DNS records map domain names to IP addresses or other resources.
</span>
<Layout.Stack gap="l">
<InputText id="name" label="Name" placeholder="subdomain" bind:value={name} />
<Layout.Stack gap="xs">
<InputSelect {options} bind:value={type} id="type" label="Type" />
<Layout.Stack direction="row" gap="xs">
<Icon icon={IconInfo} />
</Layout.Stack>
</Layout.Stack>
<InputText id="value" label="Value" placeholder="76.75.21.21" bind:value>
<Tooltip slot="info">
<Icon icon={IconInfo} />
<span slot="tooltip">
{options.find((option) => option.value === type)?.helper}
</span>
</Tooltip>
</InputText>
<Layout.Stack direction="row" gap="l">
<InputNumber id="ttl" label="TTL" placeholder="Enter number" bind:value={ttl}>
<Tooltip slot="info">
<Icon icon={IconInfo} />
<span slot="tooltip">
TTL defines how long DNS information is cached. Lower values update faster;
higher values reduce server load.
</span>
</Tooltip>
</InputNumber>
<InputNumber
id="priority"
label="Priority"
placeholder="Enter number"
bind:value={priority}>
<Tooltip slot="info">
<Icon icon={IconInfo} />
<span slot="tooltip">
Sets the priority for this DNS record. Lower numbers indicate higher
priority (e.g., 10 is higher than 20).
</span>
</Tooltip>
</InputNumber>
</Layout.Stack>
<InputTextarea
id="comment"
label="Comment"
placeholder="Provide an explanation of this DNS record's purpose"
bind:value={comment} />
</Layout.Stack>
<svelte:fragment slot="footer">
<Button text on:click={() => (show = false)}>Cancel</Button>
<Button secondary submit>Create DNS record</Button>
</svelte:fragment>
</Modal>
@@ -15,6 +15,8 @@
import { columns } from './store';
import { timeFromNow } from '$lib/helpers/date';
import type { Models } from '@appwrite.io/console';
import DeleteRecordModal from './deleteRecordModal.svelte';
import { capitalize } from '$lib/helpers/string';
export let data;
@@ -79,7 +81,7 @@
{:else if column.id === '$createdAt'}
<Table.Cell>
<Typography.Text>
{timeFromNow(record.$createdAt)}
{capitalize(timeFromNow(record.$createdAt))}
</Typography.Text>
</Table.Cell>
{/if}
@@ -137,3 +139,7 @@
offset={data.offset}
total={data.recordList.total} />
</Layout.Stack>
{#if showDelete}
<DeleteRecordModal bind:show={showDelete} {selectedRecord} />
{/if}