main2
parent
300df6001b
commit
96b933edc1
|
@ -1 +0,0 @@
|
||||||
,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.
|
@ -4,7 +4,7 @@ import Link from 'next/link'
|
||||||
|
|
||||||
export default function NavBar() {
|
export default function NavBar() {
|
||||||
const { data: session } = useSession()
|
const { data: session } = useSession()
|
||||||
console.log(session)
|
// console.log(session)
|
||||||
if (session) {
|
if (session) {
|
||||||
return (
|
return (
|
||||||
<main>
|
<main>
|
||||||
|
@ -15,6 +15,7 @@ export default function NavBar() {
|
||||||
<Link href="/add-school-form">Add School </Link>|
|
<Link href="/add-school-form">Add School </Link>|
|
||||||
<Link href="/school-list">School List</Link>|
|
<Link href="/school-list">School List</Link>|
|
||||||
<Link href="/add-user-form">Add User </Link>|
|
<Link href="/add-user-form">Add User </Link>|
|
||||||
|
<Link href="/upload-user">Upload User </Link>|
|
||||||
<Link href="/user-list">User List </Link>|
|
<Link href="/user-list">User List </Link>|
|
||||||
<button onClick={() => signOut()}>Sign out</button>
|
<button onClick={() => signOut()}>Sign out</button>
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ import NavBar from '../components/NavBar';
|
||||||
|
|
||||||
const typeParent = "parent"
|
const typeParent = "parent"
|
||||||
|
|
||||||
export default function AddUser() {
|
export default function addUserForm() {
|
||||||
const [allLanguage, setLanguage] = useState([
|
const [allLanguage, setLanguage] = useState([
|
||||||
{lang: "Assamese", value: false},
|
{lang: "Assamese", value: false},
|
||||||
{lang: "Bengali", value: false},
|
{lang: "Bengali", value: false},
|
||||||
|
@ -75,7 +75,7 @@ export default function AddUser() {
|
||||||
}
|
}
|
||||||
const [school, setSchool] = useState(null);
|
const [school, setSchool] = useState(null);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
fetch(`https://management.beanstalkedu.com/items/school`)
|
fetch(`/api/listSchlools`)
|
||||||
.then(res => res.json())
|
.then(res => res.json())
|
||||||
.then(data => {
|
.then(data => {
|
||||||
setSchool(data)
|
setSchool(data)
|
||||||
|
@ -102,13 +102,13 @@ export default function AddUser() {
|
||||||
start_month: event.target.start_month.value,
|
start_month: event.target.start_month.value,
|
||||||
start_date: event.target.start_date.value,
|
start_date: event.target.start_date.value,
|
||||||
end_date: event.target.end_date.value,
|
end_date: event.target.end_date.value,
|
||||||
annual: event.target.annual.value,
|
anual: event.target.anual.value,
|
||||||
early_start_programme: event.target.early_start_programme.value,
|
early_start_programme: event.target.early_start_programme.value,
|
||||||
toddlers: event.target.toddlers.value,
|
toddlers: event.target.toddlers.value,
|
||||||
interakto: event.target.interakto.value,
|
interakto: event.target.interakto.value,
|
||||||
}
|
}
|
||||||
const JSONdata = JSON.stringify(data)
|
const JSONdata = JSON.stringify(data)
|
||||||
const endpoint = '/api/addUsers'
|
const endpoint = '/api/addUser'
|
||||||
const options = {
|
const options = {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
|
@ -223,7 +223,7 @@ export default function AddUser() {
|
||||||
<select name="schoolID" onChange={individual}
|
<select name="schoolID" onChange={individual}
|
||||||
className='bg-white border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]'>
|
className='bg-white border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]'>
|
||||||
<option value="0"> individual</option>
|
<option value="0"> individual</option>
|
||||||
{school && school.data.map(data =>
|
{school && school.map(data =>
|
||||||
<option value={data.id} key={data.id}>{data.name}</option>
|
<option value={data.id} key={data.id}>{data.name}</option>
|
||||||
)}
|
)}
|
||||||
</select>
|
</select>
|
||||||
|
@ -242,8 +242,8 @@ export default function AddUser() {
|
||||||
{individualValue &&
|
{individualValue &&
|
||||||
<div>
|
<div>
|
||||||
<div className='flex flex-col w-full pt-4'>
|
<div className='flex flex-col w-full pt-4'>
|
||||||
<label htmlFor="annual" className='text-xl font-bold'>annual</label>
|
<label htmlFor="anual" className='text-xl font-bold'>Anual</label>
|
||||||
<select name="annual" className=' bg-white border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]'>
|
<select name="anual" className=' bg-white border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]'>
|
||||||
<option value="0">-NA-</option>
|
<option value="0">-NA-</option>
|
||||||
<option value="Jan">Jan</option>
|
<option value="Jan">Jan</option>
|
||||||
<option value="Feb">Feb</option>
|
<option value="Feb">Feb</option>
|
||||||
|
|
|
@ -14,7 +14,7 @@ export default function handler(req, res) {
|
||||||
if(req.body.end_date) end_date =req.body.end_date;
|
if(req.body.end_date) end_date =req.body.end_date;
|
||||||
if(req.body.plan) plan =req.body.plan;
|
if(req.body.plan) plan =req.body.plan;
|
||||||
if(req.body.klas) klas =req.body.klas;
|
if(req.body.klas) klas =req.body.klas;
|
||||||
if(req.body.lang) lang =req.body.lang;
|
if(req.body.lang) lang =req.body.lang; lang=JSON.stringify(lang);
|
||||||
if(req.body.phone) phone =req.body.phone;
|
if(req.body.phone) phone =req.body.phone;
|
||||||
if(req.body.pass) pass =req.body.pass;
|
if(req.body.pass) pass =req.body.pass;
|
||||||
if(req.body.annual) annual =req.body.annual;
|
if(req.body.annual) annual =req.body.annual;
|
|
@ -1,17 +1,29 @@
|
||||||
import csv from 'csv-parser';
|
import csv from 'csv-parser';
|
||||||
import fs from 'fs';
|
import formidable from "formidable";
|
||||||
|
import fs from "fs";
|
||||||
import sqlite3 from 'sqlite3';
|
import sqlite3 from 'sqlite3';
|
||||||
|
|
||||||
|
export const config = {
|
||||||
|
api: {
|
||||||
|
bodyParser: false
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
export default function handler(req,res) {
|
export default function handler(req,res) {
|
||||||
|
|
||||||
|
const form = new formidable.IncomingForm();
|
||||||
|
form.parse(req, async function (err, fields, files) {
|
||||||
|
|
||||||
|
// console.log('ppp')
|
||||||
|
console.log(files.file.filepath)
|
||||||
const DB_NAME = 'data/appUser.db';
|
const DB_NAME = 'data/appUser.db';
|
||||||
const TABLE_NAME = 'user';
|
const TABLE_NAME = 'user';
|
||||||
|
|
||||||
// Open a connection to the SQLite database
|
// Open a connection to the SQLite database
|
||||||
const db = new sqlite3.Database(DB_NAME);
|
const db = new sqlite3.Database(DB_NAME);
|
||||||
|
|
||||||
fs.createReadStream('data/user.csv')
|
// fs.createReadStream('data/user.csv')
|
||||||
|
fs.createReadStream(files.file.filepath)
|
||||||
.pipe(csv())
|
.pipe(csv())
|
||||||
.on('data', (data) => {
|
.on('data', (data) => {
|
||||||
const values = Object.values(data);
|
const values = Object.values(data);
|
||||||
|
@ -26,11 +38,19 @@ export default function handler(req,res) {
|
||||||
.on('end', () => {
|
.on('end', () => {
|
||||||
console.log(`Data inserted successfully into table ${TABLE_NAME}`);
|
console.log(`Data inserted successfully into table ${TABLE_NAME}`);
|
||||||
|
|
||||||
// Close the database connection
|
fs.unlinkSync(files.file.filepath);
|
||||||
db.close();
|
db.close();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
res.status(200).json({ name: 'John Doe' })
|
// console.log(fields)
|
||||||
|
// await saveFile(files.file,fields.fName? fields.fName:files.file.originalFilename );
|
||||||
|
return res.status(201).send("");
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
res.status(200).json({ msg: 'ok' })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,16 +7,35 @@ import Link from 'next/link'
|
||||||
|
|
||||||
export default function EditSchool() {
|
export default function EditSchool() {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
const uploadToServer = async (event) => {
|
||||||
|
const body = new FormData();
|
||||||
|
body.append("file", agreement.files[0]);
|
||||||
|
body.append("fName", `${router.query.school}.pdf`);
|
||||||
|
const response = await fetch("/api/fileUpload", {
|
||||||
|
method: "POST",
|
||||||
|
body
|
||||||
|
});
|
||||||
|
};
|
||||||
|
const uploadCsv = async (event) => {
|
||||||
|
// alert('p')
|
||||||
|
const body = new FormData();
|
||||||
|
body.append("file", csv.files[0]);
|
||||||
|
// console.log('body')
|
||||||
|
// body.append("fName", `${router.query.school}.pdf`);
|
||||||
|
const response = await fetch("/api/addUsersBulk", {
|
||||||
|
method: "POST",
|
||||||
|
body
|
||||||
|
});
|
||||||
|
};
|
||||||
const [school, setSchool] = useState({});
|
const [school, setSchool] = useState({});
|
||||||
|
|
||||||
useEffect(()=>{
|
useEffect(()=>{
|
||||||
if(router.query.school && router.query.school>0 ){
|
if(router.query.school && router.query.school>0 ){
|
||||||
console.log(router.query);
|
// console.log(router.query);
|
||||||
fetch(`/api/getSchoolDetails?school=${router.query.school}`)
|
fetch(`/api/getSchoolDetails?school=${router.query.school}`)
|
||||||
.then(res => res.json())
|
.then(res => res.json())
|
||||||
.then(data => {
|
.then(data => {
|
||||||
console.log(data);
|
// console.log(data);
|
||||||
setSchool(data[0])
|
setSchool(data[0])
|
||||||
// console.log(school)
|
// console.log(school)
|
||||||
})
|
})
|
||||||
|
@ -43,7 +62,7 @@ export default function EditSchool() {
|
||||||
email: event.target.email.value,
|
email: event.target.email.value,
|
||||||
}
|
}
|
||||||
const JSONdata = JSON.stringify(data)
|
const JSONdata = JSON.stringify(data)
|
||||||
console.log(data)
|
// console.log(data)
|
||||||
const endpoint = '/api/editSchool'
|
const endpoint = '/api/editSchool'
|
||||||
const options = {
|
const options = {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
|
@ -73,8 +92,8 @@ export default function EditSchool() {
|
||||||
List Users Under This School
|
List Users Under This School
|
||||||
</Link>
|
</Link>
|
||||||
<div className="place-items-center justify-center m-2 p-2 bg-[#FE4501] text-white font-bold rounded-full whitespace-nowrap">
|
<div className="place-items-center justify-center m-2 p-2 bg-[#FE4501] text-white font-bold rounded-full whitespace-nowrap">
|
||||||
<span className="text-small">CSV Upload </span>
|
<span className="text-small">CSV </span>
|
||||||
<input type="file" />
|
<input type="file" id="csv" onChange={uploadCsv} name="csv" />
|
||||||
</div>
|
</div>
|
||||||
{/* <img src="/img/2.svg" alt=""/> */}
|
{/* <img src="/img/2.svg" alt=""/> */}
|
||||||
|
|
||||||
|
@ -144,7 +163,7 @@ export default function EditSchool() {
|
||||||
|
|
||||||
<div className='flex flex-col w-full'>
|
<div className='flex flex-col w-full'>
|
||||||
<label htmlFor="agreement_documents" className='text-xl font-bold'>Upload Agreement Document's</label>
|
<label htmlFor="agreement_documents" className='text-xl font-bold'>Upload Agreement Document's</label>
|
||||||
<input onChange={e => setSchool(e.target.value)} type="file" name="agreement_documents" className=' bg-white border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]' />
|
<input id="agreement" onChange={uploadToServer} type="file" name="agreement_documents" className=' bg-white border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]' />
|
||||||
<div className='flex justify-end pt-2'>
|
<div className='flex justify-end pt-2'>
|
||||||
<button className=' bg-[#FE4501] px-4 py-1.5 rounded-lg text-white'>Download Agreement</button>
|
<button className=' bg-[#FE4501] px-4 py-1.5 rounded-lg text-white'>Download Agreement</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -2,7 +2,7 @@ import { signIn, signOut, useSession } from 'next-auth/react'
|
||||||
|
|
||||||
export default function Home() {
|
export default function Home() {
|
||||||
const { data: session } = useSession()
|
const { data: session } = useSession()
|
||||||
console.log(session)
|
// console.log(session)
|
||||||
if (session) {
|
if (session) {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
|
|
@ -0,0 +1,38 @@
|
||||||
|
import {useId, useState, useEffect, useMemo} from 'react';
|
||||||
|
import NavBar from '../components/NavBar';
|
||||||
|
import { useRouter } from 'next/router'
|
||||||
|
|
||||||
|
|
||||||
|
export default function EditSchool() {
|
||||||
|
const router = useRouter();
|
||||||
|
|
||||||
|
const uploadCsv = async (event) => {
|
||||||
|
// alert('p')
|
||||||
|
const body = new FormData();
|
||||||
|
body.append("file", csv.files[0]);
|
||||||
|
// console.log('body')
|
||||||
|
// body.append("fName", `${router.query.school}.pdf`);
|
||||||
|
const response = await fetch("/api/addUsersBulk", {
|
||||||
|
method: "POST",
|
||||||
|
body
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return (
|
||||||
|
<main>
|
||||||
|
<div>
|
||||||
|
<NavBar/>
|
||||||
|
<section className='container mx-auto px-4 my-16 lg:px-28 xl:px-56 2xl:px-96'>
|
||||||
|
<div className="place-items-center justify-center m-2 p-2 bg-[#FE4501] text-white font-bold rounded-full whitespace-nowrap">
|
||||||
|
<span className="text-small">CSV </span>
|
||||||
|
<input type="file" id="csv" onChange={uploadCsv} name="csv" />
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
</div>
|
||||||
|
</main>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue