import { createFormControl, createFormGroup } from "solid-forms"; import { Trans, useLingui } from "@lingui-solid/solid/macro"; import { Dialog, DialogProps, Form2 } from "@revolt/ui"; import { useModals } from ".."; import { Modals } from "../types"; /** * Add a new friend by username */ export function AddFriendModal( props: DialogProps & Modals & { type: "add_friend" }, ) { const { t } = useLingui(); const { showError } = useModals(); const group = createFormGroup({ username: createFormControl("", { required: true }), }); async function onSubmit() { try { await props.client.api.post(`/users/friend`, { username: group.controls.username.value, }); props.onClose(); } catch (error) { showError(error); } } const submit = Form2.useSubmitHandler(group, onSubmit); return ( Add a new friend} actions={[ { text: Close }, { text: Send Request, onClick: () => { onSubmit(); return false; }, isDisabled: !Form2.canSubmit(group), }, ]} isDisabled={group.isPending} >
); }