diff --git a/src/App.js b/src/App.js index 83088b2..cb06d2f 100644 --- a/src/App.js +++ b/src/App.js @@ -2,6 +2,7 @@ import React, { Component } from 'react' import { HashRouter, Route, Switch } from 'react-router-dom' import './scss/style.scss' import ForgotPassword from './views/pages/register/ForgotPassword' +import NewRegister from './views/pages/register/NewRegister' const loading = (
@@ -26,6 +27,7 @@ class App extends Component { } /> } /> + } /> {/* , - }, - { - component: CNavItem, - name: 'Courier', - to: '/courier', - icon: , - }, - { - component: CNavItem, - name: 'Airway Bills', - to: '/airwaysbill', - icon: , - }, - // { // component: CNavItem, - // name: 'Change Password', - // icon: , - // to: '/register', + // name: 'Vendors', + // to: '/vendors', + // icon: , // }, + // { + // component: CNavItem, + // name: 'Courier', + // to: '/courier', + // icon: , + // }, + // { + // component: CNavItem, + // name: 'Airway Bills', + // to: '/airwaysbill', + // icon: , + // }, + + { + component: CNavItem, + name: 'Profile', + icon: , + to: '/profile', + }, // { // component: CNavGroup, - // name: 'Pages', - // icon: , + // name: 'Profile', + // icon: , // items: [ // { // component: CNavItem, - // name: 'Error 404', - // to: '/404', + // name: 'Display', + // to: '/profile', // }, // { // component: CNavItem, - // name: 'Error 500', - // to: '/500', + // name: 'Edit', + // to: '/edit', // }, // ], // }, diff --git a/src/index.js b/src/index.js index 8fc244c..b977723 100644 --- a/src/index.js +++ b/src/index.js @@ -9,7 +9,7 @@ import store from './store' import axios from 'axios' const setupAxios = () => { - axios.defaults.baseURL = "https://api-courier-vendor.herokuapp.com/" + axios.defaults.baseURL = 'https://dating-api-server.herokuapp.com'; axios.defaults.headers = { 'Cache-Control': 'no-cache,no-store', 'Pragma': 'no-cache', diff --git a/src/routes.js b/src/routes.js index b7ec420..eadac6b 100644 --- a/src/routes.js +++ b/src/routes.js @@ -8,6 +8,8 @@ const Courier = React.lazy(() => import('./views/Courier/Courier')) const EditCourier = React.lazy(() => import('./views/Courier/EditCourier')) const AddCourier = React.lazy(() => import('./views/Courier/AddCourier')) const Register = React.lazy(() => import('./views/pages/register/Register')) +const Profile = React.lazy(() => import('./views/Profile/Profile')) +const EditProfile = React.lazy(() => import('./views/Profile/EditProfile')) const Vendor = React.lazy(() => import('./views/Vendor/Vendor')) const VendorDetail = React.lazy(() => import('./views/Vendor/VendorDetail')) const EditVendor = React.lazy(() => import('./views/Vendor/EditVendor')) @@ -66,6 +68,8 @@ const Widgets = React.lazy(() => import('./views/widgets/Widgets')) const routes = [ { path: '/', exact: true, name: 'Home' }, { path: '/register', name: 'Change Password', component: Register }, + { path: '/edit', name: 'Change Password', component: EditProfile }, + { path: '/profile', name: 'Change Password', component: Profile }, { path: '/courier', name: 'Courier', component: Courier }, { path: '/editcourier/:id', name: ' Edit Courier', component: EditCourier }, { path: '/addcourier', name: 'Courier / Add Courier', component: AddCourier }, diff --git a/src/views/Courier/Courier.js b/src/views/Courier/Courier.js index a857af2..8eb977e 100644 --- a/src/views/Courier/Courier.js +++ b/src/views/Courier/Courier.js @@ -92,6 +92,7 @@ const Courier = () => { {item.name} {item._id} + {/* {item.code} */} {formatDate(item.createdAt)} diff --git a/src/views/Profile/EditProfile.js b/src/views/Profile/EditProfile.js new file mode 100644 index 0000000..dcac3cb --- /dev/null +++ b/src/views/Profile/EditProfile.js @@ -0,0 +1,127 @@ +import React from 'react' +import { CForm, CCol, CFormLabel, CContainer, CRow, CCardGroup, CCard, CCardBody, CFormInput, CFormSelect, CFormCheck, CButton } from '@coreui/react' +import { Country, City } from 'country-state-city' +import { useState, useEffect } from 'react' +import axios from 'axios' +import { useHistory } from 'react-router-dom' +import { isAutheticated } from 'src/auth' +const EditProfile = () => { + const [cities, setCities] = useState([]) + const { token } = isAutheticated() + const [ownerDetails, setOwnerDetails] = useState({ + cafeName: '', + email: '', + location: '', + country: 'India', + city: '' + }) + const history = useHistory() + const [processing, setProcessing] = useState(false) + const countries = Country.getAllCountries() + useEffect(() => { + const countryCode = countries.find(item => item.name === ownerDetails.country) + setCities(() => City.getCitiesOfCountry(countryCode?.isoCode)) + getData() + + }, [ownerDetails.country]) + + const getData = async () => { + let res = await axios.get('/owner', { + headers: { + 'Authorization': `Bearer ${token}` + } + }) + if (res) { + setOwnerDetails({ ...res.data.user }) + } + } + console.log(ownerDetails); + const handleChange = (event) => { + const { name, value } = event.target; + setOwnerDetails({ ...ownerDetails, [name]: value }); + }; + + + async function handleSubmit() { + + let res = await axios.put(`/owner`, ownerDetails, { + headers: { + 'Content-Type': 'application/json', + 'Authorization': `Bearer ${token}`, + } + }) + setProcessing(true) + console.log(res.data); + + if (res) { + // localStorage.setItem("auth", JSON.stringify({ + + // token: res.data.token, + // })); + history.push('/profile') + } + } + + return ( +
+ + + + + + + + +

Edit Profile

+ + + Cafe Name + + + + + Email + + + {/* + Password + + */} + + + + Location + + + + Country + + + {countries.map(item => )} + + + + + City + + + {cities.map(item => )} + + + + + + Submit + + +
+
+
+
+
+
+
+ ) +} + +export default EditProfile \ No newline at end of file diff --git a/src/views/Profile/Profile.js b/src/views/Profile/Profile.js new file mode 100644 index 0000000..581fa6b --- /dev/null +++ b/src/views/Profile/Profile.js @@ -0,0 +1,77 @@ +import React, { useEffect } from 'react' +import { + CButton, + CCol, + CRow, + CTable, + CTableBody, + CTableDataCell, + CTableHead, + CTableHeaderCell, + CTableRow, +} from '@coreui/react' +import { useState } from 'react' +import axios from 'axios'; +import { isAutheticated } from 'src/auth'; +import { useHistory } from 'react-router-dom'; + +const Profile = () => { + // const user = JSON.parse(localStorage.getItem('auth')).user + const [user, setUser] = useState({}); + const { token } = isAutheticated(); + const history = useHistory() + console.log(token); + useEffect(async () => { + let res = await axios.get('/owner', { + headers: { + 'Authorization': `Bearer ${token}` + } + }) + if (res) { + setUser(res.data.user) + } + console.log(res); + }, []) + + + console.log(user); + return ( +
+ + +

Profile

+
+ + history.push('/edit')}>Edit Profile + +
+ + + + Cafe Name + {user.cafeName} + + + + + Email + {user.email} + + + + Address + {user.location},{user.city},{user.country} + + + + Item_Name + + + + + +
+ ) +} + +export default Profile \ No newline at end of file diff --git a/src/views/Vendor/AddVendor.js b/src/views/Vendor/AddVendor.js index 0c9f481..7575154 100644 --- a/src/views/Vendor/AddVendor.js +++ b/src/views/Vendor/AddVendor.js @@ -61,7 +61,7 @@ const AddVendor = () => { const scode = allStates.find(item => item.name === vendor.state) console.log(ccode.isoCode + ":" + scode.isoCode); console.log(vendor.country, vendor.state); - setCountryCode(ccode.isoCode) + setCountryCode(ccode?.isoCode) setStateCode(scode.isoCode) setStates(prev => State.getStatesOfCountry(countryCode)) setCities(prev => City.getCitiesOfState(countryCode, stateCode)) diff --git a/src/views/pages/login/Login.js b/src/views/pages/login/Login.js index 8c208c1..f6db129 100644 --- a/src/views/pages/login/Login.js +++ b/src/views/pages/login/Login.js @@ -31,11 +31,12 @@ const Login = () => { }; const Login = async () => { - const res = await axios.post("/admin-signin", auth); + const res = await axios.post("/owner/signin", auth); if (res.data.status == "ok") { localStorage.setItem("auth", JSON.stringify({ - // user: res.data.user, + user: res.data.user, token: res.data.token, + })); history.push('/dashboard') @@ -98,6 +99,11 @@ const Login = () => { + + + dont have an account? Sign Up + + diff --git a/src/views/pages/register/NewRegister.js b/src/views/pages/register/NewRegister.js new file mode 100644 index 0000000..c1c28b1 --- /dev/null +++ b/src/views/pages/register/NewRegister.js @@ -0,0 +1,123 @@ +import React from 'react' +import { CForm, CCol, CFormLabel, CContainer, CRow, CCardGroup, CCard, CCardBody, CFormInput, CFormSelect, CFormCheck, CButton } from '@coreui/react' +import { Country, City } from 'country-state-city' +import { useState, useEffect } from 'react' +import axios from 'axios' +import { useHistory } from 'react-router-dom' +const NewRegister = () => { + const [cities, setCities] = useState([]) + const [ownerDetails, setOwnerDetails] = useState({ + cafeName: '', + email: '', + password: '', + location: '', + country: 'India', + city: '' + }) + const history = useHistory() + const [processing, setProcessing] = useState(false) + const countries = Country.getAllCountries() + useEffect(() => { + // console.log(countries); + const countryCode = countries.find(item => item.name === ownerDetails.country) + // console.log(countryCode); + setCities(() => City.getCitiesOfCountry(countryCode?.isoCode)) + // console.log(cities); + }, [ownerDetails.country]) + + + const handleChange = (event) => { + const { name, value } = event.target; + setOwnerDetails({ ...ownerDetails, [name]: value }); + }; + + + async function handleSubmit() { + + let res = await axios.post(`/owner/signup`, ownerDetails, { + headers: { + 'Content-Type': 'application/json', + // 'Authorization': `Bearer ${token}`, + } + }) + setProcessing(true) + console.log(res.data); + + if (res) { + // localStorage.setItem("auth", JSON.stringify({ + + // token: res.data.token, + // })); + history.push('/') + } + } + + return ( +
+ + + + + + + + +

Sign Up!!!

+ + + Cafe Name + + + + + Email + + + + Password + + + + + + Location + + + + Country + + + {countries.map(item => )} + + + + + City + + + {cities.map(item => )} + + + + {/* + Zip + + */} + {/* + + */} + + Sign Up + + +
+
+
+
+
+
+
+ ) +} + +export default NewRegister \ No newline at end of file diff --git a/src/views/pages/register/Register.js b/src/views/pages/register/Register.js index e6b3bfe..104c5c1 100644 --- a/src/views/pages/register/Register.js +++ b/src/views/pages/register/Register.js @@ -1,4 +1,4 @@ -import React from 'react' +import React, { useState } from 'react' import { CButton, CCard, @@ -13,8 +13,48 @@ import { } from '@coreui/react' import CIcon from '@coreui/icons-react' import { cilLockLocked, cilUser } from '@coreui/icons' +import axios from 'axios' +import { isAutheticated } from 'src/auth' +import Swal from 'sweetalert2' +import { useHistory } from 'react-router-dom' const Register = () => { + const { token } = isAutheticated() + const [password, setPassword] = useState({ + oldPassword: "", + newPassword: "", + cpassword: '' + }); + const history = useHistory(); + const handleChange = (e) => (event) => { + setPassword({ ...password, [e]: event.target.value }); + }; + const handleSubmit = async () => { + if (password.cpassword !== password.newPassword) { + let res = await axios.put('/owner/changePassword', password, { + headers: { + Authorization: `Bearer ${token}` + } + }) + if (res.statusText === 'OK') { + Swal.fire({ + title: 'Done', + text: 'Password Changed', + icon: 'success', + confirmButtonText: 'ok', + confirmButtonColor: '#303c54', + iconColor: '#303c54' + }).then(() => { + history.push('/profile') + }); + } + + } else { + alert('new password and confirm password are not matched') + } + + } + return (
@@ -35,7 +75,7 @@ const Register = () => { - + @@ -45,6 +85,7 @@ const Register = () => { type="password" placeholder="Password" autoComplete="new-password" + onChange={handleChange('newPassword')} /> @@ -55,10 +96,11 @@ const Register = () => { type="password" placeholder="Confirm password" autoComplete="new-password" + onChange={handleChange('cPassword')} />
- Submit + handleSubmit()}>Submit