From 00fc51ced69a159974845d45ea52ed31c4661d15 Mon Sep 17 00:00:00 2001 From: Myrfion Date: Fri, 17 Mar 2023 11:32:00 -0400 Subject: [PATCH 1/8] Add integration for editing dns records --- app/components/dns-record/form.tsx | 33 ++++++--- app/routes/__index/domains/$dnsRecordId.tsx | 80 +++++++++++++++++++++ app/routes/__index/domains/$domainId.tsx | 11 --- app/routes/__index/domains/new.tsx | 2 +- 4 files changed, 104 insertions(+), 22 deletions(-) create mode 100644 app/routes/__index/domains/$dnsRecordId.tsx delete mode 100644 app/routes/__index/domains/$domainId.tsx diff --git a/app/components/dns-record/form.tsx b/app/components/dns-record/form.tsx index f5d26e83..4b3725bc 100644 --- a/app/components/dns-record/form.tsx +++ b/app/components/dns-record/form.tsx @@ -1,4 +1,4 @@ -import { AddIcon, InfoIcon } from '@chakra-ui/icons'; +import { AddIcon, InfoIcon, EditIcon } from '@chakra-ui/icons'; import { Button, Input, @@ -10,23 +10,31 @@ import { VStack, } from '@chakra-ui/react'; import { Form } from '@remix-run/react'; - +import type { Record } from '@prisma/client'; import { useUser } from '~/utils'; import FormField from './form-field'; +import { useMemo } from 'react'; + +type FormMode = 'CREATE' | 'EDIT'; interface DnsRecordFormProps { + mode: FormMode; typeError?: string; // Error for 'Type' field + defaultDnsRecord?: Record; } -export default function DnsRecordForm({ typeError }: DnsRecordFormProps) { +export default function DnsRecordForm({ typeError, defaultDnsRecord, mode }: DnsRecordFormProps) { const user = useUser(); + const submitButtonText = useMemo(() => (mode === 'CREATE' ? 'Create' : 'Update'), [mode]); + const SubmitButtonIcon = useMemo(() => (mode === 'CREATE' ? AddIcon : EditIcon), [mode]); + return (
- + @@ -35,7 +43,7 @@ export default function DnsRecordForm({ typeError }: DnsRecordFormProps) { - @@ -47,14 +55,14 @@ export default function DnsRecordForm({ typeError }: DnsRecordFormProps) { - + - + @@ -68,11 +76,16 @@ export default function DnsRecordForm({ typeError }: DnsRecordFormProps) { -