From d406d995be0b2d8fe51231071fbe3804f713b4e9 Mon Sep 17 00:00:00 2001 From: Raghav Date: Fri, 23 Jul 2021 17:20:25 +0530 Subject: [PATCH 01/10] fix: endpoints and schema bugs --- src/components/inputs/image.jsx | 2 +- src/config.json | 10 +++--- src/layouts/private/user/navbar.jsx | 4 +-- src/pages/private/user/messages/index.jsx | 28 +++++++-------- src/pages/private/user/messages/single.jsx | 4 +-- src/pages/private/user/profile/details.jsx | 24 ++++++------- src/pages/private/user/profile/index.jsx | 4 +-- .../user/profile/profileCard/socialCard.jsx | 35 +++++++++---------- src/pages/public/admin/login.jsx | 4 +-- src/pages/public/user/login.jsx | 20 +++++------ src/services/httpService.js | 1 + src/utils/schemas.js | 8 ++--- 12 files changed, 72 insertions(+), 72 deletions(-) diff --git a/src/components/inputs/image.jsx b/src/components/inputs/image.jsx index e2b337a..c91f9b9 100644 --- a/src/components/inputs/image.jsx +++ b/src/components/inputs/image.jsx @@ -43,7 +43,7 @@ const DropPicture = ({ defaultPicture }) => { try { const compressedFile = await imageCompression(acceptedFiles[0], options); formData.append('file', compressedFile); - const { data } = await http.post( + const { data } = await http.patch( `${apiUrl}/${endPoints.user.updateProfilePicture}`, formData, { diff --git a/src/config.json b/src/config.json index 84f97fe..d25c8ee 100644 --- a/src/config.json +++ b/src/config.json @@ -6,13 +6,13 @@ "login": "api/user/login", "signup": "api/user/signup" }, - "allUsers": "api/user/info/all", - "loggedInUser": "api/user/info", - "getClassStudents": "api/user/class/all", - "updateProfilePicture": "api/user/update/profile_picture" + "allUsers": "api/users/all", + "loggedInUser": "api/user", + "getClassStudents": "api/users/class", + "updateProfilePicture": "api/user/update-profile-picture" }, "slamBook": { - "getUserAnswers": "api/user/answers", + "getUserAnswers": "api/answers", "deleteAnswerById": "api/slambook/answer/delete", "upsertAnswer": "api/slambook/answer/upsert", "createQuestion": "api/slambook/question/new", diff --git a/src/layouts/private/user/navbar.jsx b/src/layouts/private/user/navbar.jsx index 095fdde..5c4b2aa 100644 --- a/src/layouts/private/user/navbar.jsx +++ b/src/layouts/private/user/navbar.jsx @@ -41,9 +41,9 @@ const Navbar = () => { Writes - + {/* Polls - + */} diff --git a/src/pages/private/user/messages/index.jsx b/src/pages/private/user/messages/index.jsx index e86058c..2335de0 100644 --- a/src/pages/private/user/messages/index.jsx +++ b/src/pages/private/user/messages/index.jsx @@ -25,10 +25,10 @@ class PeopleCards extends Component { const { data: persons } = await http.get(`${apiUrl}/${endPoints.user.allUsers}`); let departments = persons.map((e) => { - return e.deptSection.department; + return e.department; }); let sections = persons.map((e) => { - return e.deptSection.section; + return e.section; }); departments.sort(); departments = ['ALL', ...new Set(departments)]; @@ -51,7 +51,7 @@ class PeopleCards extends Component { filterPeople = (e) => { const people = this.state.persons.filter( (person) => - person.credentials.name + person.name .toLowerCase() .search(e.target.value.trim().toLowerCase()) !== -1, ); @@ -65,7 +65,7 @@ class PeopleCards extends Component { return this.setState({ people: persons.filter((e) => { - return e.deptSection.section === sectionSelect; + return e.section === sectionSelect; }), departmentSelect: input.value, }); @@ -75,11 +75,11 @@ class PeopleCards extends Component { people: persons.filter((e) => { if (sectionSelect !== 'ALL') { return ( - e.deptSection.department === input.value && - e.deptSection.section === sectionSelect + e.department === input.value && + e.section === sectionSelect ); } - return e.deptSection.department === input.value; + return e.department === input.value; }), departmentSelect: input.value, }); @@ -92,7 +92,7 @@ class PeopleCards extends Component { return this.setState({ people: persons.filter((e) => { - return e.deptSection.department === departmentSelect; + return e.department === departmentSelect; }), sectionSelect: input.value, }); @@ -102,11 +102,11 @@ class PeopleCards extends Component { people: persons.filter((e) => { if (departmentSelect !== 'ALL') { return ( - e.deptSection.section === input.value && - e.deptSection.department === departmentSelect + e.section === input.value && + e.department === departmentSelect ); } - return e.deptSection.section === input.value; + return e.section === input.value; }), sectionSelect: input.value, }); @@ -162,9 +162,9 @@ class PeopleCards extends Component { diff --git a/src/pages/private/user/messages/single.jsx b/src/pages/private/user/messages/single.jsx index 4906c68..78b0b4c 100644 --- a/src/pages/private/user/messages/single.jsx +++ b/src/pages/private/user/messages/single.jsx @@ -39,7 +39,7 @@ const UserCard = ({ person, personName, personBio, personImageUrl }) => { 'secondary', 'dark', ]; - classes += badgeClass[person.deptSection.section.charCodeAt(0) - 65]; + classes += badgeClass[person.section.charCodeAt(0) - 65]; return classes; }; const classes = useStyles(); @@ -61,7 +61,7 @@ const UserCard = ({ person, personName, personBio, personImageUrl }) => {
- {person.deptSection.department} - {person.deptSection.section} + {person.department} - {person.section}
{personBio ? ( diff --git a/src/pages/private/user/profile/details.jsx b/src/pages/private/user/profile/details.jsx index 8ae416d..ebc0e55 100644 --- a/src/pages/private/user/profile/details.jsx +++ b/src/pages/private/user/profile/details.jsx @@ -48,23 +48,23 @@ const UserInfo = () => { try { const { data } = await http.get(`${apiUrl}/${endPoints.user.loggedInUser}`); setCredentials({ - name: data.credentials.name, - phoneNo: data.credentials.phoneNo, - email: data.credentials.email, + name: data.name, + phoneNo: data.socialHandles.phone, + email: data.socialHandles.email, }); setDeptSection({ - department: data.deptSection.department, - section: data.deptSection.section, + department: data.department, + section: data.section, }); setInfo({ - bio: data.info.bio, - profilePicture: data.info.profilePicture, + bio: data.bio, + profilePicture: data.profilePicture, }); setSocialHandles({ - contactEmail: data.socialHandles.contactEmail, - contactNo: data.socialHandles.contactNo, + contactEmail: data.socialHandles.email, + contactNo: data.socialHandles.phone, instagram: data.socialHandles.instagram, - whatsappNo: data.socialHandles.whatsappNo, + whatsappNo: data.socialHandles.whatsapp, facebook: data.socialHandles.facebook, linkedin: data.socialHandles.linkedin, snapchat: data.socialHandles.snapchat, @@ -201,14 +201,14 @@ const UserInfo = () => { isDisabled /> - + /> */} { className="card-title text-left h6-responsive mb-2" style={{ textDecoration: 'underline' }} > - {index + 1}. {item.questionId.title} + {index + 1}. {item.title} -

{item.answer}

+

{item.content}

))} diff --git a/src/pages/private/user/profile/profileCard/socialCard.jsx b/src/pages/private/user/profile/profileCard/socialCard.jsx index 3b73eeb..0c3b541 100644 --- a/src/pages/private/user/profile/profileCard/socialCard.jsx +++ b/src/pages/private/user/profile/profileCard/socialCard.jsx @@ -9,19 +9,17 @@ const PersonalCard = () => { const [Name, setName] = useState(''); const [info, setInfo] = useState({ bio: '', profilePicture: '' }); const [socialHandles, setSocialHandles] = useState({ - contactEmail: '', - contactNo: '', + email: '', + phone: '', instagram: '', - whatsappNo: '', facebook: '', linkedin: '', snapchat: '', }); const { - contactEmail, - contactNo, - whatsappNo, + email, + phone, instagram, linkedin, facebook, @@ -32,20 +30,21 @@ const PersonalCard = () => { const fetchUserData = async () => { try { const { data } = await http.get(`${apiUrl}/${endPoints.user.loggedInUser}`); - setName(data.credentials.name); + setName(data.name); setInfo({ - bio: data.info.bio, - profilePicture: data.info.profilePicture, + bio: data.bio, + profilePicture: data.profilePicture, }); setSocialHandles({ - contactEmail: data.socialHandles.contactEmail, - contactNo: data.socialHandles.contactNo, + email: data.socialHandles.email, + phone: data.socialHandles.phone, instagram: data.socialHandles.instagram, - whatsappNo: data.socialHandles.whatsappNo, + // whatsappNo: data.socialHandles.whatsappNo, facebook: data.socialHandles.facebook, linkedin: data.socialHandles.linkedin, snapchat: data.socialHandles.snapchat, }); + console.log('socialss', data) } catch (ex) { if (ex.response && ex.response.status === 400) { TimerAlert('Error', ex.response.data, 'error'); @@ -90,24 +89,24 @@ const PersonalCard = () => {
- {contactEmail && ( + {email && ( )} - {contactNo && ( + {phone && ( )} - {whatsappNo && ( + {/* {whatsappNo && ( - )} + )} */} {linkedin && ( { TimerAlert('Success', data, 'success'); history.push('/'); } catch (ex) { - if (ex.response && ex.reponse.status && ex.response.status === 400) { + if (ex.response && ex.response.status && ex.response.status === 400) { TimerAlert('Error', ex.response.data, 'error'); } - if (ex.reponse && ex.response.status && ex.response.status === 401) { + if (ex.response && ex.response.status && ex.response.status === 401) { TimerAlert('Error', 'Invalid Username or Password', 'error'); } setLoading(false); diff --git a/src/pages/public/user/login.jsx b/src/pages/public/user/login.jsx index 17736a3..78d69b3 100644 --- a/src/pages/public/user/login.jsx +++ b/src/pages/public/user/login.jsx @@ -10,9 +10,9 @@ import { apiUrl, endPoints } from '../../../config.json'; import { http } from '../../../services'; const UserLogin = () => { - const [credentials, setCredentials] = useState({ email: '', password: '' }); + const [credentials, setCredentials] = useState({ userId: '', password: '' }); const [validationErrors, setValidationErrors] = useState({ - email: '', + userId: '', password: '', }); const [Loading, setLoading] = useState(false); @@ -65,9 +65,9 @@ const UserLogin = () => { const submitHandler = async (e) => { e.preventDefault(); e.target.className += ' was-validated'; - const errors = validateForm(); - setValidationErrors(errors || {}); - if (errors) return; + // const errors = validateForm(); + // setValidationErrors(errors || {}); + // if (errors) return; try { setLoading(true); const { headers } = await http.post( @@ -109,12 +109,12 @@ const UserLogin = () => { Sign In

{ return { - email: Joi.string() - .email() + userId: Joi + .number() .error(() => { return { - message: 'Please enter a valid Email ID', + message: 'Please enter a valid enrollment number', }; }) .required(), @@ -27,7 +27,7 @@ const SignUpSchema = () => { .min(7) .error(() => { return { - message: 'Password should be atleast 7 characters long', + message: 'Password should be at least 7 characters long', }; }) .required(), From 090442d57abe975df90a05e0e855a044587943a6 Mon Sep 17 00:00:00 2001 From: Raghav Date: Fri, 23 Jul 2021 18:16:34 +0530 Subject: [PATCH 02/10] fix: config.json and subsequent network requests --- src/config.json | 5 ++- src/pages/private/user/messages/modal.jsx | 50 ++++----------------- src/pages/private/user/messages/single.jsx | 22 ++++++--- src/pages/private/user/profile/index.jsx | 8 ++-- src/pages/private/user/profile/messages.jsx | 4 +- 5 files changed, 34 insertions(+), 55 deletions(-) diff --git a/src/config.json b/src/config.json index d25c8ee..906e223 100644 --- a/src/config.json +++ b/src/config.json @@ -21,8 +21,9 @@ "deleteQuestionById": "api/slambook/question/delete" }, "messages": { - "forLoggedInUser": "api/user/messages", - "feed": "api/user/messages/all" + "forLoggedInUser": "api/messages", + "feed": "api/messages/all", + "new": "api/message/new" } }, "routes": { diff --git a/src/pages/private/user/messages/modal.jsx b/src/pages/private/user/messages/modal.jsx index ba60039..d2f976d 100644 --- a/src/pages/private/user/messages/modal.jsx +++ b/src/pages/private/user/messages/modal.jsx @@ -9,53 +9,26 @@ import { MDBModalFooter, MDBRating, } from 'mdbreact'; -import { apiUrl } from '../../../../config.json'; +import { apiUrl, endPoints } from '../../../../config.json'; import http from '../../../../services/httpService'; import { NotifyAlert, TimerAlert } from '../../../../components'; -const ModalBox = ({ personId, personName, toggleOpen, triggerModal }) => { - const [ModalValue, setModalValue] = useState(''); - const [basic] = useState([ - { - tooltip: '1/5', - }, - { - tooltip: '2/5', - }, - { - tooltip: '3/5', - }, - { - tooltip: '4/5', - }, - { - tooltip: '5/5', - }, - ]); +const ModalBox = ({ personId, personName, toggleOpen, triggerModal, modalValue }) => { + const [ModalValue, setModalValue] = useState(() => modalValue); useEffect(() => { - const getUserMessage = async () => { - try { - const { data } = await http.get(`${apiUrl}/api/user/messages/${personId}`); - setModalValue(data.message); - } catch (ex) { - if (ex.response && ex.response.status === 404) { - // TimerAlert('Error', ex.response.data, 'error'); - } - } - }; - getUserMessage(); - }, [personId]); + setModalValue(modalValue) + }, [modalValue]) const handleSubmit = () => { const messageObject = { - message: ModalValue, - sendTo: personId, + content: ModalValue, + receiverId: personId, }; const submitData = async () => { try { const { data } = await http.put( - `${apiUrl}/api/user/messages`, + `${apiUrl}/${endPoints.messages.new}`, messageObject, ); setModalValue(data.message); @@ -68,6 +41,7 @@ const ModalBox = ({ personId, personName, toggleOpen, triggerModal }) => { submitData(); }; + // TODO: Implement handle delete. const handleDelete = () => {}; return ( @@ -92,12 +66,6 @@ const ModalBox = ({ personId, personName, toggleOpen, triggerModal }) => { value={ModalValue} />
-

- Rate your friendship -

-
- console.log(e)} /> -
diff --git a/src/pages/private/user/messages/single.jsx b/src/pages/private/user/messages/single.jsx index 78b0b4c..6dc8f34 100644 --- a/src/pages/private/user/messages/single.jsx +++ b/src/pages/private/user/messages/single.jsx @@ -6,6 +6,8 @@ import CardMedia from '@material-ui/core/CardMedia'; import propTypes from 'prop-types'; import urlPropType from 'url-prop-type'; import ModalBox from './modal'; +import { http } from '../../../../services'; +import { apiUrl, endPoints } from '../../../../config.json'; const useStyles = makeStyles(() => ({ media: { @@ -16,15 +18,21 @@ const useStyles = makeStyles(() => ({ const UserCard = ({ person, personName, personBio, personImageUrl }) => { const [modalOpen, setModalOpen] = useState(false); + const [modalValue, setModalValue] = useState(''); - useEffect(() => { - const fetchUserDetails = async () => { - // const { data } = await axios.put('http://localhost:5000/api/user/self', userObject); - }; - fetchUserDetails(); - }, []); + const getUserMessage = async () => { + try { + const { data } = await http.get(`${apiUrl}/api/message/${person._id}`); + setModalValue(data.content); + } catch (ex) { + if (ex.response && ex.response.status === 404) { + // TimerAlert('Error', ex.response.data, 'error'); + } + } + }; const triggerModal = () => { + getUserMessage() setModalOpen(!modalOpen); }; @@ -81,7 +89,7 @@ const UserCard = ({ person, personName, personBio, personImageUrl }) => { // handleSubmit={handleSubmit} triggerModal={triggerModal} // Reverse the State of the Modal toggleOpen={modalOpen} // Opens the modal - // modalValue={modalValue} // The value of the modal text area + modalValue={modalValue} // The value of the modal text area personName={personName} // Name of the person for whom the modal is opened personId={person._id} // Person object /> diff --git a/src/pages/private/user/profile/index.jsx b/src/pages/private/user/profile/index.jsx index 9e901fa..7d7b831 100644 --- a/src/pages/private/user/profile/index.jsx +++ b/src/pages/private/user/profile/index.jsx @@ -36,7 +36,9 @@ const Profile = () => { `${apiUrl}/${endPoints.messages.forLoggedInUser}`, ); setMessages(data); - if (!data.length) setMessagesStatus(true); + if (!data.length) { + setMessagesStatus(true); + } } catch (ex) {} }; @@ -86,8 +88,8 @@ const Profile = () => { {messages.map((item, index) => ( diff --git a/src/pages/private/user/profile/messages.jsx b/src/pages/private/user/profile/messages.jsx index f5cbb8a..b95b250 100644 --- a/src/pages/private/user/profile/messages.jsx +++ b/src/pages/private/user/profile/messages.jsx @@ -37,10 +37,10 @@ const Message = ({ person, message, index }) => {

{message}

-

+ {/*

{person} Rated your friendship 3.5/5 -

+

*/}
From 64027e18a2079931ce8f35326b5ae93761627144 Mon Sep 17 00:00:00 2001 From: Raghav Date: Fri, 23 Jul 2021 22:07:53 +0530 Subject: [PATCH 03/10] fix: fixed details and profile page Added isAnonymous message checkbox --- src/components/inputs/image.jsx | 2 +- src/components/utils/socialHandle.jsx | 2 +- src/config.json | 3 +- .../private/admin/questions/listQuestion.jsx | 2 +- src/pages/private/user/messages/modal.jsx | 8 +- src/pages/private/user/profile/details.jsx | 150 ++++++------------ .../private/user/resetPassword/index.jsx | 1 - 7 files changed, 59 insertions(+), 109 deletions(-) diff --git a/src/components/inputs/image.jsx b/src/components/inputs/image.jsx index c91f9b9..9bda396 100644 --- a/src/components/inputs/image.jsx +++ b/src/components/inputs/image.jsx @@ -78,7 +78,7 @@ const DropPicture = ({ defaultPicture }) => {
-
+

Upload your profile picture

diff --git a/src/components/utils/socialHandle.jsx b/src/components/utils/socialHandle.jsx index ef7ad61..004851c 100644 --- a/src/components/utils/socialHandle.jsx +++ b/src/components/utils/socialHandle.jsx @@ -4,7 +4,7 @@ import propTypes from 'prop-types'; const SocialHandle = ({ platform, iconClass }) => { return (
-
+
{platform}
diff --git a/src/config.json b/src/config.json index 906e223..faa35b2 100644 --- a/src/config.json +++ b/src/config.json @@ -9,7 +9,8 @@ "allUsers": "api/users/all", "loggedInUser": "api/user", "getClassStudents": "api/users/class", - "updateProfilePicture": "api/user/update-profile-picture" + "updateProfilePicture": "api/user/update-profile-picture", + "updateDetails": "api/user/update" }, "slamBook": { "getUserAnswers": "api/answers", diff --git a/src/pages/private/admin/questions/listQuestion.jsx b/src/pages/private/admin/questions/listQuestion.jsx index ba79e0f..241acdc 100644 --- a/src/pages/private/admin/questions/listQuestion.jsx +++ b/src/pages/private/admin/questions/listQuestion.jsx @@ -36,7 +36,7 @@ const ListQuestions = ({ onKeyDown={handleKeyPress} /> {inputValidationAlert.apply && ( - + {inputValidationAlert.message} )} diff --git a/src/pages/private/user/messages/modal.jsx b/src/pages/private/user/messages/modal.jsx index d2f976d..f463160 100644 --- a/src/pages/private/user/messages/modal.jsx +++ b/src/pages/private/user/messages/modal.jsx @@ -15,6 +15,7 @@ import { NotifyAlert, TimerAlert } from '../../../../components'; const ModalBox = ({ personId, personName, toggleOpen, triggerModal, modalValue }) => { const [ModalValue, setModalValue] = useState(() => modalValue); + const [isAnonymous, setIsAnonymous] = useState(false); useEffect(() => { setModalValue(modalValue) @@ -53,11 +54,10 @@ const ModalBox = ({ personId, personName, toggleOpen, triggerModal, modalValue
-

+

Write a nice message for {personName} :)