-
Notifications
You must be signed in to change notification settings - Fork 0
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
Create team page #3
Changes from all commits
4376985
1301294
0ac8973
dd5a361
f832f32
74abcae
05b279e
5d29570
68b49b4
cb3657d
3be41e3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -134,3 +134,5 @@ dist | |
|
||
# IDE files | ||
.idea | ||
|
||
packages/client/build |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
.create-team { | ||
max-width: 600px; | ||
margin: 0 auto; | ||
padding: 20px; | ||
border: 1px solid #ccc; | ||
border-radius: 5px; | ||
background-color: #f9f9f9; | ||
} | ||
|
||
h1 { | ||
font-size: 24px; | ||
margin-bottom: 20px; | ||
} | ||
|
||
h2 { | ||
font-size: 20px; | ||
margin-top: 30px; | ||
margin-bottom: 10px; | ||
} | ||
|
||
form { | ||
margin-bottom: 20px; | ||
} | ||
|
||
label { | ||
font-weight: bold; | ||
} | ||
|
||
input[type='text'], | ||
input[type='email'], | ||
select { | ||
width: 100%; | ||
padding: 10px; | ||
margin-bottom: 10px; | ||
border: 1px solid #ccc; | ||
border-radius: 5px; | ||
} | ||
|
||
button { | ||
padding: 10px 20px; | ||
margin-top: 10px; | ||
border: none; | ||
border-radius: 5px; | ||
background-color: #007bff; | ||
color: #fff; | ||
cursor: pointer; | ||
margin-right: 10px; | ||
} | ||
|
||
button:first-child { | ||
margin-right: 0; | ||
} | ||
|
||
button:hover { | ||
background-color: #0056b3; | ||
} | ||
|
||
ul { | ||
list-style: none; | ||
padding: 0; | ||
} | ||
|
||
li { | ||
margin-bottom: 10px; | ||
} | ||
|
||
li button { | ||
margin-left: 10px; | ||
padding: 5px 10px; | ||
background-color: #dc3545; | ||
color: #fff; | ||
border: none; | ||
border-radius: 5px; | ||
cursor: pointer; | ||
} | ||
|
||
li button:hover { | ||
background-color: #c82333; | ||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,177 @@ | ||||||
import React, { useState } from 'react'; | ||||||
import './CreateTeam.css'; | ||||||
|
||||||
function CreateTeam() { | ||||||
const [teamName, setTeamName] = useState(''); | ||||||
const [firstName, setFirstName] = useState(''); | ||||||
const [lastName, setLasttName] = useState(''); | ||||||
const [email, setEmail] = useState(''); | ||||||
const [teamMembers, setTeamMembers] = useState([]); | ||||||
const [employees] = useState([ | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could just do it like this:
Suggested change
|
||||||
{ id: 1, firstName: 'John', lastName: 'Doe', email: '[email protected]' }, | ||||||
{ id: 2, firstName: 'Jane', lastName: 'Smith', email: '[email protected]' }, | ||||||
{ | ||||||
id: 3, | ||||||
firstName: 'Alice', | ||||||
lastName: 'Johnson', | ||||||
email: '[email protected]', | ||||||
}, | ||||||
]); | ||||||
|
||||||
const handleInputChange = (inputType, e) => { | ||||||
if (inputType === 'firstNameInput') { | ||||||
setFirstName(e.target.value); | ||||||
} else if (inputType === 'lastNameInput') { | ||||||
setLasttName(e.target.value); | ||||||
} else if (inputType === 'emailInput') { | ||||||
setEmail(e.target.value); | ||||||
} | ||||||
}; | ||||||
|
||||||
const handleSubmit = (event) => { | ||||||
event.preventDefault(); | ||||||
|
||||||
if (!teamMembers.length) { | ||||||
// eslint-disable-next-line no-alert | ||||||
alert('Please add at least one member to the team.'); | ||||||
} | ||||||
}; | ||||||
|
||||||
const handleAddNewMember = () => { | ||||||
const existingTeamMember = teamMembers.find( | ||||||
(member) => member.email === email, | ||||||
); | ||||||
|
||||||
if (existingTeamMember) { | ||||||
// eslint-disable-next-line no-alert | ||||||
alert('The member already exist in the team'); | ||||||
return; | ||||||
} | ||||||
|
||||||
if (!firstName || !lastName || !email) { | ||||||
// eslint-disable-next-line no-alert | ||||||
alert('Please input first name, last name & email'); | ||||||
} else { | ||||||
const newMember = { | ||||||
id: null, | ||||||
firstName, | ||||||
lastName, | ||||||
email, | ||||||
}; | ||||||
|
||||||
teamMembers.push(newMember); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When adding new members to the team, you directly manipulate the DOM with |
||||||
|
||||||
setTeamMembers([...teamMembers]); | ||||||
setFirstName(''); | ||||||
setLasttName(''); | ||||||
setEmail(''); | ||||||
} | ||||||
}; | ||||||
|
||||||
const addExcistingMember = (e) => { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Check for typo |
||||||
const existingTeamMember = teamMembers.find( | ||||||
(member) => member.email === e.target.value, | ||||||
); | ||||||
|
||||||
if (existingTeamMember) { | ||||||
// eslint-disable-next-line no-alert | ||||||
alert('The member already exist in the team'); | ||||||
} else { | ||||||
const memeber = employees.find( | ||||||
(member) => member.email === e.target.value, | ||||||
); | ||||||
|
||||||
teamMembers.push(memeber); | ||||||
setTeamMembers([...teamMembers]); | ||||||
} | ||||||
}; | ||||||
|
||||||
const handleDelete = (emailToDelete) => { | ||||||
const newTeamMembers = teamMembers.filter( | ||||||
(member) => member.email !== emailToDelete, | ||||||
); | ||||||
|
||||||
setTeamMembers(newTeamMembers); | ||||||
}; | ||||||
|
||||||
return ( | ||||||
<div className="create-team"> | ||||||
<h1>Create New Team</h1> | ||||||
<form onSubmit={handleSubmit}> | ||||||
<label>Team Name</label> | ||||||
<input | ||||||
type="text" | ||||||
name="teamName" | ||||||
placeholder="Team Name" | ||||||
value={teamName} | ||||||
onChange={(e) => setTeamName(e.target.value)} | ||||||
required | ||||||
/> | ||||||
|
||||||
<button type="submit">Create Team</button> | ||||||
<br /> | ||||||
<h2>Members</h2> | ||||||
<br /> | ||||||
|
||||||
<div> | ||||||
<label>First Name</label> | ||||||
<input | ||||||
type="text" | ||||||
name="firstName" | ||||||
placeholder="First Name" | ||||||
value={firstName} | ||||||
onChange={(e) => handleInputChange('firstNameInput', e)} | ||||||
/> | ||||||
<label>Last Name</label> | ||||||
<input | ||||||
type="text" | ||||||
name="lastName" | ||||||
placeholder="Last Name" | ||||||
value={lastName} | ||||||
onChange={(e) => handleInputChange('lastNameInput', e)} | ||||||
/> | ||||||
<br /> | ||||||
<label>Email</label> | ||||||
<input | ||||||
type="email" | ||||||
name="email" | ||||||
placeholder="Email" | ||||||
value={email} | ||||||
onChange={(e) => handleInputChange('emailInput', e)} | ||||||
/> | ||||||
<br /> | ||||||
</div> | ||||||
<label>Select an employee</label> | ||||||
<select onChange={(e) => addExcistingMember(e)}> | ||||||
<option value="">Select an existing employee</option> | ||||||
{employees.map((employee) => ( | ||||||
<option key={employee.id} value={employee.email}> | ||||||
{employee.firstName} {employee.lastName} | ||||||
</option> | ||||||
))} | ||||||
</select> | ||||||
<button type="button" onClick={handleAddNewMember}> | ||||||
Add Member | ||||||
</button> | ||||||
|
||||||
<p>Team Secret Code:</p> | ||||||
</form> | ||||||
|
||||||
<div> | ||||||
<h2>Team Members</h2> | ||||||
<ul> | ||||||
{teamMembers.map((member) => ( | ||||||
<li key={member.email}> | ||||||
{member.firstName} {member.lastName} - {member.email} | ||||||
<button type="button" onClick={() => handleDelete(member.email)}> | ||||||
x | ||||||
</button> | ||||||
</li> | ||||||
))} | ||||||
</ul> | ||||||
</div> | ||||||
</div> | ||||||
); | ||||||
} | ||||||
|
||||||
export default CreateTeam; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// const mysql = require('mysql'); | ||
|
||
// const con = mysql.createConnection({ | ||
// host: "localhost", | ||
// user: "yourusername", | ||
// password: "yourpassword", | ||
// database: "mydb" | ||
// }); | ||
|
||
// const connectToDatabase = () => { | ||
// con.connect((err) => { | ||
// if (err) { | ||
// setTimeout(connectToDatabase, 2000); // try to reconnect every 2 seconds | ||
// } else { | ||
// // console.log("Connected to database!"); | ||
// } | ||
// }); | ||
|
||
// con.on('error', (err) => { | ||
// if(err.code === 'PROTOCOL_CONNECTION_LOST') { | ||
// connectToDatabase(); | ||
// } else { | ||
// throw err; | ||
// } | ||
// }); | ||
// } | ||
|
||
// connectToDatabase(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this file commented out? |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,8 @@ module.exports = { | |
directory: path.join(__dirname, '/seeds/development'), | ||
}, | ||
}, | ||
// Existing code... | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ?? |
||
|
||
production: { | ||
client: 'mysql2', | ||
connection: { | ||
|
@@ -26,6 +28,9 @@ module.exports = { | |
database: process.env.MYSQL_DATABASE, | ||
}, | ||
pool: { min: 0, max: 7 }, | ||
migrations: { | ||
directory: path.join(__dirname, '/migrations'), | ||
}, | ||
seeds: { | ||
directory: path.join(__dirname, '/seeds/production'), | ||
}, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/** | ||
* @param { import("knex").Knex } knex | ||
* @returns { Promise<void> } | ||
*/ | ||
exports.up = function (knex) { | ||
return knex.schema.createTable('Teams', (table) => { | ||
table.increments('id').primary(); | ||
table.string('team_name').notNullable(); | ||
table.string('team_code').notNullable(); | ||
}); | ||
}; | ||
|
||
/** | ||
* @param { import("knex").Knex } knex | ||
* @returns { Promise<void> } | ||
*/ | ||
exports.down = function (knex) { | ||
return knex.schema.dropTable('Teams'); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you have a typo in the
setter