import { createFormControl, createFormGroup } from "solid-forms"; import { Trans, useLingui } from "@lingui-solid/solid/macro"; import { useNavigate } from "@revolt/routing"; import { Column, Dialog, DialogProps, Form2, Text } from "@revolt/ui"; import { useModals } from ".."; import { Modals } from "../types"; /** * Modal to create a new server */ export function CreateServerModal( props: DialogProps & Modals & { type: "create_server" }, ) { const { t } = useLingui(); const navigate = useNavigate(); const { showError } = useModals(); const group = createFormGroup({ name: createFormControl("", { required: true }), }); async function onSubmit() { try { const server = await props.client.servers.createServer({ name: group.controls.name.value, }); setTimeout(() => navigate(`/server/${server.id}`)); props.onClose(); } catch (error) { showError(error); } } const submit = Form2.useSubmitHandler(group, onSubmit); return ( Create server} actions={[ { text: Close }, { text: Create, onClick: () => { onSubmit(); return false; }, isDisabled: !Form2.canSubmit(group), }, ]} isDisabled={group.isPending} >
By creating this server, you agree to the{" "} Acceptable Use Policy .
); }