From 08d67a6527df5ef18d60871e1bcdb16db961f618 Mon Sep 17 00:00:00 2001 From: Arman Date: Thu, 20 Feb 2025 17:15:12 +0100 Subject: [PATCH] feat: edit record modal --- src/lib/actions/analytics.ts | 1 + .../domain-[domain]/editRecordModal.svelte | 46 +++++++++++-------- .../domains/domain-[domain]/table.svelte | 4 ++ .../auth/user-[user]/updateLabels.svelte | 2 +- 4 files changed, 32 insertions(+), 21 deletions(-) diff --git a/src/lib/actions/analytics.ts b/src/lib/actions/analytics.ts index c0f5ea4d4..19975c6ee 100644 --- a/src/lib/actions/analytics.ts +++ b/src/lib/actions/analytics.ts @@ -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' } diff --git a/src/routes/(console)/organization-[organization]/domains/domain-[domain]/editRecordModal.svelte b/src/routes/(console)/organization-[organization]/domains/domain-[domain]/editRecordModal.svelte index 0571b00e4..a022a7822 100644 --- a/src/routes/(console)/organization-[organization]/domains/domain-[domain]/editRecordModal.svelte +++ b/src/routes/(console)/organization-[organization]/domains/domain-[domain]/editRecordModal.svelte @@ -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; - + DNS records map domain names to IP addresses or other resources. - + - + - + - {options.find((option) => option.value === type)?.helper} + {options.find((option) => option.value === record.type)?.helper} - + @@ -127,7 +133,7 @@ id="priority" label="Priority" placeholder="Enter number" - bind:value={priority}> + bind:value={record.priority}> @@ -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} /> - + diff --git a/src/routes/(console)/organization-[organization]/domains/domain-[domain]/table.svelte b/src/routes/(console)/organization-[organization]/domains/domain-[domain]/table.svelte index 184af04ed..13e39a9b9 100644 --- a/src/routes/(console)/organization-[organization]/domains/domain-[domain]/table.svelte +++ b/src/routes/(console)/organization-[organization]/domains/domain-[domain]/table.svelte @@ -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} {/if} +{#if showEdit} + +{/if} diff --git a/src/routes/(console)/project-[project]/auth/user-[user]/updateLabels.svelte b/src/routes/(console)/project-[project]/auth/user-[user]/updateLabels.svelte index 56e9fbf10..1e5ea732f 100644 --- a/src/routes/(console)/project-[project]/auth/user-[user]/updateLabels.svelte +++ b/src/routes/(console)/project-[project]/auth/user-[user]/updateLabels.svelte @@ -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';