From dd3c5a829ffcf329dcaccd3ba0d4ff8a9cff7725 Mon Sep 17 00:00:00 2001 From: Kar Date: Sat, 13 May 2023 17:03:58 +0530 Subject: [PATCH] editSchool --- package.json | 1 + src/pages/api/addUsers.js | 0 src/pages/edit-school.jsx | 143 ++++++++++++++++++-------------------- yarn.lock | 7 ++ 4 files changed, 76 insertions(+), 75 deletions(-) create mode 100644 src/pages/api/addUsers.js 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() {
- +
- {allStates && allStates.length > 0 &&
- + +
- + +
- +
diff --git a/yarn.lock b/yarn.lock index 237c41d..6f04b0b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -933,6 +933,13 @@ csstype@^3.0.2: resolved "https://registry.yarnpkg.com/csstype/-/csstype-3.1.2.tgz#1d4bf9d572f11c14031f0436e1c10bc1f571f50b" integrity sha512-I7K1Uu0MBPzaFKg4nI5Q7Vs2t+3gWWW648spaF+Rg7pI9ds18Ugn+lvg4SHczUdKlHI5LWBXyqfS8+DufyBsgQ== +csv-parser@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/csv-parser/-/csv-parser-3.0.0.tgz#b88a6256d79e090a97a1b56451f9327b01d710e7" + integrity sha512-s6OYSXAK3IdKqYO33y09jhypG/bSDHPuyCme/IdEHfWpLf/jKcpitVFyOC6UemgGk8v7Q5u2XE0vvwmanxhGlQ== + dependencies: + minimist "^1.2.0" + damerau-levenshtein@^1.0.8: version "1.0.8" resolved "https://registry.yarnpkg.com/damerau-levenshtein/-/damerau-levenshtein-1.0.8.tgz#b43d286ccbd36bc5b2f7ed41caf2d0aba1f8a6e7"