Skip to content

Commit

Permalink
sign up page functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
demuthsa committed May 12, 2024
1 parent 551a993 commit 5b709d9
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 12 deletions.
11 changes: 11 additions & 0 deletions trivia-forge/frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions trivia-forge/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"dependencies": {
"axios": "^1.6.8",
"bootstrap": "^5.3.3",
"node-datetime": "^2.1.2",
"openai": "^4.38.3",
"react": "^18.2.0",
"react-bootstrap": "^2.10.2",
Expand Down
39 changes: 32 additions & 7 deletions trivia-forge/frontend/src/Pages/SignUpPage.jsx
Original file line number Diff line number Diff line change
@@ -1,36 +1,61 @@
import React, { useState } from 'react';
import { useNavigate } from "react-router-dom";
import { Form, Button, Card } from "react-bootstrap";
import { addUser } from '../Services/TF-db_services';

function SignUpPage() {
const [email, setEmail] = useState('');
const [password, setPassword] = useState('');
const [confirmPassword, setConfirmPassword] = useState('');
const navigate = useNavigate();

const handleSubmit = async (event) => {
event.preventDefault();
if (password !== confirmPassword) {
alert('Passwords do not match');
return;
}
const user = {
email: email,
password: password
};
const addedUser = await addUser(user);
if (addedUser) {
alert('User added:', addedUser);
navigate('/');
} else {
console.error('Error adding user');
}
}

return (
<>
<Card style={{ width: '35rem', margin: '0 auto', float: 'none' }}>
<Form className="form-group">
<Form onSubmit={handleSubmit} className="form-group">
<Form.Group className="mb-3" controlId="formBasicEmail">
<Form.Label>Email address</Form.Label>
<Form.Control className="Form-Control" type="email" placeholder="Enter email" />
<Form.Control type="email" placeholder="Enter email" value={email} onChange={(e) => setEmail(e.target.value)} />
<Form.Text className="text-muted">
We'll never share your email with anyone else.
</Form.Text>
</Form.Group>

<Form.Group className="mb-3" controlId="formBasicPassword">
<Form.Label>Password</Form.Label>
<Form.Control type="password" placeholder="Password" />
<Form.Control type="password" placeholder="Password" value={password} onChange={(e) => setPassword(e.target.value)} />
</Form.Group>
<Form.Group className="mb-3" controlId="formBasicPassword">

<Form.Group className="mb-3" controlId="formBasicConfirmPassword">
<Form.Label>Confirm Password</Form.Label>
<Form.Control type="password" placeholder="Confirm Password" />
<Form.Control type="password" placeholder="Confirm Password" value={confirmPassword} onChange={(e) => setConfirmPassword(e.target.value)} />
</Form.Group>

<Button variant="primary" type="submit">
Create Account
</Button>
</Form>
</Card>
</>

);

}
export default SignUpPage;
4 changes: 2 additions & 2 deletions trivia-forge/frontend/src/Pages/TriviaGenPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,12 @@ function TriviaGenPage() {
}
//create a new game and category object and add category to game
let game = new Game(Title, Theme);

for (let i = 0; i < categories.length; i++) {
let newCategory = new Category(categories[i].name);
console.log(newCategory.name);
game.addCategory(newCategory);

//parse response from API
let sections = responses[i]; // store trivia questions
for (let i = 0; i < sections.length; i++) {
Expand Down
6 changes: 3 additions & 3 deletions trivia-forge/frontend/src/Services/TF-db_services.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import axios from 'axios';
import User from '../Models/User';
import Game from '../Models/Game';
import Question from '../Models/Question';
import User from '../Model/User';
import Game from '../Model/Game';
import Question from '../Model/Question';

const API_URL = 'http://localhost:5000/api';

Expand Down

0 comments on commit 5b709d9

Please sign in to comment.