Skip to content

Commit

Permalink
fix(idea/frontend): fix edit dns name validation (#1592)
Browse files Browse the repository at this point in the history
  • Loading branch information
vraja-nayaka authored Jul 9, 2024
1 parent 3a8b8a4 commit 2abe4bd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
16 changes: 9 additions & 7 deletions idea/frontend/src/features/dns/hooks/use-dns-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@ import { useProgramIdSchema } from '@/hooks';
import { FIELD_NAME, NAME_SCHEMA } from '../consts';
import { getSingleDns } from '../utils';

const useDnsSchema = () => {
const useDnsSchema = (isEditMode?: boolean) => {
const programIdSchema = useProgramIdSchema([]);

const dnsNameSchema = NAME_SCHEMA.refine(async (value) => {
const result = await getSingleDns(value).catch(() => {
// empty
});
return !result;
}, 'dDNS name already exists');
const dnsNameSchema = isEditMode
? NAME_SCHEMA
: NAME_SCHEMA.refine(async (value) => {
const result = await getSingleDns(value).catch(() => {
// empty
});
return !result;
}, 'dDNS name already exists');

const dnsSchema = z.object({
[FIELD_NAME.DNS_ADDRESS]: programIdSchema,
Expand Down
2 changes: 1 addition & 1 deletion idea/frontend/src/features/dns/ui/dns-modal/dns-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ type Props = {
};

const DnsModal = ({ heading, submitText, close, onSuccess, initialValues }: Props) => {
const dnsSchema = useDnsSchema();
const isEditMode = Boolean(initialValues);
const dnsSchema = useDnsSchema(isEditMode);

type DnsSchema = z.infer<typeof dnsSchema>;

Expand Down

0 comments on commit 2abe4bd

Please sign in to comment.