diff --git a/ui100/src/Register.tsx b/ui100/src/Register.tsx index 22c27634..af355ba6 100644 --- a/ui100/src/Register.tsx +++ b/ui100/src/Register.tsx @@ -1,12 +1,19 @@ -import {Box, Button, Checkbox, Container, FormControlLabel, TextField, Typography} from "@mui/material"; +import {Box, Button, Checkbox, Container, FormControlLabel, Grid2, TextField, Typography} from "@mui/material"; import zroket from "./assets/zrok-1.0.0-rocket-purple.svg"; import {useParams} from "react-router"; import {useFormik} from "formik"; import * as Yup from 'yup'; -import {useRef, useState} from "react"; +import {useEffect, useRef, useState} from "react"; +import {AccountApi, MetadataApi} from "./api"; +import ClipboardText from "./ClipboardText.tsx"; -const Register = () => { - const { regToken } = useParams(); +interface SetPasswordFormProps { + email: string; + touLink: string; + register: (v) => void; +} + +const SetPasswordForm = ({ email, touLink, register }: SetPasswordFormProps) => { const [checked, setChecked] = useState(false); const checkedRef = useRef(); checkedRef.current = checked; @@ -19,6 +26,7 @@ const Register = () => { }, onSubmit: v => { console.log(v); + register(v); }, validationSchema: Yup.object({ password: Yup.string() @@ -43,45 +51,193 @@ const Register = () => { }) }); + return ( + +

Welcome to zrok!

+ {email} + + + } label={

I accept the

} sx={{ mt: 2 }} /> + +
+ ); +} + +interface RegistrationCompleteProps { + token: string; +} + +const RegistrationComplete = ({ token }: RegistrationCompleteProps) => { + return ( + + + + +

Registration completed!

+
+
+
+ + + + Your account was created successfully! + + + + + Your new account token is: {token} + + + + + You can create an environment using your account token, like this: + + + + + $ zrok enable {token} + + + + + Your account token is a secret (like a password). + Please do not share it with anyone! + + + + + You can use your new password to log into the console here: + + + + + {window.location.origin} + + + + +

Enjoy zrok!

+
+
+
+
+ ); +} + +const InvalidToken = () => { + return ( + + + +

Invalid registration token?!

+
+
+ + + + Your registration token may have expired! + + + + + Please use the zrok invite command to + generate a new registration request and try again. + + + +
+ ); +} + +const Register = () => { + const { regToken } = useParams(); + const [component, setComponent] = useState(null); + const [error, setError] = useState(false); + const [email, setEmail] = useState(); + const [touLink, setTouLink] = useState(); + + const doRegistration = (v) => { + new AccountApi().register({body: {token: regToken, password: v.password}}) + .then(d => { + console.log(d); + setComponent(); + }) + .catch(e => { + console.log("doRegistration", e); + }); + } + + useEffect(() => { + if(regToken) { + new AccountApi().verify({body: {token: regToken}}) + .then((d) => { + console.log(d); + setEmail(d.email); + }) + .catch(e => { + setError(true); + console.log("error", e); + }); + } + }, [regToken]); + + useEffect(() => { + if(email) { + new MetadataApi()._configuration() + .then(d => { + setTouLink(d.touLink); + }) + .catch(e => { + e.response.json().then(ex => { + console.log("register", ex.message); + }) + }); + } + }, [email]); + + useEffect(() => { + if(!error && email && touLink) { + setComponent(); + } else { + if(error) { + setComponent(); + } + } + }, [touLink, error]); + return ( - +

z r o k

- -

Welcome to zrok!

- - - } label="I accept the Terms of Service" sx={{ mt: 2 }} /> - -
+ {component}