UNPKG

@codesandbox/api

Version:
50 lines 4.21 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SSO = void 0; const jsx_runtime_1 = require("preact/jsx-runtime"); const hooks_1 = require("preact/hooks"); function SSO({ changeSignInMode, onValidInitialize, getSSORedirectUrl, }) { const [validation, setValidation] = (0, hooks_1.useState)({ state: "IDLE", }); return ((0, jsx_runtime_1.jsxs)("div", { class: "csb-api-gDXMLZ csb-api-iaWCwi", style: { opacity: 1 }, children: [(0, jsx_runtime_1.jsx)("h1", { class: "csb-api-gDXMLZ csb-api-efjlMo csb-api-gHixVw", id: "heading", children: "Sign in with SSO" }), (0, jsx_runtime_1.jsxs)("form", { class: "csb-api-gDXMLZ csb-api-bsZwCf csb-api-iPhhHK", onSubmit: async (e) => { var _a; e.preventDefault(); const formData = new FormData(e.target); const email = (_a = formData.get("email")) === null || _a === void 0 ? void 0 : _a.toString(); if (!email) { return; } if (!email) { return; } setValidation({ state: "VALIDATING" }); try { const redirectUrl = await getSSORedirectUrl(email); onValidInitialize(redirectUrl); setValidation({ state: "VALID" }); } catch (err) { setValidation({ state: "INVALID", error: String(err) }); } }, children: [(0, jsx_runtime_1.jsxs)("div", { class: "csb-api-gDXMLZ csb-api-fygrRn", children: [(0, jsx_runtime_1.jsxs)("div", { class: "csb-api-gDXMLZ csb-api-bSzsUN", children: [(0, jsx_runtime_1.jsx)("input", { "aria-describedby": "error", "aria-labelledby": "heading", class: "csb-api-gDXMLZ csb-api-CmLhy csb-api-ejERkE", disabled: validation.state !== "IDLE", name: "email", placeholder: "Enter your email", type: "email", required: true }), (0, jsx_runtime_1.jsx)("div", { class: "csb-api-gDXMLZ csb-api-jWVHRd", children: /* { VALID: <Icon css={{ color: '#B3FBB4' }} name="simpleCheck" />, INVALID: ( <Icon css={{ color: '#ED6C6C' }} name="infoOutline" /> ), }[validation.state] } */ { VALID: null, INVALID: null, IDLE: null, VALIDATING: null, }[validation.state] })] }), (0, jsx_runtime_1.jsx)("div", { "aria-live": "polite", class: "csb-api-gDXMLZ", id: "error", children: validation.state === "INVALID" ? ((0, jsx_runtime_1.jsx)("span", { class: "csb-api-gDXMLZ csb-api-efjlMo csb-api-gFehFv", children: changeSignInMode ? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: ["Request failed with status code 422. Please contact your team admin or", " ", (0, jsx_runtime_1.jsx)("button", { class: "csb-api-hjGqFO csb-api-eYNxpT", onClick: changeSignInMode, type: "button", children: "sign in through a different method" }), "."] })) : ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: "Request failed with status code 422. Please contact your team admin." })) })) : null })] }), (0, jsx_runtime_1.jsx)("button", { class: "csb-api-gFUkTC csb-api-iMjrFU csb-api-fWRCGd", disabled: validation.state !== "IDLE", type: "submit", children: (0, jsx_runtime_1.jsx)("span", { class: "csb-api-gDXMLZ csb-api-bGdKhk csb-api-cIOuzf", children: ["VALIDATING", "VALID"].includes(validation.state) ? "Signin in..." : "Continue with SSO" }) })] })] })); } exports.SSO = SSO; //# sourceMappingURL=SSO.js.map