-
Notifications
You must be signed in to change notification settings - Fork 122
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
Refactored the code, removed bugs #527
Open
gyanpra
wants to merge
2
commits into
purnima143:master
Choose a base branch
from
gyanpra:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
226 changes: 120 additions & 106 deletions
226
client/src/components/Admin_UserUpdate/admin_userupdate.js
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 |
---|---|---|
@@ -1,118 +1,132 @@ | ||
import React,{useEffect,useState} from 'react'; | ||
import React, { useEffect, useState } from "react"; | ||
import "./adminScreen.css"; | ||
import {FormControlLabel,Checkbox} from '@material-ui/core'; | ||
import { FormControlLabel, Checkbox } from "@material-ui/core"; | ||
import Navbar from "../navbar/Navbar"; | ||
import './adminScreen.css'; | ||
import AOS from 'aos'; | ||
import 'aos/dist/aos.css'; | ||
import "./adminScreen.css"; | ||
import AOS from "aos"; | ||
import "aos/dist/aos.css"; | ||
import { toast } from "react-toastify"; | ||
import "react-toastify/dist/ReactToastify.css"; | ||
|
||
toast.configure(); | ||
|
||
|
||
export default function MultilineTextFields() { | ||
useEffect(()=>{ | ||
AOS.init({ | ||
duration:2000, | ||
delay:1000 | ||
}) | ||
},[]); | ||
|
||
const [setValue] = React.useState('Controlled'); | ||
useEffect(() => { | ||
AOS.init({ | ||
duration: 2000, | ||
delay: 1000 | ||
}); | ||
}, []); | ||
|
||
const initialState = { | ||
email: "", | ||
firstName:"", | ||
lastName:"" | ||
}; | ||
const [setValue] = React.useState("Controlled"); | ||
|
||
const [formData, setFormData] = useState(initialState); | ||
const [setValue] = React.useState('Controlled'); | ||
// eslint-disable-next-line | ||
const handleChange = (event) => { | ||
setValue(event.target.value); | ||
}; | ||
//TOAST TO DISPLAY FOR INVALID INPUTS WITH CUSTOM MESSAGE PARAMETER | ||
const errorToast = (message) => { | ||
toast.error(message, { | ||
position: "top-center", | ||
autoClose: 3000, | ||
closeOnClick: true, | ||
hideProgressBar: true, | ||
pauseOnHover: true, | ||
draggable: true, | ||
progress: undefined | ||
}); | ||
}; | ||
const initialState = { | ||
email: "", | ||
firstName: "", | ||
lastName: "" | ||
}; | ||
|
||
//TOAST TO DISPLAY FOR SUCCESSFULL SIGNIN | ||
const successToast = (message) => { | ||
toast.success(message, { | ||
position: "top-right", | ||
autoClose: 2000, | ||
hideProgressBar: true, | ||
closeOnClick: true, | ||
pauseOnHover: true, | ||
draggable: true, | ||
progress: undefined | ||
}); | ||
}; | ||
const updateUser = (e) => { | ||
//FUNCTION TO DO APPROPRIATE TASK ON CLICKING SUBMIT BUTTON | ||
// eslint-disable-next-line | ||
//CONDITIONS TO CHECK VALID INPUT DETAILS | ||
if (formData.email !== "") { | ||
// eslint-disable-next-line | ||
const valid_email = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; | ||
if (valid_email.test(formData.email)) { | ||
if (formData.firstName !== "") { | ||
if(formData.lastName!=""){ | ||
//Code to perform authentication via an api | ||
// if user is successfully signed then then we can have a .then() block | ||
// in which we will show a toast and redirect the user | ||
successToast("Successfully edited"); | ||
} else { | ||
errorToast("Please enter Last Name"); | ||
}} | ||
else { | ||
errorToast("Please enter First Name"); | ||
} | ||
} else { | ||
errorToast("Please enter a valid email id"); | ||
}} | ||
else { | ||
errorToast("Please enter email"); | ||
} | ||
}; | ||
return (<div><Navbar/><br/><br/> | ||
<div class="container" style={{width:'50%'}}> | ||
<h1>Edit User</h1> | ||
<form data-aos="fade-up"> | ||
<div class="txt_field"> | ||
<input type="text" required id="name" name="name"/> | ||
<span></span> | ||
<label>First Name</label> | ||
</div> | ||
<div class="txt_field"> | ||
<input type="text" required name="subject" id="subject"/> | ||
<span></span> | ||
<label>Last Name</label> | ||
</div> | ||
<div class="txt_field"> | ||
<input type="email" required name="messege" id="messege"/> | ||
<span></span> | ||
<label>Email</label> | ||
</div> | ||
<FormControlLabel value="isAdmin" control={<Checkbox color="primary"/>} | ||
label="isAdmin" labelPlacement="isAdmin"/> | ||
<input type="submit" value="Update" onClick={updateUser}/> | ||
<div class="signup_link"> | ||
|
||
</div> | ||
const [formData, setFormData] = useState(initialState); | ||
//const [setValue] = React.useState("Controlled"); SetValue is already assigned in line 21 | ||
// eslint-disable-next-line | ||
const handleChange = event => { | ||
setValue(event.target.value); | ||
}; | ||
//TOAST TO DISPLAY FOR INVALID INPUTS WITH CUSTOM MESSAGE PARAMETER | ||
const errorToast = message => { | ||
toast.error(message, { | ||
position: "top-center", | ||
autoClose: 3000, | ||
closeOnClick: true, | ||
hideProgressBar: true, | ||
pauseOnHover: true, | ||
draggable: true, | ||
progress: undefined | ||
}); | ||
}; | ||
|
||
</form> | ||
</div> | ||
</div> | ||
); | ||
} | ||
//TOAST TO DISPLAY FOR SUCCESSFULL SIGNIN | ||
const successToast = message => { | ||
toast.success(message, { | ||
position: "top-right", | ||
autoClose: 2000, | ||
hideProgressBar: true, | ||
closeOnClick: true, | ||
pauseOnHover: true, | ||
draggable: true, | ||
progress: undefined | ||
}); | ||
}; | ||
const updateUser = e => { | ||
//FUNCTION TO DO APPROPRIATE TASK ON CLICKING SUBMIT BUTTON | ||
// eslint-disable-next-line | ||
//CONDITIONS TO CHECK VALID INPUT DETAILS | ||
if (formData.email !== "") { | ||
// eslint-disable-next-line | ||
const valid_email = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; | ||
if (valid_email.test(formData.email)) { | ||
if (formData.firstName !== "") { | ||
if (formData.lastName !== "") { | ||
//Code to perform authentication via an api | ||
// if user is successfully signed then then we can have a .then() block | ||
// in which we will show a toast and redirect the user | ||
successToast("Successfully edited"); | ||
} else { | ||
errorToast("Please enter Last Name"); | ||
} | ||
} else { | ||
errorToast("Please enter First Name"); | ||
} | ||
} else { | ||
errorToast("Please enter a valid email id"); | ||
} | ||
} else { | ||
errorToast("Please enter email"); | ||
} | ||
}; | ||
return ( | ||
<div> | ||
<Navbar /> | ||
<br /> | ||
<br /> | ||
<div class="container" style={{ width: "50%" }}> | ||
<h1>Edit User</h1> | ||
<form data-aos="fade-up"> | ||
<div class="txt_field"> | ||
<input type="text" required id="name" name="name" /> | ||
<span></span> | ||
<label>First Name</label> | ||
</div> | ||
<div class="txt_field"> | ||
<input | ||
type="text" | ||
required | ||
name="subject" | ||
id="subject" | ||
/> | ||
<span></span> | ||
<label>Last Name</label> | ||
</div> | ||
<div class="txt_field"> | ||
<input | ||
type="email" | ||
required | ||
name="messege" | ||
id="messege" | ||
/> | ||
<span></span> | ||
<label>Email</label> | ||
</div> | ||
<FormControlLabel | ||
value="isAdmin" | ||
control={<Checkbox color="primary" />} | ||
label="isAdmin" | ||
labelPlacement="isAdmin" | ||
/> | ||
<input type="submit" value="Update" onClick={updateUser} /> | ||
<div class="signup_link"></div> | ||
</form> | ||
</div> | ||
</div> | ||
); | ||
} |
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.
Commented code should not be pushed to GitHub.