diff --git a/src/components/header/AppHeaderDropdown.js b/src/components/header/AppHeaderDropdown.js index 5f09b4e..210cad6 100644 --- a/src/components/header/AppHeaderDropdown.js +++ b/src/components/header/AppHeaderDropdown.js @@ -129,6 +129,12 @@ const AppHeaderDropdown = () => { */} {/* */} + + + + Edit Profile + + diff --git a/src/routes.js b/src/routes.js index b877721..3ad3ac6 100644 --- a/src/routes.js +++ b/src/routes.js @@ -54,6 +54,7 @@ import EditFaqs from './views/FAQs/EditFaqs' // DashBoard const Change_Password = React.lazy(() => import('./views/pages/register/Change_password')) const EditProfile = React.lazy(() => import('./views/Profile/EditProfile')) +import Profile from './views/Profile/Profile' const Dashboard = React.lazy(() => import('./views/dashboard/Dashboard')) @@ -61,8 +62,8 @@ const routes = [ { path: '/', exact: true, name: 'Home' }, { path: '/change_password', name: 'Change Password', component: Change_Password }, - { path: '/edit', name: 'Change Password', component: EditProfile }, - // { path: '/profile', name: 'Change Password', component: Profile }, + { path: '/profile/edit', name: 'Edit Profile', component: EditProfile }, + // { path: '/profile', name: 'Profile', component: Profile }, //Category route { path: '/addCategory', name: 'AddCategeory', component: AddCategeory }, diff --git a/src/views/Profile/EditProfile.js b/src/views/Profile/EditProfile.js index dcac3cb..520c35d 100644 --- a/src/views/Profile/EditProfile.js +++ b/src/views/Profile/EditProfile.js @@ -6,60 +6,118 @@ 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 [image, setImage] = useState(""); + const [loading, setLoading] = useState(false) + const [imagesPreview, setImagesPreview] = useState(); + const token = isAutheticated() + const [ownerDetails, setOwnerDetails] = useState({ - cafeName: '', + name: '', email: '', - location: '', - country: 'India', - city: '' + phone: '' + }) 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', { + let res = await axios.get(`/api/v1/user/details`, { headers: { - 'Authorization': `Bearer ${token}` - } + Authorization: `Bearer ${token}`, + }, }) - if (res) { + if (res.data.success) { + setOwnerDetails({ ...res.data.user }) + if (res.data.user.avatar) { + setImagesPreview(res.data.user.avatar.url) + } } + + + } - console.log(ownerDetails); const handleChange = (event) => { const { name, value } = event.target; setOwnerDetails({ ...ownerDetails, [name]: value }); }; + const handleImage = (e) => { + const files = e.target.files[0]; + // console.log(files) + setImage(files); + // only for file preview------------------------------------ + const Reader = new FileReader(); + Reader.readAsDataURL(files); - async function handleSubmit() { - - let res = await axios.put(`/owner`, ownerDetails, { - headers: { - 'Content-Type': 'application/json', - 'Authorization': `Bearer ${token}`, + Reader.onload = () => { + if (Reader.readyState === 2) { + setImagesPreview(Reader.result); } - }) - setProcessing(true) - console.log(res.data); + }; - if (res) { - // localStorage.setItem("auth", JSON.stringify({ - // token: res.data.token, - // })); - history.push('/profile') + // ----------------------------------------------------------------------------- + }; + async function handleSubmit() { + if (ownerDetails.name.trim() === '' || ownerDetails.email.trim() === '' || ownerDetails.phone === '') { + swal({ + title: 'Warning', + text: 'Fill all mandatory fields', + icon: 'error', + button: 'Close', + dangerMode: true, + }) + return } + const formData = new FormData() + formData.append('name', ownerDetails.name) + formData.append('email', ownerDetails.email) + formData.append('phone', ownerDetails.phone) + formData.append('avatar', image) + setLoading(true) + try { + const res = await axios + .put(`/api/v1//user/update/profile`, formData, { + headers: { + 'Access-Control-Allow-Origin': '*', + Authorization: `Bearer ${token}`, + 'Content-Type': 'multipart/formdata', + }, + }) + if (res.data.success === true) { + + setLoading(false) + swal({ + title: 'Edited', + text: 'Profile Edited Successfully!', + icon: 'success', + button: 'Return', + }) + history.goBack() + + } + } catch (error) { + const message = error?.response?.data?.message || 'Something went wrong!' + setLoading(false) + swal({ + title: 'Warning', + text: message, + icon: 'error', + button: 'Retry', + dangerMode: true, + }) + } + } + const handleCancle = () => { + history.goBack() } return ( @@ -70,49 +128,46 @@ const EditProfile = () => { - +

Edit Profile

-

Edit Profile

+ - Cafe Name - + Name * + - Email + Email * - {/* - Password - - */} - - - - Location - - - Country - - - {countries.map(item => )} - - - - - City - - - {cities.map(item => )} - - + Phone * + + + + +
+ + {imagesPreview && Product Preview} + +
- Submit + {loading ? 'Loading...' : 'Submit'} + Cancel + +
diff --git a/src/views/Profile/Profile.js b/src/views/Profile/Profile.js index 073d2ff..880d2bd 100644 --- a/src/views/Profile/Profile.js +++ b/src/views/Profile/Profile.js @@ -1,7 +1,13 @@ import React, { useEffect } from 'react' import { CButton, + CCard, + CCardBody, CCol, + CForm, + CFormInput, + CFormLabel, + CFormSelect, CRow, CTable, CTableBody, @@ -48,32 +54,65 @@ const Profile = () => { className="float-right" onClick={() => history.push('/edit')}>Edit Profile
- - - - Cafe Name - {user.cafeName} - - - - - Email - {user.email} - + + + {/*

Edit Profile

*/} + + + Cafe Name + + - - Address - {user.location},{user.city},{user.country} - + + Email + + + {/* + Password + + */} - - Item_Name - - -
-
- + + Location + + + + image + + + {/* + Country + + + {countries.map(item => )} + + + */} + {/* + City + + + {cities.map(item => )} + + + */} + + {/* + Submit + */} + + + + ) }