-
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
TCES-41 urd create and update user information to be updated #21
Merged
tsids
merged 11 commits into
main
from
taha/tces-41-urd-create-and-update-user-information-to-be-updated
Nov 8, 2023
Merged
Changes from 10 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
c7a3138
Rendering Create and Edit User
tsids cfffa9e
Completing TCES-41 Added Create & Edit User pages
tsids 1b6d8ac
fixed linting errors
tsids e340b7c
updated app.jsx
tsids 6640862
updated changes based on comments
tsids 1526f5c
fixed app
tsids 5024726
updated folder names
tsids 1339c67
changed email and password input type
tsids a698d48
changed file names
tsids 8b44f9b
added required attribute
tsids 613380d
changed onClick event to onSubmit
tsids File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
126 changes: 126 additions & 0 deletions
126
client/src/components/create-user-component/create-user-component.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
import { useState } from "react"; | ||
import { | ||
TextField, | ||
Stack, | ||
Button, | ||
Card, | ||
CardHeader, | ||
CardContent, | ||
Typography, | ||
} from "@mui/material"; | ||
import { Form, Header, Cancel } from "./index.styles"; | ||
|
||
function CreateComponent() { | ||
const [firstName, setFirstName] = useState(""); | ||
const [lastName, setLastName] = useState(""); | ||
const [email, setEmail] = useState(""); | ||
const [password, setPassword] = useState(""); | ||
|
||
const handleCreate = () => { | ||
// Create a JSON object with the required keys and values | ||
const userData = { | ||
firstName, | ||
lastName, | ||
email, | ||
password, | ||
}; | ||
|
||
// Convert the JSON object to a string | ||
const userDataJSON = JSON.stringify(userData); | ||
|
||
// Replace url with target route | ||
fetch("http://localhost:8000/create", { | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
body: userDataJSON, | ||
}); | ||
// .then((response) => { | ||
// if (response.ok) { | ||
// // Handle success response (e.g., redirect or show a success message) | ||
// console.log('Login successful'); | ||
// } else { | ||
// // Handle error response (e.g., show an error message) | ||
// console.error('Login failed'); | ||
// } | ||
// }) | ||
// .catch((error) => { | ||
// console.error('Error:', error); | ||
// }); | ||
}; | ||
|
||
return ( | ||
<Form> | ||
<Stack maxWidth="md" gap={4}> | ||
<Header> | ||
<Typography variant="h3">Create New User</Typography> | ||
<Typography variant="body1">Manually create a new user</Typography> | ||
</Header> | ||
|
||
<Card> | ||
<CardHeader title="User Information" /> | ||
<CardContent> | ||
<Stack gap={1.5}> | ||
<TextField | ||
type="text" | ||
id="firstName" | ||
name="firstName" | ||
value={firstName} | ||
onChange={(e) => setFirstName(e.target.value)} | ||
label="First Name" | ||
helperText="*Required" | ||
required | ||
/> | ||
<TextField | ||
type="text" | ||
id="lastName" | ||
name="lastName" | ||
value={lastName} | ||
onChange={(e) => setLastName(e.target.value)} | ||
label="Last Name" | ||
helperText="*Required" | ||
required | ||
/> | ||
<TextField | ||
type="email" | ||
id="email" | ||
name="email" | ||
value={email} | ||
onChange={(e) => setEmail(e.target.value)} | ||
label="Email" | ||
helperText="*Required" | ||
required | ||
/> | ||
<TextField | ||
type="password" | ||
id="password" | ||
name="password" | ||
value={password} | ||
onChange={(e) => setPassword(e.target.value)} | ||
label="Password" | ||
helperText="*Required" | ||
required | ||
/> | ||
</Stack> | ||
</CardContent> | ||
</Card> | ||
<Stack direction="row"> | ||
<Cancel variant="outlined" size="large"> | ||
Cancel | ||
</Cancel> | ||
<Button | ||
type="submit" | ||
variant="contained" | ||
size="large" | ||
onClick={handleCreate} | ||
> | ||
Submit | ||
</Button> | ||
</Stack> | ||
</Stack> | ||
</Form> | ||
); | ||
} | ||
|
||
export default CreateComponent; |
29 changes: 29 additions & 0 deletions
29
client/src/components/create-user-component/index.styles.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import styled from "styled-components"; | ||
|
||
import { Box, Button } from "@mui/material"; | ||
|
||
const Form = styled.form` | ||
height: 100vh; | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
justify-content: center; | ||
font-family: Helvetica; | ||
background-color: #f0f3f8; | ||
text-align: initial; | ||
`; | ||
|
||
const Header = styled(Box)` | ||
display: flex; | ||
width: 47.5rem; | ||
padding-right: 0px; | ||
flex-direction: column; | ||
align-items: flex-start; | ||
gap: 0.625rem; | ||
`; | ||
|
||
const Cancel = styled(Button)` | ||
margin-right: auto !important; | ||
`; | ||
|
||
export { Form, Header, Cancel }; |
128 changes: 128 additions & 0 deletions
128
client/src/components/edit-user-component/edit-user-component.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
import { useState } from "react"; | ||
import { | ||
TextField, | ||
Stack, | ||
Button, | ||
Card, | ||
CardHeader, | ||
CardContent, | ||
Typography, | ||
} from "@mui/material"; | ||
import { Form, Header, Cancel } from "./index.styles"; | ||
|
||
function EditComponent() { | ||
const [firstName, setFirstName] = useState(""); | ||
const [lastName, setLastName] = useState(""); | ||
const [email, setEmail] = useState(""); | ||
const [password, setPassword] = useState(""); | ||
|
||
const handleSave = () => { | ||
// Create a JSON object with the required keys and values | ||
const userData = { | ||
firstName, | ||
lastName, | ||
email, | ||
password, | ||
}; | ||
|
||
// Convert the JSON object to a string | ||
const userDataJSON = JSON.stringify(userData); | ||
|
||
// Replace url with target route | ||
fetch("http://localhost:8000/edit", { | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
body: userDataJSON, | ||
}); | ||
// .then((response) => { | ||
// if (response.ok) { | ||
// // Handle success response (e.g., redirect or show a success message) | ||
// console.log('Login successful'); | ||
// } else { | ||
// // Handle error response (e.g., show an error message) | ||
// console.error('Login failed'); | ||
// } | ||
// }) | ||
// .catch((error) => { | ||
// console.error('Error:', error); | ||
// }); | ||
}; | ||
|
||
return ( | ||
<Form> | ||
<Stack maxWidth="md" gap={4}> | ||
<Header> | ||
<Typography variant="h3">Edit User</Typography> | ||
<Typography variant="body1"> | ||
Edit existing user information | ||
</Typography> | ||
</Header> | ||
|
||
<Card> | ||
<CardHeader title="User Information" /> | ||
<CardContent> | ||
<Stack gap={1.5}> | ||
<TextField | ||
type="text" | ||
id="firstName" | ||
name="firstName" | ||
value={firstName} | ||
onChange={(e) => setFirstName(e.target.value)} | ||
label="First Name" | ||
helperText="*Required" | ||
required | ||
/> | ||
<TextField | ||
type="text" | ||
id="lastName" | ||
name="lastName" | ||
value={lastName} | ||
onChange={(e) => setLastName(e.target.value)} | ||
label="Last Name" | ||
helperText="*Required" | ||
required | ||
/> | ||
<TextField | ||
type="email" | ||
id="email" | ||
name="email" | ||
value={email} | ||
onChange={(e) => setEmail(e.target.value)} | ||
label="Email" | ||
helperText="*Required" | ||
required | ||
/> | ||
<TextField | ||
type="password" | ||
id="password" | ||
name="password" | ||
value={password} | ||
onChange={(e) => setPassword(e.target.value)} | ||
label="Password" | ||
helperText="*Required" | ||
required | ||
/> | ||
</Stack> | ||
</CardContent> | ||
</Card> | ||
<Stack direction="row"> | ||
<Cancel variant="outlined" size="large"> | ||
Cancel | ||
</Cancel> | ||
<Button | ||
type="submit" | ||
variant="contained" | ||
size="large" | ||
onClick={handleSave} | ||
> | ||
Save | ||
</Button> | ||
</Stack> | ||
</Stack> | ||
</Form> | ||
); | ||
} | ||
|
||
export default EditComponent; |
29 changes: 29 additions & 0 deletions
29
client/src/components/edit-user-component/index.styles.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import styled from "styled-components"; | ||
|
||
import { Box, Button } from "@mui/material"; | ||
|
||
const Form = styled.form` | ||
height: 100vh; | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
justify-content: center; | ||
font-family: Helvetica; | ||
background-color: #f0f3f8; | ||
text-align: initial; | ||
`; | ||
|
||
const Header = styled(Box)` | ||
display: flex; | ||
width: 47.5rem; | ||
padding-right: 0px; | ||
flex-direction: column; | ||
align-items: flex-start; | ||
gap: 0.625rem; | ||
`; | ||
|
||
const Cancel = styled(Button)` | ||
margin-right: auto !important; | ||
`; | ||
|
||
export { Form, Header, Cancel }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import CreateComponent from "../../components/create-user-component/create-user-component"; | ||
|
||
function Create() { | ||
return <CreateComponent />; | ||
} | ||
|
||
export default Create; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import EditComponent from "../../components/edit-user-component/edit-user-component"; | ||
|
||
function Edit() { | ||
return <EditComponent />; | ||
} | ||
|
||
export default Edit; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Currently, despite the form validation onClick is called on the button. Instead of assigning the button's onClick method to handleClick, instead assign the encompassing form's onSave method to it. This should be done in the create component as well.
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 couldn't find anything about an onSave method, but I added it to onSubmit.
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.
Whoops, thats what I meant to say!