chore: hide sign up button when disabled

This commit is contained in:
Steven 2023-06-26 22:35:12 +08:00
parent d46df916cf
commit 106cdfa7da
4 changed files with 46 additions and 11 deletions

View File

@ -4,11 +4,15 @@ import { Link, useNavigate } from "react-router-dom";
import { toast } from "react-hot-toast"; import { toast } from "react-hot-toast";
import * as api from "../helpers/api"; import * as api from "../helpers/api";
import { userService } from "../services"; import { userService } from "../services";
import { useAppSelector } from "../stores";
import useLoading from "../hooks/useLoading"; import useLoading from "../hooks/useLoading";
import Icon from "../components/Icon"; import Icon from "../components/Icon";
const SignIn: React.FC = () => { const SignIn: React.FC = () => {
const navigate = useNavigate(); const navigate = useNavigate();
const {
workspaceProfile: { disallowSignUp },
} = useAppSelector((state) => state.global);
const [email, setEmail] = useState(""); const [email, setEmail] = useState("");
const [password, setPassword] = useState(""); const [password, setPassword] = useState("");
const actionBtnLoadingState = useLoading(false); const actionBtnLoadingState = useLoading(false);
@ -91,12 +95,14 @@ const SignIn: React.FC = () => {
</Button> </Button>
</div> </div>
</form> </form>
<p className="w-full mt-4 text-sm"> {!disallowSignUp && (
<span>{"Don't have an account yet?"}</span> <p className="w-full mt-4 text-sm">
<Link to="/auth/signup" className="cursor-pointer ml-2 text-blue-600 hover:underline"> <span>{"Don't have an account yet?"}</span>
Sign up <Link to="/auth/signup" className="cursor-pointer ml-2 text-blue-600 hover:underline">
</Link> Sign up
</p> </Link>
</p>
)}
</div> </div>
</div> </div>
</div> </div>

View File

@ -1,6 +1,6 @@
import { createBrowserRouter, redirect } from "react-router-dom"; import { createBrowserRouter, redirect } from "react-router-dom";
import { isNullorUndefined } from "../helpers/utils"; import { isNullorUndefined } from "../helpers/utils";
import { userService } from "../services"; import { globalService, userService } from "../services";
import Root from "../layouts/Root"; import Root from "../layouts/Root";
import SignIn from "../pages/SignIn"; import SignIn from "../pages/SignIn";
import SignUp from "../pages/SignUp"; import SignUp from "../pages/SignUp";
@ -11,10 +11,35 @@ const router = createBrowserRouter([
{ {
path: "/auth", path: "/auth",
element: <SignIn />, element: <SignIn />,
loader: async () => {
try {
await globalService.initialState();
} catch (error) {
// do nth
}
return null;
},
}, },
{ {
path: "/auth/signup", path: "/auth/signup",
element: <SignUp />, element: <SignUp />,
loader: async () => {
try {
await globalService.initialState();
} catch (error) {
// do nth
}
const {
workspaceProfile: { disallowSignUp },
} = globalService.getState();
if (disallowSignUp) {
return redirect("/auth");
}
return null;
},
}, },
{ {
path: "/", path: "/",

View File

@ -1,3 +1,4 @@
import * as api from "../helpers/api";
import store from "../stores"; import store from "../stores";
import { setGlobalState } from "../stores/modules/global"; import { setGlobalState } from "../stores/modules/global";
import userService from "./userService"; import userService from "./userService";
@ -8,15 +9,18 @@ const globalService = {
}, },
initialState: async () => { initialState: async () => {
const defaultGlobalState = {};
try { try {
await userService.initialState(); await userService.initialState();
} catch (error) { } catch (error) {
// do nth // do nth
} }
store.dispatch(setGlobalState(defaultGlobalState)); try {
const workspaceProfile = (await api.getWorkspaceProfile()).data;
store.dispatch(setGlobalState({ workspaceProfile }));
} catch (error) {
// do nth
}
}, },
}; };

View File

@ -1,7 +1,7 @@
import { createSlice, PayloadAction } from "@reduxjs/toolkit"; import { createSlice, PayloadAction } from "@reduxjs/toolkit";
type State = { type State = {
// do nth workspaceProfile: WorkspaceProfile;
}; };
const globalSlice = createSlice({ const globalSlice = createSlice({