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

View File

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

View File

@ -1,3 +1,4 @@
import * as api from "../helpers/api";
import store from "../stores";
import { setGlobalState } from "../stores/modules/global";
import userService from "./userService";
@ -8,15 +9,18 @@ const globalService = {
},
initialState: async () => {
const defaultGlobalState = {};
try {
await userService.initialState();
} catch (error) {
// 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";
type State = {
// do nth
workspaceProfile: WorkspaceProfile;
};
const globalSlice = createSlice({