import { faUndo } from '@fortawesome/free-solid-svg-icons'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { isEmpty, pipe } from 'ramda'; import { useEffect } from 'react'; import type { InputProps } from 'reactstrap'; import { Button, DropdownItem, Input, InputGroup, UncontrolledTooltip } from 'reactstrap'; import { DropdownBtn, useToggle } from '../../shlink-frontend-kit/src'; import type { DomainsList } from './reducers/domainsList'; import './DomainSelector.scss'; export interface DomainSelectorProps extends Omit { value?: string; onChange: (domain: string) => void; } interface DomainSelectorConnectProps extends DomainSelectorProps { listDomains: Function; domainsList: DomainsList; } export const DomainSelector = ({ listDomains, value, domainsList, onChange }: DomainSelectorConnectProps) => { const [inputDisplayed,, showInput, hideInput] = useToggle(); const { domains } = domainsList; const valueIsEmpty = isEmpty(value); const unselectDomain = () => onChange(''); useEffect(() => { listDomains(); }, []); return inputDisplayed ? ( onChange(e.target.value)} /> Existing domains ) : ( {domains.map(({ domain, isDefault }) => ( onChange(domain)} > {domain} {isDefault && default} ))} New domain ); };