Skip to content

Commit 44b0699

Browse files
authored
fix(web): web signup phone err (#935)
* feat(web): login ui * feat: web auth * feat: web auth * chore(web auth): impl i18n and fix code styles * fix: env url * fix: signup phone not show * fix: signup api params
1 parent c35d339 commit 44b0699

File tree

2 files changed

+25
-16
lines changed

2 files changed

+25
-16
lines changed

web/src/pages/auth/signup/index.tsx

+21-16
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useEffect, useState } from "react";
1+
import { useState } from "react";
22
import { useForm } from "react-hook-form";
33
import { useNavigate } from "react-router-dom";
44
import { ViewIcon, ViewOffIcon } from "@chakra-ui/icons";
@@ -33,21 +33,18 @@ type FormData = {
3333
export default function SignUp() {
3434
const signupMutation = useSignupMutation();
3535
const sendSmsCodeMutation = useSendSmsCodeMutation();
36-
36+
const [isNeedPhone, setIsNeedPhone] = useState(false);
3737
const { providers, setProviders } = useAuthStore();
38+
3839
useGetProvidersQuery((data: any) => {
3940
setProviders(data?.data || []);
40-
});
41-
const [isNeedPhone, setIsNeedPhone] = useState(false);
42-
43-
useEffect(() => {
4441
if (providers.length) {
45-
const passwordProvider = providers.find((provider) => provider.type === "user-password");
42+
const passwordProvider = providers.find((provider) => provider.name === "user-password");
4643
if (passwordProvider) {
4744
setIsNeedPhone(passwordProvider.bind?.phone === "required");
4845
}
4946
}
50-
}, [providers]);
47+
});
5148

5249
const { showSuccess, showError } = useGlobalStore();
5350
const navigate = useNavigate();
@@ -78,13 +75,21 @@ export default function SignUp() {
7875
return;
7976
}
8077

81-
const res = await signupMutation.mutateAsync({
82-
phone: data.phone,
83-
code: data.validationCode,
84-
username: data.account,
85-
password: data.password,
86-
type: "Signup",
87-
});
78+
const params = isNeedPhone
79+
? {
80+
phone: data.phone,
81+
code: data.validationCode,
82+
username: data.account,
83+
password: data.password,
84+
type: "Signup",
85+
}
86+
: {
87+
username: data.account,
88+
password: data.password,
89+
type: "Signup",
90+
};
91+
92+
const res = await signupMutation.mutateAsync(params);
8893

8994
if (res?.data) {
9095
showSuccess(t("AuthPanel.SignupSuccess"));
@@ -132,7 +137,7 @@ export default function SignUp() {
132137
};
133138

134139
return (
135-
<div className="bg-white absolute left-1/2 top-1/2 -translate-y-1/2 w-[560px] h-[644px] rounded-[10px] p-[65px]">
140+
<div className="bg-white absolute left-1/2 top-1/2 -translate-y-1/2 w-[560px] rounded-[10px] p-[65px]">
136141
<div className="mb-[45px]">
137142
<img src="/logo.png" alt="logo" width={40} className="mr-4" />
138143
</div>

web/src/routes/index.tsx

+4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const routes = [
1313
{
1414
path: "/login",
1515
element: <AuthLayout />,
16+
auth: false,
1617
children: [
1718
{
1819
path: "/login",
@@ -23,6 +24,7 @@ const routes = [
2324
{
2425
path: "/signup",
2526
element: <AuthLayout />,
27+
auth: false,
2628
children: [
2729
{
2830
path: "/signup",
@@ -36,6 +38,7 @@ const routes = [
3638
{
3739
path: "/",
3840
element: <BasicLayout />,
41+
auth: true,
3942
children: [
4043
{
4144
path: "/",
@@ -46,6 +49,7 @@ const routes = [
4649
{
4750
path: "/app",
4851
element: <FunctionLayout />,
52+
auth: true,
4953
children: [
5054
{
5155
path: "/app/:appid/:pageId/:id?",

0 commit comments

Comments
 (0)