import { faArrowLeft } from '@fortawesome/free-solid-svg-icons'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import type { FC } from 'react'; import { useEffect, useMemo } from 'react'; import { ExternalLink } from 'react-external-link'; import { useLocation, useParams } from 'react-router-dom'; import { Button, Card } from 'reactstrap'; import { ShlinkApiError } from '../../src/api/ShlinkApiError'; import { useGoBack } from '../../src/utils/helpers/hooks'; import { parseQuery } from '../../src/utils/helpers/query'; import { Message } from '../../src/utils/Message'; import { Result } from '../../src/utils/Result'; import { useSetting } from '../utils/settings'; import type { ShortUrlIdentifier } from './data'; import { shortUrlDataFromShortUrl, urlDecodeShortCode } from './helpers'; import type { ShortUrlDetail } from './reducers/shortUrlDetail'; import type { EditShortUrl as EditShortUrlInfo, ShortUrlEdition } from './reducers/shortUrlEdition'; import type { ShortUrlFormProps } from './ShortUrlForm'; interface EditShortUrlConnectProps { shortUrlDetail: ShortUrlDetail; shortUrlEdition: ShortUrlEdition; getShortUrlDetail: (shortUrl: ShortUrlIdentifier) => void; editShortUrl: (editShortUrl: EditShortUrlInfo) => void; } export const EditShortUrl = (ShortUrlForm: FC) => ({ shortUrlDetail, getShortUrlDetail, shortUrlEdition, editShortUrl, }: EditShortUrlConnectProps) => { const { search } = useLocation(); const params = useParams<{ shortCode: string }>(); const goBack = useGoBack(); const { loading, error, errorData, shortUrl } = shortUrlDetail; const { saving, saved, error: savingError, errorData: savingErrorData } = shortUrlEdition; const { domain } = parseQuery<{ domain?: string }>(search); const shortUrlCreationSettings = useSetting('shortUrlCreation'); const initialState = useMemo( () => shortUrlDataFromShortUrl(shortUrl, shortUrlCreationSettings), [shortUrl, shortUrlCreationSettings], ); useEffect(() => { params.shortCode && getShortUrlDetail({ shortCode: urlDecodeShortCode(params.shortCode), domain }); }, []); if (loading) { return ; } if (error) { return ( ); } return ( <>

Edit

{ if (!shortUrl) { return; } editShortUrl({ ...shortUrl, data: shortUrlData }); }} /> {saved && savingError && ( )} {saved && !savingError && Short URL properly edited.} ); };