import { createFormControl, createFormGroup } from "solid-forms"; import { Trans } from "@lingui-solid/solid/macro"; import { useMutation } from "@tanstack/solid-query"; import { Column, Dialog, DialogProps, Form2, Text } from "@revolt/ui"; import { useModals } from ".."; import { Modals } from "../types"; /** * Modal to leave a server */ export function LeaveServerModal( props: DialogProps & Modals & { type: "leave_server" }, ) { const { showError } = useModals(); const group = createFormGroup({ silent: createFormControl(false), }); const leaveServer = useMutation(() => ({ mutationFn: () => props.server.delete(group.controls.silent.value), onError: showError, onSuccess: () => props.onClose(), })); async function onSubmit() { await leaveServer.mutateAsync(); } const submit = Form2.useSubmitHandler(group, onSubmit); return ( Leave {props.server.name}?} actions={[ { text: Cancel }, { text: Leave, onClick: () => { onSubmit(); return false; }, }, ]} isDisabled={leaveServer.isPending} >
You won't be able to rejoin unless you are re-invited. Don't notify others that you've left
); }