import { InputFormGroup, SimpleCard } from '@shlinkio/shlink-frontend-kit'; import type { FC, PropsWithChildren, ReactNode } from 'react'; import { useEffect, useState } from 'react'; import { handleEventPreventingDefault } 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(''); const [url, setUrl] = useState(''); const [apiKey, setApiKey] = useState(''); const handleSubmit = handleEventPreventingDefault(() => onSubmit({ name, url, apiKey })); useEffect(() => { if (initialValues) { setName(initialValues.name); setUrl(initialValues.url); setApiKey(initialValues.apiKey); } }, [initialValues]); return (
Name URL API key
{children}
); };