userEdit
parent
2b85a5a356
commit
81cfb6ce00
|
@ -0,0 +1 @@
|
||||||
|
,ov,d4,16.05.2023 12:44,file:///home/ov/.config/libreoffice/4;
|
BIN
data/appUser.db
BIN
data/appUser.db
Binary file not shown.
|
@ -0,0 +1,44 @@
|
||||||
|
export default function handler(req, res) {
|
||||||
|
const sqlite3 = require('sqlite3').verbose();
|
||||||
|
|
||||||
|
console.log(req.body)
|
||||||
|
// Open a new database connection
|
||||||
|
let uname, status, type, start_month, start_date, end_date, klas, lang, phone, pass, anual, early_start_programme, toddlers, interakto, email, country, state, city, address, school="";
|
||||||
|
|
||||||
|
if(req.body.uname) uname =req.body.uname;
|
||||||
|
if(req.body.status) status =req.body.status;
|
||||||
|
if(req.body.type) type =req.body.type;
|
||||||
|
if(req.body.start_date) start_date =req.body.start_date;
|
||||||
|
if(req.body.end_date) end_date =req.body.end_date;
|
||||||
|
if(req.body.klas) klas =req.body.klas;
|
||||||
|
if(req.body.lang) lang =req.body.lang;
|
||||||
|
if(req.body.lang) lang =req.body.lang;
|
||||||
|
if(req.body.phone) phone =req.body.phone;
|
||||||
|
if(req.body.pass) pass =req.body.pass;
|
||||||
|
if(req.body.anual) anual =req.body.anual;
|
||||||
|
if(req.body.early_start_programme) early_start_programme =req.body.early_start_programme;
|
||||||
|
if(req.body.toddlers) toddlers =req.body.toddlers;
|
||||||
|
if(req.body.interakto) interakto =req.body.interakto;
|
||||||
|
if(req.body.email) email =req.body.email;
|
||||||
|
if(req.body.country) country =req.body.country;
|
||||||
|
if(req.body.state) state =req.body.state;
|
||||||
|
if(req.body.city) city =req.body.city;
|
||||||
|
if(req.body.address) address =req.body.address;
|
||||||
|
if(req.body.school) school =req.body.school;
|
||||||
|
const db = new sqlite3.Database('data/appUser.db');
|
||||||
|
console.log(req.body.userId)
|
||||||
|
db.run(`UPDATE user SET uname = ?, status = ?, type = ?, start_month = ?, start_date = ?, end_date = ?, klas = ?, lang = ?, phone = ?, anual = ?, early_start_programme = ?, toddlers = ?, interakto = ?, email = ?, country = ?, state = ?, city = ?, address = ?, school = ? WHERE id = ? `, [ uname, status, type, start_month, start_date, end_date, klas, lang, phone, anual, early_start_programme, toddlers, interakto, email, country, state, city, address, school, req.body.userId],
|
||||||
|
function(err) {
|
||||||
|
if (err) {
|
||||||
|
res.status(400).json({ msg: 'Err400D' });
|
||||||
|
return console.log(err.message);
|
||||||
|
}
|
||||||
|
res.status(200).json({ msg: 'ok' });
|
||||||
|
}
|
||||||
|
);
|
||||||
|
db.close();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -6,20 +6,20 @@ import { useRouter } from 'next/router'
|
||||||
export default function editUser() {
|
export default function editUser() {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
const updateUserData = async (event) => {
|
// const updateUserData = async (event) => {
|
||||||
const body = new FormData();
|
// const body = new FormData();
|
||||||
body.append("file", agreement.files[0]);
|
// body.append("file", agreement.files[0]);
|
||||||
body.append("fName", `${router.query.school}.pdf`);
|
// body.append("fName", `${router.query.school}.pdf`);
|
||||||
const response = await fetch("/api/updateUserDetails", {
|
// const response = await fetch("/api/updateUserDetails", {
|
||||||
method: "POST",
|
// method: "POST",
|
||||||
body
|
// body
|
||||||
});
|
// });
|
||||||
};
|
// };
|
||||||
|
|
||||||
const [user, setUser] = useState({});
|
const [user, setUser] = useState({});
|
||||||
|
|
||||||
useEffect(()=>{
|
useEffect(()=>{
|
||||||
console.log(router.query);
|
// console.log(router.query);
|
||||||
// if(router.query.school<1) {
|
// if(router.query.school<1) {
|
||||||
// const { sid } = router.query;
|
// const { sid } = router.query;
|
||||||
// setSchool(sid)
|
// setSchool(sid)
|
||||||
|
@ -27,34 +27,38 @@ export default function editUser() {
|
||||||
fetch(`/api/getUserDetails?user=${router.query.user}`)
|
fetch(`/api/getUserDetails?user=${router.query.user}`)
|
||||||
.then(res => res.json())
|
.then(res => res.json())
|
||||||
.then(data => {
|
.then(data => {
|
||||||
console.log(router.query.user);
|
// console.log(data);
|
||||||
setUser(data)
|
setUser(data[0])
|
||||||
|
// console.log(user)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
}, [router.query.school]);
|
}, [router.query.user]);
|
||||||
|
|
||||||
const handleSubmit = async (event) => {
|
const updateUserData = async (event) => {
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
const data = {
|
const data = {
|
||||||
"status":"published",
|
userId: router.query.user,
|
||||||
name: event.target.schoolName.value,
|
type: event.target.type.value,
|
||||||
|
status: event.target.status.value,
|
||||||
|
uname: event.target.uname.value,
|
||||||
country: event.target.country.value,
|
country: event.target.country.value,
|
||||||
state: event.target.state.value,
|
state: event.target.state.value,
|
||||||
cities: event.target.cities.value,
|
city: event.target.city.value,
|
||||||
|
address: event.target.address.value,
|
||||||
|
start_date: event.target.start_date.value,
|
||||||
|
end_date: event.target.end_date.value,
|
||||||
|
school: event.target.school.value,
|
||||||
anual: event.target.anual.value,
|
anual: event.target.anual.value,
|
||||||
toddlers: event.target.toddlers.value,
|
toddlers: event.target.toddlers.value,
|
||||||
early_start_programme: event.target.early_start_programme.value,
|
early_start_programme: event.target.early_start_programme.value,
|
||||||
interakto: event.target.interakto.value,
|
email: event.target.email.value,
|
||||||
agreement_expiry_date: event.target.agreement_expiry_date.value,
|
phone: event.target.phone.value,
|
||||||
school_agreement: event.target.school_agreement.value,
|
klas: event.target.klas.value
|
||||||
school_contact_number: event.target.school_contact_number.value,
|
|
||||||
school_email_id: event.target.school_email_id.value,
|
|
||||||
|
|
||||||
}
|
}
|
||||||
const JSONdata = JSON.stringify(data)
|
const JSONdata = JSON.stringify(data)
|
||||||
console.log(data)
|
console.log(data)
|
||||||
const endpoint = 'https://management.beanstalkedu.com/items/school'
|
const endpoint = '/api/editUser'
|
||||||
const options = {
|
const options = {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
|
@ -66,7 +70,7 @@ export default function editUser() {
|
||||||
|
|
||||||
const result = await response.json()
|
const result = await response.json()
|
||||||
// alert(`Is this your full name: ${result.data}`)
|
// alert(`Is this your full name: ${result.data}`)
|
||||||
alert(`School Saved`)
|
alert(`User data updated`)
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -83,37 +87,73 @@ export default function editUser() {
|
||||||
<form onSubmit={updateUserData} action="" className='w-full px-6 md:px-20'>
|
<form onSubmit={updateUserData} action="" className='w-full px-6 md:px-20'>
|
||||||
<div className='flex flex-col w-full pt-4'>
|
<div className='flex flex-col w-full pt-4'>
|
||||||
<label htmlFor="class" className='text-xl font-bold'>Type</label>
|
<label htmlFor="class" className='text-xl font-bold'>Type</label>
|
||||||
<input type="text" name="type" className=' bg-white border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]' />
|
<input value={user.type} onChange={e => setUser(e.target.value)} type="text" name="type" className=' bg-white border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]' />
|
||||||
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
<div className='flex flex-col w-full'>
|
<div className='flex flex-col w-full'>
|
||||||
<label htmlFor="name" className='text-xl font-bold'> Name</label>
|
<label htmlFor="name" className='text-xl font-bold'> Name</label>
|
||||||
<input value={user.name} type="text" name="uname" className=' border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]' placeholder='Enter your Name'/>
|
<input value={user.uname} onChange={e => setUser(e.target.value)} type="text" name="uname" className=' border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]' />
|
||||||
|
</div>
|
||||||
|
<div className='flex flex-col w-full'>
|
||||||
|
<label htmlFor="status" className='text-xl font-bold'> Status</label>
|
||||||
|
<input value={user.status} onChange={e => setUser(e.target.value)} type="text" name="status" className=' border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]' />
|
||||||
|
</div>
|
||||||
|
<div className='flex flex-col w-full'>
|
||||||
|
<label htmlFor="start_date" className='text-xl font-bold'> start_date (YYYY-MM-DD) </label>
|
||||||
|
<input value={user.start_date} onChange={e => setUser(e.target.value)} type="text" name="start_date" className=' border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]' />
|
||||||
|
</div>
|
||||||
|
<div className='flex flex-col w-full'>
|
||||||
|
<label htmlFor="end_date" className='text-xl font-bold'> end_date (YYYY-MM-DD)</label>
|
||||||
|
<input value={user.end_date} onChange={e => setUser(e.target.value)} type="text" name="end_date" className=' border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]' />
|
||||||
</div>
|
</div>
|
||||||
<div className='flex flex-col w-full'>
|
<div className='flex flex-col w-full'>
|
||||||
<label htmlFor="email" className='text-xl font-bold'>Email</label>
|
<label htmlFor="email" className='text-xl font-bold'>Email</label>
|
||||||
<input type="email" name="email" placeholder='ex. xyz@email.com'
|
<input value={user.email} onChange={e => setUser(e.target.value)} type="email" name="email" placeholder='ex. xyz@email.com' className=' border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]'/>
|
||||||
className=' border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]'/>
|
</div>
|
||||||
|
<div className='flex flex-col w-full'>
|
||||||
|
<label htmlFor="phone" className='text-xl font-bold'> Phone</label>
|
||||||
|
<input value={user.phone} onChange={e => setUser(e.target.value)} type="text" name="phone" className=' bg-white border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]' />
|
||||||
</div>
|
</div>
|
||||||
<div className='flex flex-col w-full'>
|
<div className='flex flex-col w-full'>
|
||||||
<label htmlFor="country" className='text-xl font-bold'>Country</label>
|
<label htmlFor="country" className='text-xl font-bold'>Country</label>
|
||||||
<input type="text" name="type" className=' bg-white border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]' />
|
<input value={user.country} onChange={e => setUser(e.target.value)} type="text" name="country" className=' bg-white border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]' />
|
||||||
|
</div>
|
||||||
|
<div className='flex flex-col w-full'>
|
||||||
|
<label htmlFor="state" className='text-xl font-bold'> State</label>
|
||||||
|
<input value={user.state} onChange={e => setUser(e.target.value)} type="text" name="state" className=' bg-white border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]' />
|
||||||
|
</div>
|
||||||
|
<div className='flex flex-col w-full'>
|
||||||
|
<label htmlFor="city" className='text-xl font-bold'> City</label>
|
||||||
|
<input value={user.city} onChange={e => setUser(e.target.value)} type="text" name="city" className=' bg-white border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]' />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className='flex flex-col w-full'>
|
<div className='flex flex-col w-full'>
|
||||||
<label htmlFor="phone" className='text-xl font-bold'> Phone</label>
|
<label htmlFor="address" className='text-xl font-bold'> address 1st line</label>
|
||||||
<input value={user.name} type="text" name="uname" className=' border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]' placeholder='Enter your Name'/>
|
<input value={user.address} onChange={e => setUser(e.target.value)} type="text" name="address" className=' bg-white border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]' />
|
||||||
</div>
|
</div>
|
||||||
<div className='flex flex-col w-full pt-4'>
|
<div className='flex flex-col w-full pt-4'>
|
||||||
<label htmlFor="" className='text-xl font-bold'>School name</label>
|
<label htmlFor="" className='text-xl font-bold'>School ID</label>
|
||||||
<input value={user.name} type="text" name="uname" className=' border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]' placeholder='Enter your Name'/>
|
<input value={user.school} onChange={e => setUser(e.target.value)} type="text" name="school" className=' border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]' />
|
||||||
</div>
|
</div>
|
||||||
<div className='flex flex-col w-full pt-4'>
|
<div className='flex flex-col w-full pt-4'>
|
||||||
<label htmlFor="class" className='text-xl font-bold'>Class</label>
|
<label htmlFor="klas" className='text-xl font-bold'>Class</label>
|
||||||
<input value={user.name} type="text" name="uname" className=' border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]' placeholder='Enter your Name'/>
|
<input value={user.klas} onChange={e => setUser(e.target.value)} type="text" name="klas" className=' border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]' />
|
||||||
|
</div>
|
||||||
|
<div className='flex flex-col w-full pt-4'>
|
||||||
|
<label htmlFor="anual" className='text-xl font-bold'>anual</label>
|
||||||
|
<input value={user.anual} onChange={e => setUser(e.target.value)} type="text" name="anual" className=' border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]' />
|
||||||
|
</div>
|
||||||
|
<div className='flex flex-col w-full pt-4'>
|
||||||
|
<label htmlFor="early_start_programme" className='text-xl font-bold'>early_start_programme</label>
|
||||||
|
<input value={user.early_start_programme} onChange={e => setUser(e.target.value)} type="text" name="early_start_programme" className=' border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]' />
|
||||||
|
</div>
|
||||||
|
<div className='flex flex-col w-full pt-4'>
|
||||||
|
<label htmlFor="toddlers" className='text-xl font-bold'>toddlers</label>
|
||||||
|
<input value={user.toddlers} onChange={e => setUser(e.target.value)} type="text" name="toddlers" className=' border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]' />
|
||||||
|
</div>
|
||||||
|
<div className='flex flex-col w-full pt-4'>
|
||||||
|
<label htmlFor="interakto" className='text-xl font-bold'>interakto</label>
|
||||||
|
<input value={user.interakto} onChange={e => setUser(e.target.value)} type="text" name="interakto" className=' border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]' />
|
||||||
</div>
|
</div>
|
||||||
<input value={user.name} type="text" name="uname" className=' border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]' placeholder='Enter your Name'/>
|
|
||||||
|
|
||||||
<div className='flex justify-center pt-8'>
|
<div className='flex justify-center pt-8'>
|
||||||
<button type="submit"
|
<button type="submit"
|
||||||
|
|
Loading…
Reference in New Issue