Merge pull request #43 from exstake/hide-pages-to-unauthenticated-user

hide pages from unauthenticated users
This commit is contained in:
João Geonizeli
2021-09-06 09:42:37 -03:00
committed by GitHub
4 changed files with 41 additions and 21 deletions

View File

@@ -2,14 +2,19 @@ import type { FC } from "react";
import React from "react";
import { Switch, Route } from "react-router-dom";
import { useCurrentUser } from "./contexts/UserProvider";
import { Dashbaord, Home, Orders, Wallet } from "./pages";
export const Routes: FC = () => {
const { isAuthenticated } = useCurrentUser();
return (
<Switch>
<Route exact path="/">
<Home />
</Route>
{isAuthenticated && (
<>
<Route exact path="/dashboard">
<Dashbaord />
</Route>
@@ -25,6 +30,8 @@ export const Routes: FC = () => {
<Route exact path="/orders/deposit">
<Orders.Deposit />
</Route>
</>
)}
</Switch>
);
};

View File

@@ -1,5 +1,6 @@
import * as React from "react";
import { MenuIcon } from "@heroicons/react/outline";
import cs from "classnames";
import XStakeLogo from "../../assets/images/logo.png";
import { useApp } from "../../contexts/AppProvider";
@@ -9,13 +10,12 @@ const linkStyles =
"cursor-pointer bg-transparent hover:bg-gray-100 h-full px-4 font-bold flex items-center";
export const Navbar = () => {
const { isAuthenticated } = useCurrentUser();
const { setSideNavExpanded } = useApp();
const handleExpandSideNav = () => {
setSideNavExpanded((prevState) => !prevState);
};
const { isAuthenticated } = useCurrentUser();
const csrfToken =
document
.querySelector('meta[name="csrf-token"]')
@@ -24,7 +24,10 @@ export const Navbar = () => {
return (
<nav className="w-full h-16 flex bg-white shadow items-center px-4 space-x-2 z-50">
<button
className="w-12 mr-2 md:w-10 h-12 md:h-10 xl:hidden fixed md:relative bottom-8 md:bottom-auto right-8 md:right-auto bg-white rounded-full p-3 md:p-0 shadow md:shadow-none"
className={cs(
"w-12 mr-2 md:w-10 h-12 md:h-10 xl:hidden fixed md:relative bottom-8 md:bottom-auto right-8 md:right-auto bg-white rounded-full p-3 md:p-0 shadow md:shadow-none",
isAuthenticated ? "" : "hidden"
)}
onClick={() => handleExpandSideNav()}
>
<MenuIcon />

View File

@@ -4,6 +4,7 @@ import { Transition } from "@headlessui/react";
import cs from "classnames";
import { useApp } from "../../contexts/AppProvider";
import { useCurrentUser } from "../../contexts/UserProvider";
type MenuItem = {
label: string;
@@ -38,6 +39,7 @@ const MenuItems: MenuItem[] = [
];
export const SideNav = () => {
const { isAuthenticated } = useCurrentUser();
const { sideNavExpanded, setSideNavExpanded } = useApp();
const location = useLocation();
@@ -51,6 +53,8 @@ export const SideNav = () => {
}
};
if (!isAuthenticated) return null;
return (
<>
<Transition

View File

@@ -6,6 +6,7 @@ import { useRelayEnvironment } from "react-relay";
import { Button, Modal } from "../../../components";
import { commitCreateStakeOrderMutation } from "./createStakeOrder";
import { Input } from "../../../components/Input/Input";
import { useCurrentUser } from "../../../contexts/UserProvider";
type Props = {
poolName: string;
@@ -14,6 +15,7 @@ type Props = {
export const StakeOrderModal: FC<Props> = ({ poolName, balance }) => {
const environment = useRelayEnvironment();
const { isAuthenticated } = useCurrentUser();
const [isOpen, setIsOpen] = useState(false);
const [investAmountInput, setInvestAmountInput] = useState("0");
@@ -21,7 +23,11 @@ export const StakeOrderModal: FC<Props> = ({ poolName, balance }) => {
const investAmount = new BigNumber(investAmountInput);
const handleButtonClick = () => {
if (!isAuthenticated) {
window.location.href = "/users/sign_in";
} else {
setIsOpen((prevState) => !prevState);
}
};
const onSubmit = () => {
@@ -59,7 +65,7 @@ export const StakeOrderModal: FC<Props> = ({ poolName, balance }) => {
type="button"
className="py-2 px-4 text-blue-600 border-2 border-blue-600 hover:bg-blue-100 w-full transition ease-in duration-200 text-center text-base font-semibold shadow-md rounded-lg "
>
Stake
Investir
</button>
<Modal
isOpen={isOpen}
@@ -87,7 +93,7 @@ export const StakeOrderModal: FC<Props> = ({ poolName, balance }) => {
<span className="text-red-500 mb-1">Você não possuí saldo.</span>
)}
<Button disabled={!stakeAvaliable} type="submit">
Fazer Stake
Investir
</Button>
</form>
</Modal>