diff --git a/src/components/NavBar.tsx b/src/components/NavBar.tsx index 7e065e9..0b107da 100644 --- a/src/components/NavBar.tsx +++ b/src/components/NavBar.tsx @@ -3,7 +3,7 @@ import Link from 'next/link' export default function NavBar() { - const { data: session } = useSession() + const { data: session } = useSession() // console.log(session) if (session) { return ( @@ -32,6 +32,18 @@ export default function NavBar() { ) + // return ( + //
+ // <> + //
+ //

Logged out Successfully

+ // + //
+ + // + //
+ + // ) } diff --git a/src/pages/add-school-form.jsx b/src/pages/add-school-form.jsx index 993d622..ce762d7 100644 --- a/src/pages/add-school-form.jsx +++ b/src/pages/add-school-form.jsx @@ -1,4 +1,5 @@ import NavBar from '../components/NavBar' +import { signIn, signOut, useSession } from 'next-auth/react' import { useId, useState, useEffect, useMemo } from 'react'; import Select from 'react-select' import countryList from 'react-select-country-list' @@ -11,6 +12,7 @@ export default function AddSchool() { const [phoneValue, setphoneValue] = useState() const [allStates, setAllStates] = useState([]) const [allCities, setAllCities] = useState([]) + const { data: session } = useSession() const handleSelectAllStates = stateCode => { setAllCities([]) @@ -82,8 +84,8 @@ export default function AddSchool() { // alert(`Is this your full name: ${result.data}`) alert(`School Saved`) } - - return ( + if (session) { + return (
@@ -224,4 +226,12 @@ export default function AddSchool() {
) + } + return ( + <> + Not signed in
+ + + ) + } \ No newline at end of file diff --git a/src/pages/add-user-form.jsx b/src/pages/add-user-form.jsx index db8043a..cdf6860 100644 --- a/src/pages/add-user-form.jsx +++ b/src/pages/add-user-form.jsx @@ -1,5 +1,6 @@ // https://management.beanstalkedu.com/items/school // import React from 'react'; +import { signIn, signOut, useSession } from 'next-auth/react' import {useId, useState, useEffect, useMemo} from 'react'; import Select from 'react-select' import countryList from 'react-select-country-list' @@ -29,6 +30,7 @@ export default function addUserForm() { const options = useMemo(() => countryList().getData(), []) const [phoneValue, setphoneValue] = useState() let [individualValue = true, setindividualValue] = useState() + const { data: session } = useSession() const [allStates, setAllStates] = useState([]) const [allCities, setAllCities] = useState([]) @@ -154,233 +156,242 @@ export default function addUserForm() { // setLanguage(newAllLang) setCurrentType(e.target.value) } - return ( -
-
- -
-
-
- -

User Registration Form

