@codesandbox/api
Version:
The CodeSandbox API
46 lines • 3.85 kB
JavaScript
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "preact/jsx-runtime";
import { useState } from "preact/hooks";
export function SSO({ changeSignInMode, onValidInitialize, getSSORedirectUrl, }) {
const [validation, setValidation] = useState({
state: "IDLE",
});
return (_jsxs("div", { class: "csb-api-gDXMLZ csb-api-iaWCwi", style: { opacity: 1 }, children: [_jsx("h1", { class: "csb-api-gDXMLZ csb-api-efjlMo csb-api-gHixVw", id: "heading", children: "Sign in with SSO" }), _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: [_jsxs("div", { class: "csb-api-gDXMLZ csb-api-fygrRn", children: [_jsxs("div", { class: "csb-api-gDXMLZ csb-api-bSzsUN", children: [_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 }), _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] })] }), _jsx("div", { "aria-live": "polite", class: "csb-api-gDXMLZ", id: "error", children: validation.state === "INVALID" ? (_jsx("span", { class: "csb-api-gDXMLZ csb-api-efjlMo csb-api-gFehFv", children: changeSignInMode ? (_jsxs(_Fragment, { children: ["Request failed with status code 422. Please contact your team admin or", " ", _jsx("button", { class: "csb-api-hjGqFO csb-api-eYNxpT", onClick: changeSignInMode, type: "button", children: "sign in through a different method" }), "."] })) : (_jsx(_Fragment, { children: "Request failed with status code 422. Please contact your team admin." })) })) : null })] }), _jsx("button", { class: "csb-api-gFUkTC csb-api-iMjrFU csb-api-fWRCGd", disabled: validation.state !== "IDLE", type: "submit", children: _jsx("span", { class: "csb-api-gDXMLZ csb-api-bGdKhk csb-api-cIOuzf", children: ["VALIDATING", "VALID"].includes(validation.state)
? "Signin in..."
: "Continue with SSO" }) })] })] }));
}
//# sourceMappingURL=SSO.js.map