UNPKG

synapse-react-client

Version:

[![npm version](https://badge.fury.io/js/synapse-react-client.svg)](https://badge.fury.io/js/synapse-react-client) [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettie

96 lines (95 loc) 2.47 kB
import { jsx as a, jsxs as C, Fragment as v } from "react/jsx-runtime"; import { useCreatePortal as x } from "../../synapse-queries/portal/usePortal.js"; import { Alert as y } from "@mui/material"; import { useState as n } from "react"; import { ConfirmationDialog as w } from "../ConfirmationDialog/ConfirmationDialog.js"; import { displayToast as N } from "../ToastMessage/ToastMessage.js"; import c from "../TextField/TextField.js"; function j({ open: p, onClose: f, onSuccess: P }) { const [t, l] = n(""), [o, i] = n(""), [s, r] = n(), { mutate: g, isPending: h } = x({ onSuccess: (e) => { N("Portal created successfully", "success"), m(), P?.(e); }, onError: (e) => { r(e.reason || e.message); } }), m = () => { l(""), i(""), r(void 0), f(); }, u = () => { if (!t.trim()) { r("Portal name is required"); return; } if (!o.trim()) { r("Portal URL is required"); return; } const e = { name: t.trim(), url: o.trim() }; g(e); }, d = (e) => { e.key === "Enter" && t.trim() && o.trim() && u(); }; return /* @__PURE__ */ a( w, { open: p, title: "Create a New Portal", content: /* @__PURE__ */ C(v, { children: [ /* @__PURE__ */ a( c, { id: "portalNameInput", label: "Portal Name", value: t, fullWidth: !0, required: !0, onChange: (e) => { l(e.target.value), r(void 0); }, inputProps: { onKeyDown: d }, sx: { mb: 2 } } ), /* @__PURE__ */ a( c, { id: "portalUrlInput", label: "Portal URL", value: o, fullWidth: !0, required: !0, placeholder: "https://example.synapse.org", onChange: (e) => { i(e.target.value), r(void 0); }, inputProps: { onKeyDown: d } } ), s && /* @__PURE__ */ a(y, { severity: "error", sx: { mt: 2 }, children: s }) ] }), confirmButtonProps: { children: "Create", disabled: h || !t.trim() || !o.trim() }, onConfirm: u, onCancel: m, maxWidth: "sm" } ); } export { j as CreatePortalModal, j as default }; //# sourceMappingURL=CreatePortalModal.js.map