import { Checkbox, Details, Label, LabelledInput, LabelledRevealablePasswordInput, SimpleCard, useToggle, } from '@shlinkio/shlink-frontend-kit'; import type { FC, PropsWithChildren, ReactNode } from 'react'; import { useState } from 'react'; import { usePreventDefault } from '../../utils/utils'; import type { ServerData } from '../data'; type ServerFormProps = PropsWithChildren<{ onSubmit: (server: ServerData) => void; initialValues?: ServerData; title?: ReactNode; }>; export const ServerForm: FC = ({ onSubmit, initialValues, children, title }) => { const [name, setName] = useState(initialValues?.name ?? ''); const [url, setUrl] = useState(initialValues?.url ?? ''); const [apiKey, setApiKey] = useState(initialValues?.apiKey ?? ''); const { flag: forwardCredentials, toggle: toggleForwardCredentials } = useToggle( initialValues?.forwardCredentials ?? false, ); const handleSubmit = usePreventDefault(() => onSubmit({ name, url, apiKey, forwardCredentials })); return (
setName(e.target.value)} required /> setUrl(e.target.value)} required /> setApiKey(e.target.value)} required />
{'"'}Credentials{'"'} here means cookies, TLS client certificates, or authentication headers containing a username and password. Important! If you are not sure what this means, leave it unchecked. Enabling this option will make all requests fail for Shlink older than v4.5.0, as it requires the server to set a more strict value for{' '} Access-Control-Allow-Origin than *.
{children}
); };