Compare commits
37 Commits
6e44cd02a0
...
main2
| Author | SHA1 | Date | |
|---|---|---|---|
| c7f13e8808 | |||
| fefb39141d | |||
| b3df941551 | |||
| 23ef8d9803 | |||
| e2b3a28f36 | |||
| c5d0167d3c | |||
| 96b933edc1 | |||
| 300df6001b | |||
| 54f74f8860 | |||
| 37786c459e | |||
| 4ea8d4d839 | |||
| 27657679d7 | |||
| 3e7e6b8943 | |||
| 81cfb6ce00 | |||
| 2b85a5a356 | |||
| a8e3dc48df | |||
| 02874ff761 | |||
| c5a98bd991 | |||
| cd27f080d6 | |||
| 326d16f312 | |||
| 16c9718f19 | |||
| 238fb238ff | |||
| 306c26c22a | |||
| dd3c5a829f | |||
| 7ffba324e6 | |||
| 2e747ce26c | |||
| 090ec80c0f | |||
| 3d1e9cce9e | |||
| 6627d42cb6 | |||
|
|
dc53ebba06 | ||
|
|
085739d96d | ||
| 7edd783dcb | |||
| d75cd53e48 | |||
| 0469b48bcb | |||
| 75a91cc670 | |||
| 52e0800ce7 | |||
| 0dd4c47f37 |
2
.gitignore
vendored
2
.gitignore
vendored
@@ -14,7 +14,7 @@
|
||||
|
||||
# production
|
||||
/build
|
||||
|
||||
/public/uploaded/*
|
||||
# misc
|
||||
.DS_Store
|
||||
*.pem
|
||||
|
||||
BIN
appUser.db
Normal file
BIN
appUser.db
Normal file
Binary file not shown.
BIN
data/appUser.db
Normal file
BIN
data/appUser.db
Normal file
Binary file not shown.
8
data/user.csv
Normal file
8
data/user.csv
Normal file
@@ -0,0 +1,8 @@
|
||||
uname,status,user,type,year,start_month,start_date,end_date,plan,klas,lang,phone,pass,annual,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
|
||||
|
BIN
mydatabase.db
Normal file
BIN
mydatabase.db
Normal file
Binary file not shown.
19
package.json
19
package.json
@@ -12,14 +12,29 @@
|
||||
"@types/node": "18.16.1",
|
||||
"@types/react": "18.2.0",
|
||||
"@types/react-dom": "18.2.1",
|
||||
"argon2": "^0.30.3",
|
||||
"autoprefixer": "10.4.14",
|
||||
"axios": "^1.4.0",
|
||||
"csv-parser": "^3.0.0",
|
||||
"eslint": "8.39.0",
|
||||
"eslint-config-next": "13.3.1",
|
||||
"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",
|
||||
"react": "18.2.0",
|
||||
"react-dom": "18.2.0",
|
||||
"react-phone-number-input": "^3.2.22",
|
||||
"react-select": "^5.7.3",
|
||||
"react-select-country-list": "^2.2.3",
|
||||
"rxjs": "^7.8.1",
|
||||
"sqlite3": "^5.1.6",
|
||||
"tailwindcss": "3.3.2",
|
||||
"typescript": "5.0.4"
|
||||
}
|
||||
"typescript": "5.0.4",
|
||||
"yup": "^1.1.1"
|
||||
},
|
||||
"devDependencies": {}
|
||||
}
|
||||
|
||||
1
public/img/1.svg
Normal file
1
public/img/1.svg
Normal file
@@ -0,0 +1 @@
|
||||
<svg className='rounded-full shadow-2xl' fill="#FE4501" width="100px" height="100px" viewBox="-9.6 -9.6 51.20 51.20" version="1.1" xmlns="http://www.w3.org/2000/svg"><g id="SVGRepo_bgCarrier" stroke-width="0"></g><g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round"></g><g id="SVGRepo_iconCarrier"> <title>school</title> <path d="M30 21.25h-6.25v-8.957l5.877 3.358c0.107 0.062 0.236 0.098 0.373 0.099h0c0.414-0.001 0.749-0.336 0.749-0.751 0-0.277-0.15-0.519-0.373-0.649l-0.004-0.002-13.623-7.784v-0.552c0.172 0.016 0.35 0.068 0.519 0.068 0.004 0 0.010 0 0.015 0 0.475 0 0.934-0.067 1.368-0.193l-0.035 0.009c0.323-0.063 0.693-0.099 1.073-0.099 0.392 0 0.775 0.039 1.146 0.112l-0.037-0.006c0.039 0.007 0.083 0.012 0.129 0.012 0.184 0 0.352-0.068 0.479-0.181l-0.001 0.001c0.161-0.139 0.263-0.343 0.264-0.571v-2.812c0 0 0-0 0-0 0-0.355-0.247-0.653-0.579-0.73l-0.005-0.001c-0.419-0.111-0.9-0.176-1.396-0.176-0.5 0-0.985 0.065-1.446 0.187l0.039-0.009c-0.288 0.067-0.618 0.105-0.958 0.105-0.231 0-0.457-0.018-0.678-0.052l0.025 0.003c-0.122-0.256-0.378-0.43-0.676-0.43-0.412 0-0.746 0.334-0.746 0.746 0 0.001 0 0.003 0 0.004v-0 4.565l-13.622 7.784c-0.227 0.132-0.378 0.374-0.378 0.651 0 0.414 0.336 0.75 0.75 0.75 0.137 0 0.265-0.037 0.376-0.101l-0.004 0.002 5.878-3.359v8.957h-6.25c-0.414 0-0.75 0.336-0.75 0.75v0 8c0 0.414 0.336 0.75 0.75 0.75h28c0.414-0 0.75-0.336 0.75-0.75v0-8c-0-0.414-0.336-0.75-0.75-0.75v0zM18.658 3.075c0.298-0.082 0.64-0.13 0.993-0.13 0.183 0 0.363 0.013 0.539 0.037l-0.020-0.002v1.339c-0.16-0.013-0.345-0.021-0.533-0.021-0.489 0-0.966 0.052-1.425 0.151l0.044-0.008c-0.304 0.088-0.653 0.139-1.014 0.139-0.174 0-0.344-0.012-0.512-0.034l0.020 0.002v-1.323c0.15 0.014 0.325 0.021 0.502 0.021 0.499 0 0.984-0.062 1.447-0.18l-0.041 0.009zM2.75 22.75h5.5v6.5h-5.5zM9.75 22v-10.564l6.25-3.571 6.25 3.572v17.814h-2.5v-5.25c-0-0.414-0.336-0.75-0.75-0.75h-6c-0.414 0-0.75 0.336-0.75 0.75v0 5.25h-2.5zM13.75 29.25v-4.5h4.5v4.5zM29.25 29.25h-5.5v-6.5h5.5zM16 19.75c2.071 0 3.75-1.679 3.75-3.75s-1.679-3.75-3.75-3.75c-2.071 0-3.75 1.679-3.75 3.75v0c0.002 2.070 1.68 3.748 3.75 3.75h0zM16 13.75c1.243 0 2.25 1.007 2.25 2.25s-1.007 2.25-2.25 2.25c-1.243 0-2.25-1.007-2.25-2.25v0c0.002-1.242 1.008-2.248 2.25-2.25h0z"></path> </g></svg>
|
||||
|
After Width: | Height: | Size: 2.2 KiB |
1
public/img/2.svg
Normal file
1
public/img/2.svg
Normal file
@@ -0,0 +1 @@
|
||||
<svg className='rounded-full shadow-md ' width="100px" height="100px" viewBox="-3.12 -3.12 30.24 30.24" fill="none" xmlns="http://www.w3.org/2000/svg"><g id="SVGRepo_bgCarrier" stroke-width="0"></g><g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round"></g><g id="SVGRepo_iconCarrier"> <path opacity="0.4" d="M11.4604 13.7299C13.0123 13.7299 14.2704 12.4718 14.2704 10.9199C14.2704 9.36794 13.0123 8.10986 11.4604 8.10986C9.90847 8.10986 8.65039 9.36794 8.65039 10.9199C8.65039 12.4718 9.90847 13.7299 11.4604 13.7299Z" stroke="#FE4501" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"></path> <path opacity="0.4" d="M16.6495 20.1998C16.6495 17.8698 14.3295 15.9697 11.4595 15.9697C8.58953 15.9697 6.26953 17.8598 6.26953 20.1998" stroke="#FE4501" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"></path> <path d="M21 12.5C21 17.75 16.75 22 11.5 22C6.25 22 2 17.75 2 12.5C2 7.25 6.25 3 11.5 3C12.81 3 14.06 3.25999 15.2 3.73999C15.07 4.13999 15 4.56 15 5C15 5.75 15.21 6.46 15.58 7.06C15.78 7.4 16.04 7.70997 16.34 7.96997C17.04 8.60997 17.97 9 19 9C19.44 9 19.86 8.92998 20.25 8.78998C20.73 9.92998 21 11.19 21 12.5Z" stroke="#FE4501" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"></path> <path d="M23 5C23 5.32 22.96 5.62999 22.88 5.92999C22.79 6.32999 22.63 6.72 22.42 7.06C21.94 7.87 21.17 8.49998 20.25 8.78998C19.86 8.92998 19.44 9 19 9C17.97 9 17.04 8.60997 16.34 7.96997C16.04 7.70997 15.78 7.4 15.58 7.06C15.21 6.46 15 5.75 15 5C15 4.56 15.07 4.13999 15.2 3.73999C15.39 3.15999 15.71 2.64002 16.13 2.21002C16.86 1.46002 17.88 1 19 1C20.18 1 21.25 1.51002 21.97 2.33002C22.61 3.04002 23 3.98 23 5Z" stroke="#FE4501" stroke-width="1.5" stroke-miterlimit="10" stroke-linecap="round" stroke-linejoin="round"></path> <path d="M20.4898 4.97998H17.5098" stroke="#FE4501" stroke-width="1.5" stroke-miterlimit="10" stroke-linecap="round" stroke-linejoin="round"></path> <path d="M19 3.52002V6.51001" stroke="#FE4501" stroke-width="1.5" stroke-miterlimit="10" stroke-linecap="round" stroke-linejoin="round"></path> </g></svg>
|
||||
|
After Width: | Height: | Size: 2.1 KiB |
1
public/img/3.svg
Normal file
1
public/img/3.svg
Normal file
@@ -0,0 +1 @@
|
||||
<svg width="20px" height="20px" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><g id="SVGRepo_bgCarrier" stroke-width="0"></g><g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round"></g><g id="SVGRepo_iconCarrier"> <path fill-rule="evenodd" clip-rule="evenodd" d="M21.1213 2.70705C19.9497 1.53548 18.0503 1.53547 16.8787 2.70705L15.1989 4.38685L7.29289 12.2928C7.16473 12.421 7.07382 12.5816 7.02986 12.7574L6.02986 16.7574C5.94466 17.0982 6.04451 17.4587 6.29289 17.707C6.54127 17.9554 6.90176 18.0553 7.24254 17.9701L11.2425 16.9701C11.4184 16.9261 11.5789 16.8352 11.7071 16.707L19.5556 8.85857L21.2929 7.12126C22.4645 5.94969 22.4645 4.05019 21.2929 2.87862L21.1213 2.70705ZM18.2929 4.12126C18.6834 3.73074 19.3166 3.73074 19.7071 4.12126L19.8787 4.29283C20.2692 4.68336 20.2692 5.31653 19.8787 5.70705L18.8622 6.72357L17.3068 5.10738L18.2929 4.12126ZM15.8923 6.52185L17.4477 8.13804L10.4888 15.097L8.37437 15.6256L8.90296 13.5112L15.8923 6.52185ZM4 7.99994C4 7.44766 4.44772 6.99994 5 6.99994H10C10.5523 6.99994 11 6.55223 11 5.99994C11 5.44766 10.5523 4.99994 10 4.99994H5C3.34315 4.99994 2 6.34309 2 7.99994V18.9999C2 20.6568 3.34315 21.9999 5 21.9999H16C17.6569 21.9999 19 20.6568 19 18.9999V13.9999C19 13.4477 18.5523 12.9999 18 12.9999C17.4477 12.9999 17 13.4477 17 13.9999V18.9999C17 19.5522 16.5523 19.9999 16 19.9999H5C4.44772 19.9999 4 19.5522 4 18.9999V7.99994Z" fill="#1d1d1d"></path> </g></svg>
|
||||
|
After Width: | Height: | Size: 1.4 KiB |
1
public/img/4.svg
Normal file
1
public/img/4.svg
Normal file
@@ -0,0 +1 @@
|
||||
<svg width="20px" height="20px" viewBox="0 0 15 15" fill="none" xmlns="http://www.w3.org/2000/svg" stroke="#ffffff"><g id="SVGRepo_bgCarrier" stroke-width="0"></g><g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round"></g><g id="SVGRepo_iconCarrier"> <path d="M7.5 4.5L11.5 6.5V14.5H3.5V6.5L7.5 4.5ZM7.5 4.5V0M0 14.5H15M1.5 14.5V8.5H3.5M13.5 14.5V8.5H11.5M6.5 14.5V11.5H8.5V14.5M7.5 0.5H10.5V2.5H7.5M7.5 9.5C6.94772 9.5 6.5 9.05228 6.5 8.5C6.5 7.94772 6.94772 7.5 7.5 7.5C8.05228 7.5 8.5 7.94772 8.5 8.5C8.5 9.05228 8.05228 9.5 7.5 9.5Z" stroke="#ffffff"></path> </g></svg>
|
||||
|
After Width: | Height: | Size: 595 B |
@@ -1,19 +1,23 @@
|
||||
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 (
|
||||
<main>
|
||||
<div>
|
||||
<section className="container-fluid bg-[#FFF6F2]">
|
||||
<div className="container mx-auto px-4">
|
||||
<div className='flex flex-row gap-x-2 md:gap-x-16 p-4 justify-center whitespace-nowrap'>
|
||||
<a href="/add-school-form">Add School </a>|
|
||||
<a href="/school-list">School List</a>|
|
||||
<a href="/add-user-form">Add User </a>|
|
||||
<a href="/user-list">User List </a>
|
||||
<div className='flex flex-row p-2 justify-center whitespace-nowrap'>
|
||||
<Link href="/add-school-form" className='text-grey-400 hover:bg-blue-200 rounded-lg p-2 pt-1 pb-1 ml-2 mr-2'>Add School </Link>
|
||||
<Link href="/school-list" className='text-grey-400 hover:bg-blue-200 rounded-lg p-2 pt-1 pb-1 ml-2 mr-2'>School List</Link>
|
||||
<Link href="/add-user-form" className='text-grey-400 hover:bg-blue-200 rounded-lg p-2 pt-1 pb-1 ml-2 mr-2'>Add User </Link>
|
||||
<Link href="/upload-user" className='text-grey-400 hover:bg-blue-200 rounded-lg p-2 pt-1 pb-1 ml-2 mr-2'>Upload User </Link>
|
||||
<Link href="/user-list" className='text-grey-400 hover:bg-blue-200 rounded-lg p-2 pt-1 pb-1 ml-2 mr-2'> User List </Link>
|
||||
<Link href="#" className='text-grey-400 hover:bg-blue-200 rounded-lg p-2 pt-1 pb-1 ml-2 mr-2' onClick={() => signOut()}>Sign out</Link>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
@@ -22,3 +26,24 @@ export default function Home() {
|
||||
</main>
|
||||
)
|
||||
}
|
||||
return (
|
||||
<>
|
||||
Not signed in <br />
|
||||
<button onClick={() => signIn()}>Sign in</button>
|
||||
</>
|
||||
)
|
||||
// return (
|
||||
// <div className='container mx-auto flex-col justify-center place-items-center 2xl:px-[500px] mt-24 '>
|
||||
// <>
|
||||
// <div className='grid grid-rows-2 lg:py-56 rounded-xl place-items-center bg-[#FFF6F2]'>
|
||||
// <p className='text-center text-2xl italic'>Logged out Successfully </p>
|
||||
// <button onClick={() => signIn()} className="bg-[#FE4501] w-fit px-6 py-1.5 rounded-lg text-white font-bold text-xl">Sign in Now</button>
|
||||
// </div>
|
||||
|
||||
// </>
|
||||
// </div>
|
||||
|
||||
// )
|
||||
|
||||
}
|
||||
|
||||
|
||||
216
src/components/SchoolEditForm.jsx
Normal file
216
src/components/SchoolEditForm.jsx
Normal file
@@ -0,0 +1,216 @@
|
||||
import React, { useId, useEffect, useState, 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 Modal() {
|
||||
const options = useMemo(() => countryList().getData(), [])
|
||||
const [phoneValue, setphoneValue] = useState()
|
||||
const [allStates, setAllStates] = useState([])
|
||||
const [allCities, setAllCities] = useState([])
|
||||
|
||||
const [showModal, setShowModal] = React.useState(false);
|
||||
const [school, setSchool] = useState([]);
|
||||
const fetchData = async () => {
|
||||
const response = await fetch("https://management.beanstalkedu.com/items/school?filter[status][_eq]=published");
|
||||
const data = await response.json();
|
||||
return setSchool(data.data);
|
||||
}
|
||||
console.log(school)
|
||||
|
||||
useEffect(() => {
|
||||
fetchData();
|
||||
},[])
|
||||
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 (
|
||||
|
||||
<>
|
||||
<div className="mt-4 items-center flex justify-center place-items-center">
|
||||
<button className="block bg-[#FFF6F2] focus:ring-4 focus:outline-none focus:ring-[#FFF6F2] font-medium rounded-lg text-sm px-2 py-1.5 text-center dark:bg-blue-600 dark:hover:bg-blue-700 dark:focus:ring-blue-800 mb-8" type="button" onClick={() => setShowModal(true)}>Edit</button>
|
||||
</div>
|
||||
{showModal ? (
|
||||
<>
|
||||
<div
|
||||
className="justify-center items-center flex overflow-x-hidden overflow-y-auto fixed inset-0 z-50 outline-none focus:outline-none"
|
||||
>
|
||||
<div className="relative w-auto my-6 mx-auto max-w-3xl">
|
||||
{/*content*/}
|
||||
<div className="border-0 rounded-lg shadow-lg relative flex flex-col w-full bg-white outline-none focus:outline-none">
|
||||
{/*header*/}
|
||||
|
||||
<div>
|
||||
<section className='container-fluid'>
|
||||
<div className="">
|
||||
<h3 className=" font-semibold text-blue-700">Edit Form</h3>
|
||||
<button className="p-1 ml-auto text-blue-700" onClick={() => setShowModal(false)}>
|
||||
<span className="text-3xl text-blue-700">x</span>
|
||||
</button>
|
||||
</div>
|
||||
<div className='flex flex-row justify-center place-items-center bg-[#FFF6F2] pt-6 pb-20 rounded-tl-[50px] rounded-br-[50px]'>
|
||||
<div className='flex flex-col justify-center place-items-center'>
|
||||
{/* <img src="/img/1.svg" alt="" /> */}
|
||||
{/* <p className='text-2xl md:text-4xl font-bold underline decoration-4 decoration-[#FE4501] pb-10'>School Registration Form</p> */}
|
||||
</div>
|
||||
<form onSubmit={handleSubmit} className='w-full px-6 md:px-20'>
|
||||
<div className='flex flex-col w-full'>
|
||||
<label htmlFor="school" className='text-xl font-bold'>School Name</label>
|
||||
<input type="text" name="schoolName" placeholder='School Name' className='border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]' />
|
||||
</div>
|
||||
<div className='flex flex-col w-full pt-4'>
|
||||
<label htmlFor="school_email_id" className='text-xl font-bold'> Email ID</label>
|
||||
<input type="text" 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]' />
|
||||
</div>
|
||||
<div className='flex flex-col w-full'>
|
||||
<label htmlFor="country" className='text-xl font-bold'>Country</label>
|
||||
<select
|
||||
className='bg-white border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]'
|
||||
name="country" instanceId="" options="" value=""
|
||||
onChange="" ></select>
|
||||
</div>
|
||||
{/* <div className='flex flex-col w-full'>
|
||||
<label htmlFor="state" className='text-xl font-bold'>State</label>
|
||||
<select
|
||||
className='bg-white border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]'
|
||||
name="state" options={allStates} value={allStates[0].name}
|
||||
onChange={handleSelectAllStates} >
|
||||
|
||||
</select>
|
||||
</div> */}
|
||||
<div className='flex flex-col w-full'>
|
||||
<label htmlFor="Cities" className='text-xl font-bold'>Cities</label>
|
||||
<select
|
||||
className='bg-white border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]'
|
||||
name="cities" options="" value=""
|
||||
></select>
|
||||
</div>
|
||||
<div className='flex flex-col w-full'>
|
||||
<label htmlFor="phone" className='text-xl font-bold'> Phone</label>
|
||||
</div>
|
||||
<div className='flex flex-col w-full pt-4'>
|
||||
<label htmlFor="annual" className='text-xl font-bold'>annual</label>
|
||||
<select name="annual" className=' bg-white border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]'>
|
||||
<option value="0" >-NA-</option>
|
||||
<option value="January">January</option>
|
||||
<option value="February">February</option>
|
||||
<option value="March">March</option>
|
||||
<option value="April">April</option>
|
||||
<option value="May">May</option>
|
||||
<option value="June">June</option>
|
||||
<option value="July">July</option>
|
||||
<option value="August">August</option>
|
||||
<option value="September">September</option>
|
||||
<option value="October">October</option>
|
||||
<option value="November">November</option>
|
||||
<option value="December">December</option>
|
||||
</select>
|
||||
</div>
|
||||
<div className='flex flex-col w-full pt-4'>
|
||||
<label htmlFor="toddlers" className='text-xl font-bold'>Toddlers</label>
|
||||
<select name="toddlers" className=' bg-white border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]'>
|
||||
<option value="0" >-NA-</option>
|
||||
<option value="January">January</option>
|
||||
<option value="February">February</option>
|
||||
<option value="March">March</option>
|
||||
<option value="April">April</option>
|
||||
<option value="May">May</option>
|
||||
<option value="June">June</option>
|
||||
<option value="July">July</option>
|
||||
<option value="August">August</option>
|
||||
<option value="September">September</option>
|
||||
<option value="October">October</option>
|
||||
<option value="November">November</option>
|
||||
<option value="December">December</option>
|
||||
</select>
|
||||
</div>
|
||||
<div className='flex flex-col w-full pt-4'>
|
||||
<label htmlFor="early_start_programme" className='text-xl font-bold'>Early Start Program</label>
|
||||
<select name="early_start_programme" className='bg-white border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]'>
|
||||
<option value="0" >-NA-</option>
|
||||
<option value="January">January</option>
|
||||
<option value="February">February</option>
|
||||
<option value="March">March</option>
|
||||
<option value="April">April</option>
|
||||
<option value="May">May</option>
|
||||
<option value="June">June</option>
|
||||
<option value="July">July</option>
|
||||
<option value="August">August</option>
|
||||
<option value="September">September</option>
|
||||
<option value="October">October</option>
|
||||
<option value="November">November</option>
|
||||
<option value="December">December</option>
|
||||
</select>
|
||||
</div>
|
||||
<div className='flex flex-col w-full pt-4'>
|
||||
<label htmlFor="interakto" className='text-xl font-bold'>Interakto</label>
|
||||
<select name="interakto" className='bg-white border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]'>
|
||||
<option value="na">-NA-</option>
|
||||
<option value="January"> January</option>
|
||||
<option value="February"> February</option>
|
||||
<option value="March"> March</option>
|
||||
<option value="April"> April</option>
|
||||
<option value="May"> May</option>
|
||||
<option value="June"> June</option>
|
||||
<option value="July"> July</option>
|
||||
<option value="August"> August</option>
|
||||
<option value="September"> September</option>
|
||||
<option value="November"> November</option>
|
||||
<option value="December"> December</option>
|
||||
</select>
|
||||
</div>
|
||||
<div className='flex flex-col w-full'>
|
||||
<label htmlFor="agreement_expiry_date" className='text-xl font-bold pt-4'>Agreement Expiry Date</label>
|
||||
<input type="date" name="agreement_expiry_date" id="agreement_expiry_date" className=' border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]' />
|
||||
</div>
|
||||
{/* <div className='flex flex-col w-full'>
|
||||
<label htmlFor="school_agreement" className='text-xl font-bold pt-4'>Upload School Agreement</label>
|
||||
<input type="file" name="school_agreement" id="school_agreement" className=' border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]' />
|
||||
</div> */}
|
||||
<div className='flex justify-center pt-8'>
|
||||
{/* <a href="/school-list"><button type='submit' className='bg-[#FE4501] hover:shadow-2xl hover:shadow-[#F2B705] p-2.5 rounded-lg px-10 rounded-tl-full rounded-br-full hover:scale-110 active:scale-75 duration-200 text-xl font-bold text-white cursor-pointer'>Submit Now</button></a> */}
|
||||
<input type="submit" value="Save" className='bg-[#FE4501] hover:shadow-2xl hover:shadow-[#F2B705] p-2.5 rounded-lg px-10 rounded-tl-full rounded-br-full hover:scale-110 active:scale-75 duration-200 text-xl font-bold text-white cursor-pointer' />
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="opacity-25 fixed inset-0 z-40 bg-black"></div>
|
||||
</>
|
||||
) : null}
|
||||
</>
|
||||
);
|
||||
}
|
||||
18
src/components/refreshTokenHandler.js
Normal file
18
src/components/refreshTokenHandler.js
Normal file
@@ -0,0 +1,18 @@
|
||||
import { useSession } from "next-auth/react";
|
||||
import { useEffect } from "react";
|
||||
|
||||
const RefreshTokenHandler = (props) => {
|
||||
const { data: session } = useSession();
|
||||
|
||||
useEffect(() => {
|
||||
if(!!session) {
|
||||
// We did set the token to be ready to refresh after 23 hours, here we set interval of 23 hours 30 minutes.
|
||||
const timeRemaining = Math.round((((session.accessTokenExpiry - 30 * 60 * 1000) - Date.now()) / 1000));
|
||||
props.setInterval(timeRemaining > 0 ? timeRemaining : 0);
|
||||
}
|
||||
}, [session]);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
export default RefreshTokenHandler;
|
||||
29
src/components/useAuth.js
Normal file
29
src/components/useAuth.js
Normal file
@@ -0,0 +1,29 @@
|
||||
import { signOut, useSession } from "next-auth/react";
|
||||
import { useRouter } from "next/router";
|
||||
import { useEffect, useState } from "react";
|
||||
|
||||
export default function useAuth(shouldRedirect) {
|
||||
const { data: session } = useSession();
|
||||
const router = useRouter();
|
||||
const [isAuthenticated, setIsAuthenticated] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
if (session?.error === "RefreshAccessTokenError") {
|
||||
signOut({ callbackUrl: '/login', redirect: shouldRedirect });
|
||||
}
|
||||
|
||||
if (session === null) {
|
||||
if (router.route !== '/login') {
|
||||
router.replace('/login');
|
||||
}
|
||||
setIsAuthenticated(false);
|
||||
} else if (session !== undefined) {
|
||||
if (router.route === '/login') {
|
||||
router.replace('/');
|
||||
}
|
||||
setIsAuthenticated(true);
|
||||
}
|
||||
}, [session]);
|
||||
|
||||
return isAuthenticated;
|
||||
}
|
||||
@@ -1,6 +1,18 @@
|
||||
import '@/styles/globals.css'
|
||||
import type { AppProps } from 'next/app'
|
||||
|
||||
import { SessionProvider } from 'next-auth/react';
|
||||
import { useState } from 'react';
|
||||
import RefreshTokenHandler from '../components/refreshTokenHandler.js';
|
||||
|
||||
|
||||
export default function App({ Component, pageProps }: AppProps) {
|
||||
return <Component {...pageProps} />
|
||||
const [interval, setInterval] = useState(0);
|
||||
return (
|
||||
<SessionProvider session={pageProps.session} refetchInterval={interval}>
|
||||
<Component {...pageProps} />
|
||||
<RefreshTokenHandler setInterval={setInterval} />
|
||||
</SessionProvider>
|
||||
)
|
||||
// return <Component {...pageProps} />
|
||||
}
|
||||
|
||||
237
src/pages/add-school-form.jsx
Normal file
237
src/pages/add-school-form.jsx
Normal file
@@ -0,0 +1,237 @@
|
||||
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'
|
||||
import 'react-phone-number-input/style.css'
|
||||
import PhoneInput from 'react-phone-number-input'
|
||||
|
||||
export default function AddSchool() {
|
||||
const [countryValue, setCountryValue] =useState('')
|
||||
const options = useMemo(() => countryList().getData(), [])
|
||||
const [phoneValue, setphoneValue] = useState()
|
||||
const [allStates, setAllStates] = useState([])
|
||||
const [allCities, setAllCities] = useState([])
|
||||
const { data: session } = useSession()
|
||||
|
||||
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",
|
||||
sname: event.target.sname.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 JSONdata = JSON.stringify(data)
|
||||
console.log(data)
|
||||
const endpoint = '/api/addSchool'
|
||||
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`)
|
||||
}
|
||||
if (session) {
|
||||
return (
|
||||
<main>
|
||||
<div>
|
||||
<NavBar />
|
||||
<section className='container mx-auto px-4 my-16 lg:px-28 xl:px-56 2xl:px-96'>
|
||||
<div className='flex flex-col justify-center place-items-center bg-[#FFF6F2] pt-6 pb-20 rounded-tl-[50px] rounded-br-[50px]'>
|
||||
<div className='flex flex-col justify-center place-items-center'>
|
||||
<img src="/img/1.svg" alt="" />
|
||||
<p className='text-2xl md:text-4xl font-bold underline decoration-4 decoration-[#FE4501] pb-10'>School Registration Form</p>
|
||||
</div>
|
||||
<form onSubmit={handleSubmit} className='w-full px-6 md:px-20'>
|
||||
<div className='flex flex-col w-full'>
|
||||
<label htmlFor="school" className='text-xl font-bold'>School Name</label>
|
||||
<input type="text" name="sname" placeholder='School Name' className='border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]' />
|
||||
</div>
|
||||
<div className='flex flex-col w-full pt-4'>
|
||||
<label htmlFor="email" className='text-xl font-bold'> Email ID</label>
|
||||
<input type="text" name="email" id="email" placeholder='School Email ID' className=' border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]' />
|
||||
</div>
|
||||
<div className='flex flex-col w-full'>
|
||||
<label htmlFor="country" className='text-xl font-bold'>Country</label>
|
||||
<Select
|
||||
className='bg-white border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]'
|
||||
name="country" instanceId={useId()} options={options} value={countryValue}
|
||||
onChange={selectCountry}/>
|
||||
</div>
|
||||
{allStates && allStates.length > 0 &&
|
||||
<div className='flex flex-col w-full'>
|
||||
<label htmlFor="state" className='text-xl font-bold'>State</label>
|
||||
<Select
|
||||
className='bg-white border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]'
|
||||
name="state" options={allStates} value={allStates[0].name}
|
||||
onChange={handleSelectAllStates}/>
|
||||
</div>}
|
||||
{
|
||||
allCities && allCities.length > 0 &&
|
||||
<div className='flex flex-col w-full'>
|
||||
<label htmlFor="cyti" className='text-xl font-bold'>City</label>
|
||||
<Select
|
||||
className='bg-white border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]'
|
||||
name="city" options={allCities} value={allCities[0].name}
|
||||
// onChange={() => {}}
|
||||
/>
|
||||
</div>}
|
||||
<div className='flex flex-col w-full'>
|
||||
<label htmlFor="phone" className='text-xl font-bold'> Phone</label>
|
||||
<PhoneInput className=' border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]' name="phone" placeholder="Enter phone number" value={phoneValue} onChange={setphoneValue}/>
|
||||
</div>
|
||||
<div className='flex flex-col w-full pt-4'>
|
||||
<label htmlFor="annual" className='text-xl font-bold'> Annual</label>
|
||||
<select name="annual" className=' bg-white border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]'>
|
||||
<option value="0" >-NA-</option>
|
||||
<option value="Jan">Jan</option>
|
||||
<option value="Feb">Feb</option>
|
||||
<option value="Mar">Mar</option>
|
||||
<option value="Apr">Apr</option>
|
||||
<option value="May">May</option>
|
||||
<option value="Jun">Jun</option>
|
||||
<option value="Jul">Jul</option>
|
||||
<option value="Aug">Aug</option>
|
||||
<option value="Sept">Sept</option>
|
||||
<option value="Oct">Oct</option>
|
||||
<option value="Nov">Nov</option>
|
||||
<option value="Dec">Dec</option>
|
||||
</select>
|
||||
</div>
|
||||
<div className='flex flex-col w-full pt-4'>
|
||||
<label htmlFor="toddlers" className='text-xl font-bold'>Toddlers</label>
|
||||
<select name="toddlers" className=' bg-white border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]'>
|
||||
<option value="0" >-NA-</option>
|
||||
<option value="Jan">Jan</option>
|
||||
<option value="Feb">Feb</option>
|
||||
<option value="Mar">Mar</option>
|
||||
<option value="Apr">Apr</option>
|
||||
<option value="May">May</option>
|
||||
<option value="Jun">Jun</option>
|
||||
<option value="Jul">Jul</option>
|
||||
<option value="Aug">Aug</option>
|
||||
<option value="Sept">Sept</option>
|
||||
<option value="Oct">Oct</option>
|
||||
<option value="Nov">Nov</option>
|
||||
<option value="Dec">Dec</option>
|
||||
</select>
|
||||
</div>
|
||||
<div className='flex flex-col w-full pt-4'>
|
||||
<label htmlFor="early_start_programme" className='text-xl font-bold'>Early Start Programme</label>
|
||||
<select name="early_start_programme" className='bg-white border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]'>
|
||||
<option value="0" >-NA-</option>
|
||||
<option value="Jan">Jan</option>
|
||||
<option value="Feb">Feb</option>
|
||||
<option value="Mar">Mar</option>
|
||||
<option value="Apr">Apr</option>
|
||||
<option value="May">May</option>
|
||||
<option value="Jun">Jun</option>
|
||||
<option value="Jul">Jul</option>
|
||||
<option value="Aug">Aug</option>
|
||||
<option value="Sept">Sept</option>
|
||||
<option value="Oct">Oct</option>
|
||||
<option value="Nov">Nov</option>
|
||||
<option value="Dec">Dec</option>
|
||||
</select>
|
||||
</div>
|
||||
<div className='flex flex-col w-full pt-4'>
|
||||
<label htmlFor="interakto" className='text-xl font-bold'>Interakto</label>
|
||||
<select name="interakto" className='bg-white border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]'>
|
||||
<option value="na">-NA-</option>
|
||||
<option value="Jan"> Jan</option>
|
||||
<option value="Feb"> Feb</option>
|
||||
<option value="Mar"> Mar</option>
|
||||
<option value="Apr"> Apr</option>
|
||||
<option value="May"> May</option>
|
||||
<option value="Jun"> Jun</option>
|
||||
<option value="Jul"> Jul</option>
|
||||
<option value="Aug"> Aug</option>
|
||||
<option value="Sept"> Sept</option>
|
||||
<option value="Nov"> Nov</option>
|
||||
<option value="Dec"> Dec</option>
|
||||
</select>
|
||||
</div>
|
||||
<div className='flex flex-col w-full'>
|
||||
<label htmlFor="agg_expiry" className='text-xl font-bold pt-4'>Agreement Expiry Date</label>
|
||||
<input type="date" name="agg_expiry" id="agg_expiry" className=' border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]' />
|
||||
</div>
|
||||
<div className='flex flex-col w-full'>
|
||||
<label htmlFor="usage_expiry" className='text-xl font-bold pt-4'>Usage Expiry Date</label>
|
||||
<input type="date" name="usage_expiry" id="usage_expiry" className=' border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]' />
|
||||
</div>
|
||||
{/* <div className='flex flex-col w-full'>
|
||||
<label htmlFor="school_agreement" className='text-xl font-bold pt-4'>Upload School Agreement</label>
|
||||
<input type="file" name="school_agreement" id="school_agreement" className=' border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]' />
|
||||
</div> */}
|
||||
<div className='flex justify-center pt-8'>
|
||||
{/* <a href="/school-list"><button type='submit' className='bg-[#FE4501] hover:shadow-2xl hover:shadow-[#F2B705] p-2.5 rounded-lg px-10 rounded-tl-full rounded-br-full hover:scale-110 active:scale-75 duration-200 text-xl font-bold text-white cursor-pointer'>Submit Now</button></a> */}
|
||||
<input type="submit" value="Save" className='bg-[#FE4501] hover:shadow-2xl hover:shadow-[#F2B705] p-2.5 rounded-lg px-10 rounded-tl-full rounded-br-full hover:scale-110 active:scale-75 duration-200 text-xl font-bold text-white cursor-pointer' />
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
</main>
|
||||
)
|
||||
}
|
||||
return (
|
||||
<>
|
||||
Not signed in <br />
|
||||
<button onClick={() => signIn()}>Sign in</button>
|
||||
</>
|
||||
)
|
||||
|
||||
}
|
||||
@@ -1,138 +0,0 @@
|
||||
import React, { useState } from 'react';
|
||||
import Image from 'next/image'
|
||||
import NavBar from '../components/NavBar'
|
||||
import { Inter } from 'next/font/google'
|
||||
|
||||
const inter = Inter({ subsets: ['latin'] })
|
||||
|
||||
function Postformvalue(props) {
|
||||
const [formvalue, setFormvalue]= useState({school:'', interakto:'', early_start_program:'', anual:'', toddlers:'', country:'', end_date:'', });
|
||||
|
||||
const handleInput =(e)=>{
|
||||
const { name, value}= e.target;
|
||||
setFormvalue({...formvalue, [name]:value});
|
||||
console.log(formvalue);
|
||||
}
|
||||
const handleFormsubmit= async (e)=>{
|
||||
e.preventDefault();
|
||||
|
||||
await fetch('http://localhost/devopsdeveloper/ReactFormvalue/', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
name:formvalue.school,
|
||||
anual: formvalue.anual,
|
||||
toddlers: formvalue.toddlers,
|
||||
start_date: formvalue.country,
|
||||
early_start_program: formvalue.early_start_program,
|
||||
interakto: formvalue.interakto,
|
||||
|
||||
})
|
||||
});
|
||||
console.log("success");
|
||||
|
||||
}
|
||||
|
||||
return (
|
||||
<main>
|
||||
<div>
|
||||
<NavBar />
|
||||
<section className='container mx-auto px-4 my-16 lg:px-28 xl:px-56 2xl:px-96'>
|
||||
<div className='flex flex-col justify-center place-items-center bg-[#FFF6F2] pt-6 pb-20 rounded-tl-[50px] rounded-br-[50px]'>
|
||||
<div className='flex flex-col justify-center place-items-center'>
|
||||
<svg className='rounded-full shadow-2xl' fill="#FE4501" width="100px" height="100px" viewBox="-9.6 -9.6 51.20 51.20" version="1.1" xmlns="http://www.w3.org/2000/svg"><g id="SVGRepo_bgCarrier" stroke-width="0"></g><g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round"></g><g id="SVGRepo_iconCarrier"> <title>school</title> <path d="M30 21.25h-6.25v-8.957l5.877 3.358c0.107 0.062 0.236 0.098 0.373 0.099h0c0.414-0.001 0.749-0.336 0.749-0.751 0-0.277-0.15-0.519-0.373-0.649l-0.004-0.002-13.623-7.784v-0.552c0.172 0.016 0.35 0.068 0.519 0.068 0.004 0 0.010 0 0.015 0 0.475 0 0.934-0.067 1.368-0.193l-0.035 0.009c0.323-0.063 0.693-0.099 1.073-0.099 0.392 0 0.775 0.039 1.146 0.112l-0.037-0.006c0.039 0.007 0.083 0.012 0.129 0.012 0.184 0 0.352-0.068 0.479-0.181l-0.001 0.001c0.161-0.139 0.263-0.343 0.264-0.571v-2.812c0 0 0-0 0-0 0-0.355-0.247-0.653-0.579-0.73l-0.005-0.001c-0.419-0.111-0.9-0.176-1.396-0.176-0.5 0-0.985 0.065-1.446 0.187l0.039-0.009c-0.288 0.067-0.618 0.105-0.958 0.105-0.231 0-0.457-0.018-0.678-0.052l0.025 0.003c-0.122-0.256-0.378-0.43-0.676-0.43-0.412 0-0.746 0.334-0.746 0.746 0 0.001 0 0.003 0 0.004v-0 4.565l-13.622 7.784c-0.227 0.132-0.378 0.374-0.378 0.651 0 0.414 0.336 0.75 0.75 0.75 0.137 0 0.265-0.037 0.376-0.101l-0.004 0.002 5.878-3.359v8.957h-6.25c-0.414 0-0.75 0.336-0.75 0.75v0 8c0 0.414 0.336 0.75 0.75 0.75h28c0.414-0 0.75-0.336 0.75-0.75v0-8c-0-0.414-0.336-0.75-0.75-0.75v0zM18.658 3.075c0.298-0.082 0.64-0.13 0.993-0.13 0.183 0 0.363 0.013 0.539 0.037l-0.020-0.002v1.339c-0.16-0.013-0.345-0.021-0.533-0.021-0.489 0-0.966 0.052-1.425 0.151l0.044-0.008c-0.304 0.088-0.653 0.139-1.014 0.139-0.174 0-0.344-0.012-0.512-0.034l0.020 0.002v-1.323c0.15 0.014 0.325 0.021 0.502 0.021 0.499 0 0.984-0.062 1.447-0.18l-0.041 0.009zM2.75 22.75h5.5v6.5h-5.5zM9.75 22v-10.564l6.25-3.571 6.25 3.572v17.814h-2.5v-5.25c-0-0.414-0.336-0.75-0.75-0.75h-6c-0.414 0-0.75 0.336-0.75 0.75v0 5.25h-2.5zM13.75 29.25v-4.5h4.5v4.5zM29.25 29.25h-5.5v-6.5h5.5zM16 19.75c2.071 0 3.75-1.679 3.75-3.75s-1.679-3.75-3.75-3.75c-2.071 0-3.75 1.679-3.75 3.75v0c0.002 2.070 1.68 3.748 3.75 3.75h0zM16 13.75c1.243 0 2.25 1.007 2.25 2.25s-1.007 2.25-2.25 2.25c-1.243 0-2.25-1.007-2.25-2.25v0c0.002-1.242 1.008-2.248 2.25-2.25h0z"></path> </g></svg>
|
||||
<p className='text-2xl md:text-4xl font-bold underline decoration-4 decoration-[#FE4501] pb-10'>School Registration Form</p>
|
||||
</div>
|
||||
<form onSubmit={handleFormsubmit} action="" className='w-full px-6 md:px-20'>
|
||||
<div className='flex flex-col w-full'>
|
||||
<label htmlFor="school" className='text-xl font-bold'>School Name</label>
|
||||
<input value={formvalue.school} onChange={handleInput} type="text" name="school" id="school" placeholder='School Name' className=' border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]' />
|
||||
</div>
|
||||
<div className='flex flex-col w-full pt-4'>
|
||||
<label htmlFor="country" className='text-xl font-bold'>Country</label>
|
||||
<input value={formvalue.country} onChange={handleInput} type="text" name="country" id="country" placeholder='Country' className=' border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]' />
|
||||
</div>
|
||||
<div className='flex flex-col w-full pt-4'>
|
||||
<label htmlFor="anual" className='text-xl font-bold'>Anual</label>
|
||||
<select value={formvalue.anual} onChange={handleInput} name="anual" id="anual" className=' bg-white border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]'>
|
||||
<option value="0" selected>-Select-</option>
|
||||
<option value="January">January</option>
|
||||
<option value="February">February</option>
|
||||
<option value="March">March</option>
|
||||
<option value="April">April</option>
|
||||
<option value="May">May</option>
|
||||
<option value="June">June</option>
|
||||
<option value="July">July</option>
|
||||
<option value="August">August</option>
|
||||
<option value="September">September</option>
|
||||
<option value="October">October</option>
|
||||
<option value="November">November</option>
|
||||
<option value="December">December</option>
|
||||
</select>
|
||||
</div>
|
||||
<div className='flex flex-col w-full pt-4'>
|
||||
<label htmlFor="toddlers" className='text-xl font-bold'>Toddlers</label>
|
||||
<select value={formvalue.toddlers} onChange={handleInput} name="toddlers" id="toddlers" className=' bg-white border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]'>
|
||||
<option value="0" selected>-Select-</option>
|
||||
<option value="January">January</option>
|
||||
<option value="February">February</option>
|
||||
<option value="March">March</option>
|
||||
<option value="April">April</option>
|
||||
<option value="May">May</option>
|
||||
<option value="June">June</option>
|
||||
<option value="July">July</option>
|
||||
<option value="August">August</option>
|
||||
<option value="September">September</option>
|
||||
<option value="October">October</option>
|
||||
<option value="November">November</option>
|
||||
<option value="December">December</option>
|
||||
</select>
|
||||
</div>
|
||||
<div className='flex flex-col w-full pt-4'>
|
||||
<label htmlFor="early_start_program" className='text-xl font-bold'>Early Start Program</label>
|
||||
<select value={formvalue.early_start_program} onChange={handleInput} name="early_start_program" id="early_start_program" className='bg-white border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]'>
|
||||
<option value="0" selected>-Select-</option>
|
||||
<option value="January">January</option>
|
||||
<option value="February">February</option>
|
||||
<option value="March">March</option>
|
||||
<option value="April">April</option>
|
||||
<option value="May">May</option>
|
||||
<option value="June">June</option>
|
||||
<option value="July">July</option>
|
||||
<option value="August">August</option>
|
||||
<option value="September">September</option>
|
||||
<option value="October">October</option>
|
||||
<option value="November">November</option>
|
||||
<option value="December">December</option>
|
||||
</select>
|
||||
</div>
|
||||
<div className='flex flex-col w-full pt-4'>
|
||||
<label htmlFor="interakto" className='text-xl font-bold'>Interakto</label>
|
||||
<select value={formvalue.interakto} onChange={handleInput} name="interakto" id="interakto" className='bg-white border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]'>
|
||||
<option value="0" selected>-Select-</option>
|
||||
<option value="na">N/A</option>
|
||||
<option value="January"> January</option>
|
||||
<option value="February"> February</option>
|
||||
<option value="March"> March</option>
|
||||
<option value="April"> April</option>
|
||||
<option value="May"> May</option>
|
||||
<option value="June"> June</option>
|
||||
<option value="July"> July</option>
|
||||
<option value="August"> August</option>
|
||||
<option value="September"> September</option>
|
||||
<option value="November"> November</option>
|
||||
<option value="December"> December</option>
|
||||
</select>
|
||||
</div>
|
||||
<div className='flex justify-center pt-8'>
|
||||
<button className='bg-[#FE4501] hover:shadow-2xl hover:shadow-[#F2B705] p-2.5 rounded-lg px-10 rounded-tl-full rounded-br-full hover:scale-110 active:scale-75 duration-200 text-xl font-bold text-white cursor-pointer'>Submit Now</button>
|
||||
{/* <input type="submit" value="Submit Now" className='bg-[#FE4501] hover:shadow-2xl hover:shadow-[#F2B705] p-2.5 rounded-lg px-10 rounded-tl-full rounded-br-full hover:scale-110 active:scale-75 duration-200 text-xl font-bold text-white cursor-pointer' /> */}
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
</main>
|
||||
)
|
||||
}
|
||||
export default Postformvalue;
|
||||
397
src/pages/add-user-form.jsx
Normal file
397
src/pages/add-user-form.jsx
Normal file
@@ -0,0 +1,397 @@
|
||||
// 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'
|
||||
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},
|
||||
])
|
||||
// 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 { data: session } = useSession()
|
||||
|
||||
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(`/api/listSchlools`)
|
||||
.then(res => res.json())
|
||||
.then(data => {
|
||||
setSchool(data)
|
||||
|
||||
})
|
||||
}, [])
|
||||
// console.log(school);
|
||||
|
||||
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/addUser'
|
||||
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)
|
||||
}
|
||||
if (session) {
|
||||
return (
|
||||
<main>
|
||||
<div>
|
||||
<NavBar/>
|
||||
<section className='container mx-auto px-4 my-16 lg:px-28 xl:px-56 2xl:px-96'>
|
||||
<div
|
||||
className='flex flex-col justify-center place-items-center bg-[#FFF6F2] pt-6 pb-20 rounded-tl-[50px] rounded-br-[50px]'>
|
||||
<div className='flex flex-col justify-center place-items-center'>
|
||||
<img src="/img/2.svg" alt=""/>
|
||||
<p className='text-2xl md:text-4xl font-bold underline decoration-4 decoration-[#FE4501] pb-10'>User Registration Form</p>
|
||||
</div>
|
||||
<form onSubmit={handleFormsubmit} action="" className='w-full px-6 md:px-20'>
|
||||
<div className='flex flex-col w-full pt-4'>
|
||||
<label htmlFor="class" className='text-xl font-bold'>Type</label>
|
||||
<select name="type" onChange={handleTypeOnChange} className=' bg-white border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]'>
|
||||
<option value={typeParent}>Parent</option>
|
||||
<option value="teacher">Teacher</option>
|
||||
<option value="coordinator">Coordinator</option>
|
||||
<option value="master">Master</option>
|
||||
</select>
|
||||
</div>
|
||||
<div className='flex flex-col w-full'>
|
||||
<label htmlFor="name" className='text-xl font-bold'> Name</label>
|
||||
<input type="text" name="uname"
|
||||
className=' border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]'
|
||||
placeholder='Enter your Name'/>
|
||||
</div>
|
||||
<div className='flex flex-col w-full'>
|
||||
<label htmlFor="email" className='text-xl font-bold'>Email</label>
|
||||
<input 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]'/>
|
||||
</div>
|
||||
<div className='flex flex-col w-full'>
|
||||
<label htmlFor="country" className='text-xl font-bold'>Country</label>
|
||||
<Select
|
||||
className='bg-white border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]'
|
||||
name="country" instanceId={useId()} options={options} value={countryValue}
|
||||
onChange={selectCountry}/>
|
||||
</div>
|
||||
{allStates && allStates.length > 0 &&
|
||||
<div className='flex flex-col w-full'>
|
||||
<label htmlFor="state" className='text-xl font-bold'>State</label>
|
||||
<Select
|
||||
className='bg-white border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]'
|
||||
name="state" options={allStates} value={allStates[0].name}
|
||||
onChange={handleSelectAllStates}/>
|
||||
</div>}
|
||||
{
|
||||
allCities && allCities.length > 0 &&
|
||||
<div className='flex flex-col w-full'>
|
||||
<label htmlFor="city" className='text-xl font-bold'>City</label>
|
||||
<Select
|
||||
className='bg-white border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]'
|
||||
name="city" options={allCities} value={allCities[0].name}
|
||||
// onChange={() => {}}
|
||||
/>
|
||||
</div>}
|
||||
<div className='flex flex-col w-full'>
|
||||
<label htmlFor="phone" className='text-xl font-bold'> Phone</label>
|
||||
<PhoneInput
|
||||
className=' border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]'
|
||||
name="phone" placeholder="Enter phone number" value={phoneValue}
|
||||
onChange={setphoneValue}/>
|
||||
</div>
|
||||
<div className='flex flex-col w-full pt-4'>
|
||||
<label htmlFor="" className='text-xl font-bold'>School name</label>
|
||||
<select name="schoolID" onChange={individual}
|
||||
className='bg-white border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]'>
|
||||
<option value="0"> individual</option>
|
||||
{school && school.map(data =>
|
||||
<option value={data.id} key={data.id}>{data.name}</option>
|
||||
)}
|
||||
</select>
|
||||
</div>
|
||||
<div className='flex flex-col w-full pt-4'>
|
||||
<label htmlFor="class" className='text-xl font-bold'>Class</label>
|
||||
<select name="klas"
|
||||
className=' bg-white border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]'>
|
||||
<option value="0">-Select-</option>
|
||||
<option value="IK1">IK1</option>
|
||||
<option value="IK2">IK2</option>
|
||||
<option value="IK3">IK3</option>
|
||||
<option value="PG">PG</option>
|
||||
</select>
|
||||
</div>
|
||||
{individualValue &&
|
||||
<div>
|
||||
<div className='flex flex-col w-full pt-4'>
|
||||
<label htmlFor="anual" className='text-xl font-bold'>Anual</label>
|
||||
<select name="anual" className=' bg-white border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]'>
|
||||
<option value="0">-NA-</option>
|
||||
<option value="Jan">Jan</option>
|
||||
<option value="Feb">Feb</option>
|
||||
<option value="Mar">Mar</option>
|
||||
<option value="Apr">Apr</option>
|
||||
<option value="May">May</option>
|
||||
<option value="Jun">Jun</option>
|
||||
<option value="Jul">Jul</option>
|
||||
<option value="Aug">Aug</option>
|
||||
<option value="Sept">Sept</option>
|
||||
<option value="Oct">Oct</option>
|
||||
<option value="Nov">Nov</option>
|
||||
<option value="Dec">Dec</option>
|
||||
</select>
|
||||
</div>
|
||||
<div className='flex flex-col w-full pt-4'>
|
||||
<label htmlFor="early_start_programme" className='text-xl font-bold'>Early Start Programme</label>
|
||||
<select name="early_start_programme" className=' bg-white border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]'>
|
||||
<option value="0">-NA-</option>
|
||||
<option value="Jan">Jan</option>
|
||||
<option value="Feb">Feb</option>
|
||||
<option value="Mar">Mar</option>
|
||||
<option value="Apr">Apr</option>
|
||||
<option value="May">May</option>
|
||||
<option value="Jun">Jun</option>
|
||||
<option value="Jul">Jul</option>
|
||||
<option value="Aug">Aug</option>
|
||||
<option value="Sept">Sept</option>
|
||||
<option value="Oct">Oct</option>
|
||||
<option value="Nov">Nov</option>
|
||||
<option value="Dec">Dec</option>
|
||||
</select>
|
||||
</div>
|
||||
<div className='flex flex-col w-full pt-4'>
|
||||
<label htmlFor="toddlers" className='text-xl font-bold'>Toddlers</label>
|
||||
<select name="toddlers" className=' bg-white border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]'>
|
||||
<option value="0">-NA-</option>
|
||||
<option value="Jan">Jan</option>
|
||||
<option value="Feb">Feb</option>
|
||||
<option value="Mar">Mar</option>
|
||||
<option value="Apr">Apr</option>
|
||||
<option value="May">May</option>
|
||||
<option value="Jun">Jun</option>
|
||||
<option value="Jul">Jul</option>
|
||||
<option value="Aug">Aug</option>
|
||||
<option value="Sept">Sept</option>
|
||||
<option value="Oct">Oct</option>
|
||||
<option value="Nov">Nov</option>
|
||||
<option value="Dec">Dec</option>
|
||||
</select>
|
||||
</div>
|
||||
<div className='flex flex-col w-full pt-4'>
|
||||
<label htmlFor="interakto" className='text-xl font-bold'>Interakto</label>
|
||||
<select name="interakto" className=' bg-white border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]'>
|
||||
<option value="0">-NA-</option>
|
||||
<option value="Jan">Jan</option>
|
||||
<option value="Feb">Feb</option>
|
||||
<option value="Mar">Mar</option>
|
||||
<option value="Apr">Apr</option>
|
||||
<option value="May">May</option>
|
||||
<option value="Jun">Jun</option>
|
||||
<option value="Jul">Jul</option>
|
||||
<option value="Aug">Aug</option>
|
||||
<option value="Sept">Sept</option>
|
||||
<option value="Oct">Oct</option>
|
||||
<option value="Nov">Nov</option>
|
||||
<option value="Dec">Dec</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div className='flex flex-col w-full pt-4'>
|
||||
<label htmlFor="lang" className='text-xl font-bold'>Language</label>
|
||||
<div className='grid grid-cols-3 md:grid-cols-4 lg:grid-cols-5 gap-y-2 pt-2'>
|
||||
{/* <label className='cursor-pointer' htmlFor="Assamese"> Assamese </label> <input type="checkbox" name="lang" value="Assamese" className='check-box'/> <br />
|
||||
<label className='cursor-pointer' htmlFor="Bengali"> Bengali </label> <input type="checkbox" name="lang" value="Bengali" className='check-box'/> <br />
|
||||
<label className='cursor-pointer' htmlFor="English"> English </label> <input type="checkbox" name="lang" value="English" className='check-box'/> <br />
|
||||
<label className='cursor-pointer' htmlFor="Hindi"> Hindi </label> <input type="checkbox" name="lang" value="Hindi" className='check-box'/> <br />
|
||||
<label className='cursor-pointer' htmlFor="Telegu"> Telegu </label> <input type="checkbox" name="lang" value="Telegu" className='check-box'/> <br />
|
||||
<label className='cursor-pointer' htmlFor="Punjabi"> Punjabi </label> <input type="checkbox" name="lang" value="Punjabi" className='check-box'/> <br />
|
||||
<label className='cursor-pointer' htmlFor="Malayalam"> Malayalam </label> <input type="checkbox" name="lang" value="Malayalam" className='check-box'/> <br />
|
||||
<label className='cursor-pointer' htmlFor="Tamil"> Tamil </label> <input type="checkbox" name="lang" value="Tamil" className='check-box'/> <br />
|
||||
<label className='cursor-pointer' htmlFor="Kannada"> Kannada </label> <input type="checkbox" name="lang" value="Kannada" className='check-box'/> <br />
|
||||
<label className='cursor-pointer' htmlFor="Gujrati"> Gujrati </label> <input type="checkbox" name="lang" value="Gujrati" className='check-box'/> <br /> */}
|
||||
{allLanguage && allLanguage.length && allLanguage.map(n => {
|
||||
return (
|
||||
<div key={n.lang} className=''>
|
||||
<label className='cursor-pointer'
|
||||
htmlFor="assamese">{n.lang}</label>
|
||||
<input type="checkbox" disabled={n.disabled} name="lang" value={n.lang} checked={n.value}
|
||||
onChange={handleOnLanguageChange}
|
||||
className='check-box'/>
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
<div className='flex flex-col w-full pt-4'>
|
||||
<label htmlFor="start_month" className='text-xl font-bold'>Start Month</label>
|
||||
<select name="start_month" id="start_month" className='bg-white border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]'>
|
||||
<option value="0">-Select-</option>
|
||||
<option value="Jan"> Jan</option>
|
||||
<option value="Feb"> Feb</option>
|
||||
<option value="Mar"> Mar</option>
|
||||
<option value="Apr"> Apr</option>
|
||||
<option value="May"> May</option>
|
||||
<option value="Jun"> Jun</option>
|
||||
<option value="Jul"> Jul</option>
|
||||
<option value="Aug"> Aug</option>
|
||||
<option value="Sept"> Sept</option>
|
||||
<option value="Nov"> Nov</option>
|
||||
<option value="Dec"> Dec</option>
|
||||
</select>
|
||||
</div>
|
||||
<div className='flex flex-col w-full'>
|
||||
<label htmlFor="start_date" className='text-xl font-bold pt-4'>Start
|
||||
Date</label>
|
||||
<input type="date" name="start_date" id="start_date"
|
||||
className=' border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]'/>
|
||||
</div>
|
||||
<div className='flex flex-col w-full'>
|
||||
<label htmlFor="end_date" className='text-xl font-bold pt-4'>Subscription Expiry
|
||||
Date.</label>
|
||||
<input type="date" name="end_date" id="end_date"
|
||||
className=' border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]'/>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
<div className='flex justify-center pt-8'>
|
||||
<button type="submit"
|
||||
className='bg-[#FE4501] hover:shadow-2xl hover:shadow-[#F2B705] p-2.5 rounded-lg px-10 rounded-tl-full rounded-br-full hover:scale-110 active:scale-75 duration-200 text-xl font-bold text-white cursor-pointer'>Save
|
||||
</button>
|
||||
{/* <input type="submit" value="Submit Now" className='bg-[#FE4501] hover:shadow-2xl hover:shadow-[#F2B705] p-2.5 rounded-lg px-10 rounded-tl-full rounded-br-full hover:scale-110 active:scale-75 duration-200 text-xl font-bold text-white cursor-pointer' /> */}
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
</main>
|
||||
)
|
||||
}
|
||||
return (
|
||||
<>
|
||||
Not signed in <br />
|
||||
<button onClick={() => signIn()}>Sign in</button>
|
||||
</>
|
||||
)
|
||||
|
||||
}
|
||||
@@ -1,129 +0,0 @@
|
||||
import React, { useState } from 'react';
|
||||
import Image from 'next/image'
|
||||
import NavBar from '../components/NavBar'
|
||||
import { Inter } from 'next/font/google'
|
||||
|
||||
const inter = Inter({ subsets: ['latin'] })
|
||||
|
||||
function Postformvalue(props) {
|
||||
const [formvalue, setFormvalue]= useState({name:'',school:'', plan:'', class:'', lang:'', start_month:'', start_date:'', end_date:'', });
|
||||
|
||||
const handleInput =(e)=>{
|
||||
const { name, value}= e.target;
|
||||
setFormvalue({...formvalue, [name]:value});
|
||||
console.log(formvalue);
|
||||
}
|
||||
const handleFormsubmit= async (e)=>{
|
||||
e.preventDefault();
|
||||
|
||||
await fetch('http://localhost/devopsdeveloper/ReactFormvalue/', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
name:formvalue.name,
|
||||
school: formvalue.school,
|
||||
plan: formvalue.plan,
|
||||
class: formvalue.class,
|
||||
lang: formvalue.lang,
|
||||
start_month: formvalue.start_month,
|
||||
start_date: formvalue.start_date,
|
||||
end_date: formvalue.end_date
|
||||
|
||||
})
|
||||
});
|
||||
console.log("success");
|
||||
|
||||
}
|
||||
|
||||
return (
|
||||
<main>
|
||||
<div>
|
||||
<NavBar />
|
||||
<section className='container mx-auto px-4 my-16 lg:px-28 xl:px-56 2xl:px-96'>
|
||||
<div className='flex flex-col justify-center place-items-center bg-[#FFF6F2] pt-6 pb-20 rounded-tl-[50px] rounded-br-[50px]'>
|
||||
<div className='flex flex-col justify-center place-items-center'>
|
||||
<svg className='rounded-full shadow-md ' width="100px" height="100px" viewBox="-3.12 -3.12 30.24 30.24" fill="none" xmlns="http://www.w3.org/2000/svg"><g id="SVGRepo_bgCarrier" stroke-width="0"></g><g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round"></g><g id="SVGRepo_iconCarrier"> <path opacity="0.4" d="M11.4604 13.7299C13.0123 13.7299 14.2704 12.4718 14.2704 10.9199C14.2704 9.36794 13.0123 8.10986 11.4604 8.10986C9.90847 8.10986 8.65039 9.36794 8.65039 10.9199C8.65039 12.4718 9.90847 13.7299 11.4604 13.7299Z" stroke="#FE4501" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"></path> <path opacity="0.4" d="M16.6495 20.1998C16.6495 17.8698 14.3295 15.9697 11.4595 15.9697C8.58953 15.9697 6.26953 17.8598 6.26953 20.1998" stroke="#FE4501" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"></path> <path d="M21 12.5C21 17.75 16.75 22 11.5 22C6.25 22 2 17.75 2 12.5C2 7.25 6.25 3 11.5 3C12.81 3 14.06 3.25999 15.2 3.73999C15.07 4.13999 15 4.56 15 5C15 5.75 15.21 6.46 15.58 7.06C15.78 7.4 16.04 7.70997 16.34 7.96997C17.04 8.60997 17.97 9 19 9C19.44 9 19.86 8.92998 20.25 8.78998C20.73 9.92998 21 11.19 21 12.5Z" stroke="#FE4501" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"></path> <path d="M23 5C23 5.32 22.96 5.62999 22.88 5.92999C22.79 6.32999 22.63 6.72 22.42 7.06C21.94 7.87 21.17 8.49998 20.25 8.78998C19.86 8.92998 19.44 9 19 9C17.97 9 17.04 8.60997 16.34 7.96997C16.04 7.70997 15.78 7.4 15.58 7.06C15.21 6.46 15 5.75 15 5C15 4.56 15.07 4.13999 15.2 3.73999C15.39 3.15999 15.71 2.64002 16.13 2.21002C16.86 1.46002 17.88 1 19 1C20.18 1 21.25 1.51002 21.97 2.33002C22.61 3.04002 23 3.98 23 5Z" stroke="#FE4501" stroke-width="1.5" stroke-miterlimit="10" stroke-linecap="round" stroke-linejoin="round"></path> <path d="M20.4898 4.97998H17.5098" stroke="#FE4501" stroke-width="1.5" stroke-miterlimit="10" stroke-linecap="round" stroke-linejoin="round"></path> <path d="M19 3.52002V6.51001" stroke="#FE4501" stroke-width="1.5" stroke-miterlimit="10" stroke-linecap="round" stroke-linejoin="round"></path> </g></svg>
|
||||
<p className='text-2xl md:text-4xl font-bold underline decoration-4 decoration-[#FE4501] pb-10'>User Registration Form</p>
|
||||
</div>
|
||||
<form onSubmit={handleFormsubmit} action="" className='w-full px-6 md:px-20'>
|
||||
<div className='flex flex-col w-full'>
|
||||
<label htmlFor="name" className='text-xl font-bold'>User Name</label>
|
||||
<input value={formvalue.name} onChange={handleInput} type="text" name="name" id="name" placeholder='ex. xyz@email.com' className=' border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]' />
|
||||
</div>
|
||||
<div className='flex flex-col w-full pt-4'>
|
||||
<label htmlFor="school" className='text-xl font-bold'>School Name</label>
|
||||
<input value={formvalue.school} onChange={handleInput} type="text" name="school" id="school" placeholder='School Name' className=' border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]' />
|
||||
</div>
|
||||
<div className='flex flex-col w-full pt-4'>
|
||||
<label htmlFor="plan" className='text-xl font-bold'>Plan</label>
|
||||
<select value={formvalue.plan} onChange={handleInput} name="plan" id="plan" className=' bg-white border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]'>
|
||||
<option value="0" selected>-Select-</option>
|
||||
<option value="Anual">Anual</option>
|
||||
<option value="Early-Start-Program">Early Start Program</option>
|
||||
<option value="Toddlers">Toddlers</option>
|
||||
<option value="Interakto">Interakto</option>
|
||||
</select>
|
||||
</div>
|
||||
<div className='flex flex-col w-full pt-4'>
|
||||
<label htmlFor="class" className='text-xl font-bold'>Class</label>
|
||||
<select value={formvalue.class} onChange={handleInput} name="class" id="class" className=' bg-white border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]'>
|
||||
<option value="0" selected>-Select-</option>
|
||||
<option value="IK1">IK1</option>
|
||||
<option value="IK2">IK2</option>
|
||||
<option value="IK3">IK3</option>
|
||||
<option value="PG">PG</option>
|
||||
</select>
|
||||
</div>
|
||||
<div className='flex flex-col w-full pt-4'>
|
||||
<label htmlFor="lang" className='text-xl font-bold'>Language</label>
|
||||
<select value={formvalue.lang} onChange={handleInput} name="lang" id="lang" className='bg-white border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]'>
|
||||
<option value="" selected>-Select-</option>
|
||||
<option value="Bengali"> Bengali</option>
|
||||
<option value="English"> English</option>
|
||||
<option value="Hindi"> Hindi</option>
|
||||
<option value="Urdu"> Urdu</option>
|
||||
<option value="Punjabi"> Punjabi</option>
|
||||
<option value="Telugu"> Telugu</option>
|
||||
<option value="Marathi"> Marathi</option>
|
||||
<option value="Nepali"> Nepali</option>
|
||||
<option value="Kannada"> Kannada</option>
|
||||
<option value="Gujrati"> Gujrati</option>
|
||||
</select>
|
||||
</div>
|
||||
<div className='flex flex-col w-full pt-4'>
|
||||
<label htmlFor="start_month" className='text-xl font-bold'>Start Month</label>
|
||||
<select value={formvalue.start_month} onChange={handleInput} name="start_month" id="start_month" className='bg-white border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]'>
|
||||
<option value="0" selected>-Select-</option>
|
||||
<option value="January"> January</option>
|
||||
<option value="February"> February</option>
|
||||
<option value="March"> March</option>
|
||||
<option value="April"> April</option>
|
||||
<option value="May"> May</option>
|
||||
<option value="June"> June</option>
|
||||
<option value="July"> July</option>
|
||||
<option value="August"> August</option>
|
||||
<option value="September"> September</option>
|
||||
<option value="November"> November</option>
|
||||
<option value="December"> December</option>
|
||||
</select>
|
||||
</div>
|
||||
<div className='flex flex-col w-full'>
|
||||
<label htmlFor="start_date" className='text-xl font-bold pt-4'>Start Date</label>
|
||||
<input value={formvalue.start_date} onChange={handleInput} type="date" name="start_date" id="start_date" className=' border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]' />
|
||||
</div>
|
||||
<div className='flex flex-col w-full'>
|
||||
<label htmlFor="end_date" className='text-xl font-bold pt-4'>End Date</label>
|
||||
<input value={formvalue.end_date} onChange={handleInput} type="date" name="end_date" id="end_date" className=' border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]' />
|
||||
</div>
|
||||
<div className='flex justify-center pt-8'>
|
||||
<button className='bg-[#FE4501] hover:shadow-2xl hover:shadow-[#F2B705] p-2.5 rounded-lg px-10 rounded-tl-full rounded-br-full hover:scale-110 active:scale-75 duration-200 text-xl font-bold text-white cursor-pointer'>Submit Now</button>
|
||||
{/* <input type="submit" value="Submit Now" className='bg-[#FE4501] hover:shadow-2xl hover:shadow-[#F2B705] p-2.5 rounded-lg px-10 rounded-tl-full rounded-br-full hover:scale-110 active:scale-75 duration-200 text-xl font-bold text-white cursor-pointer' /> */}
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
</main>
|
||||
)
|
||||
}
|
||||
export default Postformvalue;
|
||||
37
src/pages/api/addSchool.js
Normal file
37
src/pages/api/addSchool.js
Normal file
@@ -0,0 +1,37 @@
|
||||
export default function handler(req, res) {
|
||||
const sqlite3 = require('sqlite3').verbose();
|
||||
|
||||
// console.log(req.body)
|
||||
// Open a new database connection
|
||||
let sname, status, phone, annual, early_start_programme, toddlers, interakto, email, country, state, city, address, agg_expiry, usage_expiry = "";
|
||||
|
||||
if(req.body.sname) sname =req.body.sname;
|
||||
// if(req.body.status) status =req.body.status;
|
||||
if(req.body.status) status ="published";
|
||||
if(req.body.phone) phone =req.body.phone;
|
||||
if(req.body.annual) annual =req.body.annual;
|
||||
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.agg_expiry) agg_expiry =req.body.agg_expiry;
|
||||
if(req.body.usage_expiry) usage_expiry =req.body.usage_expiry;
|
||||
|
||||
const db = new sqlite3.Database('data/appUser.db');
|
||||
db.run(`INSERT INTO school (sname, status, phone, annual, early_start_programme, toddlers, interakto, email, country, state, city, address, agg_expiry, usage_expiry ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, [ sname, status, phone, annual, early_start_programme, toddlers, interakto, email, country, state, city, address, agg_expiry, usage_expiry],
|
||||
function(err) {
|
||||
if (err) {
|
||||
return console.log(err.message);
|
||||
}
|
||||
}
|
||||
);
|
||||
db.close();
|
||||
|
||||
|
||||
res.status(200).json({ msg: 'ok' });
|
||||
}
|
||||
|
||||
42
src/pages/api/addUser.js
Normal file
42
src/pages/api/addUser.js
Normal file
@@ -0,0 +1,42 @@
|
||||
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, annual, 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; lang=JSON.stringify(lang);
|
||||
if(req.body.phone) phone =req.body.phone;
|
||||
if(req.body.pass) pass =req.body.pass;
|
||||
if(req.body.annual) annual =req.body.annual;
|
||||
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, annual, 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, annual, 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({ msg: 'ok' });
|
||||
}
|
||||
21
src/pages/api/addUsersBulk copy.js
Normal file
21
src/pages/api/addUsersBulk copy.js
Normal file
@@ -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();
|
||||
});
|
||||
56
src/pages/api/addUsersBulk.js
Normal file
56
src/pages/api/addUsersBulk.js
Normal file
@@ -0,0 +1,56 @@
|
||||
import csv from 'csv-parser';
|
||||
import formidable from "formidable";
|
||||
import fs from "fs";
|
||||
import sqlite3 from 'sqlite3';
|
||||
|
||||
export const config = {
|
||||
api: {
|
||||
bodyParser: false
|
||||
}
|
||||
};
|
||||
|
||||
export default function handler(req,res) {
|
||||
|
||||
const form = new formidable.IncomingForm();
|
||||
form.parse(req, async function (err, fields, files) {
|
||||
|
||||
// console.log('ppp')
|
||||
console.log(files.file.filepath)
|
||||
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')
|
||||
fs.createReadStream(files.file.filepath)
|
||||
.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}`);
|
||||
|
||||
fs.unlinkSync(files.file.filepath);
|
||||
db.close();
|
||||
});
|
||||
|
||||
|
||||
// console.log(fields)
|
||||
// await saveFile(files.file,fields.fName? fields.fName:files.file.originalFilename );
|
||||
return res.status(201).send("");
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
res.status(200).json({ msg: 'ok' })
|
||||
}
|
||||
|
||||
129
src/pages/api/auth/[...nextauth].js
Normal file
129
src/pages/api/auth/[...nextauth].js
Normal file
@@ -0,0 +1,129 @@
|
||||
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;
|
||||
|
||||
export const options = {
|
||||
providers: [
|
||||
CredentialsProvider({
|
||||
name: "Credentials",
|
||||
credentials: {
|
||||
email: { label: "Email", type: "text" },
|
||||
password: { label: "Mot de passe", type: "password" },
|
||||
},
|
||||
async authorize(credentials, req) {
|
||||
const payload = {
|
||||
email: credentials.email,
|
||||
password: credentials.password,
|
||||
};
|
||||
const res = await fetch(pubAPI + "auth/login", {
|
||||
method: "POST",
|
||||
body: JSON.stringify(payload),
|
||||
headers: { "Content-Type": "application/json" },
|
||||
credentials: "include",
|
||||
});
|
||||
const user = await res.json();
|
||||
// console.log(user)
|
||||
|
||||
if (!res.ok) {
|
||||
throw new Error("Email ou mot de passe incorrect.");
|
||||
}
|
||||
|
||||
if (res.ok && user) {
|
||||
return user;
|
||||
}
|
||||
|
||||
return null;
|
||||
},
|
||||
}),
|
||||
],
|
||||
session: {
|
||||
jwt: true,
|
||||
},
|
||||
callbacks: {
|
||||
async jwt({ token, user, account }) {
|
||||
if (account && user) {
|
||||
var tokenJwt =user.data.access_token
|
||||
var roleID = jwt_decode(tokenJwt).role;
|
||||
if(roleID==='f9a8ec44-685c-4b59-8e50-5b49981ba526')
|
||||
return {
|
||||
...token,
|
||||
roleID:roleID,
|
||||
accessToken: user.data.access_token,
|
||||
expires: Date.now() + user.data.expires,
|
||||
refreshToken: user.data.refresh_token,
|
||||
error: user.data.error,
|
||||
};
|
||||
else
|
||||
return {
|
||||
error: user.data.error,
|
||||
};
|
||||
}
|
||||
|
||||
if (Date.now() < token.expires) {
|
||||
return token;
|
||||
}
|
||||
|
||||
const refreshed = await refreshAccessToken(token);
|
||||
return await refreshed;
|
||||
},
|
||||
|
||||
async session({ session, token }) {
|
||||
session.user.roleID = token.roleID;
|
||||
session.user.accessToken = token.accessToken;
|
||||
session.user.refreshToken = token.refreshToken;
|
||||
session.user.expires = token.expires;
|
||||
session.user.error = token.error;
|
||||
|
||||
return session;
|
||||
},
|
||||
},
|
||||
secret: process.env.NEXTAUTH_SECRET,
|
||||
pages: {
|
||||
signIn: "/login",
|
||||
},
|
||||
debug: true,
|
||||
};
|
||||
|
||||
async function refreshAccessToken(token) {
|
||||
try {
|
||||
const response = await fetch(pubAPI + "auth/refresh", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ refresh_token: token.refreshToken }),
|
||||
credentials: "include",
|
||||
});
|
||||
|
||||
const refreshedTokens = await response.json();
|
||||
|
||||
if (!response.ok) {
|
||||
signIn();
|
||||
}
|
||||
|
||||
if (response.ok && refreshedTokens) {
|
||||
return {
|
||||
...token,
|
||||
accessToken: refreshedTokens.data.access_token,
|
||||
expires: Date.now() + refreshedTokens.data.expires,
|
||||
refreshToken: refreshedTokens.data.refresh_token,
|
||||
};
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(
|
||||
new Date().toUTCString() + " Error in refreshAccessToken:",
|
||||
error
|
||||
);
|
||||
|
||||
return {
|
||||
...token,
|
||||
error: "RefreshAccessTokenError",
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
const nextauthfunc = (req, res) => NextAuth(req, res, options);
|
||||
|
||||
export default nextauthfunc;
|
||||
41
src/pages/api/editSchool.js
Normal file
41
src/pages/api/editSchool.js
Normal file
@@ -0,0 +1,41 @@
|
||||
export default function handler(req, res) {
|
||||
const sqlite3 = require('sqlite3').verbose();
|
||||
|
||||
console.log(req.body)
|
||||
|
||||
// Open a new database connection
|
||||
let sname, status, phone, annual, early_start_programme, toddlers, interakto, email, country, state, city, address, agg_expiry, usage_expiry = "";
|
||||
|
||||
if(req.body.sname) sname =req.body.sname;
|
||||
if(req.body.status) status =req.body.status;
|
||||
// if(req.body.status) status ="published";
|
||||
if(req.body.phone) phone =req.body.phone;
|
||||
if(req.body.annual) annual =req.body.annual;
|
||||
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.agg_expiry) agg_expiry =req.body.agg_expiry;
|
||||
if(req.body.usage_expiry) usage_expiry =req.body.usage_expiry;
|
||||
|
||||
const db = new sqlite3.Database('data/appUser.db');
|
||||
console.log(req.body.userId)
|
||||
db.run(`UPDATE school SET sname = ?, status = ?, phone = ?, annual = ?, early_start_programme = ?, toddlers = ?, interakto = ?, email = ?, country = ?, state = ?, city = ?, address = ?, agg_expiry = ?, usage_expiry = ? WHERE id = ? `, [ sname, status, phone, annual, early_start_programme, toddlers, interakto, email, country, state, city, address, agg_expiry, usage_expiry, req.body.schoolId],
|
||||
function(err) {
|
||||
if (err) {
|
||||
res.status(400).json({ msg: 'Err400D' });
|
||||
return console.log(err.message);
|
||||
}
|
||||
res.status(200).json({ msg: 'ok' });
|
||||
}
|
||||
);
|
||||
db.close();
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
56
src/pages/api/editUser.js
Normal file
56
src/pages/api/editUser.js
Normal file
@@ -0,0 +1,56 @@
|
||||
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, klas, lang, phone, pass, annual, 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.type) type =req.body.type;
|
||||
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.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.annual) annual =req.body.annual;
|
||||
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');
|
||||
var msg=null;
|
||||
console.log(req.body.userId)
|
||||
db.run(`UPDATE user SET uname = ?, status = ?, type = ?, start_month = ?, start_date = ?, end_date = ?, klas = ?, lang = ?, phone = ?, annual = ?, early_start_programme = ?, toddlers = ?, interakto = ?, email = ?, country = ?, state = ?, city = ?, address = ?, school = ? WHERE id = ? `, [ uname, status, type, start_month, start_date, end_date, klas, lang, phone, annual, early_start_programme, toddlers, interakto, email, country, state, city, address, school, req.body.userId],
|
||||
function(err) {
|
||||
if (err) {
|
||||
msg={ msg: 'Err400D' };
|
||||
res.status(400).send({ msg: 'Err400D' });
|
||||
// return console.log(err.message);
|
||||
}
|
||||
// console.log('message');
|
||||
msg="{ msg: 'ok' }";
|
||||
// res.statusCode = 200;
|
||||
// res.setHeader('Content-Type', 'application/json');
|
||||
// res.setHeader('Cache-Control', 'max-age=180000');
|
||||
// res.end(JSON.stringify({ msg: 'ok' }));
|
||||
// res.status(200).json({ msg: 'ok' });
|
||||
}
|
||||
);
|
||||
db.close();
|
||||
|
||||
res.statusCode = 200;
|
||||
res.setHeader('Content-Type', 'application/json');
|
||||
res.setHeader('Cache-Control', 'max-age=180000');
|
||||
res.end(JSON.stringify(msg));
|
||||
|
||||
|
||||
}
|
||||
|
||||
38
src/pages/api/fileUpload.js
Normal file
38
src/pages/api/fileUpload.js
Normal file
@@ -0,0 +1,38 @@
|
||||
import formidable from "formidable";
|
||||
import fs from "fs";
|
||||
|
||||
export const config = {
|
||||
api: {
|
||||
bodyParser: false
|
||||
}
|
||||
};
|
||||
|
||||
const post = async (req, res) => {
|
||||
const form = new formidable.IncomingForm();
|
||||
form.parse(req, async function (err, fields, files) {
|
||||
// console.log(fields)
|
||||
await saveFile(files.file,fields.fName? fields.fName:files.file.originalFilename );
|
||||
return res.status(201).send("");
|
||||
});
|
||||
};
|
||||
|
||||
const saveFile = async (file,fName) => {
|
||||
// console.log(file.filepath)
|
||||
// console.log(fName)
|
||||
const data = fs.readFileSync(file.filepath);
|
||||
fs.writeFileSync(`./public/uploaded/${fName}`, data);
|
||||
fs.unlinkSync(file.filepath);
|
||||
return;
|
||||
};
|
||||
|
||||
export default (req, res) => {
|
||||
req.method === "POST"
|
||||
? post(req, res)
|
||||
: req.method === "PUT"
|
||||
? console.log("PUT")
|
||||
: req.method === "DELETE"
|
||||
? console.log("DELETE")
|
||||
: req.method === "GET"
|
||||
? console.log("GET")
|
||||
: res.status(404).send("");
|
||||
};
|
||||
41
src/pages/api/getSchoolDetails.js
Normal file
41
src/pages/api/getSchoolDetails.js
Normal file
@@ -0,0 +1,41 @@
|
||||
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 = 'school';
|
||||
|
||||
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} WHERE id = ?`;
|
||||
db.all(sql, [req.query.school], (err, rows) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
return;
|
||||
}
|
||||
const data = rows;
|
||||
resolve(data);
|
||||
});
|
||||
});
|
||||
};
|
||||
async function doSomething() {
|
||||
try {
|
||||
const returnData = await getAllRows('school');
|
||||
res.setHeader('Content-Type', 'application/json')
|
||||
res.status(200).json(returnData)
|
||||
// console.log(data);
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
}
|
||||
}
|
||||
|
||||
doSomething();
|
||||
}
|
||||
|
||||
67
src/pages/api/getUserDetails.js
Normal file
67
src/pages/api/getUserDetails.js
Normal file
@@ -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} WHERE id = ?`;
|
||||
db.all(sql, [req.query.user], (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();
|
||||
// });
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
73
src/pages/api/listSchlools.js
Normal file
73
src/pages/api/listSchlools.js
Normal file
@@ -0,0 +1,73 @@
|
||||
import csv from 'csv-parser';
|
||||
import fs from 'fs';
|
||||
import sqlite3 from 'sqlite3';
|
||||
|
||||
export default function handler(req,res) {
|
||||
|
||||
console.log(req.body.school)
|
||||
// const {
|
||||
// query: { name, keyword },
|
||||
// method,
|
||||
// } = req;
|
||||
// console.log(name, keyword, method);
|
||||
|
||||
const DB_NAME = 'data/appUser.db';
|
||||
const TABLE_NAME = 'school';
|
||||
|
||||
// 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(TABLE_NAME);
|
||||
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();
|
||||
// });
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
91
src/pages/api/listUsers copy.js
Normal file
91
src/pages/api/listUsers copy.js
Normal file
@@ -0,0 +1,91 @@
|
||||
import csv from 'csv-parser';
|
||||
import fs from 'fs';
|
||||
import sqlite3 from 'sqlite3';
|
||||
|
||||
export default function handler(req,res) {
|
||||
|
||||
console.log(req.body.school)
|
||||
// const {
|
||||
// query: { name, keyword },
|
||||
// method,
|
||||
// } = req;
|
||||
// console.log(name, keyword, method);
|
||||
|
||||
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) => {
|
||||
|
||||
db.get(`SELECT COUNT(*) AS count FROM ${tableName}`, (err, row) => {
|
||||
if (err) {
|
||||
console.error(err.message);
|
||||
return;
|
||||
}
|
||||
|
||||
// Access the row count
|
||||
const rowCount = row.count;
|
||||
// console.log(`Row count: ${rowCount}`);
|
||||
const pageNo=0;
|
||||
const perPage=5;
|
||||
let noOfPage= Math.floor(rowCount/perPage); if((rowCount % perPage) !=0) noOfPage++;
|
||||
console.log(`noOfPage: ${noOfPage}`);
|
||||
const offset=(rowCount-5*perPage*pageNo)-1;
|
||||
const sql = `SELECT * FROM ${tableName} ORDER BY id DESC LIMIT 5 OFFSET ${rowCount-1}`;
|
||||
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();
|
||||
// });
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
93
src/pages/api/listUsers.js
Normal file
93
src/pages/api/listUsers.js
Normal file
@@ -0,0 +1,93 @@
|
||||
import csv from 'csv-parser';
|
||||
import fs from 'fs';
|
||||
import sqlite3 from 'sqlite3';
|
||||
|
||||
export default function handler(req,res) {
|
||||
|
||||
// const query = req.query;
|
||||
const { page, limit } = req.query;
|
||||
console.log(page)
|
||||
// const {
|
||||
// query: { name, keyword },
|
||||
// method,
|
||||
// } = req;
|
||||
// console.log(name, keyword, method);
|
||||
|
||||
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, pageNumber, pageSize) {
|
||||
const offset = (pageNumber - 1) * pageSize;
|
||||
const sql = `SELECT * FROM ${tableName} LIMIT ${pageSize} OFFSET ${offset}`;
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
db.all(sql, [], (err, rows) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
return;
|
||||
}
|
||||
db.get(`SELECT COUNT(*) AS count FROM ${tableName}`, (err, row) => {
|
||||
if (err) {
|
||||
console.error(err.message);
|
||||
return;
|
||||
}
|
||||
|
||||
// Access the row count
|
||||
const rowCount = row.count;
|
||||
console.log(`Row count: ${rowCount}`);
|
||||
const maxPageNumber = Math.ceil(rowCount / pageSize);
|
||||
const pages = Array.from({ length: maxPageNumber }, (_, index) => index + 1);
|
||||
let tData={data:rows,maxPageNumber:pages}
|
||||
const data = tData;
|
||||
resolve(data);
|
||||
});
|
||||
// let tData={data:rows,page:7}
|
||||
// const data = tData;
|
||||
// resolve(data);
|
||||
});
|
||||
});
|
||||
};
|
||||
async function doSomething() {
|
||||
try {
|
||||
const returnData = await getAllRows('user',page,limit);
|
||||
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();
|
||||
// });
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
72
src/pages/api/login.js
Normal file
72
src/pages/api/login.js
Normal file
@@ -0,0 +1,72 @@
|
||||
export default function handler(req, res) {
|
||||
// const sqlite3 = require('sqlite3').verbose();
|
||||
|
||||
// console.log(req.body)
|
||||
const sqlite3 = require('sqlite3');
|
||||
const argon2 = require('argon2');
|
||||
const jwt = require('jsonwebtoken');
|
||||
|
||||
// Connect to the SQLite database
|
||||
const db = new sqlite3.Database('data/appUser.db');
|
||||
|
||||
// Fetch the user record
|
||||
const username = req.body.email;
|
||||
// console.log(username)
|
||||
const sql = 'SELECT * FROM user WHERE email = ?';
|
||||
db.get(sql, [username], async (err, userRecord) => {
|
||||
if (err) {
|
||||
console.error(err);
|
||||
return;
|
||||
}
|
||||
|
||||
if (userRecord) {
|
||||
const storedHash = userRecord.pass;
|
||||
console.log(storedHash)
|
||||
const providedPassword = req.body.password;
|
||||
|
||||
try {
|
||||
// Verify the provided password with the stored hash
|
||||
const isPasswordValid = await argon2.verify(storedHash, providedPassword);
|
||||
|
||||
if (isPasswordValid) {
|
||||
// Passwords match, generate JWT token
|
||||
const secretKey = process.env.TOKEN_HEADER_KEY;
|
||||
const tokenPayload = {
|
||||
email:userRecord.email,
|
||||
role: userRecord.type,
|
||||
iat: Math.floor(Date.now() / 1000),
|
||||
exp: Math.floor(Date.now() / 1000) + 3600*24*7,
|
||||
|
||||
};
|
||||
const jwtToken = jwt.sign(tokenPayload, secretKey, { algorithm: 'HS256' });
|
||||
const jwtTokenData ={
|
||||
data:{
|
||||
access_token:jwtToken,
|
||||
role: userRecord.type,
|
||||
email: userRecord.email,
|
||||
expires: 3600*24*7,
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
// Return the JWT token
|
||||
res.status(200).json(jwtTokenData);
|
||||
console.log(jwtToken);
|
||||
} else {
|
||||
console.log('Invalid password');
|
||||
res.status(400).json({err:'400P'});
|
||||
}
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
}
|
||||
} else {
|
||||
res.status(400).json({err:'400U'});
|
||||
console.log('User not found');
|
||||
}
|
||||
|
||||
// Close the database connection
|
||||
db.close();
|
||||
});
|
||||
|
||||
// res.status(200).json({ name: 'John Doe' });
|
||||
}
|
||||
0
src/pages/api/updateUserDetails.js
Normal file
0
src/pages/api/updateUserDetails.js
Normal file
191
src/pages/edit-school.jsx
Normal file
191
src/pages/edit-school.jsx
Normal file
@@ -0,0 +1,191 @@
|
||||
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';
|
||||
import { useRouter } from 'next/router'
|
||||
import Link from 'next/link'
|
||||
|
||||
|
||||
export default function EditSchool() {
|
||||
const { data: session } = useSession()
|
||||
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 uploadCsv = async (event) => {
|
||||
// alert('p')
|
||||
const body = new FormData();
|
||||
body.append("file", csv.files[0]);
|
||||
// console.log('body')
|
||||
// body.append("fName", `${router.query.school}.pdf`);
|
||||
const response = await fetch("/api/addUsersBulk", {
|
||||
method: "POST",
|
||||
body
|
||||
});
|
||||
};
|
||||
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)
|
||||
})
|
||||
}
|
||||
|
||||
}, [router.query.school]);
|
||||
|
||||
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 JSONdata = JSON.stringify(data)
|
||||
// console.log(data)
|
||||
const endpoint = '/api/editSchool'
|
||||
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(`User data updated`)
|
||||
|
||||
}
|
||||
if (session) {
|
||||
return (
|
||||
<main>
|
||||
<div>
|
||||
<NavBar/>
|
||||
<section className='container mx-auto px-4 my-16 lg:px-28 xl:px-56 2xl:px-96'>
|
||||
<div
|
||||
className='flex flex-col justify-center place-items-center bg-[#FFF6F2] pt-6 pb-20 rounded-tl-[50px] rounded-br-[50px]'>
|
||||
<div className='inline-flex p-4 '>
|
||||
<Link href="/add-school-form" className="m-2 inline-flex place-items-center justify-center p-2 pl-4 pr-4 bg-[#FE4501] text-white font-bold rounded-full whitespace-nowrap">
|
||||
<img src="/img/4.svg" alt="" />
|
||||
List Users Under This School
|
||||
</Link>
|
||||
<div className="place-items-center justify-center m-2 p-2 bg-[#FE4501] text-white font-bold rounded-full whitespace-nowrap">
|
||||
<span className="text-small">CSV </span>
|
||||
<input type="file" id="csv" onChange={uploadCsv} name="csv" />
|
||||
</div>
|
||||
{/* <img src="/img/2.svg" alt=""/> */}
|
||||
|
||||
</div>
|
||||
<p className='text-2xl font-bold underline decoration-4 decoration-[#FE4501] pb-10'>Update School Information </p>
|
||||
<form onSubmit={updateSchoolData} action="" className='w-full px-6 md:px-20'>
|
||||
<div className='flex flex-col w-full pt-4'>
|
||||
<label htmlFor="sname" className='text-xl font-bold'>School Name</label>
|
||||
<input value={school.sname} onChange={e => 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]' />
|
||||
</div>
|
||||
<div className='flex flex-col w-full pt-4'>
|
||||
<label htmlFor="status" className='text-xl font-bold'>Status</label>
|
||||
<input value={school.status} onChange={e => 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]' />
|
||||
</div>
|
||||
<div className='flex flex-col w-full'>
|
||||
<label htmlFor="phone" className='text-xl font-bold'>School contact Number</label>
|
||||
<input value={school.phone} onChange={e => 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]' />
|
||||
</div>
|
||||
<div className='flex flex-col w-full'>
|
||||
<label htmlFor="email" className='text-xl font-bold'> School contact Email ID</label>
|
||||
<input value={school.email} onChange={e => 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]' />
|
||||
</div>
|
||||
<div className='flex flex-col w-full'>
|
||||
<label htmlFor="country" className='text-xl font-bold'>Country</label>
|
||||
<input value={school.country} onChange={e => 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]' />
|
||||
</div>
|
||||
<div className='flex flex-col w-full'>
|
||||
<label htmlFor="state" className='text-xl font-bold'>State</label>
|
||||
<input value={school.state} onChange={e => 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]' />
|
||||
</div>
|
||||
<div className='flex flex-col w-full'>
|
||||
<label htmlFor="city" className='text-xl font-bold'>Cities</label>
|
||||
<input value={school.city} onChange={e => 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]' />
|
||||
</div>
|
||||
<div className='flex flex-col w-full'>
|
||||
<label htmlFor="annual" className='text-xl font-bold'>Annual</label>
|
||||
<input value={school.annual} onChange={e => 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]'/>
|
||||
</div>
|
||||
<div className='flex flex-col w-full'>
|
||||
<label htmlFor="toddlers" className='text-xl font-bold'>Toddlers</label>
|
||||
<input value={school.toddlers} onChange={e => 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]' />
|
||||
</div>
|
||||
<div className='flex flex-col w-full'>
|
||||
<label htmlFor="early_start_programme" className='text-xl font-bold'>Early Start Program</label>
|
||||
<input value={school.early_start_programme} onChange={e => 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]' />
|
||||
</div>
|
||||
<div className='flex flex-col w-full'>
|
||||
<label htmlFor="interakto" className='text-xl font-bold'>Interakto</label>
|
||||
<input value={school.interakto} onChange={e => 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]' />
|
||||
</div>
|
||||
<div className='flex flex-col w-full'>
|
||||
<label htmlFor="usage_expiry" className='text-xl font-bold'> Usage Expiry Date: (YYYY-MM-DD)</label>
|
||||
<input value={school.usage_expiry} onChange={e => 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]' />
|
||||
</div>
|
||||
|
||||
<div className='flex flex-col w-full'>
|
||||
<label htmlFor="agg_expiry" className='text-xl font-bold'> Agreement Expiry Date: (YYYY-MM-DD)</label>
|
||||
<input value={school.agg_expiry} onChange={e => 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]' />
|
||||
</div>
|
||||
<div className='flex justify-center pt-8'>
|
||||
<button type="submit"
|
||||
className='bg-[#FE4501] hover:shadow-2xl hover:shadow-[#F2B705] p-2.5 rounded-lg px-10 rounded-tl-full rounded-br-full hover:scale-110 active:scale-75 duration-200 text-xl font-bold text-white cursor-pointer'>Update
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div className='flex flex-col w-full'>
|
||||
<label htmlFor="agreement_documents" className='text-xl font-bold'>Upload Agreement Document's</label>
|
||||
<input id="agreement" onChange={uploadToServer} 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]' />
|
||||
<div className='flex justify-end pt-2'>
|
||||
<button className=' bg-[#FE4501] px-4 py-1.5 rounded-lg text-white'>Download Agreement</button>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
</section>
|
||||
</div>
|
||||
</main>
|
||||
)
|
||||
}
|
||||
return (
|
||||
<>
|
||||
Not signed in <br />
|
||||
<button onClick={() => signIn()}>Sign in</button>
|
||||
</>
|
||||
)
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
178
src/pages/edit-user.jsx
Normal file
178
src/pages/edit-user.jsx
Normal file
@@ -0,0 +1,178 @@
|
||||
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';
|
||||
import { useRouter } from 'next/router'
|
||||
|
||||
export default function EditUser() {
|
||||
const router = useRouter();
|
||||
|
||||
const [user, setUser] = useState({});
|
||||
const { data: session } = useSession()
|
||||
|
||||
useEffect(()=>{
|
||||
if(router.query.user && router.query.user>0 ){
|
||||
fetch(`/api/getUserDetails?user=${router.query.user}`)
|
||||
.then(res => res.json())
|
||||
.then(data => {
|
||||
// console.log(data);
|
||||
setUser(data[0])
|
||||
// console.log(user)
|
||||
})
|
||||
}
|
||||
|
||||
}, [router.query.user]);
|
||||
|
||||
const updateUserData = async (event) => {
|
||||
event.preventDefault()
|
||||
const data = {
|
||||
userId: router.query.user,
|
||||
type: event.target.type.value,
|
||||
status: event.target.status.value,
|
||||
uname: event.target.uname.value,
|
||||
country: event.target.country.value,
|
||||
state: event.target.state.value,
|
||||
city: event.target.city.value,
|
||||
address: event.target.address.value,
|
||||
start_date: event.target.start_date.value,
|
||||
end_date: event.target.end_date.value,
|
||||
school: event.target.school.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,
|
||||
email: event.target.email.value,
|
||||
phone: event.target.phone.value,
|
||||
klas: event.target.klas.value
|
||||
}
|
||||
const JSONdata = JSON.stringify(data)
|
||||
// console.log(data)
|
||||
const endpoint = '/api/editUser'
|
||||
const options = {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSONdata,
|
||||
}
|
||||
const response = await fetch(endpoint, options)
|
||||
// .then(res => res.json())
|
||||
// .then(data => {
|
||||
// console.log(data);
|
||||
// // setUser(data[0])
|
||||
// // console.log(user)
|
||||
// })
|
||||
|
||||
const result = await response.json()
|
||||
console.log(result)
|
||||
// alert(`Is this your full name: ${result.data}`)
|
||||
alert(`User data updated`)
|
||||
|
||||
}
|
||||
if (session) {
|
||||
return (
|
||||
<main>
|
||||
<div>
|
||||
<NavBar/>
|
||||
<section className='container mx-auto px-4 my-16 lg:px-28 xl:px-56 2xl:px-96'>
|
||||
<div
|
||||
className='flex flex-col justify-center place-items-center bg-[#FFF6F2] pt-6 pb-20 rounded-tl-[50px] rounded-br-[50px]'>
|
||||
<div className='flex flex-col justify-center place-items-center'>
|
||||
<img src="/img/2.svg" alt=""/>
|
||||
<p className='text-2xl md:text-4xl font-bold underline decoration-4 decoration-[#FE4501] pb-10'>Update User Information </p>
|
||||
</div>
|
||||
<form onSubmit={updateUserData} action="" className='w-full px-6 md:px-20'>
|
||||
<div className='flex flex-col w-full pt-4'>
|
||||
<label htmlFor="class" className='text-xl font-bold'>Type</label>
|
||||
<input value={user.type} onChange={e => 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]' />
|
||||
</div>
|
||||
<div className='flex flex-col w-full'>
|
||||
<label htmlFor="name" className='text-xl font-bold'> Name</label>
|
||||
<input value={user.uname} onChange={e => 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]' />
|
||||
</div>
|
||||
<div className='flex flex-col w-full'>
|
||||
<label htmlFor="status" className='text-xl font-bold'> Status</label>
|
||||
<input value={user.status} onChange={e => 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]' />
|
||||
</div>
|
||||
<div className='flex flex-col w-full'>
|
||||
<label htmlFor="start_date" className='text-xl font-bold'> Start Date (YYYY-MM-DD) </label>
|
||||
<input value={user.start_date} onChange={e => 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]' />
|
||||
</div>
|
||||
<div className='flex flex-col w-full'>
|
||||
<label htmlFor="end_date" className='text-xl font-bold'> End Date (YYYY-MM-DD)</label>
|
||||
<input value={user.end_date} onChange={e => 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]' />
|
||||
</div>
|
||||
<div className='flex flex-col w-full'>
|
||||
<label htmlFor="email" className='text-xl font-bold'>Email</label>
|
||||
<input value={user.email} onChange={e => 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]'/>
|
||||
</div>
|
||||
<div className='flex flex-col w-full'>
|
||||
<label htmlFor="phone" className='text-xl font-bold'> Phone</label>
|
||||
<input value={user.phone} onChange={e => 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]' />
|
||||
</div>
|
||||
<div className='flex flex-col w-full'>
|
||||
<label htmlFor="country" className='text-xl font-bold'>Country</label>
|
||||
<input value={user.country} onChange={e => 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]' />
|
||||
</div>
|
||||
<div className='flex flex-col w-full'>
|
||||
<label htmlFor="state" className='text-xl font-bold'> State</label>
|
||||
<input value={user.state} onChange={e => 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]' />
|
||||
</div>
|
||||
<div className='flex flex-col w-full'>
|
||||
<label htmlFor="city" className='text-xl font-bold'> City</label>
|
||||
<input value={user.city} onChange={e => 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]' />
|
||||
</div>
|
||||
|
||||
<div className='flex flex-col w-full'>
|
||||
<label htmlFor="address" className='text-xl font-bold'> Address Line-1</label>
|
||||
<input value={user.address} onChange={e => 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]' />
|
||||
</div>
|
||||
{/* <div className='flex flex-col w-full'>
|
||||
<label htmlFor="address" className='text-xl font-bold'> Address Line-2</label>
|
||||
<input value={user.address} onChange={e => 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]' />
|
||||
</div> */}
|
||||
<div className='flex flex-col w-full pt-4'>
|
||||
<label htmlFor="" className='text-xl font-bold'>School ID</label>
|
||||
<input value={user.school} onChange={e => 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]' />
|
||||
</div>
|
||||
<div className='flex flex-col w-full pt-4'>
|
||||
<label htmlFor="klas" className='text-xl font-bold'>Class</label>
|
||||
<input value={user.klas} onChange={e => 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]' />
|
||||
</div>
|
||||
<div className='flex flex-col w-full pt-4'>
|
||||
<label htmlFor="annual" className='text-xl font-bold'>annual</label>
|
||||
<input value={user.annual} onChange={e => 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]' />
|
||||
</div>
|
||||
<div className='flex flex-col w-full pt-4'>
|
||||
<label htmlFor="early_start_programme" className='text-xl font-bold'>Early Start Programme</label>
|
||||
<input value={user.early_start_programme} onChange={e => 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]' />
|
||||
</div>
|
||||
<div className='flex flex-col w-full pt-4'>
|
||||
<label htmlFor="toddlers" className='text-xl font-bold'>Toddlers</label>
|
||||
<input value={user.toddlers} onChange={e => 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]' />
|
||||
</div>
|
||||
<div className='flex flex-col w-full pt-4'>
|
||||
<label htmlFor="interakto" className='text-xl font-bold'>Interakto</label>
|
||||
<input value={user.interakto} onChange={e => 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]' />
|
||||
</div>
|
||||
|
||||
<div className='flex justify-center pt-8'>
|
||||
<button type="submit"
|
||||
className='bg-[#FE4501] hover:shadow-2xl hover:shadow-[#F2B705] p-2.5 rounded-lg px-10 rounded-tl-full rounded-br-full hover:scale-110 active:scale-75 duration-200 text-xl font-bold text-white cursor-pointer'>Update
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
</main>
|
||||
)
|
||||
}
|
||||
return (
|
||||
<>
|
||||
Not signed in <br />
|
||||
<button onClick={() => signIn()}>Sign in</button>
|
||||
</>
|
||||
)
|
||||
|
||||
}
|
||||
426
src/pages/edit-user4.jsx
Normal file
426
src/pages/edit-user4.jsx
Normal file
@@ -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 (
|
||||
<main>
|
||||
<div>
|
||||
<NavBar/>
|
||||
<section className='container mx-auto px-4 my-16 lg:px-28 xl:px-56 2xl:px-96'>
|
||||
<div
|
||||
className='flex flex-col justify-center place-items-center bg-[#FFF6F2] pt-6 pb-20 rounded-tl-[50px] rounded-br-[50px]'>
|
||||
<div className='flex flex-col justify-center place-items-center'>
|
||||
<img src="/img/2.svg" alt=""/>
|
||||
<p className='text-2xl md:text-4xl font-bold underline decoration-4 decoration-[#FE4501] pb-10'>Update User Information </p>
|
||||
</div>
|
||||
<form onSubmit={handleFormsubmit} action="" className='w-full px-6 md:px-20'>
|
||||
<div className='flex flex-col w-full pt-4'>
|
||||
<label htmlFor="class" className='text-xl font-bold'>Type</label>
|
||||
<input type="text" value="wvgfbhvwhvf" name="type" onChange={handleTypeOnChange} className=' bg-white border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]' />
|
||||
|
||||
|
||||
</div>
|
||||
<div className='flex flex-col w-full'>
|
||||
<label htmlFor="name" className='text-xl font-bold'> Name</label>
|
||||
<input type="text" name="uname"
|
||||
className=' border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]'
|
||||
placeholder='Enter your Name'/>
|
||||
</div>
|
||||
<div className='flex flex-col w-full'>
|
||||
<label htmlFor="email" className='text-xl font-bold'>Email</label>
|
||||
<input 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]'/>
|
||||
</div>
|
||||
<div className='flex flex-col w-full'>
|
||||
<label htmlFor="country" className='text-xl font-bold'>Country</label>
|
||||
<Select
|
||||
className='bg-white border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]'
|
||||
name="country" instanceId={useId()} options={options} value={countryValue}
|
||||
onChange={selectCountry}/>
|
||||
</div>
|
||||
{allStates && allStates.length > 0 &&
|
||||
<div className='flex flex-col w-full'>
|
||||
<label htmlFor="state" className='text-xl font-bold'>State</label>
|
||||
<Select
|
||||
className='bg-white border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]'
|
||||
name="state" options={allStates} value={allStates[0].name}
|
||||
onChange={handleSelectAllStates}/>
|
||||
</div>}
|
||||
{
|
||||
allCities && allCities.length > 0 &&
|
||||
<div className='flex flex-col w-full'>
|
||||
<label htmlFor="city" className='text-xl font-bold'>City</label>
|
||||
<Select
|
||||
className='bg-white border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]'
|
||||
name="city" options={allCities} value={allCities[0].name}
|
||||
// onChange={() => {}}
|
||||
/>
|
||||
</div>}
|
||||
<div className='flex flex-col w-full'>
|
||||
<label htmlFor="phone" className='text-xl font-bold'> Phone</label>
|
||||
<PhoneInput
|
||||
className=' border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]'
|
||||
name="phone" placeholder="Enter phone number" value={phoneValue}
|
||||
onChange={setphoneValue}/>
|
||||
</div>
|
||||
<div className='flex flex-col w-full pt-4'>
|
||||
<label htmlFor="" className='text-xl font-bold'>School name</label>
|
||||
<select name="schoolID" onChange={individual}
|
||||
className='bg-white border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]'>
|
||||
<option value="0"> individual</option>
|
||||
{school && school.data.map(data =>
|
||||
<option value={data.id} key={data.id}>{data.name}</option>
|
||||
)}
|
||||
</select>
|
||||
</div>
|
||||
<div className='flex flex-col w-full pt-4'>
|
||||
<label htmlFor="class" className='text-xl font-bold'>Class</label>
|
||||
<select name="klas"
|
||||
className=' bg-white border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]'>
|
||||
<option value="0">-Select-</option>
|
||||
<option value="IK1">IK1</option>
|
||||
<option value="IK2">IK2</option>
|
||||
<option value="IK3">IK3</option>
|
||||
<option value="PG">PG</option>
|
||||
</select>
|
||||
</div>
|
||||
{individualValue &&
|
||||
<div>
|
||||
<div className='flex flex-col w-full pt-4'>
|
||||
<label htmlFor="anual" className='text-xl font-bold'>Anual</label>
|
||||
<select name="anual" className=' bg-white border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]'>
|
||||
<option value="0">-NA-</option>
|
||||
<option value="Jan">Jan</option>
|
||||
<option value="Feb">Feb</option>
|
||||
<option value="Mar">Mar</option>
|
||||
<option value="Apr">Apr</option>
|
||||
<option value="May">May</option>
|
||||
<option value="Jun">Jun</option>
|
||||
<option value="Jul">Jul</option>
|
||||
<option value="Aug">Aug</option>
|
||||
<option value="Sept">Sept</option>
|
||||
<option value="Oct">Oct</option>
|
||||
<option value="Nov">Nov</option>
|
||||
<option value="Dec">Dec</option>
|
||||
</select>
|
||||
</div>
|
||||
<div className='flex flex-col w-full pt-4'>
|
||||
<label htmlFor="early_start_programme" className='text-xl font-bold'>Early Start Programme</label>
|
||||
<select name="early_start_programme" className=' bg-white border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]'>
|
||||
<option value="0">-NA-</option>
|
||||
<option value="Jan">Jan</option>
|
||||
<option value="Feb">Feb</option>
|
||||
<option value="Mar">Mar</option>
|
||||
<option value="Apr">Apr</option>
|
||||
<option value="May">May</option>
|
||||
<option value="Jun">Jun</option>
|
||||
<option value="Jul">Jul</option>
|
||||
<option value="Aug">Aug</option>
|
||||
<option value="Sept">Sept</option>
|
||||
<option value="Oct">Oct</option>
|
||||
<option value="Nov">Nov</option>
|
||||
<option value="Dec">Dec</option>
|
||||
</select>
|
||||
</div>
|
||||
<div className='flex flex-col w-full pt-4'>
|
||||
<label htmlFor="toddlers" className='text-xl font-bold'>Toddlers</label>
|
||||
<select name="toddlers" className=' bg-white border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]'>
|
||||
<option value="0">-NA-</option>
|
||||
<option value="Jan">Jan</option>
|
||||
<option value="Feb">Feb</option>
|
||||
<option value="Mar">Mar</option>
|
||||
<option value="Apr">Apr</option>
|
||||
<option value="May">May</option>
|
||||
<option value="Jun">Jun</option>
|
||||
<option value="Jul">Jul</option>
|
||||
<option value="Aug">Aug</option>
|
||||
<option value="Sept">Sept</option>
|
||||
<option value="Oct">Oct</option>
|
||||
<option value="Nov">Nov</option>
|
||||
<option value="Dec">Dec</option>
|
||||
</select>
|
||||
</div>
|
||||
<div className='flex flex-col w-full pt-4'>
|
||||
<label htmlFor="interakto" className='text-xl font-bold'>Interakto</label>
|
||||
<select name="interakto" className=' bg-white border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]'>
|
||||
<option value="0">-NA-</option>
|
||||
<option value="Jan">Jan</option>
|
||||
<option value="Feb">Feb</option>
|
||||
<option value="Mar">Mar</option>
|
||||
<option value="Apr">Apr</option>
|
||||
<option value="May">May</option>
|
||||
<option value="Jun">Jun</option>
|
||||
<option value="Jul">Jul</option>
|
||||
<option value="Aug">Aug</option>
|
||||
<option value="Sept">Sept</option>
|
||||
<option value="Oct">Oct</option>
|
||||
<option value="Nov">Nov</option>
|
||||
<option value="Dec">Dec</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div className='flex flex-col w-full pt-4'>
|
||||
<label htmlFor="lang" className='text-xl font-bold'>Language</label>
|
||||
<div className='grid grid-cols-3 md:grid-cols-4 lg:grid-cols-5 gap-y-2 pt-2'>
|
||||
{/* <label className='cursor-pointer' htmlFor="Assamese"> Assamese </label> <input type="checkbox" name="lang" value="Assamese" className='check-box'/> <br />
|
||||
<label className='cursor-pointer' htmlFor="Bengali"> Bengali </label> <input type="checkbox" name="lang" value="Bengali" className='check-box'/> <br />
|
||||
<label className='cursor-pointer' htmlFor="English"> English </label> <input type="checkbox" name="lang" value="English" className='check-box'/> <br />
|
||||
<label className='cursor-pointer' htmlFor="Hindi"> Hindi </label> <input type="checkbox" name="lang" value="Hindi" className='check-box'/> <br />
|
||||
<label className='cursor-pointer' htmlFor="Telegu"> Telegu </label> <input type="checkbox" name="lang" value="Telegu" className='check-box'/> <br />
|
||||
<label className='cursor-pointer' htmlFor="Punjabi"> Punjabi </label> <input type="checkbox" name="lang" value="Punjabi" className='check-box'/> <br />
|
||||
<label className='cursor-pointer' htmlFor="Malayalam"> Malayalam </label> <input type="checkbox" name="lang" value="Malayalam" className='check-box'/> <br />
|
||||
<label className='cursor-pointer' htmlFor="Tamil"> Tamil </label> <input type="checkbox" name="lang" value="Tamil" className='check-box'/> <br />
|
||||
<label className='cursor-pointer' htmlFor="Kannada"> Kannada </label> <input type="checkbox" name="lang" value="Kannada" className='check-box'/> <br />
|
||||
<label className='cursor-pointer' htmlFor="Gujrati"> Gujrati </label> <input type="checkbox" name="lang" value="Gujrati" className='check-box'/> <br /> */}
|
||||
{allLanguage && allLanguage.length && allLanguage.map(n => {
|
||||
return (
|
||||
<div key={n.lang} className=''>
|
||||
<label className='cursor-pointer'
|
||||
htmlFor="assamese">{n.lang}</label>
|
||||
<input type="checkbox" disabled={n.disabled} name="lang" value={n.lang} checked={n.value}
|
||||
onChange={handleOnLanguageChange}
|
||||
className='check-box'/>
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
<div className='flex flex-col w-full pt-4'>
|
||||
<label htmlFor="start_month" className='text-xl font-bold'>Start Month</label>
|
||||
<select name="start_month" id="start_month" className='bg-white border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]'>
|
||||
<option value="0">-Select-</option>
|
||||
<option value="Jan"> Jan</option>
|
||||
<option value="Feb"> Feb</option>
|
||||
<option value="Mar"> Mar</option>
|
||||
<option value="Apr"> Apr</option>
|
||||
<option value="May"> May</option>
|
||||
<option value="Jun"> Jun</option>
|
||||
<option value="Jul"> Jul</option>
|
||||
<option value="Aug"> Aug</option>
|
||||
<option value="Sept"> Sept</option>
|
||||
<option value="Nov"> Nov</option>
|
||||
<option value="Dec"> Dec</option>
|
||||
</select>
|
||||
</div>
|
||||
<div className='flex flex-col w-full'>
|
||||
<label htmlFor="start_date" className='text-xl font-bold pt-4'>Start
|
||||
Date</label>
|
||||
<input type="date" name="start_date" id="start_date"
|
||||
className=' border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]'/>
|
||||
</div>
|
||||
<div className='flex flex-col w-full'>
|
||||
<label htmlFor="end_date" className='text-xl font-bold pt-4'>Subscription Expiry
|
||||
Date.</label>
|
||||
<input type="date" name="end_date" id="end_date"
|
||||
className=' border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]'/>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
<div className='flex justify-center pt-8'>
|
||||
<button type="submit"
|
||||
className='bg-[#FE4501] hover:shadow-2xl hover:shadow-[#F2B705] p-2.5 rounded-lg px-10 rounded-tl-full rounded-br-full hover:scale-110 active:scale-75 duration-200 text-xl font-bold text-white cursor-pointer'>Update
|
||||
</button>
|
||||
{/* <input type="submit" value="Submit Now" className='bg-[#FE4501] hover:shadow-2xl hover:shadow-[#F2B705] p-2.5 rounded-lg px-10 rounded-tl-full rounded-br-full hover:scale-110 active:scale-75 duration-200 text-xl font-bold text-white cursor-pointer' /> */}
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
</main>
|
||||
)
|
||||
}
|
||||
15
src/pages/index.jsx
Normal file
15
src/pages/index.jsx
Normal file
@@ -0,0 +1,15 @@
|
||||
import { signIn, signOut } from 'next-auth/react';
|
||||
import NavBar from '../components/NavBar'
|
||||
import { useSession } from "next-auth/react";
|
||||
|
||||
// const { data: session } = useSession();
|
||||
// console.log(session)
|
||||
|
||||
export default function Home() {
|
||||
return (
|
||||
<main>
|
||||
<NavBar />
|
||||
<br />
|
||||
</main>
|
||||
)
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
import Image from 'next/image'
|
||||
import NavBar from '../components/NavBar'
|
||||
import { Inter } from 'next/font/google'
|
||||
|
||||
const inter = Inter({ subsets: ['latin'] })
|
||||
|
||||
export default function Home() {
|
||||
return (
|
||||
<main>
|
||||
<NavBar />
|
||||
</main>
|
||||
)
|
||||
}
|
||||
131
src/pages/login.jsx
Normal file
131
src/pages/login.jsx
Normal file
@@ -0,0 +1,131 @@
|
||||
import { useState } from 'react';
|
||||
import { signIn, signOut, getCsrfToken, useSession } from 'next-auth/react';
|
||||
import { Formik, Field, ErrorMessage } from 'formik';
|
||||
import * as Yup from 'yup';
|
||||
import { useRouter } from 'next/router';
|
||||
import Link from 'next/link'
|
||||
|
||||
|
||||
export default function SignIn({ csrfToken }) {
|
||||
const router = useRouter();
|
||||
const [error, setError] = useState(null);
|
||||
const { data: session } = useSession()
|
||||
// console.log(session)
|
||||
if (session) {
|
||||
return (
|
||||
<>
|
||||
<br /><br />
|
||||
You are already Signed in, click on continue
|
||||
<br />
|
||||
<Link href="/">Continue...</Link>
|
||||
<br /><br />
|
||||
or : <button onClick={() => signOut()}>Sign out</button>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<Formik
|
||||
initialValues={{ email: '', password: '', tenantKey: '' }}
|
||||
validationSchema={Yup.object({
|
||||
email: Yup.string()
|
||||
.max(30, 'Must be 30 characters or less')
|
||||
.email('Invalid email address')
|
||||
.required('Please enter your email'),
|
||||
password: Yup.string().required('Please enter your password'),
|
||||
})}
|
||||
onSubmit={async (values, { setSubmitting }) => {
|
||||
const res = await signIn('credentials', {
|
||||
redirect: false,
|
||||
email: values.email,
|
||||
password: values.password,
|
||||
callbackUrl: `${window.location.origin}`,
|
||||
});
|
||||
if (res?.error) {
|
||||
setError(res.error);
|
||||
} else {
|
||||
setError(null);
|
||||
}
|
||||
if (res.url) router.push(res.url);
|
||||
setSubmitting(false);
|
||||
}}
|
||||
>
|
||||
{(formik) => (
|
||||
<form onSubmit={formik.handleSubmit}>
|
||||
<div
|
||||
className="bg-[#FFF6F2] flex flex-col items-center
|
||||
justify-center min-h-screen py-2 shadow-lg">
|
||||
<div className="bg-white shadow-md rounded px-8 pt-6 pb-8 mb-4">
|
||||
<input
|
||||
name="csrfToken"
|
||||
type="hidden"
|
||||
defaultValue={csrfToken}
|
||||
/>
|
||||
|
||||
<div className="text-red-400 text-md text-center rounded p-2">
|
||||
{error}
|
||||
</div>
|
||||
<div className="mb-4">
|
||||
<label
|
||||
htmlFor="email"
|
||||
className="uppercase text-sm text-gray-600 font-bold"
|
||||
>
|
||||
Email
|
||||
<Field
|
||||
name="email"
|
||||
aria-label="enter your email"
|
||||
aria-required="true"
|
||||
type="text"
|
||||
className="w-full focus:bg-gray-300 text-gray-900 mt-2 p-3 border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]"
|
||||
/>
|
||||
</label>
|
||||
|
||||
<div className="text-red-600 text-sm">
|
||||
<ErrorMessage name="email" />
|
||||
</div>
|
||||
</div>
|
||||
<div className="mb-6">
|
||||
<label
|
||||
htmlFor="password"
|
||||
className="uppercase text-sm text-gray-600 font-bold "
|
||||
>
|
||||
password
|
||||
<Field
|
||||
name="password"
|
||||
aria-label="enter your password"
|
||||
aria-required="true"
|
||||
type="password"
|
||||
className="w-full bg-gray-300 text-gray-900 mt-2 p-3 border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]"
|
||||
/>
|
||||
</label>
|
||||
|
||||
<div className="text-red-600 text-sm">
|
||||
<ErrorMessage name="password" />
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex items-center justify-center">
|
||||
<button
|
||||
type="submit"
|
||||
className="bg-[#FE4501] text-white p-3 rounded-lg w-full"
|
||||
>
|
||||
{formik.isSubmitting ? 'Please wait...' : 'Sign In'}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
)}
|
||||
</Formik>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
// This is the recommended way for Next.js 9.3 or newer
|
||||
export async function getServerSideProps(context) {
|
||||
return {
|
||||
props: {
|
||||
csrfToken: await getCsrfToken(context),
|
||||
},
|
||||
};
|
||||
}
|
||||
22
src/pages/profile.jsx
Normal file
22
src/pages/profile.jsx
Normal file
@@ -0,0 +1,22 @@
|
||||
import { signIn, signOut, useSession } from 'next-auth/react'
|
||||
|
||||
export default function Home() {
|
||||
const { data: session } = useSession()
|
||||
// console.log(session)
|
||||
if (session) {
|
||||
return (
|
||||
<>
|
||||
Signed in
|
||||
<br />
|
||||
<button onClick={() => signOut()}>Sign out</button>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
Not signed in <br />
|
||||
<button onClick={() => signIn()}>Sign in</button>
|
||||
</>
|
||||
)
|
||||
}
|
||||
32
src/pages/sampleform.jsx
Normal file
32
src/pages/sampleform.jsx
Normal file
@@ -0,0 +1,32 @@
|
||||
import React from "react";
|
||||
class App extends React.Component {
|
||||
upload(e)
|
||||
{
|
||||
console.warn(e.target.files)
|
||||
const files=e.target.files
|
||||
const formData=new FormData();
|
||||
formData.append("img", files[0])
|
||||
fetch('https://management.beanstalkedu.com/items/school',{
|
||||
method: 'POST',
|
||||
body: formData
|
||||
}
|
||||
)
|
||||
.then((resp)=>{
|
||||
resp.json()
|
||||
.then((result)=>{
|
||||
console.warn("result", result)
|
||||
})
|
||||
})
|
||||
}
|
||||
render(){
|
||||
return (
|
||||
<div>
|
||||
<div className='flex flex-col w-full'>
|
||||
<label htmlFor="school_agreement" className='text-xl font-bold pt-4'>Upload School Agreement</label>
|
||||
<input type="file" onChange={(e)=>this.upload(e)} name="school_agreement" id="school_agreement" className=' border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]' />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
export default App;
|
||||
37
src/pages/sampleform2.jsx
Normal file
37
src/pages/sampleform2.jsx
Normal file
@@ -0,0 +1,37 @@
|
||||
import React from "react";
|
||||
import { useState } from "react";
|
||||
|
||||
function FileUpload(){
|
||||
const [file, setFile] = useState()
|
||||
|
||||
function handleFile(event) {
|
||||
setFile(event.target.files[0])
|
||||
}
|
||||
function handleUpload() {
|
||||
const formData = new FormData()
|
||||
formData.append('file', file)
|
||||
fetch('https://management.beanstalkedu.com/items/school', {
|
||||
method: "POST",
|
||||
body: formData
|
||||
})
|
||||
.then((respons)=> respons.json())
|
||||
.then((result)=>{
|
||||
console.log('success', result)
|
||||
})
|
||||
.catch(error => {
|
||||
console.error("Error:", error)
|
||||
})
|
||||
}
|
||||
return (
|
||||
<div>
|
||||
<form onSubmit={handleUpload}>
|
||||
<div className='flex flex-col w-full'>
|
||||
<label htmlFor="school_agreement" className='text-xl font-bold pt-4'>Upload School Agreement</label>
|
||||
<input type="file" name="school_agreement" onChange={handleFile} id="school_agreement" className=' border-2 border-[#FE4501] p-2 rounded-md focus:outline-none focus:border-2 focus:border-[#F2B705]' />
|
||||
<button>Upload</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
export default FileUpload;
|
||||
@@ -1,64 +0,0 @@
|
||||
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(user)
|
||||
|
||||
useEffect(() => {
|
||||
fetchData();
|
||||
},[])
|
||||
|
||||
return (
|
||||
<main>
|
||||
<div>
|
||||
<NavBar />
|
||||
<section className='container mx-auto px-4 mt-16'>
|
||||
<div className="flex justify-end bg-[#FFF6F2] p-2 border-x-2 border-t-2 rounded-t-xl ">
|
||||
<a href="/add-school-form" className=" inline-flex place-items-center p-2">
|
||||
<svg width="20px" height="20px" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><g id="SVGRepo_bgCarrier" stroke-width="0"></g><g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round"></g><g id="SVGRepo_iconCarrier"> <path fill-rule="evenodd" clip-rule="evenodd" d="M21.1213 2.70705C19.9497 1.53548 18.0503 1.53547 16.8787 2.70705L15.1989 4.38685L7.29289 12.2928C7.16473 12.421 7.07382 12.5816 7.02986 12.7574L6.02986 16.7574C5.94466 17.0982 6.04451 17.4587 6.29289 17.707C6.54127 17.9554 6.90176 18.0553 7.24254 17.9701L11.2425 16.9701C11.4184 16.9261 11.5789 16.8352 11.7071 16.707L19.5556 8.85857L21.2929 7.12126C22.4645 5.94969 22.4645 4.05019 21.2929 2.87862L21.1213 2.70705ZM18.2929 4.12126C18.6834 3.73074 19.3166 3.73074 19.7071 4.12126L19.8787 4.29283C20.2692 4.68336 20.2692 5.31653 19.8787 5.70705L18.8622 6.72357L17.3068 5.10738L18.2929 4.12126ZM15.8923 6.52185L17.4477 8.13804L10.4888 15.097L8.37437 15.6256L8.90296 13.5112L15.8923 6.52185ZM4 7.99994C4 7.44766 4.44772 6.99994 5 6.99994H10C10.5523 6.99994 11 6.55223 11 5.99994C11 5.44766 10.5523 4.99994 10 4.99994H5C3.34315 4.99994 2 6.34309 2 7.99994V18.9999C2 20.6568 3.34315 21.9999 5 21.9999H16C17.6569 21.9999 19 20.6568 19 18.9999V13.9999C19 13.4477 18.5523 12.9999 18 12.9999C17.4477 12.9999 17 13.4477 17 13.9999V18.9999C17 19.5522 16.5523 19.9999 16 19.9999H5C4.44772 19.9999 4 19.5522 4 18.9999V7.99994Z" fill="#1d1d1d"></path> </g></svg>
|
||||
Add School
|
||||
</a>
|
||||
</div>
|
||||
<div className='flex xl:justify-center overflow-x-scroll pb-4 w-full'>
|
||||
<table className=" text-center border-x-2 border-b-2 p-2 w-full">
|
||||
<thead className=''>
|
||||
<tr className='bg-[#FFF6F2] text-[#1D1D1D] text-xl whitespace-nowrap'>
|
||||
<th className=" p-2">School Name</th>
|
||||
<th className=" p-2">Country</th>
|
||||
<th className=" p-2">Anual</th>
|
||||
<th className=" p-2">Early Start Program</th>
|
||||
<th className=" p-2">Toddlers</th>
|
||||
<th className=" p-2">Interakto</th>
|
||||
<th className=" p-2">Status</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{school.map(data=>
|
||||
<tr className="border-b-2 whitespace-normal">
|
||||
<td className=" p-2">{data.name}</td>
|
||||
<td className="p-2">{data.country}</td>
|
||||
<td className="p-2">{data.anual}</td>
|
||||
<td className="p-2">{data.early_start_program}</td>
|
||||
<td className="p-2">{data.toddlers}</td>
|
||||
<td className="p-2">{data.interakto}</td>
|
||||
<td className="p-2">{data.status}</td>
|
||||
</tr>
|
||||
)}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
</main>
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
161
src/pages/school-list/[slug].jsx
Normal file
161
src/pages/school-list/[slug].jsx
Normal file
@@ -0,0 +1,161 @@
|
||||
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 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)
|
||||
})
|
||||
}
|
||||
|
||||
}, [router.query.school]);
|
||||
|
||||
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 JSONdata = JSON.stringify(data)
|
||||
console.log(data)
|
||||
const endpoint = '/api/editSchool'
|
||||
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(`User data updated`)
|
||||
|
||||
}
|
||||
|
||||
return (
|
||||
<main>
|
||||
<div>
|
||||
<NavBar/>
|
||||
<section className='container mx-auto px-4 my-16 lg:px-28 xl:px-56 2xl:px-96'>
|
||||
<div
|
||||
className='flex flex-col justify-center place-items-center bg-[#FFF6F2] pt-6 pb-20 rounded-tl-[50px] rounded-br-[50px]'>
|
||||
<div className='inline-flex p-4 '>
|
||||
<Link href="/add-school-form" className="m-2 inline-flex place-items-center justify-center p-2 pl-4 pr-4 bg-[#FE4501] text-white font-bold rounded-full whitespace-nowrap">
|
||||
<img src="/img/4.svg" alt="" />
|
||||
List Users Under This School
|
||||
</Link>
|
||||
<div className="place-items-center justify-center m-2 p-2 bg-[#FE4501] text-white font-bold rounded-full whitespace-nowrap">
|
||||
<span className="text-small">CSV Upload </span>
|
||||
<input type="file" />
|
||||
</div>
|
||||
{/* <img src="/img/2.svg" alt=""/> */}
|
||||
|
||||
</div>
|
||||
<p className='text-2xl font-bold underline decoration-4 decoration-[#FE4501] pb-10'>Update School Information </p>
|
||||
<form onSubmit={updateSchoolData} action="" className='w-full px-6 md:px-20'>
|
||||
<div className='flex flex-col w-full pt-4'>
|
||||
<label htmlFor="sname" className='text-xl font-bold'>School Name</label>
|
||||
<input value={school.sname} onChange={e => 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]' />
|
||||
</div>
|
||||
<div className='flex flex-col w-full pt-4'>
|
||||
<label htmlFor="status" className='text-xl font-bold'>Status</label>
|
||||
<input value={school.status} onChange={e => 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]' />
|
||||
</div>
|
||||
<div className='flex flex-col w-full'>
|
||||
<label htmlFor="phone" className='text-xl font-bold'>School contact Number</label>
|
||||
<input value={school.phone} onChange={e => 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]' />
|
||||
</div>
|
||||
<div className='flex flex-col w-full'>
|
||||
<label htmlFor="email" className='text-xl font-bold'> School contact Email ID</label>
|
||||
<input value={school.email} onChange={e => 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]' />
|
||||
</div>
|
||||
<div className='flex flex-col w-full'>
|
||||
<label htmlFor="country" className='text-xl font-bold'>Country</label>
|
||||
<input value={school.country} onChange={e => 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]' />
|
||||
</div>
|
||||
<div className='flex flex-col w-full'>
|
||||
<label htmlFor="state" className='text-xl font-bold'>State</label>
|
||||
<input value={school.state} onChange={e => 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]' />
|
||||
</div>
|
||||
<div className='flex flex-col w-full'>
|
||||
<label htmlFor="city" className='text-xl font-bold'>Cities</label>
|
||||
<input value={school.city} onChange={e => 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]' />
|
||||
</div>
|
||||
<div className='flex flex-col w-full'>
|
||||
<label htmlFor="annual" className='text-xl font-bold'>Annual</label>
|
||||
<input value={school.annual} onChange={e => 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]'/>
|
||||
</div>
|
||||
<div className='flex flex-col w-full'>
|
||||
<label htmlFor="toddlers" className='text-xl font-bold'>Toddlers</label>
|
||||
<input value={school.toddlers} onChange={e => 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]' />
|
||||
</div>
|
||||
<div className='flex flex-col w-full'>
|
||||
<label htmlFor="early_start_programme" className='text-xl font-bold'>Early Start Program</label>
|
||||
<input value={school.early_start_programme} onChange={e => 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]' />
|
||||
</div>
|
||||
<div className='flex flex-col w-full'>
|
||||
<label htmlFor="interakto" className='text-xl font-bold'>Interakto</label>
|
||||
<input value={school.interakto} onChange={e => 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]' />
|
||||
</div>
|
||||
<div className='flex flex-col w-full'>
|
||||
<label htmlFor="usage_expiry" className='text-xl font-bold'> Usage Expiry Date: (YYYY-MM-DD)</label>
|
||||
<input value={school.usage_expiry} onChange={e => 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]' />
|
||||
</div>
|
||||
|
||||
<div className='flex flex-col w-full'>
|
||||
<label htmlFor="agg_expiry" className='text-xl font-bold'> Agreement Expiry Date: (YYYY-MM-DD)</label>
|
||||
<input value={school.agg_expiry} onChange={e => 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]' />
|
||||
</div>
|
||||
<div className='flex justify-center pt-8'>
|
||||
<button type="submit"
|
||||
className='bg-[#FE4501] hover:shadow-2xl hover:shadow-[#F2B705] p-2.5 rounded-lg px-10 rounded-tl-full rounded-br-full hover:scale-110 active:scale-75 duration-200 text-xl font-bold text-white cursor-pointer'>Update
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div className='flex flex-col w-full'>
|
||||
<label htmlFor="agreement_documents" className='text-xl font-bold'>Upload Agreement Document's</label>
|
||||
<input onChange={e => 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]' />
|
||||
<div className='flex justify-end pt-2'>
|
||||
<button className=' bg-[#FE4501] px-4 py-1.5 rounded-lg text-white'>Download Agreement</button>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
</section>
|
||||
</div>
|
||||
</main>
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
85
src/pages/school-list/index.jsx
Normal file
85
src/pages/school-list/index.jsx
Normal file
@@ -0,0 +1,85 @@
|
||||
// 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'
|
||||
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();
|
||||
return setSchool(data);
|
||||
}
|
||||
console.log(school)
|
||||
|
||||
useEffect(() => {
|
||||
fetchData();
|
||||
},[])
|
||||
if (session) {
|
||||
return (
|
||||
<main>
|
||||
<div>
|
||||
<NavBar />
|
||||
<section className='container mx-auto px-4 mt-16'>
|
||||
<div className="flex flex-row justify-end bg-[#FFF6F2] p-2 gap-x-4 border-x-2 border-t-2 rounded-t-xl">
|
||||
<div className="flex flex-row justify-center place-items-center">
|
||||
<input type="text" className="md:w-32 md:focus:w-96 duration-[1s] border-2 border-[#FE4501] w-full rounded-l-full p-2 focus:outline-none focus:border-[#F2B705] bg-[#FFF6F2] focus:bg-white text-center" placeholder="Search School" />
|
||||
<a href="" className="bg-[#FE4501] rounded-r-full p-2 px-4 border-2 border-[#FE4501] text-white font-bold ">
|
||||
<svg width="24px" height="24px" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg" fill="none" stroke="#ffffff"><g id="SVGRepo_bgCarrier" stroke-width="0"></g><g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round"></g><g id="SVGRepo_iconCarrier"> <path fill="#ffffff" fill-rule="evenodd" d="M4 9a5 5 0 1110 0A5 5 0 014 9zm5-7a7 7 0 104.2 12.6.999.999 0 00.093.107l3 3a1 1 0 001.414-1.414l-3-3a.999.999 0 00-.107-.093A7 7 0 009 2z"></path> </g></svg>
|
||||
</a>
|
||||
</div>
|
||||
{/* <a href="/add-school-form" className="inline-flex place-items-center justify-center p-2 bg-[#FE4501] text-white font-bold rounded-full whitespace-nowrap">
|
||||
<svg width="20px" height="20px" viewBox="0 0 15 15" fill="none" xmlns="http://www.w3.org/2000/svg" stroke="#ffffff"><g id="SVGRepo_bgCarrier" stroke-width="0"></g><g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round"></g><g id="SVGRepo_iconCarrier"> <path d="M7.5 4.5L11.5 6.5V14.5H3.5V6.5L7.5 4.5ZM7.5 4.5V0M0 14.5H15M1.5 14.5V8.5H3.5M13.5 14.5V8.5H11.5M6.5 14.5V11.5H8.5V14.5M7.5 0.5H10.5V2.5H7.5M7.5 9.5C6.94772 9.5 6.5 9.05228 6.5 8.5C6.5 7.94772 6.94772 7.5 7.5 7.5C8.05228 7.5 8.5 7.94772 8.5 8.5C8.5 9.05228 8.05228 9.5 7.5 9.5Z" stroke="#ffffff"></path> </g></svg>
|
||||
Add School
|
||||
</a> */}
|
||||
|
||||
|
||||
</div>
|
||||
<div className='flex xl:justify-center overflow-x-scroll pb-4 w-full'>
|
||||
<table className=" text-center border-x-2 border-b-2 p-2 w-full">
|
||||
<thead className=''>
|
||||
<tr className='bg-[#FFF6F2] text-[#1D1D1D] text-xl whitespace-nowrap'>
|
||||
<th className=" p-2">ID</th>
|
||||
<th className=" p-2"> Name</th>
|
||||
<th className=" p-2">City</th>
|
||||
<th className=" p-2">Status</th>
|
||||
<th className=" p-2">Expiry</th>
|
||||
<th className=" p-2 inline-flex"> <img src="/img/3.svg" alt="" />Edit</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{school.map(data=>
|
||||
<tr key={data.id} className="border-b-2 whitespace-normal">
|
||||
<td className=" p-2">{data.id}</td>
|
||||
<td className=" p-2">{data.sname}</td>
|
||||
<td className="p-2">{data.city}</td>
|
||||
<td className="p-2">{data.status}</td>
|
||||
<td className="p-2">{data.usage_expiry}</td>
|
||||
<td className="p-2">
|
||||
<a href={'/edit-school?school='+data.id} className="flex justify-center place-items-center">
|
||||
<svg width="35px" height="35px" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" stroke="#166435"><g id="SVGRepo_bgCarrier" stroke-width="0"></g><g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round"></g><g id="SVGRepo_iconCarrier"> <path opacity="0.15" d="M8 16H12L18 10L14 6L8 12V16Z" fill="#166435"></path> <path d="M14 6L8 12V16H12L18 10M14 6L17 3L21 7L18 10M14 6L18 10M10 4L4 4L4 20L20 20V14" stroke="#166435" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"></path> </g></svg></a>
|
||||
</td>
|
||||
</tr>
|
||||
)}
|
||||
</tbody>
|
||||
{/* <SchoolEditForm /> */}
|
||||
</table>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
</main>
|
||||
)
|
||||
}
|
||||
{/* <LogOutPage /> */}
|
||||
return (
|
||||
|
||||
<>
|
||||
Not signed in <br />
|
||||
<button onClick={() => signIn()}>Sign in</button>
|
||||
</>
|
||||
)
|
||||
|
||||
}
|
||||
84
src/pages/school-list/index22.jsx
Normal file
84
src/pages/school-list/index22.jsx
Normal file
@@ -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 (
|
||||
<main>
|
||||
<div>
|
||||
<NavBar />
|
||||
<section className='container mx-auto px-4 mt-16'>
|
||||
<div className="flex flex-row justify-end bg-[#FFF6F2] p-2 gap-x-4 border-x-2 border-t-2 rounded-t-xl">
|
||||
<div className="flex flex-row justify-center place-items-center">
|
||||
<input type="text" className="md:w-32 md:focus:w-96 duration-[1s] border-2 border-[#FE4501] w-full rounded-l-full p-2 focus:outline-none focus:border-[#F2B705] bg-[#FFF6F2] focus:bg-white text-center" placeholder="Search School" />
|
||||
<a href="" className="bg-[#FE4501] rounded-r-full p-2 px-4 border-2 border-[#FE4501] text-white font-bold ">
|
||||
<svg width="24px" height="24px" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg" fill="none" stroke="#ffffff"><g id="SVGRepo_bgCarrier" stroke-width="0"></g><g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round"></g><g id="SVGRepo_iconCarrier"> <path fill="#ffffff" fill-rule="evenodd" d="M4 9a5 5 0 1110 0A5 5 0 014 9zm5-7a7 7 0 104.2 12.6.999.999 0 00.093.107l3 3a1 1 0 001.414-1.414l-3-3a.999.999 0 00-.107-.093A7 7 0 009 2z"></path> </g></svg>
|
||||
</a>
|
||||
</div>
|
||||
{/* <a href="/add-school-form" className="inline-flex place-items-center justify-center p-2 bg-[#FE4501] text-white font-bold rounded-full whitespace-nowrap">
|
||||
<svg width="20px" height="20px" viewBox="0 0 15 15" fill="none" xmlns="http://www.w3.org/2000/svg" stroke="#ffffff"><g id="SVGRepo_bgCarrier" stroke-width="0"></g><g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round"></g><g id="SVGRepo_iconCarrier"> <path d="M7.5 4.5L11.5 6.5V14.5H3.5V6.5L7.5 4.5ZM7.5 4.5V0M0 14.5H15M1.5 14.5V8.5H3.5M13.5 14.5V8.5H11.5M6.5 14.5V11.5H8.5V14.5M7.5 0.5H10.5V2.5H7.5M7.5 9.5C6.94772 9.5 6.5 9.05228 6.5 8.5C6.5 7.94772 6.94772 7.5 7.5 7.5C8.05228 7.5 8.5 7.94772 8.5 8.5C8.5 9.05228 8.05228 9.5 7.5 9.5Z" stroke="#ffffff"></path> </g></svg>
|
||||
Add School
|
||||
</a> */}
|
||||
<a href="/add-school-form" className="inline-flex place-items-center justify-center p-2 bg-[#FE4501] text-white font-bold rounded-full whitespace-nowrap">
|
||||
<svg width="20px" height="20px" viewBox="0 0 15 15" fill="none" xmlns="http://www.w3.org/2000/svg" stroke="#ffffff"><g id="SVGRepo_bgCarrier" stroke-width="0"></g><g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round"></g><g id="SVGRepo_iconCarrier"> <path d="M7.5 4.5L11.5 6.5V14.5H3.5V6.5L7.5 4.5ZM7.5 4.5V0M0 14.5H15M1.5 14.5V8.5H3.5M13.5 14.5V8.5H11.5M6.5 14.5V11.5H8.5V14.5M7.5 0.5H10.5V2.5H7.5M7.5 9.5C6.94772 9.5 6.5 9.05228 6.5 8.5C6.5 7.94772 6.94772 7.5 7.5 7.5C8.05228 7.5 8.5 7.94772 8.5 8.5C8.5 9.05228 8.05228 9.5 7.5 9.5Z" stroke="#ffffff"></path> </g></svg>
|
||||
List Users Under This School
|
||||
</a>
|
||||
<div className="inline-flex place-items-center justify-center p-2 bg-[#FE4501] text-white font-bold rounded-full whitespace-nowrap">
|
||||
<span className="text-small">CSV Upload</span>
|
||||
<input type="file" />
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<div className='flex xl:justify-center overflow-x-scroll pb-4 w-full'>
|
||||
<table className=" text-center border-x-2 border-b-2 p-2 w-full">
|
||||
<thead className=''>
|
||||
<tr className='bg-[#FFF6F2] text-[#1D1D1D] text-xl whitespace-nowrap'>
|
||||
<th className=" p-2">ID</th>
|
||||
<th className=" p-2">School Name</th>
|
||||
<th className=" p-2">City</th>
|
||||
<th className=" p-2">Annual</th>
|
||||
<th className=" p-2">Interakto</th>
|
||||
<th className=" p-2">Status</th>
|
||||
<th className=" p-2 inline-flex"> <img src="/img/3.svg" alt="" />Edit</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{school.map(data=>
|
||||
<tr className="border-b-2 whitespace-normal">
|
||||
<td className=" p-2">{data.id}</td>
|
||||
<td className=" p-2">{data.name}</td>
|
||||
<td className="p-2">{data.city}</td>
|
||||
<td className="p-2">{data.anual}</td>
|
||||
<td className="p-2">{data.agreement_expiry_date}</td>
|
||||
<td className="p-2">{data.early_start_programme}</td>
|
||||
<td className="p-2">{data.toddlers}</td>
|
||||
<td className="p-2">{data.interakto}</td>
|
||||
<td className="p-2">{data.status}</td>
|
||||
<td className="p-2"><a href={'/edit-school?school='+data.id} className="flex justify-center place-items-center">
|
||||
<svg width="35px" height="35px" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" stroke="#166435"><g id="SVGRepo_bgCarrier" stroke-width="0"></g><g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round"></g><g id="SVGRepo_iconCarrier"> <path opacity="0.15" d="M8 16H12L18 10L14 6L8 12V16Z" fill="#166435"></path> <path d="M14 6L8 12V16H12L18 10M14 6L17 3L21 7L18 10M14 6L18 10M10 4L4 4L4 20L20 20V14" stroke="#166435" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"></path> </g></svg></a> </td>
|
||||
</tr>
|
||||
)}
|
||||
</tbody>
|
||||
{/* <SchoolEditForm /> */}
|
||||
</table>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
</main>
|
||||
)
|
||||
|
||||
}
|
||||
36
src/pages/test/2.jsx
Normal file
36
src/pages/test/2.jsx
Normal file
@@ -0,0 +1,36 @@
|
||||
export default function PageWithJSbasedForm() {
|
||||
const handleSubmit = async (event) => {
|
||||
event.preventDefault()
|
||||
const data = {
|
||||
"status":"published",
|
||||
name: event.target.schoolName.value,
|
||||
country: event.target.country.value,
|
||||
|
||||
}
|
||||
const JSONdata = JSON.stringify(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}`)
|
||||
}
|
||||
return (
|
||||
<form onSubmit={handleSubmit}>
|
||||
<label >School Name</label>
|
||||
<input type="text" name="schoolName" required />
|
||||
|
||||
<label htmlFor="last">Country</label>
|
||||
<input type="text" id="last" name="country" required />
|
||||
|
||||
<button type="submit">Submit</button>
|
||||
</form>
|
||||
)
|
||||
}
|
||||
|
||||
40
src/pages/test/file-upload.jsx
Normal file
40
src/pages/test/file-upload.jsx
Normal file
@@ -0,0 +1,40 @@
|
||||
import { useState } from "react";
|
||||
export default function PrivatePage(props) {
|
||||
const [image, setImage] = useState(null);
|
||||
const [createObjectURL, setCreateObjectURL] = useState(null);
|
||||
|
||||
const uploadToClient = (event) => {
|
||||
if (event.target.files && event.target.files[0]) {
|
||||
const i = event.target.files[0];
|
||||
|
||||
setImage(i);
|
||||
setCreateObjectURL(URL.createObjectURL(i));
|
||||
}
|
||||
};
|
||||
|
||||
const uploadToServer = async (event) => {
|
||||
const body = new FormData();
|
||||
body.append("file", image);
|
||||
const response = await fetch("/api/fileUpload", {
|
||||
method: "POST",
|
||||
body
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div>
|
||||
<img src={createObjectURL} />
|
||||
<h4>Select Image</h4>
|
||||
<input type="file" name="myImage" onChange={uploadToClient} />
|
||||
<button
|
||||
className="btn btn-primary"
|
||||
type="submit"
|
||||
onClick={uploadToServer}
|
||||
>
|
||||
Send to server
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
38
src/pages/upload-user.jsx
Normal file
38
src/pages/upload-user.jsx
Normal file
@@ -0,0 +1,38 @@
|
||||
import {useId, useState, useEffect, useMemo} from 'react';
|
||||
import NavBar from '../components/NavBar';
|
||||
import { useRouter } from 'next/router'
|
||||
|
||||
|
||||
export default function EditSchool() {
|
||||
const router = useRouter();
|
||||
|
||||
const uploadCsv = async (event) => {
|
||||
// alert('p')
|
||||
const body = new FormData();
|
||||
body.append("file", csv.files[0]);
|
||||
// console.log('body')
|
||||
// body.append("fName", `${router.query.school}.pdf`);
|
||||
const response = await fetch("/api/addUsersBulk", {
|
||||
method: "POST",
|
||||
body
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
|
||||
return (
|
||||
<main>
|
||||
<div>
|
||||
<NavBar/>
|
||||
<section className='container mx-auto px-4 my-16 lg:px-28 xl:px-56 2xl:px-96'>
|
||||
<div className="place-items-center justify-center m-2 p-2 bg-[#FE4501] text-white font-bold rounded-full whitespace-nowrap">
|
||||
<span className="text-small">CSV </span>
|
||||
<input type="file" id="csv" onChange={uploadCsv} name="csv" />
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
</main>
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
90
src/pages/user-list-by-school.jsx
Normal file
90
src/pages/user-list-by-school.jsx
Normal file
@@ -0,0 +1,90 @@
|
||||
import React, { useEffect, useState } from "react";
|
||||
import Link from 'next/link'
|
||||
|
||||
|
||||
import NavBar from '../components/NavBar'
|
||||
export default function Modal() {
|
||||
const [user, setUser] = useState([]);
|
||||
const fetchData = async () => {
|
||||
const response = await fetch("/api/listUsers");
|
||||
const data = await response.json();
|
||||
// console.log(data)
|
||||
return setUser(data);
|
||||
}
|
||||
// console.log(user)
|
||||
|
||||
useEffect(() => {
|
||||
fetchData();
|
||||
},[])
|
||||
|
||||
return (
|
||||
<main>
|
||||
<div>
|
||||
<NavBar />
|
||||
<section className='container mx-auto px-4 mt-16'>
|
||||
<div className="flex flex-row justify-end bg-[#FFF6F2] p-2 gap-x-4 border-x-2 border-t-2 rounded-t-xl">
|
||||
<div className="flex flex-row justify-center place-items-center">
|
||||
<input type="text" className="md:w-32 md:focus:w-96 duration-[1s] border-2 border-[#FE4501] w-full rounded-l-full p-2 focus:outline-none focus:border-[#F2B705] bg-[#FFF6F2] focus:bg-white text-center" placeholder="Search User" />
|
||||
<Link href="" className="bg-[#FE4501] rounded-r-full p-2 px-4 border-2 border-[#FE4501] text-white font-bold ">
|
||||
<svg className="hover:scale-110 active:scale-75 duration-300" width="24px" height="24px" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg" fill="none" stroke="#ffffff"><g id="SVGRepo_bgCarrier" stroke-width="0"></g><g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round"></g><g id="SVGRepo_iconCarrier"> <path fill="#ffffff" fill-rule="evenodd" d="M4 9a5 5 0 1110 0A5 5 0 014 9zm5-7a7 7 0 104.2 12.6.999.999 0 00.093.107l3 3a1 1 0 001.414-1.414l-3-3a.999.999 0 00-.107-.093A7 7 0 009 2z"></path> </g></svg>
|
||||
</Link>
|
||||
</div>
|
||||
<Link href="/add-user-form" className="inline-flex place-items-center p-2 bg-[#FE4501] text-white font-bold rounded-full whitespace-nowrap">
|
||||
<svg className="font-bold" width="25px" height="25px" viewBox="0 0 21 21" xmlns="http://www.w3.org/2000/svg" fill="#ffffff" stroke="#ffffff"><g id="SVGRepo_bgCarrier" stroke-width="2"></g><g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round"></g><g id="SVGRepo_iconCarrier"> <g fill="none" fill-rule="evenodd" stroke="#ffffff" stroke-linecap="round" stroke-linejoin="round" transform="translate(3 2)"> <path d="m7.5.5c1.65685425 0 3 1.34314575 3 3v2c0 1.65685425-1.34314575 3-3 3s-3-1.34314575-3-3v-2c0-1.65685425 1.34314575-3 3-3z"></path> <path d="m14.5 2.5v4"></path> <path d="m16.5 4.5h-4"></path> <path d="m14.5 14.5v-.7281753c0-3.1864098-3.6862915-5.2718247-7-5.2718247s-7 2.0854149-7 5.2718247v.7281753c0 .5522847.44771525 1 1 1h12c.5522847 0 1-.4477153 1-1z"></path> </g> </g></svg>
|
||||
Add User
|
||||
</Link>
|
||||
</div>
|
||||
<div className='flex overflow-x-scroll xl:justify-center'>
|
||||
<table className=" text-center border-2 p-2 w-full">
|
||||
<thead className=''>
|
||||
<tr className='bg-[#FFF6F2] text-[#1D1D1D] text-xl whitespace-nowrap'>
|
||||
<th className="border-x-2 p-4">Name</th>
|
||||
<th className="border-x-2 p-4">Mobile</th>
|
||||
<th className="border-x-2 p-4">Email</th>
|
||||
<th className="border-x-2 p-4">School Name</th>
|
||||
<th className="border-x-2 p-4">User Type</th>
|
||||
<th className="border-x-2 p-4">Start Date</th>
|
||||
<th className="border-x-2 p-4">End Date</th>
|
||||
<th className="border-x-2 p-4">Action</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{user.map
|
||||
(data=>
|
||||
<tr key={data.id} className="border-b-2 whitespace-normal text-left">
|
||||
<td className="border-x-2 p-2 text-center">{data.uname}</td>
|
||||
<td className="border-x-2 p-2 text-center">{data.phone}</td>
|
||||
<td className="border-x-2 p-2 text-center">{data.email}</td>
|
||||
<td className="border-x-2 p-2 text-center">{data.school}</td>
|
||||
<td className="border-x-2 p-2 text-center">{data.type}</td>
|
||||
<td className="border-x-2 p-2 text-center">{data.start_date}</td>
|
||||
<td className="border-x-2 p-2 text-center">{data.end_date}</td>
|
||||
<td>
|
||||
<div className="flex flex-row justify-center place-items-center">
|
||||
<div className="flex justify-center">
|
||||
<a href={'/edit-user/?user='+data.id} className="px-2 py-1 rounded-md">
|
||||
<svg width="35px" height="35px" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" stroke="#166435"><g id="SVGRepo_bgCarrier" stroke-width="0"></g><g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round"></g><g id="SVGRepo_iconCarrier"> <path opacity="0.15" d="M8 16H12L18 10L14 6L8 12V16Z" fill="#166435"></path> <path d="M14 6L8 12V16H12L18 10M14 6L17 3L21 7L18 10M14 6L18 10M10 4L4 4L4 20L20 20V14" stroke="#166435" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"></path> </g></svg>
|
||||
{/* <p className="text-[16px] text-green-800">Edit</p> */}
|
||||
</a>
|
||||
</div>
|
||||
<div className="flex justify-center">
|
||||
<button className=" text-white px-2 py-1 rounded-md">
|
||||
<svg width="35px" height="35px" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" stroke="#991b1b"><g id="SVGRepo_bgCarrier" stroke-width="0"></g><g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round"></g><g id="SVGRepo_iconCarrier"> <path d="M10 12V17" stroke="#991b1b" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path> <path d="M14 12V17" stroke="#991b1b" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path> <path d="M4 7H20" stroke="#991b1b" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path> <path d="M6 10V18C6 19.6569 7.34315 21 9 21H15C16.6569 21 18 19.6569 18 18V10" stroke="#991b1b" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path> <path d="M9 5C9 3.89543 9.89543 3 11 3H13C14.1046 3 15 3.89543 15 5V7H9V5Z" stroke="#991b1b" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path> </g></svg>
|
||||
{/* <p className="text-[16px] text-red-800">Delete</p> */}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
)
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
</div>
|
||||
</main>
|
||||
)
|
||||
|
||||
}
|
||||
118
src/pages/user-list.jsx
Normal file
118
src/pages/user-list.jsx
Normal file
@@ -0,0 +1,118 @@
|
||||
import { signIn, signOut, useSession } from 'next-auth/react'
|
||||
import React, { useEffect, useState } from "react";
|
||||
import { useRouter } from 'next/router'
|
||||
|
||||
import Link from 'next/link'
|
||||
import NavBar from '../components/NavBar'
|
||||
export default function UserList() {
|
||||
const router = useRouter();
|
||||
const { data: session } = useSession()
|
||||
const [user, setUser] = useState([]);
|
||||
const [maxPageNumber, setMaxPageNumber] = useState([]);
|
||||
const fetchData = async (page) => {
|
||||
const response = await fetch("/api/listUsers?page="+page+"&limit=10");
|
||||
const data = await response.json();
|
||||
setMaxPageNumber(data.maxPageNumber);
|
||||
return setUser(data.data);
|
||||
};
|
||||
|
||||
|
||||
// console.log(user)
|
||||
useEffect(()=>{ if(!router.isReady) return; fetchData(4); }, [router.isReady]);
|
||||
|
||||
// useEffect(() => {
|
||||
// fetchData();
|
||||
// },[])
|
||||
if(session) {
|
||||
return (
|
||||
<main>
|
||||
<div>
|
||||
<NavBar />
|
||||
<section className='container mx-auto px-4 mt-16'>
|
||||
<div className="flex flex-row justify-end bg-[#FFF6F2] p-2 gap-x-4 border-x-2 border-t-2 rounded-t-xl">
|
||||
<nav aria-label="Page navigation example">
|
||||
<ul className="inline-flex items-center -space-x-px">
|
||||
{/* <li>
|
||||
<a href="#" className="block px-3 py-2 ml-0 leading-tight text-gray-500 bg-white border border-gray-300 rounded-l-lg hover:bg-gray-100 hover:text-gray-700 ">
|
||||
<span className="sr-only">Previous</span>
|
||||
<
|
||||
</a>
|
||||
</li> */}
|
||||
{maxPageNumber.map((number) => (
|
||||
<button key={number} onClick={() => fetchData(number)} className="px-3 py-2 leading-tight text-gray-500 bg-white border border-gray-300 hover:bg-gray-100 hover:text-gray-700 ">{number} </button>
|
||||
))}
|
||||
|
||||
{/* <li>
|
||||
<a href="?page=6" className="block px-3 py-2 leading-tight text-gray-500 bg-white border border-gray-300 rounded-r-lg hover:bg-gray-100 hover:text-gray-700 ">
|
||||
<span className="sr-only">Next</span>
|
||||
>
|
||||
</a>
|
||||
</li> */}
|
||||
</ul>
|
||||
</nav>
|
||||
<div className="flex flex-row justify-center place-items-center">
|
||||
<input type="text" className="md:w-32 md:focus:w-96 duration-[1s] border-2 border-[#FE4501] w-full rounded-l-full p-2 focus:outline-none focus:border-[#F2B705] bg-[#FFF6F2] focus:bg-white text-center" placeholder="Search User" />
|
||||
<a href="" className="bg-[#FE4501] rounded-r-full p-2 px-4 border-2 border-[#FE4501] text-white font-bold ">
|
||||
🔍
|
||||
</a>
|
||||
</div>
|
||||
<Link href="/add-user-form" className="inline-flex place-items-center p-2 bg-[#FE4501] text-white font-bold rounded-full whitespace-nowrap">
|
||||
⛨
|
||||
Add User
|
||||
</Link>
|
||||
</div>
|
||||
<div className='flex overflow-x-scroll xl:justify-center'>
|
||||
<table className=" text-center border-2 p-2 w-full">
|
||||
<thead className=''>
|
||||
<tr className='bg-[#FFF6F2] text-[#1D1D1D] text-xl whitespace-nowrap'>
|
||||
<th className="border-x-2 p-4">ID</th>
|
||||
<th className="border-x-2 p-4">School Name</th>
|
||||
<th className="border-x-2 p-4">Mobile</th>
|
||||
<th className="border-x-2 p-4">Email</th>
|
||||
<th className="border-x-2 p-4">School ID</th>
|
||||
<th className="border-x-2 p-4">User Type</th>
|
||||
<th className="border-x-2 p-4">End Date</th>
|
||||
<th className="border-x-2 p-4">Action</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{user.map
|
||||
(data=>
|
||||
<tr key={data.id} className="border-b-2 whitespace-normal text-left">
|
||||
<td className="border-x-2 p-2 text-center">{data.id}</td>
|
||||
<td className="border-x-2 p-2 text-center">{data.uname}</td>
|
||||
<td className="border-x-2 p-2 text-center">{data.phone}</td>
|
||||
<td className="border-x-2 p-2 text-center">{data.email}</td>
|
||||
<td className="border-x-2 p-2 text-center">{data.school}</td>
|
||||
<td className="border-x-2 p-2 text-center">{data.type}</td>
|
||||
<td className="border-x-2 p-2 text-center">{data.end_date}</td>
|
||||
<td>
|
||||
<div className="flex flex-row justify-center place-items-center">
|
||||
<div className="flex justify-center">
|
||||
<a href={'/edit-user/?user='+data.id} className="px-2 py-1 rounded-md">
|
||||
✎
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
)
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
</div>
|
||||
</main>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
Not signed in <br />
|
||||
<button onClick={() => signIn()}>Sign in</button>
|
||||
</>
|
||||
)
|
||||
|
||||
}
|
||||
@@ -1,69 +0,0 @@
|
||||
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 [user, setUser] = useState([]);
|
||||
const fetchData = async () => {
|
||||
const response = await fetch("https://management.beanstalkedu.com/items/enrolled_user?filter[status][_eq]=published");
|
||||
const data = await response.json();
|
||||
return setUser(data.data);
|
||||
}
|
||||
// console.log(user)
|
||||
|
||||
useEffect(() => {
|
||||
fetchData();
|
||||
},[])
|
||||
|
||||
return (
|
||||
<main>
|
||||
<div>
|
||||
<NavBar />
|
||||
<section className='container mx-auto px-4 mt-16'>
|
||||
<div className="flex justify-end bg-[#FFF6F2] p-2 border-x-2 border-t-2 rounded-t-xl">
|
||||
<a href="/add-user-form" className=" inline-flex place-items-center p-2">
|
||||
<svg width="20px" height="20px" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><g id="SVGRepo_bgCarrier" stroke-width="0"></g><g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round"></g><g id="SVGRepo_iconCarrier"> <path fill-rule="evenodd" clip-rule="evenodd" d="M21.1213 2.70705C19.9497 1.53548 18.0503 1.53547 16.8787 2.70705L15.1989 4.38685L7.29289 12.2928C7.16473 12.421 7.07382 12.5816 7.02986 12.7574L6.02986 16.7574C5.94466 17.0982 6.04451 17.4587 6.29289 17.707C6.54127 17.9554 6.90176 18.0553 7.24254 17.9701L11.2425 16.9701C11.4184 16.9261 11.5789 16.8352 11.7071 16.707L19.5556 8.85857L21.2929 7.12126C22.4645 5.94969 22.4645 4.05019 21.2929 2.87862L21.1213 2.70705ZM18.2929 4.12126C18.6834 3.73074 19.3166 3.73074 19.7071 4.12126L19.8787 4.29283C20.2692 4.68336 20.2692 5.31653 19.8787 5.70705L18.8622 6.72357L17.3068 5.10738L18.2929 4.12126ZM15.8923 6.52185L17.4477 8.13804L10.4888 15.097L8.37437 15.6256L8.90296 13.5112L15.8923 6.52185ZM4 7.99994C4 7.44766 4.44772 6.99994 5 6.99994H10C10.5523 6.99994 11 6.55223 11 5.99994C11 5.44766 10.5523 4.99994 10 4.99994H5C3.34315 4.99994 2 6.34309 2 7.99994V18.9999C2 20.6568 3.34315 21.9999 5 21.9999H16C17.6569 21.9999 19 20.6568 19 18.9999V13.9999C19 13.4477 18.5523 12.9999 18 12.9999C17.4477 12.9999 17 13.4477 17 13.9999V18.9999C17 19.5522 16.5523 19.9999 16 19.9999H5C4.44772 19.9999 4 19.5522 4 18.9999V7.99994Z" fill="#1d1d1d"></path> </g></svg>
|
||||
Add User
|
||||
</a>
|
||||
</div>
|
||||
<div className='flex overflow-x-scroll xl:justify-center'>
|
||||
<table className=" text-center border-2 p-2 w-full">
|
||||
<thead className=''>
|
||||
<tr className='bg-[#FFF6F2] text-[#1D1D1D] text-xl whitespace-nowrap'>
|
||||
<th className="border-x-2 p-4">user Name</th>
|
||||
<th className="border-x-2 p-4">School Name</th>
|
||||
<th className="border-x-2 p-4">User Type</th>
|
||||
<th className="border-x-2 p-4">Plan</th>
|
||||
<th className="border-x-2 p-4">Class</th>
|
||||
<th className="border-x-2 p-4">Language</th>
|
||||
{/* <th className="border-x-2 p-4">Year</th> */}
|
||||
<th className="border-x-2 p-4">Start Date</th>
|
||||
<th className="border-x-2 p-4">End Date</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{user.map(data=>
|
||||
<tr className="border-b-2 whitespace-normal text-left">
|
||||
<td className="border-x-2 p-2">{data.user}</td>
|
||||
<td className="border-x-2 p-2">{data.school}</td>
|
||||
<td className="border-x-2 p-2 text-center">{data.type}</td>
|
||||
<td className="border-x-2 p-2 text-center">{data.plan}</td>
|
||||
<td className="border-x-2 p-2 text-center">{data.class}</td>
|
||||
<td className="border-x-2 p-2 text-center">{data.lang}</td>
|
||||
{/* <td className="border-x-2 p-2">{data.year}</td> */}
|
||||
<td className="border-x-2 p-2 text-center">{data.start_date}</td>
|
||||
<td className="border-x-2 p-2 text-center">{data.end_date}</td>
|
||||
</tr>
|
||||
)}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
</div>
|
||||
</main>
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
0
src/styles/Checkbox.css
Normal file
0
src/styles/Checkbox.css
Normal file
@@ -15,7 +15,21 @@
|
||||
--background-end-rgb: 0, 0, 0;
|
||||
}
|
||||
}
|
||||
|
||||
.check-box {
|
||||
border:2px solid white;
|
||||
box-shadow:0 0 0 2px #FE4501;
|
||||
appearance:none;
|
||||
width:15px;
|
||||
height:15px;
|
||||
background-color:#fff;
|
||||
transition:all ease-in .2s;
|
||||
cursor: pointer;
|
||||
}
|
||||
.check-box:checked{
|
||||
background-color:#FE4501;
|
||||
transform: scale(1.2);
|
||||
border-radius: 2px;
|
||||
}
|
||||
/* body {
|
||||
color: rgb(var(--foreground-rgb));
|
||||
background: linear-gradient(
|
||||
|
||||
@@ -18,6 +18,6 @@
|
||||
"@/*": ["./src/*"]
|
||||
}
|
||||
},
|
||||
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
|
||||
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", "src/pages/add-school-form.jsx", "src/pages/add-school-form.jsx", "src/pages/add-user-form.jsx", "src/pages/test/file-upload.jsx", "src/pages/user-list.jsx"],
|
||||
"exclude": ["node_modules"]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user