diff --git a/src/pages/edit-school.jsx b/src/pages/edit-school.jsx new file mode 100644 index 0000000..dd454b6 --- /dev/null +++ b/src/pages/edit-school.jsx @@ -0,0 +1,227 @@ +import NavBar from '../components/NavBar' +import { useId, useState, useEffect, useMemo } from 'react'; +import Select from 'react-select' +import countryList from 'react-select-country-list' +import 'react-phone-number-input/style.css' +import PhoneInput from 'react-phone-number-input' +import { useRouter } from 'next/router' + + +export default function addSchoolForm() { + const [countryValue, setCountryValue] = useState('') + const options = useMemo(() => countryList().getData(), []) + const [phoneValue, setphoneValue] = useState() + const [allStates, setAllStates] = useState([]) + const [allCities, setAllCities] = useState([]) + + const handleSelectAllStates = stateCode => { + setAllCities([]) + fetch(`https://api.siliconpin.com/v3/list/country/city/?country=${countryValue.value}&state=${stateCode.value}`) + .then(res => res.json()) + .then(data => { + console.log("handleSelectAllStates:", data, options) + let newData = data && data.length > 0 && data.map(n => { + return { + label: n.name, + value: n.name + } + }) + setAllCities(newData) + }) + } + const selectCountry = countryValue => { + setAllStates([]) + fetch(`https://api.siliconpin.com/v3/list/country/state/?country=${countryValue.value}`) + .then(res => res.json()) + .then(data => { + console.log("countryValue:", data, options) + let newData = data && data.length > 0 && data.map(n => { + return { + label: n.name, + value: n.iso2 + } + }) + setAllStates(newData) + setAllCities([]) + }) + setCountryValue(countryValue) + } + const router = useRouter() + console.log(router.query.school) + // console.log(phoneValue) + // const selectCountry = countryValue => { + // setCountryValue(countryValue) + // } + const handleSubmit = async (event) => { + event.preventDefault() + const data = { + "status":"published", + name: event.target.schoolName.value, + country: event.target.country.value, + state: event.target.state.value, + cities: event.target.cities.value, + anual: event.target.anual.value, + toddlers: event.target.toddlers.value, + early_start_programme: event.target.early_start_programme.value, + interakto: event.target.interakto.value, + agreement_expiry_date: event.target.agreement_expiry_date.value, + school_agreement: event.target.school_agreement.value, + school_contact_number: event.target.school_contact_number.value, + school_email_id: event.target.school_email_id.value, + + } + const JSONdata = JSON.stringify(data) + console.log(data) + const endpoint = 'https://management.beanstalkedu.com/items/school' + const options = { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSONdata, + } + const response = await fetch(endpoint, options) + + const result = await response.json() + // alert(`Is this your full name: ${result.data}`) + alert(`School Saved`) + } + + return ( +
+
+ +
+
+
+ +

School Registration Form

+
+
+
+ + +
+
+ + +
+
+ + +
} + { + allCities && allCities.length > 0 && +
+ + + + + + + + + + + + + + + + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+ {/*
+ + +
*/} +
+ {/* */} + +
+
+
+
+
+
+ ) + } \ No newline at end of file diff --git a/src/pages/school-list/index.jsx b/src/pages/school-list/index.jsx index 1d22ede..be8d64f 100644 --- a/src/pages/school-list/index.jsx +++ b/src/pages/school-list/index.jsx @@ -52,7 +52,7 @@ const fetchData = async () => { {data.toddlers} {data.interakto} {data.status} - Edit + Edit )}