-
-
-
- - + if (session) { + return ( +
+
+ +
+
+
+ +

User Registration Form

-
- - -
-
- - -
-
- - -
} - { - allCities && allCities.length > 0 && + +
+ + +
- + + +
+
+ + +
+
+
} -
- - -
-
- - -
-
- - -
- {individualValue && -
-
- - -
-
- - -
-
- - -
-
- - -
- -
- -
- {/*  
-  
-  
-  
-  
-  
-  
-  
-  
-  
*/} - {allLanguage && allLanguage.length && allLanguage.map(n => { - return ( -
-   - -
- ) - })} + { + allCities && allCities.length > 0 && +
+ + + + {school && school.map(data => + + )} + +
+
+ + +
+ {individualValue && +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+ +
+ +
+ {/*  
+  
+  
+  
+  
+  
+  
+  
+  
+  
*/} + {allLanguage && allLanguage.length && allLanguage.map(n => { + return ( +
+   + +
+ ) + })} +
+
+
+ + +
+
+ + +
+
+ +
-
- - -
-
- - -
-
- - -
+ } +
+ + {/* */}
- } -
- - {/* */} -
- -
-
-
-
+ +
+
+
+
+ ) + } + return ( + <> + Not signed in
+ + ) + } diff --git a/src/pages/api/listUsers.js b/src/pages/api/listUsers.js index dc02289..bb21264 100644 --- a/src/pages/api/listUsers.js +++ b/src/pages/api/listUsers.js @@ -15,7 +15,7 @@ console.log(req.body.school) const TABLE_NAME = 'user'; // Open a connection to the SQLite database - const db = new sqlite3.Database(DB_NAME); + const db = new sqlite3.Database(DB_NAME); const query = `SELECT * FROM ${TABLE_NAME}`; @@ -52,7 +52,7 @@ console.log(req.body.school) }; async function doSomething() { try { - const returnData = await getAllRows('user',4,10); + const returnData = await getAllRows('user',2,10); res.setHeader('Content-Type', 'application/json') res.status(200).json(returnData) // console.log(data); diff --git a/src/pages/edit-school.jsx b/src/pages/edit-school.jsx index da7ea0b..c3e74f4 100644 --- a/src/pages/edit-school.jsx +++ b/src/pages/edit-school.jsx @@ -1,3 +1,4 @@ +import { signIn, signOut, useSession } from 'next-auth/react' import {useId, useState, useEffect, useMemo} from 'react'; import 'react-phone-number-input/style.css' import NavBar from '../components/NavBar'; @@ -6,6 +7,7 @@ import Link from 'next/link' export default function EditSchool() { + const { data: session } = useSession() const router = useRouter(); const uploadToServer = async (event) => { const body = new FormData(); @@ -78,103 +80,112 @@ export default function EditSchool() { alert(`User data updated`) } - - return ( -
-
- -
-
-
- -   - List Users Under This School - -
- CSV   - + if (session) { + return ( +
+
+ +
+
+
+ +   + List Users Under This School + +
+ CSV   + +
+ {/* */} + +
+

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]' /> +
+
+ + 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]' /> +
+
+ +
+
+
+ +
+ + +
+ +
-

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]' /> -
-
- - 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]' /> -
-
- -
-
-
- -
- - -
- -
- -
- - -
-
-
+ + + + + + ) + } + return ( + <> + Not signed in
+ + ) + + } diff --git a/src/pages/edit-user.jsx b/src/pages/edit-user.jsx index 222933a..5732951 100644 --- a/src/pages/edit-user.jsx +++ b/src/pages/edit-user.jsx @@ -1,3 +1,4 @@ +import { signIn, signOut, useSession } from 'next-auth/react' import {useId, useState, useEffect, useMemo} from 'react'; import 'react-phone-number-input/style.css' import NavBar from '../components/NavBar'; @@ -7,6 +8,7 @@ export default function EditUser() { const router = useRouter(); const [user, setUser] = useState({}); + const { data: session } = useSession() useEffect(()=>{ if(router.query.user && router.query.user>0 ){ @@ -67,102 +69,110 @@ export default function EditUser() { alert(`User data updated`) } - - return ( -
-
- -
-
-
- -

Update User Information

+ if (session) { + return ( +
+
+ +
+
+
+ +

Update User Information

+
+
+
+ + setUser(e.target.value)} type="text" name="type" className=' bg-white border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]' /> +
+
+ + setUser(e.target.value)} type="text" name="uname" className=' border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]' /> +
+
+ + setUser(e.target.value)} type="text" name="status" className=' border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]' /> +
+
+ + setUser(e.target.value)} type="text" name="start_date" className=' border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]' /> +
+
+ + setUser(e.target.value)} type="text" name="end_date" className=' border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]' /> +
+
+ + setUser(e.target.value)} type="email" name="email" placeholder='ex. xyz@email.com' className=' border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]'/> +
+
+ + setUser(e.target.value)} type="text" name="phone" className=' bg-white border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]' /> +
+
+ + setUser(e.target.value)} type="text" name="country" className=' bg-white border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]' /> +
+
+ + setUser(e.target.value)} type="text" name="state" className=' bg-white border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]' /> +
+
+ + setUser(e.target.value)} type="text" name="city" className=' bg-white border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]' /> +
+ +
+ + setUser(e.target.value)} type="text" name="address" className=' bg-white border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]' /> +
+ {/*
+ + setUser(e.target.value)} type="text" name="address" className=' bg-white border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]' /> +
*/} +
+ + setUser(e.target.value)} type="text" name="school" className=' border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]' /> +
+
+ + setUser(e.target.value)} type="text" name="klas" className=' border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]' /> +
+
+ + setUser(e.target.value)} type="text" name="annual" className=' border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]' /> +
+
+ + setUser(e.target.value)} type="text" name="early_start_programme" className=' border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]' /> +
+
+ + setUser(e.target.value)} type="text" name="toddlers" className=' border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]' /> +
+
+ + setUser(e.target.value)} type="text" name="interakto" className=' border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]' /> +
+ +
+ +
+
-
-
- - setUser(e.target.value)} type="text" name="type" className=' bg-white border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]' /> -
-
- - setUser(e.target.value)} type="text" name="uname" className=' border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]' /> -
-
- - setUser(e.target.value)} type="text" name="status" className=' border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]' /> -
-
- - setUser(e.target.value)} type="text" name="start_date" className=' border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]' /> -
-
- - setUser(e.target.value)} type="text" name="end_date" className=' border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]' /> -
-
- - setUser(e.target.value)} type="email" name="email" placeholder='ex. xyz@email.com' className=' border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]'/> -
-
- - setUser(e.target.value)} type="text" name="phone" className=' bg-white border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]' /> -
-
- - setUser(e.target.value)} type="text" name="country" className=' bg-white border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]' /> -
-
- - setUser(e.target.value)} type="text" name="state" className=' bg-white border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]' /> -
-
- - setUser(e.target.value)} type="text" name="city" className=' bg-white border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]' /> -
- -
- - setUser(e.target.value)} type="text" name="address" className=' bg-white border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]' /> -
- {/*
- - setUser(e.target.value)} type="text" name="address" className=' bg-white border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]' /> -
*/} -
- - setUser(e.target.value)} type="text" name="school" className=' border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]' /> -
-
- - setUser(e.target.value)} type="text" name="klas" className=' border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]' /> -
-
- - setUser(e.target.value)} type="text" name="annual" className=' border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]' /> -
-
- - setUser(e.target.value)} type="text" name="early_start_programme" className=' border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]' /> -
-
- - setUser(e.target.value)} type="text" name="toddlers" className=' border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]' /> -
-
- - setUser(e.target.value)} type="text" name="interakto" className=' border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]' /> -
- -
- -
-
-
-
-
-
+ + + + ) + } + return ( + <> + Not signed in
+ + ) + } diff --git a/src/pages/edit-user4.jsx b/src/pages/edit-user4.jsx new file mode 100644 index 0000000..f282754 --- /dev/null +++ b/src/pages/edit-user4.jsx @@ -0,0 +1,426 @@ +// 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 [userDetails, setUserDetails] = useState({}); + + useEffect(()=>{ + if(router.query.user && router.query.user>1 ){ + const body = new FormData(); + body.append("user", router.query.user); + const response = await fetch("/api/getUserDetails", { + method: "POST", + body + }); + + fetch(`/api/getUserDetails?${router.query.user}`) + .then(res => res.json()) + .then(data => { + // console.log(router.query.school); + setUserDetails(data.data) + }) + } + + }, [router.query.school]); + const response = await fetch(endpoint, options) + + const result = await response.json() + + 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, + 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 = '/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 1a396be..864fc19 100644 --- a/src/pages/index.jsx +++ b/src/pages/index.jsx @@ -10,7 +10,6 @@ export default function Home() {

