Added support to enable/disable validating the URL while it is created

This commit is contained in:
Alejandro Celaya 2020-12-06 13:07:44 +01:00
parent 0ed88079ad
commit 8f7e356e54
4 changed files with 28 additions and 12 deletions

View file

@ -38,6 +38,7 @@ const initialState: ShortUrlData = {
validUntil: undefined, validUntil: undefined,
maxVisits: undefined, maxVisits: undefined,
findIfExists: false, findIfExists: false,
validateUrl: true,
}; };
type NonDateFields = 'longUrl' | 'customSlug' | 'shortCodeLength' | 'domain' | 'maxVisits'; type NonDateFields = 'longUrl' | 'customSlug' | 'shortCodeLength' | 'domain' | 'maxVisits';
@ -154,16 +155,29 @@ const CreateShortUrl = (
</div> </div>
<ForServerVersion minVersion="1.16.0"> <ForServerVersion minVersion="1.16.0">
<div className="mb-4 text-right"> <div className="mb-4 row">
<Checkbox <div className="col-6">
inline <ForServerVersion minVersion="2.4.0">
className="mr-2" <Checkbox
checked={shortUrlCreation.findIfExists} inline
onChange={(findIfExists) => setShortUrlCreation({ ...shortUrlCreation, findIfExists })} checked={shortUrlCreation.validateUrl}
> onChange={(validateUrl) => setShortUrlCreation({ ...shortUrlCreation, validateUrl })}
Use existing URL if found >
</Checkbox> Validate URL
<UseExistingIfFoundInfoIcon /> </Checkbox>
</ForServerVersion>
</div>
<div className="col-6 text-right">
<Checkbox
inline
className="mr-2"
checked={shortUrlCreation.findIfExists}
onChange={(findIfExists) => setShortUrlCreation({ ...shortUrlCreation, findIfExists })}
>
Use existing URL if found
</Checkbox>
<UseExistingIfFoundInfoIcon />
</div>
</div> </div>
</ForServerVersion> </ForServerVersion>
</Collapse> </Collapse>

View file

@ -11,6 +11,7 @@ export interface ShortUrlData {
validUntil?: m.Moment | string; validUntil?: m.Moment | string;
maxVisits?: number; maxVisits?: number;
findIfExists?: boolean; findIfExists?: boolean;
validateUrl?: boolean;
} }
export interface ShortUrl { export interface ShortUrl {

View file

@ -1,4 +1,4 @@
import { ChangeEvent, FC } from 'react'; import { ChangeEvent, FC, useRef } from 'react';
import classNames from 'classnames'; import classNames from 'classnames';
import { v4 as uuid } from 'uuid'; import { v4 as uuid } from 'uuid';
import { identity } from 'ramda'; import { identity } from 'ramda';
@ -17,7 +17,7 @@ interface BooleanControlWithTypeProps extends BooleanControlProps {
const BooleanControl: FC<BooleanControlWithTypeProps> = ( const BooleanControl: FC<BooleanControlWithTypeProps> = (
{ checked = false, onChange = identity, className, children, type, inline = false }, { checked = false, onChange = identity, className, children, type, inline = false },
) => { ) => {
const id = uuid(); const { current: id } = useRef(uuid());
const onChecked = (e: ChangeEvent<HTMLInputElement>) => onChange(e.target.checked, e); const onChecked = (e: ChangeEvent<HTMLInputElement>) => onChange(e.target.checked, e);
const typeClasses = { const typeClasses = {
'custom-switch': type === 'switch', 'custom-switch': type === 'switch',

View file

@ -52,6 +52,7 @@ describe('<CreateShortUrl />', () => {
maxVisits: '20', maxVisits: '20',
findIfExists: false, findIfExists: false,
shortCodeLength: 15, shortCodeLength: 15,
validateUrl: true,
}); });
}); });
}); });