Skip to content

Commit

Permalink
Updated Register Page Design
Browse files Browse the repository at this point in the history
  • Loading branch information
TPH777 committed Jul 25, 2024
1 parent d1af53f commit 73d35b7
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 36 deletions.
2 changes: 1 addition & 1 deletion src/pages/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export const LoginPage = () => {
height="30"
className="d-inline-block align-top me-2"
/>
{authenticating ? "Signing In..." : "Google Sign In (Consumer)"}
{authenticating ? "Signing In..." : "Google Sign In for Consumers"}
</button>
</div>

Expand Down
115 changes: 80 additions & 35 deletions src/pages/Register.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import { useState } from "react";
import { Link, useNavigate } from "react-router-dom";
import ErrorText from "../components/ErrorText";
import { auth, db } from "../config/firebase";
import { createUserWithEmailAndPassword, updateProfile } from "firebase/auth";
import { auth, db, googleProvider } from "../config/firebase";
import {
createUserWithEmailAndPassword,
signInWithPopup,
updateProfile,
} from "firebase/auth";
import { ButtonGroup, ToggleButton } from "react-bootstrap";
import { doc, setDoc } from "firebase/firestore";

Expand Down Expand Up @@ -59,25 +63,88 @@ export const RegisterPage = () => {
});
};

const googleSignIn = async () => {
setRegistering(true);
await signInWithPopup(auth, googleProvider)
.then(async (userCredential) => {
const user = userCredential.user;
if (!doc(db, "consumer", user.uid)) {
// Document don't exist (New user)
await setDoc(doc(db, "consumer", user.uid), {});
}
navigate("/");
})
.catch((error) => {
setRegistering(false);
setError(error.message);
});
};

return (
<form
onSubmit={(e) => {
e.preventDefault();
signUpWithEmailAndPassword();
}}
>
<div className="d-grid gap-2 mb-4">
<ButtonGroup>
<ToggleButton
id="post-checked"
type="radio"
variant={"outline-success"}
value={1}
checked={isConsumer === true}
onChange={() => setIsConsumer(true)}
>
Consumer
</ToggleButton>
<ToggleButton
id="post-unchecked"
type="radio"
variant={"outline-dark"}
value={2}
checked={isConsumer === false}
onChange={() => setIsConsumer(false)}
>
Business
</ToggleButton>
</ButtonGroup>
</div>

<div className="form-outline mb-4">
<label>Name</label>
<input
type="text"
name="name"
id="name"
placeholder="Name"
className="form-control"
required
value={name}
onChange={(e) => setName(e.target.value)}
/>
{isConsumer ? (
<>
<button
onClick={googleSignIn}
disabled={registering}
className="btn btn-dark ms-3"
>
<img
src="/pictures/google-logo.png"
alt="logo"
width="30"
height="30"
className="d-inline-block align-top me-2"
/>
{registering ? "Registering..." : "Register with Google"}
</button>
</>
) : (
<>
<label>Name</label>
<input
type="text"
name="name"
id="name"
placeholder="Name"
className="form-control"
required
value={name}
onChange={(e) => setName(e.target.value)}
/>
</>
)}
</div>

<div className="form-outline mb-4">
Expand Down Expand Up @@ -124,28 +191,6 @@ export const RegisterPage = () => {
/>
</div>
<div className="mb-4">
<ButtonGroup>
<ToggleButton
id="post-checked"
type="radio"
variant={"outline-success"}
value={1}
checked={isConsumer === true}
onChange={() => setIsConsumer(true)}
>
Consumer
</ToggleButton>
<ToggleButton
id="post-unchecked"
type="radio"
variant={"outline-dark"}
value={2}
checked={isConsumer === false}
onChange={() => setIsConsumer(false)}
>
Business
</ToggleButton>
</ButtonGroup>
<button
disabled={registering}
type="submit"
Expand Down

0 comments on commit 73d35b7

Please sign in to comment.