Skip to content
This repository has been archived by the owner on Nov 15, 2024. It is now read-only.

fix: endpoints and schema bugs #73

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
4 changes: 2 additions & 2 deletions src/components/inputs/image.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
{
Expand Down Expand Up @@ -78,7 +78,7 @@ const DropPicture = ({ defaultPicture }) => {
<section className="container" style={customStyle}>
<div {...getRootProps({ className: 'dropzone' })}>
<input {...getInputProps()} />
<div className="text-center" style={{ fontFamily: 'Inter' }}>
<div className="text-center">
<BackupIcon className="mb-1" fontSize="large" />
<strong>
<p className="text-center">Upload your profile picture</p>
Expand Down
2 changes: 1 addition & 1 deletion src/components/utils/socialHandle.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import propTypes from 'prop-types';
const SocialHandle = ({ platform, iconClass }) => {
return (
<div className="row">
<div className="col ml-5">
<div className="col mx-5">
<i className={iconClass} />
</div>
<div className="col pl-1">{platform}</div>
Expand Down
16 changes: 9 additions & 7 deletions src/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
"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",
"updateDetails": "api/user/update"
},
"slamBook": {
"getUserAnswers": "api/user/answers",
"getUserAnswers": "api/answers",
"deleteAnswerById": "api/slambook/answer/delete",
"upsertAnswer": "api/slambook/answer/upsert",
"createQuestion": "api/slambook/question/new",
Expand All @@ -21,8 +22,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": {
Expand Down
4 changes: 2 additions & 2 deletions src/layouts/private/user/navbar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ const Navbar = () => {
<MDBNavItem>
<MDBNavLink to="/write">Writes</MDBNavLink>
</MDBNavItem>
<MDBNavItem>
{/* <MDBNavItem>
<MDBNavLink to="/polls">Polls</MDBNavLink>
</MDBNavItem>
</MDBNavItem> */}
</MDBNavbarNav>
<MDBNavbarNav right>
<MDBNavItem>
Expand Down
2 changes: 1 addition & 1 deletion src/pages/private/admin/questions/listQuestion.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const ListQuestions = ({
onKeyDown={handleKeyPress}
/>
{inputValidationAlert.apply && (
<Alert severity="error" style={{ fontFamily: 'Sofia Pro Medium' }}>
<Alert severity="error">
{inputValidationAlert.message}
</Alert>
)}
Expand Down
28 changes: 14 additions & 14 deletions src/pages/private/user/messages/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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)];
Expand All @@ -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,
);
Expand All @@ -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,
});
Expand All @@ -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,
});
Expand All @@ -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,
});
Expand All @@ -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,
});
Expand Down Expand Up @@ -162,9 +162,9 @@ class PeopleCards extends Component {
<UserCard
person={person}
key={person._id}
personName={person.credentials.name}
personImageUrl={person.info.profilePicture}
personBio={person.info.bio}
personName={person.name}
personImageUrl={person.profilePicture}
personBio={person.bio}
triggerModal={this.triggerModal}
/>
</div>
Expand Down
58 changes: 15 additions & 43 deletions src/pages/private/user/messages/modal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,53 +9,27 @@ 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);
const [isAnonymous, setIsAnonymous] = useState(false);

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);
Expand All @@ -68,6 +42,7 @@ const ModalBox = ({ personId, personName, toggleOpen, triggerModal }) => {
submitData();
};

// TODO: Implement handle delete.
const handleDelete = () => {};

return (
Expand All @@ -79,11 +54,10 @@ const ModalBox = ({ personId, personName, toggleOpen, triggerModal }) => {

<MDBModalBody>
<div className="form-group">
<p className="text-center" style={{ fontFamily: 'Inter' }}>
<p className="text-center">
Write a nice message for {personName} :)
</p>
<textarea
style={{ fontFamily: 'Inter' }}
className="form-control"
id={personId}
rows="5"
Expand All @@ -92,14 +66,12 @@ const ModalBox = ({ personId, personName, toggleOpen, triggerModal }) => {
value={ModalValue}
/>
</div>
<p className="text-center" style={{ fontFamily: 'Inter' }}>
Rate your friendship
</p>
<div className="row d-flex justify-content-center mb-1">
<MDBRating data={basic} getValue={(e) => console.log(e)} />
</div>
</MDBModalBody>
<MDBModalFooter>
<span className="custom-control custom-checkbox">
<input type="checkbox" className="custom-control-input" id="defaultUnchecked" value={isAnonymous} onChange={() => setIsAnonymous(!isAnonymous)} />
<label className="custom-control-label" for="defaultUnchecked">Send Anonymously</label>
</span>
<div>
<button
className="btn btn-danger btn-sm"
Expand Down
26 changes: 17 additions & 9 deletions src/pages/private/user/messages/single.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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);
};

Expand All @@ -39,7 +47,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();
Expand All @@ -61,7 +69,7 @@ const UserCard = ({ person, personName, personBio, personImageUrl }) => {
</div>
<div className="text-center">
<span className={getBadgeClass()}>
{person.deptSection.department} - {person.deptSection.section}
{person.department} - {person.section}
</span>
</div>
{personBio ? (
Expand All @@ -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
/>
Expand Down
Loading