Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

S24/daniel/changing login and landing page #20

Merged
merged 3 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Login from "./components/auth/Login";
import Signup from "./components/auth/Signup";
import PrivateRoute from "./components/auth/PrivateRoute";
import CreatePage from "./components/pages/CreatePage";
import Default from "./components/pages/Default";
import LandingPage from "./components/pages/LandingPage";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's name this to PetListPage

import DisplayPage from "./components/pages/DisplayPage";
import SimpleEntityCreatePage from "./components/pages/SimpleEntityCreatePage";
import SimpleEntityDisplayPage from "./components/pages/SimpleEntityDisplayPage";
Expand Down Expand Up @@ -55,7 +55,11 @@ const App = (): React.ReactElement => {
<Switch>
<Route exact path={Routes.LOGIN_PAGE} component={Login} />
<Route exact path={Routes.SIGNUP_PAGE} component={Signup} />
<PrivateRoute exact path={Routes.HOME_PAGE} component={Default} />
<PrivateRoute
exact
path={Routes.HOME_PAGE}
component={LandingPage}
/>
<PrivateRoute
exact
path={Routes.CREATE_ENTITY_PAGE}
Expand Down
54 changes: 2 additions & 52 deletions frontend/src/components/auth/Login.tsx
Original file line number Diff line number Diff line change
@@ -1,45 +1,20 @@
import React, { useContext, useState } from "react";
import { Redirect, useHistory } from "react-router-dom";
import {
GoogleLogin,
GoogleLoginResponse,
GoogleLoginResponseOffline,
} from "react-google-login";
import { Redirect } from "react-router-dom";

import authAPIClient from "../../APIClients/AuthAPIClient";
import { HOME_PAGE, SIGNUP_PAGE } from "../../constants/Routes";
import { HOME_PAGE } from "../../constants/Routes";
import AuthContext from "../../contexts/AuthContext";
import { AuthenticatedUser } from "../../types/AuthTypes";

type GoogleResponse = GoogleLoginResponse | GoogleLoginResponseOffline;

type GoogleErrorResponse = {
error: string;
details: string;
};

const Login = (): React.ReactElement => {
const { authenticatedUser, setAuthenticatedUser } = useContext(AuthContext);
const [email, setEmail] = useState("");
const [password, setPassword] = useState("");
const history = useHistory();

const onLogInClick = async () => {
const user: AuthenticatedUser = await authAPIClient.login(email, password);
setAuthenticatedUser(user);
};

const onSignUpClick = () => {
history.push(SIGNUP_PAGE);
};

const onGoogleLoginSuccess = async (tokenId: string) => {
const user: AuthenticatedUser = await authAPIClient.loginWithGoogle(
tokenId,
);
setAuthenticatedUser(user);
};

if (authenticatedUser) {
return <Redirect to={HOME_PAGE} />;
}
Expand Down Expand Up @@ -73,32 +48,7 @@ const Login = (): React.ReactElement => {
Log In
</button>
</div>
<GoogleLogin
clientId={process.env.REACT_APP_OAUTH_CLIENT_ID || ""}
buttonText="Login with Google"
onSuccess={(response: GoogleResponse): void => {
if ("tokenId" in response) {
onGoogleLoginSuccess(response.tokenId);
} else {
// eslint-disable-next-line no-alert
window.alert(response);
}
}}
onFailure={(error: GoogleErrorResponse) =>
// eslint-disable-next-line no-alert
window.alert(JSON.stringify(error))
}
/>
</form>
<div>
<button
className="btn btn-primary"
type="button"
onClick={onSignUpClick}
>
Sign Up
</button>
</div>
</div>
);
};
Expand Down
11 changes: 11 additions & 0 deletions frontend/src/components/pages/LandingPage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import React from "react";

const GetPage = (): React.ReactElement => {
return (
<div style={{ textAlign: "center", width: "25%", margin: "0px auto" }}>
<h1>Pets</h1>
</div>
);
};

export default GetPage;
Loading