import * as React from 'react' import { Button, Dialog, TextField } from "mdui" import MainSharedContext from '../MainSharedContext' import showSnackbar from '../../utils/showSnackbar' import showCircleProgressDialog from '../showCircleProgressDialog' import getClient from '../../getClient' import performAuth from '../../performAuth' export default function RegisterDialog({ ...props }: { open: boolean } & React.HTMLAttributes) { const shared = React.useContext(MainSharedContext) const registerInputUserNameRef = React.useRef(null) const registerInputNickNameRef = React.useRef(null) const registerInputPasswordRef = React.useRef(null) return (
shared.setShowRegisterDialog(false)}>返回 { const waitingForRegister = showCircleProgressDialog("注册中...") const username = registerInputUserNameRef.current!.value let user_id: string try { user_id = await getClient().registerOrThrow({ username: username, nickname: registerInputNickNameRef.current!.value, password: registerInputPasswordRef.current!.value, }) } catch (e) { user_id = '' if (e instanceof Error) { waitingForRegister.open = false showSnackbar({ message: '注册失败: ' + e.message }) return } } waitingForRegister.open = false const waitingForLogin = showCircleProgressDialog("登录中...") try { await performAuth({ account: username == '' ? username : user_id, password: registerInputPasswordRef.current!.value, }) location.reload() } catch (e) { if (e instanceof Error) { showSnackbar({ message: '登录失败: ' + e.message }) } } waitingForLogin.open = false }}>注册
) }