import { createForm } from '@felte/solid' import { validator } from '@felte/validator-zod' import { useNavigate } from '@solidjs/router' import { IconX } from '@tabler/icons-solidjs' import ky from 'ky' import { For } from 'solid-js' import { v4 as uuid } from 'uuid' import { z } from 'zod' import { endpointList, setEndpointList, setSelectedEndpoint } from '~/signals' const schema = z.object({ url: z.string().url().nonempty(), secret: z.string(), }) export default () => { const navigate = useNavigate() const { form } = createForm>({ extend: validator({ schema }), async onSubmit(values) { const { hello } = await ky .get(values.url, { headers: values.secret ? { Authorization: `Bearer ${values.secret}`, } : {}, }) .json<{ hello: string }>() if (!hello) { return } setEndpointList([ { id: uuid(), url: values.url, secret: values.secret, }, ...endpointList(), ]) }, }) const onRemove = (id: string) => setEndpointList(endpointList().filter((e) => e.id !== id)) return (
{({ id, url }) => (
{ setSelectedEndpoint(id) navigate('/') }} > {url}
)}
) }