diff --git a/src/servers/Overview.tsx b/src/servers/Overview.tsx index 822dd8e7..f032a39e 100644 --- a/src/servers/Overview.tsx +++ b/src/servers/Overview.tsx @@ -7,6 +7,7 @@ import { prettify } from '../utils/helpers/numbers'; import { TagsList } from '../tags/reducers/tagsList'; import { ShortUrlsTableProps } from '../short-urls/ShortUrlsTable'; import { boundToMercureHub } from '../mercure/helpers/boundToMercureHub'; +import { CreateShortUrlProps } from '../short-urls/CreateShortUrl'; import { VisitsOverview } from '../visits/reducers/visitsOverview'; import { isServerWithId, SelectedServer } from './data'; import './Overview.scss'; @@ -21,7 +22,10 @@ interface OverviewConnectProps { loadVisitsOverview: Function; } -export const Overview = (ShortUrlsTable: FC) => boundToMercureHub(({ +export const Overview = ( + ShortUrlsTable: FC, + CreateShortUrl: FC, +) => boundToMercureHub(({ shortUrlsList, listShortUrls, listTags, @@ -67,10 +71,12 @@ export const Overview = (ShortUrlsTable: FC) => boundToMerc - Create short URL + Create a short URL Advanced options » - Create + + + diff --git a/src/servers/services/provideServices.ts b/src/servers/services/provideServices.ts index ebf127bf..13ce2ddc 100644 --- a/src/servers/services/provideServices.ts +++ b/src/servers/services/provideServices.ts @@ -44,7 +44,7 @@ const provideServices = (bottle: Bottle, connect: ConnectDecorator, withRouter: bottle.serviceFactory('ServerError', ServerError, 'DeleteServerButton'); bottle.decorator('ServerError', connect([ 'servers', 'selectedServer' ])); - bottle.serviceFactory('Overview', Overview, 'ShortUrlsTable'); + bottle.serviceFactory('Overview', Overview, 'ShortUrlsTable', 'CreateShortUrl'); bottle.decorator('Overview', connect( [ 'shortUrlsList', 'tagsList', 'selectedServer', 'mercureInfo', 'visitsOverview' ], [ 'listShortUrls', 'listTags', 'createNewVisits', 'loadMercureInfo', 'loadVisitsOverview' ], diff --git a/src/short-urls/CreateShortUrl.tsx b/src/short-urls/CreateShortUrl.tsx index fa26689e..14b434ae 100644 --- a/src/short-urls/CreateShortUrl.tsx +++ b/src/short-urls/CreateShortUrl.tsx @@ -17,15 +17,19 @@ import UseExistingIfFoundInfoIcon from './UseExistingIfFoundInfoIcon'; import { CreateShortUrlResultProps } from './helpers/CreateShortUrlResult'; import './CreateShortUrl.scss'; -const normalizeTag = pipe(trim, replace(/ /g, '-')); +export interface CreateShortUrlProps { + basicMode?: boolean; +} -interface CreateShortUrlProps { +interface CreateShortUrlConnectProps extends CreateShortUrlProps { shortUrlCreationResult: ShortUrlCreation; selectedServer: SelectedServer; - createShortUrl: Function; + createShortUrl: (data: ShortUrlData) => Promise; resetCreateShortUrl: () => void; } +export const normalizeTag = pipe(trim, replace(/ /g, '-')); + const initialState: ShortUrlData = { longUrl: '', tags: [], @@ -47,7 +51,13 @@ const CreateShortUrl = ( CreateShortUrlResult: FC, ForServerVersion: FC, DomainSelector: FC, -) => ({ createShortUrl, shortUrlCreationResult, resetCreateShortUrl, selectedServer }: CreateShortUrlProps) => { +) => ({ + createShortUrl, + shortUrlCreationResult, + resetCreateShortUrl, + selectedServer, + basicMode = false, +}: CreateShortUrlConnectProps) => { const [ shortUrlCreation, setShortUrlCreation ] = useState(initialState); const changeTags = (tags: string[]) => setShortUrlCreation({ ...shortUrlCreation, tags: tags.map(normalizeTag) }); @@ -55,8 +65,8 @@ const CreateShortUrl = ( const save = handleEventPreventingDefault(() => { const shortUrlData = { ...shortUrlCreation, - validSince: formatIsoDate(shortUrlCreation.validSince), - validUntil: formatIsoDate(shortUrlCreation.validUntil), + validSince: formatIsoDate(shortUrlCreation.validSince) ?? undefined, + validUntil: formatIsoDate(shortUrlCreation.validUntil) ?? undefined, }; createShortUrl(shortUrlData).then(reset).catch(() => {}); @@ -92,90 +102,94 @@ const CreateShortUrl = ( return (
-
- + setShortUrlCreation({ ...shortUrlCreation, longUrl: e.target.value })} /> -
+ -
+ -
+ -
-
- {renderOptionalInput('customSlug', 'Custom slug', 'text', { - disabled: hasValue(shortUrlCreation.shortCodeLength), - })} -
-
- {renderOptionalInput('shortCodeLength', 'Short code length', 'number', { - min: 4, - disabled: disableShortCodeLength || hasValue(shortUrlCreation.customSlug), - ...disableShortCodeLength && { - title: 'Shlink 2.1.0 or higher is required to be able to provide the short code length', - }, - })} -
-
- {!showDomainSelector && renderOptionalInput('domain', 'Domain', 'text', { - disabled: disableDomain, - ...disableDomain && { title: 'Shlink 1.19.0 or higher is required to be able to provide the domain' }, - })} - {showDomainSelector && ( - - setShortUrlCreation({ ...shortUrlCreation, domain })} - /> - - )} -
-
- -
-
- {renderOptionalInput('maxVisits', 'Maximum number of visits allowed', 'number', { min: 1 })} -
-
- {renderDateInput('validSince', 'Enabled since...', { maxDate: shortUrlCreation.validUntil as m.Moment | undefined })} -
-
- {renderDateInput('validUntil', 'Enabled until...', { minDate: shortUrlCreation.validSince as m.Moment | undefined })} -
-
- - -
-
- - setShortUrlCreation({ ...shortUrlCreation, validateUrl })} - > - Validate URL - - + {!basicMode && ( + <> +
+
+ {renderOptionalInput('customSlug', 'Custom slug', 'text', { + disabled: hasValue(shortUrlCreation.shortCodeLength), + })} +
+
+ {renderOptionalInput('shortCodeLength', 'Short code length', 'number', { + min: 4, + disabled: disableShortCodeLength || hasValue(shortUrlCreation.customSlug), + ...disableShortCodeLength && { + title: 'Shlink 2.1.0 or higher is required to be able to provide the short code length', + }, + })} +
+
+ {!showDomainSelector && renderOptionalInput('domain', 'Domain', 'text', { + disabled: disableDomain, + ...disableDomain && { title: 'Shlink 1.19.0 or higher is required to be able to provide the domain' }, + })} + {showDomainSelector && ( + + setShortUrlCreation({ ...shortUrlCreation, domain })} + /> + + )} +
-
- setShortUrlCreation({ ...shortUrlCreation, findIfExists })} - > - Use existing URL if found - - + +
+
+ {renderOptionalInput('maxVisits', 'Maximum number of visits allowed', 'number', { min: 1 })} +
+
+ {renderDateInput('validSince', 'Enabled since...', { maxDate: shortUrlCreation.validUntil as m.Moment | undefined })} +
+
+ {renderDateInput('validUntil', 'Enabled until...', { minDate: shortUrlCreation.validSince as m.Moment | undefined })} +
-
- + + +
+
+ + setShortUrlCreation({ ...shortUrlCreation, validateUrl })} + > + Validate URL + + +
+
+ setShortUrlCreation({ ...shortUrlCreation, findIfExists })} + > + Use existing URL if found + + +
+
+
+ + )}