diff --git a/Backend/controllers/profileCtrl.js b/Backend/controllers/profileCtrl.js index 3079118..523be67 100644 --- a/Backend/controllers/profileCtrl.js +++ b/Backend/controllers/profileCtrl.js @@ -19,4 +19,20 @@ const getProfile = async (req,res)=>{ } } -module.exports = {getProfile}; \ No newline at end of file +const updateProfile = (req,res) =>{ + const id = req.user + Interviewer.updateOne({id:id},req.body) + .then((doc)=>{ + return res.status(200).json({ + success:true, + update:doc, + }) + }).catch((err)=>{ + return res.status(500).json({ + success:false, + msg:"Update not possible", + }) + }) +} + +module.exports = {getProfile,updateProfile}; \ No newline at end of file diff --git a/Backend/routes/profileRouter.js b/Backend/routes/profileRouter.js index d3936b0..0b784f2 100644 --- a/Backend/routes/profileRouter.js +++ b/Backend/routes/profileRouter.js @@ -5,5 +5,6 @@ const profileCtrl = require('../controllers/profileCtrl') const verifyUser = require('../middlewares/verifyMW').user; router.get('/interviewer/own',verifyUser,profileCtrl.getProfile); +router.post('/interviewer/update',verifyUser,profileCtrl.updateProfile); module.exports = router; \ No newline at end of file diff --git a/Frontend/package-lock.json b/Frontend/package-lock.json index b22f111..942869d 100644 --- a/Frontend/package-lock.json +++ b/Frontend/package-lock.json @@ -1284,9 +1284,9 @@ "integrity": "sha512-QF5CAuYOHE6Zbsn1uEg6wkl836iP+i6C0C/Zs3kF60eebxZvTWp8JSZk19Ar+jj4w+ye8/7H5olu5CqDNjWpEA==" }, "@firebase/functions": { - "version": "0.5.0", - "resolved": "https://registry.npmjs.org/@firebase/functions/-/functions-0.5.0.tgz", - "integrity": "sha512-j7/HVJR8uMlnTgavF8W1Vq+8IRJstxEtSVzK1yUhng7OParUCR+b3uMbMk7pcE+oQdeYTPtRoDf4deggTFws+A==", + "version": "0.5.1", + "resolved": "https://registry.npmjs.org/@firebase/functions/-/functions-0.5.1.tgz", + "integrity": "sha512-yyjPZXXvzFPjkGRSqFVS5Hc2Y7Y48GyyMH+M3i7hLGe69r/59w6wzgXKqTiSYmyE1pxfjxU4a1YqBDHNkQkrYQ==", "requires": { "@firebase/component": "0.1.19", "@firebase/functions-types": "0.3.17", @@ -1446,9 +1446,9 @@ } }, "@types/node": { - "version": "12.12.62", - "resolved": "https://registry.npmjs.org/@types/node/-/node-12.12.62.tgz", - "integrity": "sha512-qAfo81CsD7yQIM9mVyh6B/U47li5g7cfpVQEDMfQeF8pSZVwzbhwU3crc0qG4DmpsebpJPR49AKOExQyJ05Cpg==" + "version": "12.12.63", + "resolved": "https://registry.npmjs.org/@types/node/-/node-12.12.63.tgz", + "integrity": "sha512-jRP6uNtUKAFz3Cl7zwCKW9hoRSNzuNSsQ3sLGSv5Uf+yWQvx226DF9a0Moa3HADkIp7ae/FhLwlqQzrgfg9hFg==" }, "ansi-styles": { "version": "4.3.0", @@ -6484,9 +6484,9 @@ } }, "firebase": { - "version": "7.22.0", - "resolved": "https://registry.npmjs.org/firebase/-/firebase-7.22.0.tgz", - "integrity": "sha512-DoE93JoTYppZc+vOB10HDpp49UHPaz4MklE5tJ2XGCZ8ejbU/MOUwOtG4jakAkrl/rZNKVQ6yEimVsQQtZY+5w==", + "version": "7.22.1", + "resolved": "https://registry.npmjs.org/firebase/-/firebase-7.22.1.tgz", + "integrity": "sha512-pMx+Wg6Bl74PNdWxjGLrFxLqtmIB/Ggl8oYQZLl1baa9xPcb9rxut5ZgDcLZlFERBL6vNRhLEszv/+3H827m9A==", "requires": { "@firebase/analytics": "0.5.0", "@firebase/app": "0.6.11", @@ -6494,7 +6494,7 @@ "@firebase/auth": "0.14.9", "@firebase/database": "0.6.13", "@firebase/firestore": "1.17.2", - "@firebase/functions": "0.5.0", + "@firebase/functions": "0.5.1", "@firebase/installations": "0.4.17", "@firebase/messaging": "0.7.1", "@firebase/performance": "0.4.1", @@ -11241,9 +11241,9 @@ }, "dependencies": { "@types/node": { - "version": "13.13.21", - "resolved": "https://registry.npmjs.org/@types/node/-/node-13.13.21.tgz", - "integrity": "sha512-tlFWakSzBITITJSxHV4hg4KvrhR/7h3xbJdSFbYJBVzKubrASbnnIFuSgolUh7qKGo/ZeJPKUfbZ0WS6Jp14DQ==" + "version": "13.13.22", + "resolved": "https://registry.npmjs.org/@types/node/-/node-13.13.22.tgz", + "integrity": "sha512-JfiEW8exAjw25GqrY0qyV1KAqkCDXC8osxSGuWVE4HWE3RfVVcxx2IrZUlgd1whLytKI7rxHvqKy9Mh11hC5bw==" } } }, diff --git a/Frontend/package.json b/Frontend/package.json index 32354f5..993db75 100644 --- a/Frontend/package.json +++ b/Frontend/package.json @@ -8,7 +8,7 @@ "@testing-library/jest-dom": "^4.2.4", "@testing-library/react": "^9.5.0", "@testing-library/user-event": "^7.2.1", - "firebase": "^7.22.0", + "firebase": "^7.22.1", "react": "^16.13.1", "react-dom": "^16.13.1", "react-google-login": "^5.1.21", diff --git a/Frontend/src/app/Main.js b/Frontend/src/app/Main.js index be8f0ba..a406152 100644 --- a/Frontend/src/app/Main.js +++ b/Frontend/src/app/Main.js @@ -5,6 +5,7 @@ import {firebaseConfig} from './config' import firebase from 'firebase' import LoginScreen from './components/screens/LoginScreen' +import RegistrationScreen from './components/screens/RegisterScreen' function LoadingScreen(props){ @@ -23,9 +24,7 @@ function Main(props){ const googleSigninScript = document.createElement('script'); googleSigninScript.src = "https://apis.google.com/js/platform.js"; - googleSigninScript.onload = ()=>{setScriptLoading(scriptLoading+1)}; - - firebase.initializeApp(firebaseConfig); + googleSigninScript.onload = ()=>{setScriptLoading(scriptLoading+1)}; document.body.append(googleSigninScript); },[1]) @@ -36,7 +35,7 @@ function Main(props){ {scriptLoading == scriptCount?: - + } ) diff --git a/Frontend/src/app/components/molecules/RegistrationForm.js b/Frontend/src/app/components/molecules/RegistrationForm.js new file mode 100644 index 0000000..0a4f30e --- /dev/null +++ b/Frontend/src/app/components/molecules/RegistrationForm.js @@ -0,0 +1,102 @@ +import React from 'react' + +import { Button, TextField, Input,CircularProgress, Snackbar} from '@material-ui/core' +import {uploadFile} from '../../utils/firebase/storage'; +import {UserData} from '../../utils/localStorage' + +import AvatarIcon from '../../res/icons/user.png' + +function ImageUploader(props){ + const onUpload = props.onUpload; + const uploadState = props.uploadState; + + const [uploading,setUploading] = React.useState(false); + const [image,setImage] = React.useState(AvatarIcon); + const [snackbarStatus, setSnackbarStatus] = React.useState(false); + + + const handleImageSelect = (event)=>{ + setImage(URL.createObjectURL(event.target.files[0])); + const file = event.target.files[0]; + setUploading(true); + const path = "profile/"+UserData.getEmail()+"/profileImage.jpg"; + uploadFile(file,path) + .then((snapshot)=>{ + setUploading(false); + console.log("Upload Successfull!"); + onUpload(path); + + }).catch((err)=>{ + console.log("Error",err); + + }) + } + + return( +
+
+ +
+
+ + {uploading? :
} +
+ + {setSnackbarStatus(false)}}> + Upload Successfull + + +
+ ) +} + +function RegistrationForm(props){ + const onSubmit = props.onSubmit; + + const [imageUploading, setImageUploading] = React.useState(false); + + var data={ + name:"", + phone:"", + company:"", + website:"", + photo:"", + + } + + return( +
+ + {data.photo= path}} uploadState={imageUploading}/> + + {data.name = event.target.value}}/> + {data.phone = event.target.value}}/> + {data.company = event.target.value}}/> + {data.website = event.target.value}}/> +
+ +
+ +
+ ) +} + +export default RegistrationForm; diff --git a/Frontend/src/app/components/screens/LoginScreen.js b/Frontend/src/app/components/screens/LoginScreen.js index 4303613..d653ad8 100644 --- a/Frontend/src/app/components/screens/LoginScreen.js +++ b/Frontend/src/app/components/screens/LoginScreen.js @@ -43,7 +43,6 @@ const InterviewerDialog = withRouter((props)=>{ } }) - } }else{ console.log(data.msg); diff --git a/Frontend/src/app/components/screens/RegisterScreen.js b/Frontend/src/app/components/screens/RegisterScreen.js new file mode 100644 index 0000000..8fc03fb --- /dev/null +++ b/Frontend/src/app/components/screens/RegisterScreen.js @@ -0,0 +1,43 @@ +import React from 'react' +import './style.css' + +import RegistrationForm from '../../components/molecules/RegistrationForm' + +import {withRouter} from 'react-router-dom' + +import {updateProfile} from '../../utils/api/controllers/profileCtrl' +import {UserData} from '../../utils/localStorage' + +function RegisterScreen(props){ + + const handleSubmit = (data)=>{ + //updating the profile + console.log("Token",UserData.getToken()); + updateProfile(data).then((res)=>(res.json())) + .then((res)=>{ + if(res.success){ + UserData.setProfileData(data); + UserData.userExists(true); + props.history.push('/interviewer'); + }else{ + console.log("Error",res.msg); + } + }).catch((err)=>{ + console.log("Error",err); + }) + } + + return( +
+
+ Please enter the details. +
+
+ +
+ +
+ ) +} + +export default withRouter(RegisterScreen); \ No newline at end of file diff --git a/Frontend/src/app/components/screens/SignInScreen.js b/Frontend/src/app/components/screens/SignInScreen.js deleted file mode 100644 index e69de29..0000000 diff --git a/Frontend/src/app/res/icons/user.png b/Frontend/src/app/res/icons/user.png new file mode 100644 index 0000000..4845359 Binary files /dev/null and b/Frontend/src/app/res/icons/user.png differ diff --git a/Frontend/src/app/utils/api/controllers/profileCtrl.js b/Frontend/src/app/utils/api/controllers/profileCtrl.js index a84bce6..26bd706 100644 --- a/Frontend/src/app/utils/api/controllers/profileCtrl.js +++ b/Frontend/src/app/utils/api/controllers/profileCtrl.js @@ -2,13 +2,14 @@ import {profileEndPoints} from '../endpoints' import {UserData} from '../../localStorage' export const updateProfile = (data)=>{ + console.log("Data",JSON.stringify(data)); const requestOptions = { method:"POST", - headers:{ "token": UserData.getToken(),'Content-Type': 'application/json'}, + headers:{ "token": UserData.getToken(),'Content-Type': 'application/json',}, body: JSON.stringify(data) } - return fetch(profileEndPoints.update, requestOptions); + return fetch(profileEndPoints.updateProfile, requestOptions); } diff --git a/Frontend/src/app/utils/api/endpoints.js b/Frontend/src/app/utils/api/endpoints.js index 882b279..907a472 100644 --- a/Frontend/src/app/utils/api/endpoints.js +++ b/Frontend/src/app/utils/api/endpoints.js @@ -8,6 +8,6 @@ export const signInEndpoints = { export const profileEndPoints = { getOwnProfile:BASE_URL+"/profile/interviewer/own", getOthersProfile:BASE_URL+"/profile/interviewer/others", - updateProfile:BASE_URL+"", + updateProfile:BASE_URL+"/profile/interviewer/update", } \ No newline at end of file diff --git a/Frontend/src/app/utils/firebase/storage.js b/Frontend/src/app/utils/firebase/storage.js new file mode 100644 index 0000000..c3aadad --- /dev/null +++ b/Frontend/src/app/utils/firebase/storage.js @@ -0,0 +1,17 @@ +import firebase from 'firebase' +import {firebaseConfig}from '../../config'; +import {UserData} from '../localStorage' + +firebase.initializeApp(firebaseConfig); +const storageRef = firebase.storage().ref(); + + +export const uploadFile = (file,path)=>{ + const fileRef = storageRef.child(path); + return fileRef.put(file); +} + +export const downloadFile = (path)=>{ + const fileRef = storageRef.child(path); + return fileRef.getDownloadURL(); +} \ No newline at end of file