import { Button, Input } from "@mui/joy"; import { useState } from "react"; import { toast } from "react-hot-toast"; import { Link } from "react-router-dom"; import AppearanceSelect from "@/components/AppearanceSelect"; import LocaleSelect from "@/components/LocaleSelect"; import { authServiceClient } from "@/grpcweb"; import useLoading from "@/hooks/useLoading"; import useNavigateTo from "@/hooks/useNavigateTo"; import { useGlobalStore } from "@/store/module"; import { useUserStore } from "@/store/v1"; import { useTranslate } from "@/utils/i18n"; const SignUp = () => { const t = useTranslate(); const navigateTo = useNavigateTo(); const globalStore = useGlobalStore(); const userStore = useUserStore(); const actionBtnLoadingState = useLoading(false); const { appearance, locale, systemStatus, workspaceProfile } = globalStore.state; const [username, setUsername] = useState(""); const [password, setPassword] = useState(""); const handleUsernameInputChanged = (e: React.ChangeEvent) => { const text = e.target.value as string; setUsername(text); }; const handlePasswordInputChanged = (e: React.ChangeEvent) => { const text = e.target.value as string; setPassword(text); }; const handleLocaleSelectChange = (locale: Locale) => { globalStore.setLocale(locale); }; const handleAppearanceSelectChange = (appearance: Appearance) => { globalStore.setAppearance(appearance); }; const handleFormSubmit = (e: React.FormEvent) => { e.preventDefault(); handleSignUpButtonClick(); }; const handleSignUpButtonClick = async () => { if (username === "" || password === "") { return; } if (actionBtnLoadingState.isLoading) { return; } try { actionBtnLoadingState.setLoading(); const { user } = await authServiceClient.signUp({ username, password }); if (user) { await userStore.fetchCurrentUser(); navigateTo("/"); } else { toast.error(t("message.signup-failed")); } } catch (error: any) { console.error(error); toast.error(error.response.data.message || error.message || t("message.signup-failed")); } actionBtnLoadingState.setFinish(); }; return (

{systemStatus.customizedProfile.name}

{t("auth.create-your-account")}

{t("common.username")}
{t("common.password")}
{!workspaceProfile.owner &&

{t("auth.host-tip")}

}

{t("auth.sign-in-tip")} {t("common.sign-in")}

); }; export default SignUp;