-
) } diff --git a/src/pages/login.jsx b/src/pages/login.jsx index 37ed896..2e95163 100644 --- a/src/pages/login.jsx +++ b/src/pages/login.jsx @@ -54,7 +54,7 @@ export default function SignIn({ csrfToken }) { {(formik) => (
@@ -88,7 +88,7 @@ export default function SignIn({ csrfToken }) {
@@ -107,7 +107,7 @@ export default function SignIn({ csrfToken }) {
diff --git a/src/pages/school-list/index.jsx b/src/pages/school-list/index.jsx index e0caabe..d84e445 100644 --- a/src/pages/school-list/index.jsx +++ b/src/pages/school-list/index.jsx @@ -1,4 +1,5 @@ // import SchoolEditForm from '../../components/SchoolEditForm' +import { signIn, signOut, useSession } from 'next-auth/react' import React, { useEffect, useState } from "react"; import Image from 'next/image' import { Inter } from 'next/font/google' @@ -6,6 +7,7 @@ const inter = Inter({ subsets: ['latin'] }) import NavBar from '../../components/NavBar' export default function Modal() { const [school, setSchool] = useState([]); + const { data: session} = useSession() const fetchData = async () => { const response = await fetch("/api/listSchlools"); const data = await response.json(); @@ -16,59 +18,68 @@ const fetchData = async () => { useEffect(() => { fetchData(); },[]) - +if (session) { + return ( +
+
+ +
+
+
+ + + + +
+ {/* +   + Add School + */} + + +
+
+ + + + + + + + + + + + + {school.map(data=> + + + + + + + + + )} + + {/* */} +
ID NameCityStatusExpiry Edit
{data.id}{data.sname}{data.city}{data.status}{data.usage_expiry} + + +
+
+
+
+
+ ) +} +{/* */} return ( -
-
- -
-
-
- - - - -
- {/* -   - Add School - */} - - -
-
- - - - - - - - - - - - - {school.map(data=> - - - - - - - - - )} - - {/* */} -
ID NameCityStatusExpiry Edit
{data.id}{data.sname}{data.city}{data.status}{data.usage_expiry} - - -
-
-
-
-
+ + <> + Not signed in
+ + ) } diff --git a/src/pages/school-list/index22.jsx b/src/pages/school-list/index22.jsx new file mode 100644 index 0000000..2cb9c9e --- /dev/null +++ b/src/pages/school-list/index22.jsx @@ -0,0 +1,84 @@ +// import SchoolEditForm from '../../components/SchoolEditForm' +import React, { useEffect, useState } from "react"; +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 [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); + } + console.log(school) + + useEffect(() => { + fetchData(); + },[]) + + return ( +
+
+ +
+ +
+ + + + + + + + + + + + + + {school.map(data=> + + + + + + + + + + + + + )} + + {/* */} +
IDSchool NameCityAnnualInteraktoStatus Edit
{data.id}{data.name}{data.city}{data.anual}{data.agreement_expiry_date}{data.early_start_programme}{data.toddlers}{data.interakto}{data.status} +
+
+
+
+
+ ) + +} diff --git a/src/pages/user-list.jsx b/src/pages/user-list.jsx index 35d48e4..af66822 100644 --- a/src/pages/user-list.jsx +++ b/src/pages/user-list.jsx @@ -1,7 +1,9 @@ +import { signIn, signOut, useSession } from 'next-auth/react' import React, { useEffect, useState } from "react"; import Link from 'next/link' import NavBar from '../components/NavBar' export default function Modal() { + const { data: session } = useSession() const [user, setUser] = useState([]); const [maxPageNumber, setMaxPageNumber] = useState([]); const fetchData = async () => { @@ -16,52 +18,50 @@ const fetchData = async () => { useEffect(() => { fetchData(); },[]) - +if(session) { return (
-
+
+
-
+
  • + + Next + + +
  • + + +
    + + + + +
    + + + Add User + +
    +
    - + @@ -71,36 +71,44 @@ const fetchData = async () => { - {user.map - (data=> - - - - - - - - - - - ) - } - -
    IDNameSchool Name Mobile Email School ID
    {data.id}{data.uname}{data.phone}{data.email}{data.school}{data.type}{data.end_date} - -
    -
    + {user.map + (data=> + + {data.id} + {data.uname} + {data.phone} + {data.email} + {data.school} + {data.type} + {data.end_date} + + + + + ) + } + + +
    ) +} + + return ( + <> + Not signed in
    + + + ) }