diff --git a/appUser.db b/appUser.db new file mode 100644 index 0000000..4a36550 Binary files /dev/null and b/appUser.db differ diff --git a/data/appUser.db b/data/appUser.db new file mode 100644 index 0000000..df169fa Binary files /dev/null and b/data/appUser.db differ diff --git a/data/user.csv b/data/user.csv new file mode 100644 index 0000000..a84ac63 --- /dev/null +++ b/data/user.csv @@ -0,0 +1,8 @@ +uname,status,user,type,year,start_month,start_date,end_date,plan,klas,lang,phone,pass,anual,early_start_programme,toddlers,interakto,email,country,state,city,address,school +name 1,published,,parent,,Feb,2023-05-14,2024-05-13,,IK2,,70000000011,,Jan,Feb,Mar,Jul,1@email.com,IN,WB,Habra,sample road near landmark,individual +name 5,published,,parent,,Feb,2023-05-14,2024-05-13,,IK2,,70000000011,,Jan,Feb,Mar,Jul,5@email.com,IN,WB,Habra,sample road near landmark,individual +name 4,published,,parent,,Feb,2023-05-14,2024-05-13,,IK2,,70000000011,,Jan,Feb,Mar,Jul,4@email.com,IN,WB,Habra,sample road near landmark,individual +name 3,published,,parent,,Apr,2023-05-14,2024-05-13,,IK2,,70000000011,,Feb,Sept,Oct,Jul,3@email.com,IN,WB,Habra,sample road near landmark,individual +name 2,published,,parent,,Apr,2023-05-14,2024-05-13,,IK2,,70000000011,,Feb,Sept,Oct,Jul,2@email.com,IN,WB,Habra,sample road near landmark,individual +name 6,published,,parent,,Jun,2023-05-14,2024-05-13,,IK3,,70000000011,,Mar,Sept,Jul,Apr,6@email.com,BD,55,Lalmonirhat,sample road near landmark,individual +teacher name,published,,teacher,,Apr,2023-05-15,2024-05-13,,IK2,,99999 99933,,Mar,0,0,0,t1@email.com,IN,WB,Barasat,,individual diff --git a/mydatabase.db b/mydatabase.db new file mode 100644 index 0000000..780e104 Binary files /dev/null and b/mydatabase.db differ diff --git a/src/pages/add-user-form.jsx b/src/pages/add-user-form.jsx index e056714..7290a9b 100644 --- a/src/pages/add-user-form.jsx +++ b/src/pages/add-user-form.jsx @@ -23,6 +23,7 @@ export default function addUserForm() { {lang: "kannada", value: false}, {lang: "gujrati", value: false}, ]) + console.log(allLanguage.value) const [currentType, setCurrentType] = useState(typeParent) const [countryValue, setCountryValue] = useState('') const options = useMemo(() => countryList().getData(), []) @@ -88,20 +89,25 @@ export default function addUserForm() { const data = { "status": "published", type: event.target.type.value, - name: event.target.name.value, - user: event.target.email.value, + uname: event.target.uname.value, country: event.target.country.value, + state: event.target.state.value, + city: event.target.city.value, phone: event.target.phone.value, + email: event.target.email.value, school: event.target.schoolID.value, - class: event.target.class.value, + klas: event.target.klas.value, lang: event.target.lang.value, start_month: event.target.start_month.value, start_date: event.target.start_date.value, end_date: event.target.end_date.value, anual: event.target.anual.value, + early_start_programme: event.target.early_start_programme.value, + toddlers: event.target.toddlers.value, + interakto: event.target.interakto.value, } const JSONdata = JSON.stringify(data) - const endpoint = 'https://management.beanstalkedu.com/items/enrolled_user' + const endpoint = '/api/addUsers' const options = { method: 'POST', headers: { @@ -111,7 +117,8 @@ export default function addUserForm() { } const response = await fetch(endpoint, options) const result = await response.json() - alert(`Is this your full name: ${result.data}`) + console.log(result) + // alert(`Is this your full name: ${result}`) } const handleOnLanguageChange = (e, v) => { let idx = allLanguage.findIndex(o => o.lang === e.target.value); @@ -152,15 +159,12 @@ export default function addUserForm() { className='flex flex-col justify-center place-items-center bg-[#FFF6F2] pt-6 pb-20 rounded-tl-[50px] rounded-br-[50px]'>
-

User - Registration Form

+

User Registration Form

- @@ -169,7 +173,7 @@ export default function addUserForm() {
-
@@ -196,10 +200,10 @@ export default function addUserForm() { { allCities && allCities.length > 0 &&
- + @@ -235,8 +239,7 @@ export default function addUserForm() {
- @@ -252,27 +255,61 @@ export default function addUserForm() {
- {/*
- -
-
-   - -
-
-   - -
-
-   - -
-
-   - -
-
-
*/} +
+ + +
+
+ + +
+
+ + +
+
@@ -291,8 +328,7 @@ export default function addUserForm() {
- diff --git a/src/pages/add-user-form2.jsx b/src/pages/add-user-form2.jsx index 44a11f1..7782eab 100644 --- a/src/pages/add-user-form2.jsx +++ b/src/pages/add-user-form2.jsx @@ -1,132 +1,258 @@ // https://management.beanstalkedu.com/items/school // import React from 'react'; -import { useId,useState, useEffect,useMemo } from 'react'; +import {useId, useState, useEffect, useMemo} from 'react'; import Select from 'react-select' import countryList from 'react-select-country-list' import 'react-phone-number-input/style.css' import PhoneInput from 'react-phone-number-input' - - import NavBar from '../components/NavBar'; // import { Inter } from 'next/font/google' -export default function addUserForm (){ - const [countryValue, setCountryValue] = useState('') - const options = useMemo(() => countryList().getData(), []) - const [phoneValue, setphoneValue] = useState() - let [individualValue=true, setindividualValue] = useState() +const typeParent = "parent" -// console.log(phoneValue) - const selectCountry = countryValue => { - setCountryValue(countryValue) +export default function addUserForm() { + const [allLanguage, setLanguage] = useState([ + {lang: "Assamese", value: false}, + {lang: "Bengali", value: false}, + {lang: "English", value: false}, + {lang: "Hindi", value: false}, + {lang: "telegu", value: false}, + {lang: "Punjabi", value: false}, + {lang: "malayalam", value: false}, + {lang: "tamil", value: false}, + {lang: "kannada", value: false}, + {lang: "gujrati", value: false}, + ]) + const [currentType, setCurrentType] = useState(typeParent) + const [countryValue, setCountryValue] = useState('') + const options = useMemo(() => countryList().getData(), []) + const [phoneValue, setphoneValue] = useState() + let [individualValue = true, setindividualValue] = useState() + + const [allStates, setAllStates] = useState([]) + const [allCities, setAllCities] = useState([]) + + const handleSelectAllStates = stateCode => { + setAllCities([]) + fetch(`https://api.siliconpin.com/v3/list/country/city/?country=${countryValue.value}&state=${stateCode.value}`).then(res => res.json()) + .then(data => { + console.log("handleSelectAllStates:", data, options) + let newData = data && data.length > 0 && data.map(n => { + return { + label: n.name, + value: n.name + + } + }) + setAllCities(newData) + }) + } + + const selectCountry = countryValue => { + setAllStates([]) + fetch(`https://api.siliconpin.com/v3/list/country/state/?country=${countryValue.value}`).then(res => res.json()) + .then(data => { + console.log("countryValue:", data, options) + let newData = data && data.length > 0 && data.map(n => { + return { + label: n.name, + value: n.iso2 + + } + }) + setAllStates(newData) + setAllCities([]) + }) + + setCountryValue(countryValue) + } + + const individual = (event) => { + // console.log(event.target.schoolID.value) + + setindividualValue(individualValue = false) + } + const [school, setSchool] = useState(null); + useEffect(() => { + fetch(`https://management.beanstalkedu.com/items/school`) + .then(res => res.json()) + .then(data => { + setSchool(data) + + }) + }, []) + // console.log(school); + + const handleFormsubmit = async (event) => { + event.preventDefault() + const data = { + "status": "published", + type: event.target.type.value, + name: event.target.name.value, + user: event.target.email.value, + country: event.target.country.value, + phone: event.target.phone.value, + school: event.target.schoolID.value, + class: event.target.class.value, + lang: event.target.lang.value, + start_month: event.target.start_month.value, + start_date: event.target.start_date.value, + end_date: event.target.end_date.value, + anual: event.target.anual.value, } - - const individual = (event) => { - // console.log(event.target.schoolID.value) - - setindividualValue(individualValue=false) + const JSONdata = JSON.stringify(data) + const endpoint = '/api/addUsers' + const options = { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSONdata, } - const [school, setSchool] = useState(null); - useEffect(() => { - fetch(`https://management.beanstalkedu.com/items/school`). - then(res => res.json()) - .then(data => { - setSchool(data) - - }) - }, []) - // console.log(school); + const response = await fetch(endpoint, options) + const result = await response.json() + alert(`Is this your full name: ${result.data}`) + } + const handleOnLanguageChange = (e, v) => { + let idx = allLanguage.findIndex(o => o.lang === e.target.value); + let newAllLang = [...allLanguage] + newAllLang[idx].value = true - const handleFormsubmit = async (event) => { - event.preventDefault() - const data = { - "status":"published", - type: event.target.type.value, - name: event.target.name.value, - user: event.target.email.value, - country: event.target.country.value, - phone: event.target.phone.value, - school: event.target.schoolID.value, - class: event.target.class.value, - lang: event.target.lang.value, - start_month: event.target.start_month.value, - start_date: event.target.start_date.value, - end_date: event.target.end_date.value, - // user: event.target.user.value, + + if ([typeParent, "teacher"].includes(currentType)) { + let counter = 0 + newAllLang.forEach((n, idx) => { + if (n.value) { + counter++ } - const JSONdata = JSON.stringify(data) - const endpoint = 'https://management.beanstalkedu.com/items/enrolled_user' - const options = { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - body: JSONdata, - } - const response = await fetch(endpoint, options) - const result = await response.json() - alert(`Is this your full name: ${result.data}`) + }) + if (counter >= 2) { + newAllLang.forEach((n, idx) => { + newAllLang[idx].disabled = true + }) } + } + setLanguage(newAllLang) + } + const handleTypeOnChange = (e) => { + let newAllLang = [...allLanguage] + newAllLang.forEach((n, idx) => { + newAllLang[idx].value = false + newAllLang[idx].disabled = false + }) + setLanguage(newAllLang) + setCurrentType(e.target.value) + } return ( -
-
- +
+
+
-
-
- -

User Registration Form

-
- - -
- - -
+
+
+ +

User + Registration Form

+
+ +
+ + +
+
+ + +
+
+ + +
+
+ + +
} + { + allCities && allCities.length > 0 &&
- - -
-
- - -
-
- - - - {school && school.data.map(data=> - - )} - -
- { individualValue && + + + + {school && school.data.map(data => + + )} + +
+
+ + +
+ {individualValue &&
-
- - -
-
+
+ + +
+ {/*
@@ -145,93 +271,66 @@ export default function addUserForm (){  
-
-
- -
- -
-
-   - -
-
-   - -
-
-   - -
-
-   - -
-
-   - -
-
-   - -
-
-   - -
-
-   - -
-
-   - -
-
-   - -
- -
- -
-
- - -
-
- - -
-
- - -
+
*/} +
+ +
+ {allLanguage && allLanguage.length && allLanguage.map(n => { + return ( +
+   + +
+ ) + })} +
+
+
+ + +
+
+ + +
+
+ + +
- - } -
- - {/* */} -
- -
+ } +
+ + {/* */} +
+ +
-
+
) } diff --git a/src/pages/api/addUsers.js b/src/pages/api/addUsers.js index e69de29..258cabe 100644 --- a/src/pages/api/addUsers.js +++ b/src/pages/api/addUsers.js @@ -0,0 +1,43 @@ +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, plan, 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.status) status ="published"; + if(req.body.type) type =req.body.type; + if(req.body.start_month) start_month =req.body.start_month; + 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.plan) plan =req.body.plan; + 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'); + db.run(`INSERT INTO user (uname, status, type, start_month, start_date, end_date, plan, klas, lang, phone, pass, anual, early_start_programme, toddlers, interakto, email, country, state, city, address, school ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, [ uname, status, type, start_month, start_date, end_date, plan, klas, lang, phone, pass, anual, early_start_programme, toddlers, interakto, email, country, state, city, address, school], + function(err) { + if (err) { + return console.log(err.message); + } + } + ); + db.close(); + + + res.status(200).json({ name: 'John Doe' }); +} diff --git a/src/pages/api/addUsersBulk copy.js b/src/pages/api/addUsersBulk copy.js new file mode 100644 index 0000000..13cf797 --- /dev/null +++ b/src/pages/api/addUsersBulk copy.js @@ -0,0 +1,21 @@ +const csv = require('csv-parser'); +const fs = require('fs'); +const sqlite3 = require('sqlite3').verbose(); + +// Open a new database connection +const db = new sqlite3.Database('data/appUser.db'); + +// Create a new table in the database +// db.run('CREATE TABLE mytable (column1 TEXT, column2 TEXT, column3 TEXT)'); + +// Read the CSV file and insert the data into the database +fs.createReadStream('mycsvfile.csv') + .pipe(csv()) + .on('data', (row) => { + db.run(`INSERT INTO mytable (column1, column2, column3) VALUES (?, ?, ?)`, [row.column1, row.column2, row.column3]); + }) + .on('end', () => { + console.log('CSV file successfully imported into SQLite.'); + // Close the database connection + db.close(); + }); diff --git a/src/pages/api/addUsersBulk.js b/src/pages/api/addUsersBulk.js new file mode 100644 index 0000000..c15f89f --- /dev/null +++ b/src/pages/api/addUsersBulk.js @@ -0,0 +1,36 @@ +import csv from 'csv-parser'; +import fs from 'fs'; +import sqlite3 from 'sqlite3'; + +export default function handler(req,res) { + + + const DB_NAME = 'data/appUser.db'; + const TABLE_NAME = 'user'; + + // Open a connection to the SQLite database + const db = new sqlite3.Database(DB_NAME); + + fs.createReadStream('data/user.csv') + .pipe(csv()) + .on('data', (data) => { + const values = Object.values(data); + const placeholders = values.map(() => '?').join(','); + const sql = `INSERT INTO ${TABLE_NAME} (${Object.keys(data).join(',')}) VALUES (${placeholders})`; + db.run(sql, values, (err) => { + if (err) { + console.error(err); + } + }); + }) + .on('end', () => { + console.log(`Data inserted successfully into table ${TABLE_NAME}`); + + // Close the database connection + db.close(); + }); + + + res.status(200).json({ name: 'John Doe' }) +} + diff --git a/src/pages/api/fileUpload.js b/src/pages/api/fileUpload.js index fc811f1..843ab77 100644 --- a/src/pages/api/fileUpload.js +++ b/src/pages/api/fileUpload.js @@ -10,15 +10,17 @@ export const config = { const post = async (req, res) => { const form = new formidable.IncomingForm(); form.parse(req, async function (err, fields, files) { - await saveFile(files.file); + // console.log(fields) + await saveFile(files.file,fields.fName? fields.fName:files.file.originalFilename ); return res.status(201).send(""); }); }; -const saveFile = async (file) => { +const saveFile = async (file,fName) => { // console.log(file.filepath) + // console.log(fName) const data = fs.readFileSync(file.filepath); - fs.writeFileSync(`./public/uploaded/${file.originalFilename}`, data); + fs.writeFileSync(`./public/uploaded/${fName}`, data); fs.unlinkSync(file.filepath); return; }; diff --git a/src/pages/api/listUsers.js b/src/pages/api/listUsers.js new file mode 100644 index 0000000..d1d3d8c --- /dev/null +++ b/src/pages/api/listUsers.js @@ -0,0 +1,67 @@ +import csv from 'csv-parser'; +import fs from 'fs'; +import sqlite3 from 'sqlite3'; + +export default function handler(req,res) { + + + const DB_NAME = 'data/appUser.db'; + const TABLE_NAME = 'user'; + + // Open a connection to the SQLite database + const db = new sqlite3.Database(DB_NAME); + + const query = `SELECT * FROM ${TABLE_NAME}`; + + function getAllRows(tableName) { + return new Promise((resolve, reject) => { + const sql = `SELECT * FROM ${tableName}`; + db.all(sql, [], (err, rows) => { + if (err) { + reject(err); + return; + } + const data = rows; + resolve(data); + }); + }); + }; + async function doSomething() { + try { + const returnData = await getAllRows('user'); + res.setHeader('Content-Type', 'application/json') + res.status(200).json(returnData) + // console.log(data); + } catch (err) { + console.error(err); + } + } + + doSomething(); +// const returnData = getAllRows('user'); +// console.log(getAllRows('user')); +// const returnData= db.run('SELECT * FROM user'); + +// fs.createReadStream('data/user.csv') +// .pipe(csv()) +// .on('data', (data) => { +// const values = Object.values(data); +// const placeholders = values.map(() => '?').join(','); +// const sql = `INSERT INTO ${TABLE_NAME} (${Object.keys(data).join(',')}) VALUES (${placeholders})`; +// db.run(sql, values, (err) => { +// if (err) { +// console.error(err); +// } +// }); +// }) +// .on('end', () => { +// console.log(`Data inserted successfully into table ${TABLE_NAME}`); + +// // Close the database connection +// db.close(); +// }); + + + +} + diff --git a/src/pages/edit-school copy.jsx b/src/pages/edit-school copy.jsx new file mode 100644 index 0000000..fb04449 --- /dev/null +++ b/src/pages/edit-school copy.jsx @@ -0,0 +1,131 @@ +import NavBar from '../components/NavBar' +import { useId, useState, useEffect, useMemo } from 'react'; +import 'react-phone-number-input/style.css' +import { useRouter } from 'next/router' + + +export default function addSchoolForm() { + + + const router = useRouter(); + + const [school, setSchool] = useState({}); + + useEffect(()=>{ + // if(router.query.school<1) { + // const { sid } = router.query; + // setSchool(sid) + if(router.query.school && router.query.school>1 ){ + fetch(`https://management.beanstalkedu.com/items/school/${router.query.school}`) + .then(res => res.json()) + .then(data => { + console.log(router.query.school); setSchool(data.data) + }) + } + + }, [router.query.school]); + + const handleSubmit = async (event) => { + event.preventDefault() + const data = { + "status":"published", + name: event.target.schoolName.value, + country: event.target.country.value, + state: event.target.state.value, + cities: event.target.cities.value, + anual: event.target.anual.value, + toddlers: event.target.toddlers.value, + early_start_programme: event.target.early_start_programme.value, + interakto: event.target.interakto.value, + agreement_expiry_date: event.target.agreement_expiry_date.value, + school_agreement: event.target.school_agreement.value, + school_contact_number: event.target.school_contact_number.value, + school_email_id: event.target.school_email_id.value, + + } + const JSONdata = JSON.stringify(data) + console.log(data) + const endpoint = 'https://management.beanstalkedu.com/items/school' + const options = { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSONdata, + } + const response = await fetch(endpoint, options) + + const result = await response.json() + // alert(`Is this your full name: ${result.data}`) + alert(`School Saved`) + } + + + return ( +
+
+ +
+
+
+ +

School Registration Form

+
+
+
+ + setSchool(e.target.value)} name="schoolName" placeholder='School Name' className='border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]' /> +
+
+ + setSchool(e.target.value)} name="school_email_id" id="school_email_id" placeholder='School Email ID' className=' border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]' /> +
+
+ + setSchool(e.target.value)} name="country" /> + +
+
+ + setSchool(e.target.value)} name="state" /> + +
+
+ + setSchool(e.target.value)} name="cities" /> + +
+
+ + setSchool(e.target.value)} name="school_contact_number" /> +
+
+ + setSchool(e.target.value)} /> +
+
+ + setSchool(e.target.value)} /> +
+
+ + setSchool(e.target.value)} /> +
+
+ + setSchool(e.target.value)} /> +
+
+ + setSchool(e.target.value)} id="agreement_expiry_date" className=' border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]' /> +
+
+ +
+
+
+
+
+
+ ) + } \ No newline at end of file diff --git a/src/pages/edit-school.jsx b/src/pages/edit-school.jsx index 0dba02f..905c281 100644 --- a/src/pages/edit-school.jsx +++ b/src/pages/edit-school.jsx @@ -5,52 +5,20 @@ import { useRouter } from 'next/router' export default function addSchoolForm() { + 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 router = useRouter() - // const sid= router.query.school - // const query = useQuery(); - - - const [school, setSchool] = useState([]); - // if(sid){console.log(sid)} - // const getSchoolData = async (sid) => { - - - // let getSchoolApi=`https://management.beanstalkedu.com/items/school?filter[status][_eq]=published&school=${sid}` - // console.log(sid) - // const response = await fetch(getSchoolApi); - // const data = await response.json(); - // let schoolData = data && data.length > 0 - // return setSchool(schoolData.data); - - // } - // console.log(sid) - // useEffect(() => { - // // async function getSchoolData() { - // // // You can await here - // // const response = await MyAPI.getData(someId); - // // // ... - // // } - // // getSchoolData(); - // // if(!router.isReady) return; - // // const { sid } = router.query; - // // console.log(sid); - // // // getSchoolData(); - // // let getSchoolApi=`https://management.beanstalkedu.com/items/school?filter[status][_eq]=published&school=${sid}` - // // console.log(sid) - // // await fetch(getSchoolApi); - // if (!query) { - // return; - // } - // fetch(`https://management.beanstalkedu.com/items/school?filter[status][_eq]=published&school=${sid}`) - // .then(res => res.json()) - // .then(data => { - // console.log("handleSelectAllStates:", data, options) - // let newData = data && data.length > 0 - // setSchool(newData) - // }) - // },[]) + const [school, setSchool] = useState({}); + useEffect(()=>{ // if(router.query.school<1) { // const { sid } = router.query; @@ -59,53 +27,47 @@ export default function addSchoolForm() { fetch(`https://management.beanstalkedu.com/items/school/${router.query.school}`) .then(res => res.json()) .then(data => { - // console.log("handleSelectAllStates:", data, options) - // let newData = data && data.length > 0 console.log(router.query.school); setSchool(data.data) }) } }, [router.query.school]); - // console.log(school.data); - // console.log(phoneValue) - // const selectCountry = countryValue => { - // setCountryValue(countryValue) - // } - // const handleSubmit = async (event) => { - // event.preventDefault() - // const data = { - // "status":"published", - // name: event.target.schoolName.value, - // country: event.target.country.value, - // state: event.target.state.value, - // cities: event.target.cities.value, - // anual: event.target.anual.value, - // toddlers: event.target.toddlers.value, - // early_start_programme: event.target.early_start_programme.value, - // interakto: event.target.interakto.value, - // agreement_expiry_date: event.target.agreement_expiry_date.value, - // school_agreement: event.target.school_agreement.value, - // school_contact_number: event.target.school_contact_number.value, - // school_email_id: event.target.school_email_id.value, + const handleSubmit = async (event) => { + event.preventDefault() + const data = { + "status":"published", + name: event.target.schoolName.value, + country: event.target.country.value, + state: event.target.state.value, + cities: event.target.cities.value, + anual: event.target.anual.value, + toddlers: event.target.toddlers.value, + early_start_programme: event.target.early_start_programme.value, + interakto: event.target.interakto.value, + agreement_expiry_date: event.target.agreement_expiry_date.value, + school_agreement: event.target.school_agreement.value, + school_contact_number: event.target.school_contact_number.value, + school_email_id: event.target.school_email_id.value, - // } - // const JSONdata = JSON.stringify(data) - // console.log(data) - // const endpoint = 'https://management.beanstalkedu.com/items/school' - // const options = { - // method: 'POST', - // headers: { - // 'Content-Type': 'application/json', - // }, - // body: JSONdata, - // } - // const response = await fetch(endpoint, options) + } + const JSONdata = JSON.stringify(data) + console.log(data) + const endpoint = 'https://management.beanstalkedu.com/items/school' + const options = { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSONdata, + } + const response = await fetch(endpoint, options) + + const result = await response.json() + // alert(`Is this your full name: ${result.data}`) + alert(`School Saved`) + } - // const result = await response.json() - // // alert(`Is this your full name: ${result.data}`) - // alert(`School Saved`) - // } return (
@@ -120,115 +82,81 @@ export default function addSchoolForm() {
- + setSchool(e.target.value)} name="schoolName" placeholder='School Name' className='border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]' />
- + setSchool(e.target.value)} name="school_email_id" id="school_email_id" placeholder='School Email ID' className=' border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]' />
- + setSchool(e.target.value)} name="country" />
- + setSchool(e.target.value)} name="state" />
- + setSchool(e.target.value)} name="cities" />
- - + + setSchool(e.target.value)} name="school_contact_number" />
- + setSchool(e.target.value)} />
- + setSchool(e.target.value)} />
- + setSchool(e.target.value)} />
- + setSchool(e.target.value)} />
- + setSchool(e.target.value)} id="agreement_expiry_date" className=' border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]' />
{/*
- - + +
*/} -
- {/* */} + {/*
-
+
*/}
+ +
+
+ + {/* */} +
+ +
diff --git a/src/pages/user-list.tsx b/src/pages/user-list.tsx index fc66ad4..de65963 100644 --- a/src/pages/user-list.tsx +++ b/src/pages/user-list.tsx @@ -6,9 +6,10 @@ import NavBar from '../components/NavBar' export default function Modal() { const [user, setUser] = useState([]); const fetchData = async () => { - const response = await fetch("https://management.beanstalkedu.com/items/enrolled_user?filter[status][_eq]=published"); + const response = await fetch("/api/listUsers"); const data = await response.json(); - return setUser(data.data); + console.log(data) + return setUser(data); } // console.log(user) @@ -28,7 +29,7 @@ const fetchData = async () => {
- +
user Name