From 300df6001b962b80099aefd81a96d47acbb01a05 Mon Sep 17 00:00:00 2001 From: Kar Date: Sat, 20 May 2023 23:04:29 +0530 Subject: [PATCH] lint --- package.json | 1 + src/components/NavBar.tsx | 50 ++-- src/pages/add-school-form.jsx | 4 +- src/pages/add-user-form.jsx | 2 +- src/pages/add-user-form2.jsx | 336 ----------------------- src/pages/api/auth/[...nextauth].js | 6 + src/pages/edit-school copy.jsx | 131 --------- src/pages/edit-school.jsx | 10 +- src/pages/edit-school2.jsx | 167 ------------ src/pages/edit-user.jsx | 16 +- src/pages/edit-user2.jsx | 402 ---------------------------- src/pages/index.jsx | 7 +- src/pages/school-list/[slug].jsx | 380 +++++++++++--------------- src/pages/school-list/index.jsx | 2 +- src/pages/school-list/slug.jsx | 241 ----------------- src/pages/user-list-by-school.jsx | 15 +- src/pages/user-list.jsx | 11 +- yarn.lock | 5 + 18 files changed, 216 insertions(+), 1570 deletions(-) delete mode 100644 src/pages/add-user-form2.jsx delete mode 100644 src/pages/edit-school copy.jsx delete mode 100644 src/pages/edit-school2.jsx delete mode 100644 src/pages/edit-user2.jsx delete mode 100644 src/pages/school-list/slug.jsx diff --git a/package.json b/package.json index 7a1995a..09184f6 100644 --- a/package.json +++ b/package.json @@ -21,6 +21,7 @@ "formidable": "^2.1.1", "formik": "^2.2.9", "jsonwebtoken": "^9.0.0", + "jwt-decode": "^3.1.2", "next": "13.3.1", "next-auth": "^4.22.1", "postcss": "8.4.23", diff --git a/src/components/NavBar.tsx b/src/components/NavBar.tsx index 960f7ab..9512dc4 100644 --- a/src/components/NavBar.tsx +++ b/src/components/NavBar.tsx @@ -1,24 +1,36 @@ -import Image from 'next/image' -import { Inter } from 'next/font/google' +import { signIn, signOut, useSession } from 'next-auth/react' +import Link from 'next/link' -const inter = Inter({ subsets: ['latin'] }) -export default function Home() { +export default function NavBar() { + const { data: session } = useSession() + console.log(session) + if (session) { + return ( +
+
+
+
+
+ Add School | + School List| + Add User | + User List | + + +
+
+
+
+
+ ) + } return ( -
-
-
-
- -
-
-
-
+ <> + Not signed in
+ + ) + } + diff --git a/src/pages/add-school-form.jsx b/src/pages/add-school-form.jsx index 6c436c2..993d622 100644 --- a/src/pages/add-school-form.jsx +++ b/src/pages/add-school-form.jsx @@ -5,8 +5,8 @@ import countryList from 'react-select-country-list' import 'react-phone-number-input/style.css' import PhoneInput from 'react-phone-number-input' -export default function addSchoolForm() { - const [countryValue, setCountryValue] = useState('') +export default function AddSchool() { + const [countryValue, setCountryValue] =useState('') const options = useMemo(() => countryList().getData(), []) const [phoneValue, setphoneValue] = useState() const [allStates, setAllStates] = useState([]) diff --git a/src/pages/add-user-form.jsx b/src/pages/add-user-form.jsx index 7ee95db..d1ef08b 100644 --- a/src/pages/add-user-form.jsx +++ b/src/pages/add-user-form.jsx @@ -10,7 +10,7 @@ import NavBar from '../components/NavBar'; const typeParent = "parent" -export default function addUserForm() { +export default function AddUser() { const [allLanguage, setLanguage] = useState([ {lang: "Assamese", value: false}, {lang: "Bengali", value: false}, diff --git a/src/pages/add-user-form2.jsx b/src/pages/add-user-form2.jsx deleted file mode 100644 index 64f05aa..0000000 --- a/src/pages/add-user-form2.jsx +++ /dev/null @@ -1,336 +0,0 @@ -// https://management.beanstalkedu.com/items/school -// import React 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' - -const typeParent = "parent" - -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, - annual: event.target.annual.value, - } - const JSONdata = JSON.stringify(data) - const endpoint = '/api/addUsers' - 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}`) - } - const handleOnLanguageChange = (e, v) => { - let idx = allLanguage.findIndex(o => o.lang === e.target.value); - let newAllLang = [...allLanguage] - newAllLang[idx].value = true - - - if ([typeParent, "teacher"].includes(currentType)) { - let counter = 0 - newAllLang.forEach((n, idx) => { - if (n.value) { - counter++ - } - }) - 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

-
-
-
- - -
-
- - -
-
- - -
-
- - -
} - { - allCities && allCities.length > 0 && -
- - - - {school && school.data.map(data => - - )} - -
-
- - -
- {individualValue && -
-
- - -
- {/*
- -
-
-   - -
-
-   - -
-
-   - -
-
-   - -
-
-
*/} -
- -
- {allLanguage && allLanguage.length && allLanguage.map(n => { - return ( -
-   - -
- ) - })} -
-
-
- - -
-
- - -
-
- - -
-
- } -
- - {/* */} -
-
-
-
-
-
- ) -} diff --git a/src/pages/api/auth/[...nextauth].js b/src/pages/api/auth/[...nextauth].js index 4ba1e79..911bf20 100644 --- a/src/pages/api/auth/[...nextauth].js +++ b/src/pages/api/auth/[...nextauth].js @@ -1,6 +1,8 @@ import NextAuth from "next-auth/next"; import CredentialsProvider from "next-auth/providers/credentials"; import { signIn } from "next-auth/react"; +import jwt_decode from "jwt-decode"; + const pubAPI = process.env.DIRECTUS_PUBLIC_API; @@ -44,8 +46,11 @@ export const options = { callbacks: { async jwt({ token, user, account }) { if (account && user) { + var tokenJwt =user.data.access_token + var roleID = jwt_decode(tokenJwt).role; return { ...token, + roleID:roleID, accessToken: user.data.access_token, expires: Date.now() + user.data.expires, refreshToken: user.data.refresh_token, @@ -62,6 +67,7 @@ export const options = { }, async session({ session, token }) { + session.user.roleID = token.roleID; session.user.accessToken = token.accessToken; session.user.refreshToken = token.refreshToken; session.user.expires = token.expires; diff --git a/src/pages/edit-school copy.jsx b/src/pages/edit-school copy.jsx deleted file mode 100644 index 2b2c4d2..0000000 --- a/src/pages/edit-school copy.jsx +++ /dev/null @@ -1,131 +0,0 @@ -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, - annual: event.target.annual.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 48cbc50..4728526 100644 --- a/src/pages/edit-school.jsx +++ b/src/pages/edit-school.jsx @@ -2,8 +2,10 @@ import {useId, useState, useEffect, useMemo} from 'react'; import 'react-phone-number-input/style.css' import NavBar from '../components/NavBar'; import { useRouter } from 'next/router' +import Link from 'next/link' -export default function editSchool() { + +export default function EditSchool() { const router = useRouter(); const [school, setSchool] = useState({}); @@ -66,10 +68,10 @@ export default function editSchool() {
- +   List Users Under This School - +
CSV Upload   @@ -141,7 +143,7 @@ export default function editSchool() {
- + 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]' />
diff --git a/src/pages/edit-school2.jsx b/src/pages/edit-school2.jsx deleted file mode 100644 index 6a53869..0000000 --- a/src/pages/edit-school2.jsx +++ /dev/null @@ -1,167 +0,0 @@ -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 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 [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]); - // console.log(setSchool) - - 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, - annual: event.target.annual.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 ( -
-
- -
-
-
- -

Update School Information

-
-
-
- - 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" className='border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]' /> - -
-
- - setSchool(e.target.value)} name="cities" className='border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]'/> - -
-
- - setSchool(e.target.value)} name="school_contact_number" className='border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]' /> -
-
- - setSchool(e.target.value)} className='border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]' /> -
-
- - setSchool(e.target.value)} className='border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]' /> -
-
- - setSchool(e.target.value)} className='border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]' /> -
-
- - setSchool(e.target.value)} className='border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]' /> -
-
- - 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-user.jsx b/src/pages/edit-user.jsx index 127eb33..222933a 100644 --- a/src/pages/edit-user.jsx +++ b/src/pages/edit-user.jsx @@ -3,26 +3,12 @@ import 'react-phone-number-input/style.css' import NavBar from '../components/NavBar'; import { useRouter } from 'next/router' -export default function editUser() { +export default function EditUser() { const router = useRouter(); - // const updateUserData = async (event) => { - // const body = new FormData(); - // body.append("file", agreement.files[0]); - // body.append("fName", `${router.query.school}.pdf`); - // const response = await fetch("/api/updateUserDetails", { - // method: "POST", - // body - // }); - // }; - const [user, setUser] = useState({}); useEffect(()=>{ - // console.log(router.query); - // if(router.query.school<1) { - // const { sid } = router.query; - // setSchool(sid) if(router.query.user && router.query.user>0 ){ fetch(`/api/getUserDetails?user=${router.query.user}`) .then(res => res.json()) diff --git a/src/pages/edit-user2.jsx b/src/pages/edit-user2.jsx deleted file mode 100644 index 18a9be3..0000000 --- a/src/pages/edit-user2.jsx +++ /dev/null @@ -1,402 +0,0 @@ -// https://management.beanstalkedu.com/items/school -// import React 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 { useRouter } from 'next/router' -// import { Inter } from 'next/font/google' - -const typeParent = "parent" - -export default function addUserForm() { - - const router = useRouter(); - - 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}, - ]) - // console.log(allLanguage) - 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) - - }) - }, []) - - const [user, setUser] = useState({}); - - useEffect(()=>{ - if(router.query.user && router.query.user>1){ - fetch(`/api/listUsers/${router.query.user}`) - .then(res => res.json()) - .then(data => { - setUser(data) - } - ) - } - }, - [router.query.user]); - console.log(user) - - const handleFormsubmit = async (event) => { - event.preventDefault() - console.log(event.target.lang.checked) - const data = { - "status": "published", - type: event.target.type.value, - uname: event.target.uname.value, - country: event.target.country.value, - state: event.target.state.value ? event.target.state.value:"", - city: event.target.city.value ? event.target.city.value:"", - phone: event.target.phone.value, - email: event.target.email.value, - school: event.target.schoolID.value, - klas: event.target.klas.value, - lang: allLanguage, - start_month: event.target.start_month.value, - start_date: event.target.start_date.value, - end_date: event.target.end_date.value, - annual: event.target.annual.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 = '/api/addUsers' - const options = { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - body: JSONdata, - } - const response = await fetch(endpoint, options) - const result = await response.json() - // console.log(result) - // alert(`Is this your full name: ${result}`) - } - const handleOnLanguageChange = (e, v) => { - let idx = allLanguage.findIndex(o => o.lang === e.target.value); - let newAllLang = [...allLanguage] - newAllLang[idx].value = true - // console.log(newAllLang) - - if ([typeParent, "teacher"].includes(currentType)) { - let counter = 0 - newAllLang.forEach((n, idx) => { - if (n.value) { - counter++ - } - }) - 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 - }) - const { name, checked } = e.target; - setLanguage({ ...allLanguage, [name]: checked }); - - // setLanguage(newAllLang) - setCurrentType(e.target.value) - } - return ( -
-
- -
-
-
- -

Update User Information

-
-
-
- - - - -
-
- - -
-
- - -
-
- - -
} - { - allCities && allCities.length > 0 && -
- - - - {school && school.data.map(data => - - )} - -
-
- - -
- {individualValue && -
-
- - -
-
- - -
-
- - -
-
- - -
- -
- -
- {/*  
-  
-  
-  
-  
-  
-  
-  
-  
-  
*/} - {allLanguage && allLanguage.length && allLanguage.map(n => { - return ( -
-   - -
- ) - })} -
-
-
- - -
-
- - -
-
- - -
-
- } -
- - {/* */} -
-
-
-
-
-
- ) -} diff --git a/src/pages/index.jsx b/src/pages/index.jsx index 9616e74..1a396be 100644 --- a/src/pages/index.jsx +++ b/src/pages/index.jsx @@ -10,12 +10,7 @@ export default function Home() {

- - +
) } diff --git a/src/pages/school-list/[slug].jsx b/src/pages/school-list/[slug].jsx index 54a7da4..1a41fe6 100644 --- a/src/pages/school-list/[slug].jsx +++ b/src/pages/school-list/[slug].jsx @@ -1,241 +1,161 @@ -import NavBar from '../../components/NavBar' -import {useRouter} from "next/router"; -import { useId, useState, useEffect, useMemo } from 'react'; -import Select from 'react-select' -import countryList from 'react-select-country-list' +import {useId, useState, useEffect, useMemo} from 'react'; import 'react-phone-number-input/style.css' -import PhoneInput from 'react-phone-number-input' +import NavBar from '../../components/NavBar'; +import { useRouter } from 'next/router' +import Link from 'next/link' -export default function addSchoolForm() { - const { query } = useRouter(); - 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 - } +export default function SchoolSlug() { + const router = useRouter(); + + const [school, setSchool] = useState({}); + + useEffect(()=>{ + if(router.query.school && router.query.school>0 ){ + console.log(router.query); + fetch(`/api/getSchoolDetails?school=${router.query.school}`) + .then(res => res.json()) + .then(data => { + console.log(data); + setSchool(data[0]) + // console.log(school) }) - 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) - } - // 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, - annual: event.target.annual.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) + + }, [router.query.school]); - const result = await response.json() - // alert(`Is this your full name: ${result.data}`) - alert(`School Saved`) + const updateSchoolData = async (event) => { + event.preventDefault() + const data = { + schoolId: router.query.school, + sname: event.target.sname.value, + status: event.target.status.value, + country: event.target.country.value, + state: event.target.state.value, + city: event.target.city.value, + annual: event.target.annual.value, + toddlers: event.target.toddlers.value, + early_start_programme: event.target.early_start_programme.value, + interakto: event.target.interakto.value, + agg_expiry: event.target.agg_expiry.value, + usage_expiry: event.target.usage_expiry.value, + phone: event.target.phone.value, + email: event.target.email.value, } - const [school, setUser] = useState([]); - const fetchData = async () => { - const response = await fetch("https://management.beanstalkedu.com/items/school?filter[status][_eq]=published&"); - const data = await response.json(); - return setUser(data.data[0]); - } - // console.log(school.name) - - useEffect(() => { - fetchData(); - },[]) - - return ( -
-
- -
-

Items page

-

{query.id}

-

{query.name}

-
-
-
-
- -

Update School Information

-
-
-
- - -
-
- - -
-
- - +
+ {/* */} + +
+

Update School Information

+ +
+ + setSchool(e.target.value)} type="text" name="sname" className=' bg-white border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]' /> +
+
+ + setSchool(e.target.value)} type="text" name="status" className=' bg-white border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]' /> +
+
+ + setSchool(e.target.value)} type="text" name="phone" className=' border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]' /> +
+
+ + setSchool(e.target.value)} type="text" name="email" className=' border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]' /> +
+
+ + setSchool(e.target.value)} type="text" name="country" className=' border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]' />
- {allStates && allStates.length > 0 &&
- {}} - /> -
} -
- - -
-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
- {/*
- - -
*/} -
- {/* */} - -
- -
- + setSchool(e.target.value)} type="text" name="state" className=' border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]' /> +
+
+ + setSchool(e.target.value)} type="text" name="city" className=' border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]' /> +
+
+ + setSchool(e.target.value)} type="text" name="annual" placeholder='' className=' border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]'/> +
+
+ + setSchool(e.target.value)} type="text" name="toddlers" className=' bg-white border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]' /> +
+
+ + setSchool(e.target.value)} type="text" name="early_start_programme" className=' bg-white border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]' /> +
+
+ + setSchool(e.target.value)} type="text" name="interakto" className=' bg-white border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]' /> +
+
+ + setSchool(e.target.value)} type="text" name="usage_expiry" className=' bg-white border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]' /> +
+ +
+ + setSchool(e.target.value)} type="text" name="agg_expiry" className=' bg-white border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]' /> +
+
+ +
+ +
+ +
+ + 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]' /> +
+
- - ) - } \ No newline at end of file + +
+ + + +
+ + ) +} + + diff --git a/src/pages/school-list/index.jsx b/src/pages/school-list/index.jsx index 6fe6eda..e0caabe 100644 --- a/src/pages/school-list/index.jsx +++ b/src/pages/school-list/index.jsx @@ -50,7 +50,7 @@ const fetchData = async () => { {school.map(data=> - + {data.id} {data.sname} {data.city} diff --git a/src/pages/school-list/slug.jsx b/src/pages/school-list/slug.jsx deleted file mode 100644 index ea2b87f..0000000 --- a/src/pages/school-list/slug.jsx +++ /dev/null @@ -1,241 +0,0 @@ -import NavBar from '../../components/NavBar' -import {useRouter} from "next/router"; -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' - -export default function addSchoolForm() { - const { query } = useRouter(); - 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) - } - // 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, - annual: event.target.annual.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`) - } - const [school, setUser] = useState([]); - const fetchData = async () => { - const response = await fetch("https://management.beanstalkedu.com/items/school?filter[status][_eq]=published"); - const data = await response.json(); - return setUser(data.data[0]); - } - // console.log(school.name) - - useEffect(() => { - fetchData(); - },[]) - - return ( -
-
- -
-

Items page

-

{query.id}

-

{query.name}

-
-
-
-
- -

Update School Information

-
-
-
- - -
-
- - -
-
- - -
} - { - allCities && allCities.length > 0 && -
- - - - - - - - - - - - - - - - -
-
- - -
-
- - -
-
- - -
-
- - -
- {/*
- - -
*/} -
- {/* */} - -
-
-
-
-
-
- ) - } \ No newline at end of file diff --git a/src/pages/user-list-by-school.jsx b/src/pages/user-list-by-school.jsx index a1d8f36..60cce76 100644 --- a/src/pages/user-list-by-school.jsx +++ b/src/pages/user-list-by-school.jsx @@ -1,8 +1,7 @@ import React, { useEffect, useState } from "react"; +import Link from 'next/link' + -import Image from 'next/image' -import { Inter } from 'next/font/google' -const inter = Inter({ subsets: ['latin'] }) import NavBar from '../components/NavBar' export default function Modal() { const [user, setUser] = useState([]); @@ -26,14 +25,14 @@ const fetchData = async () => {
- + - +
- + Add User - +
@@ -52,7 +51,7 @@ const fetchData = async () => { {user.map (data=> - + diff --git a/src/pages/user-list.jsx b/src/pages/user-list.jsx index a1d8f36..a30a2c2 100644 --- a/src/pages/user-list.jsx +++ b/src/pages/user-list.jsx @@ -1,8 +1,5 @@ import React, { useEffect, useState } from "react"; - -import Image from 'next/image' -import { Inter } from 'next/font/google' -const inter = Inter({ subsets: ['latin'] }) +import Link from 'next/link' import NavBar from '../components/NavBar' export default function Modal() { const [user, setUser] = useState([]); @@ -30,10 +27,10 @@ const fetchData = async () => { - + Add User - +
{data.uname} {data.phone} {data.email}
@@ -52,7 +49,7 @@ const fetchData = async () => { {user.map (data=> - + diff --git a/yarn.lock b/yarn.lock index d80d0da..18e599c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2245,6 +2245,11 @@ jws@^3.2.2: jwa "^1.4.1" safe-buffer "^5.0.1" +jwt-decode@^3.1.2: + version "3.1.2" + resolved "https://registry.yarnpkg.com/jwt-decode/-/jwt-decode-3.1.2.tgz#3fb319f3675a2df0c2895c8f5e9fa4b67b04ed59" + integrity sha512-UfpWE/VZn0iP50d8cz9NrZLM9lSWhcJ+0Gt/nm4by88UL+J1SiKN8/5dkjMmbEzwL2CAe+67GsegCbIKtbp75A== + language-subtag-registry@~0.3.2: version "0.3.22" resolved "https://registry.yarnpkg.com/language-subtag-registry/-/language-subtag-registry-0.3.22.tgz#2e1500861b2e457eba7e7ae86877cbd08fa1fd1d"
{data.uname} {data.phone} {data.email}