feat: edit record modal

This commit is contained in:
Arman committed 2025-02-20 17:15:12 +01:00
1 parent cd55074172
commit 08d67a6527
4 files changed
+32 -21

No files matched your search

+1
View File
@@ -343,5 +343,6 @@ export enum Submit {
SiteDisconnectRepo = 'submit_site_disconnect_repo',
SiteActivateDeployment = 'submit_site_activate_deployment',
RecordCreate = 'submit_dns_record_create',
RecordUpdate = 'submit_dns_record_update',
RecordDelete = 'submit_dns_record_delete'
}
@@ -11,10 +11,14 @@
import { IconInfo } from '@appwrite.io/pink-icons-svelte';
import { addNotification } from '$lib/stores/notifications';
import { Submit, trackError, trackEvent } from '$lib/actions/analytics';
import type { Models } from '@appwrite.io/console';
import { symmetricDifference } from '$lib/helpers/array';
import { deepClone } from '$lib/helpers/object';
type RecordType = 'A' | 'AAAA' | 'CNAME' | 'MX' | 'TXT' | 'NS' | 'SRV' | 'CAA' | 'PTR';
// type RecordType = 'A' | 'AAAA' | 'CNAME' | 'MX' | 'TXT' | 'NS' | 'SRV' | 'CAA' | 'PTR';
export let show = false;
export let selectedRecord: Models.DnsRecord;
const options = [
{
value: 'A',
@@ -67,54 +71,56 @@
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 record = deepClone(selectedRecord);
let error = '';
async function handleSubmit() {
try {
//TODO: create DNS record
//TODO: update DNS record
show = false;
addNotification({
type: 'success',
message: `Record has been created`
message: `Record has been updated`
});
trackEvent(Submit.RecordCreate);
trackEvent(Submit.RecordUpdate);
} catch (e) {
error = e.message;
trackError(e, Submit.RecordCreate);
trackError(e, Submit.RecordUpdate);
}
}
$: if (!show) {
selectedRecord = null;
}
$: isDisabled = !symmetricDifference(Object.values(record), Object.values(selectedRecord))
?.length;
</script>
<Modal title="Create DNS record" bind:show bind:error onSubmit={handleSubmit}>
<Modal title="Update 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} />
<InputText id="name" label="Name" placeholder="subdomain" bind:value={record.name} />
<Layout.Stack gap="xs">
<InputSelect {options} bind:value={type} id="type" label="Type" />
<InputSelect {options} bind:value={record.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>
<InputText id="value" label="Value" placeholder="76.75.21.21" bind:value={record.value}>
<Tooltip slot="info">
<Icon icon={IconInfo} />
<span slot="tooltip">
{options.find((option) => option.value === type)?.helper}
{options.find((option) => option.value === record.type)?.helper}
</span>
</Tooltip>
</InputText>
<Layout.Stack direction="row" gap="l">
<InputNumber id="ttl" label="TTL" placeholder="Enter number" bind:value={ttl}>
<InputNumber id="ttl" label="TTL" placeholder="Enter number" bind:value={record.ttl}>
<Tooltip slot="info">
<Icon icon={IconInfo} />
<span slot="tooltip">
@@ -127,7 +133,7 @@
id="priority"
label="Priority"
placeholder="Enter number"
bind:value={priority}>
bind:value={record.priority}>
<Tooltip slot="info">
<Icon icon={IconInfo} />
<span slot="tooltip">
@@ -142,11 +148,11 @@
id="comment"
label="Comment"
placeholder="Provide an explanation of this DNS record's purpose"
bind:value={comment} />
bind:value={record.comment} />
</Layout.Stack>
<svelte:fragment slot="footer">
<Button text on:click={() => (show = false)}>Cancel</Button>
<Button secondary submit>Create DNS record</Button>
<Button secondary submit disabled={isDisabled}>Update DNS record</Button>
</svelte:fragment>
</Modal>
@@ -17,6 +17,7 @@
import type { Models } from '@appwrite.io/console';
import DeleteRecordModal from './deleteRecordModal.svelte';
import { capitalize } from '$lib/helpers/string';
import EditRecordModal from './editRecordModal.svelte';
export let data;
@@ -143,3 +144,6 @@
{#if showDelete}
<DeleteRecordModal bind:show={showDelete} {selectedRecord} />
{/if}
{#if showEdit}
<EditRecordModal bind:show={showEdit} {selectedRecord} />
{/if}
@@ -2,7 +2,7 @@
import { onMount } from 'svelte';
import { invalidate } from '$app/navigation';
import { Submit, trackEvent, trackError } from '$lib/actions/analytics';
import { CardGrid, Heading } from '$lib/components';
import { CardGrid } from '$lib/components';
import { Dependencies } from '$lib/constants';
import { Button, Form, Helper, InputTags } from '$lib/elements/forms';
import { symmetricDifference } from '$lib/helpers/array';