diff --git a/package.json b/package.json index 4fdebf2..9239623 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,7 @@ "@types/react": "18.2.0", "@types/react-dom": "18.2.1", "autoprefixer": "10.4.14", + "csv-parser": "^3.0.0", "eslint": "8.39.0", "eslint-config-next": "13.3.1", "formidable": "^2.1.1", diff --git a/src/pages/api/addUsers.js b/src/pages/api/addUsers.js new file mode 100644 index 0000000..e69de29 diff --git a/src/pages/edit-school.jsx b/src/pages/edit-school.jsx index 5491024..9c80b6f 100644 --- a/src/pages/edit-school.jsx +++ b/src/pages/edit-school.jsx @@ -1,71 +1,74 @@ import NavBar from '../components/NavBar' 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 { useRouter } from 'next/router' export default function addSchoolForm() { - const [countryValue, setCountryValue] = useState('') - const options = useMemo(() => countryList().getData(), []) - const [phoneValue, setphoneValue] = 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 router = useRouter() - let sid= router.query.school - - if(sid){ + const router = useRouter() + // const sid= router.query.school + // const query = useQuery(); + + const [school, setSchool] = useState([]); - const fetchData = async () => { - const response = await fetch("https://management.beanstalkedu.com/items/school?filter[status][_eq]=published&school="+sid); - const data = await response.json(); - return setSchool(data.data); + // 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) + // }) + // },[]) + 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("handleSelectAllStates:", data, options) + // let newData = data && data.length > 0 + console.log(router.query.school); setSchool(data) + }) } - console.log(school) - useEffect(() => { - fetchData(); - },[]) - } - + }, [router.query.school]); + + console.log(school); // console.log(phoneValue) // const selectCountry = countryValue => { // setCountryValue(countryValue) @@ -126,32 +129,22 @@ export default function addSchoolForm() {