diff --git a/src/short-urls/CreateShortUrl.tsx b/src/short-urls/CreateShortUrl.tsx index da07dffa..c42f4674 100644 --- a/src/short-urls/CreateShortUrl.tsx +++ b/src/short-urls/CreateShortUrl.tsx @@ -38,6 +38,7 @@ const initialState: ShortUrlData = { validUntil: undefined, maxVisits: undefined, findIfExists: false, + validateUrl: true, }; type NonDateFields = 'longUrl' | 'customSlug' | 'shortCodeLength' | 'domain' | 'maxVisits'; @@ -154,16 +155,29 @@ const CreateShortUrl = ( -
- setShortUrlCreation({ ...shortUrlCreation, findIfExists })} - > - Use existing URL if found - - +
+
+ + setShortUrlCreation({ ...shortUrlCreation, validateUrl })} + > + Validate URL + + +
+
+ setShortUrlCreation({ ...shortUrlCreation, findIfExists })} + > + Use existing URL if found + + +
diff --git a/src/short-urls/data/index.ts b/src/short-urls/data/index.ts index ba7d7c6e..237c6b6a 100644 --- a/src/short-urls/data/index.ts +++ b/src/short-urls/data/index.ts @@ -11,6 +11,7 @@ export interface ShortUrlData { validUntil?: m.Moment | string; maxVisits?: number; findIfExists?: boolean; + validateUrl?: boolean; } export interface ShortUrl { diff --git a/src/utils/BooleanControl.tsx b/src/utils/BooleanControl.tsx index 72f7056e..0b642dd0 100644 --- a/src/utils/BooleanControl.tsx +++ b/src/utils/BooleanControl.tsx @@ -1,4 +1,4 @@ -import { ChangeEvent, FC } from 'react'; +import { ChangeEvent, FC, useRef } from 'react'; import classNames from 'classnames'; import { v4 as uuid } from 'uuid'; import { identity } from 'ramda'; @@ -17,7 +17,7 @@ interface BooleanControlWithTypeProps extends BooleanControlProps { const BooleanControl: FC = ( { checked = false, onChange = identity, className, children, type, inline = false }, ) => { - const id = uuid(); + const { current: id } = useRef(uuid()); const onChecked = (e: ChangeEvent) => onChange(e.target.checked, e); const typeClasses = { 'custom-switch': type === 'switch', diff --git a/test/short-urls/CreateShortUrl.test.tsx b/test/short-urls/CreateShortUrl.test.tsx index 4aeb72bb..797b2169 100644 --- a/test/short-urls/CreateShortUrl.test.tsx +++ b/test/short-urls/CreateShortUrl.test.tsx @@ -52,6 +52,7 @@ describe('', () => { maxVisits: '20', findIfExists: false, shortCodeLength: 15, + validateUrl: true, }); }); });