From dbd6bbcb7082d2be2e953060ce8cd225a32cfbad Mon Sep 17 00:00:00 2001 From: YoussrAbouYoussif Date: Sat, 4 May 2019 00:35:26 +0200 Subject: [PATCH] backend and popups --- client/package.json | 1 + .../src/components/pages/ApprovedCompanies.js | 7 +- client/src/components/pages/Delete.js | 72 +++++++++++++++++++ .../src/components/pages/GetCaseReviewer.js | 6 +- .../src/components/pages/assignToReviewer.js | 6 +- client/src/components/pages/getCaseLawyer.js | 6 +- .../pages/inProgressInvestorCases.js | 67 ++++++++++------- client/src/components/pages/unassignedForm.js | 6 +- .../inProgressInvestorTranslation.js | 2 + controllers/userController.js | 2 +- models/DynamicForm.js | 2 +- routes/api/userDynamicForms.js | 6 +- routes/api/users.js | 5 +- validations/userValidations.js | 4 +- 14 files changed, 151 insertions(+), 41 deletions(-) create mode 100644 client/src/components/pages/Delete.js diff --git a/client/package.json b/client/package.json index 95e136a..fe756d3 100644 --- a/client/package.json +++ b/client/package.json @@ -51,6 +51,7 @@ "redux-thunk": "^2.3.0", "semantic-ui-react": "^0.86.0", "styled-components": "^4.2.0", + "sweetalert": "^2.1.2", "validator": "^10.11.0" }, "scripts": { diff --git a/client/src/components/pages/ApprovedCompanies.js b/client/src/components/pages/ApprovedCompanies.js index ffcde66..2b30d9b 100644 --- a/client/src/components/pages/ApprovedCompanies.js +++ b/client/src/components/pages/ApprovedCompanies.js @@ -16,6 +16,7 @@ import {MDBIcon } from "mdbreact"; import {Button,Card} from"react-bootstrap" import egypt from '../../egypt.jpeg' import gafi from '../../gafi.jpeg' +import swal from 'sweetalert'; class ApprovedCompanies extends Component { @@ -27,9 +28,11 @@ class ApprovedCompanies extends Component { axios.defaults.headers.common['Authorization'] = 'Bearer ' + localStorage.getItem('jwtToken'); axios.get('/routes/api/userDynamicForms/getInvestorApprovedCompanies',{headers: { "Authorization": localStorage.getItem('jwtToken') }}) .then(res => { - if(Array.isArray(res.data.data)){ + if(Array.isArray(res.data.data)&& res.data.data.length>0){ this.setState({approvedCompanies: res.data.data,sscManagers:[]}) - + } + else{ + swal('You do not have any Approved Companies yet!') } }) } diff --git a/client/src/components/pages/Delete.js b/client/src/components/pages/Delete.js new file mode 100644 index 0000000..bacd047 --- /dev/null +++ b/client/src/components/pages/Delete.js @@ -0,0 +1,72 @@ +import React, { Component } from 'react'; +import { Button } from 'react-bootstrap'; +import { Modal } from 'react-bootstrap'; +import '../../App.css'; +import axios from 'axios'; +import Mongoose from 'mongoose'; + +class Delete extends Component +{ + constructor(props) + { + super(props); + } + + DeleteForm = (formId) => { + axios.defaults.headers.common['Authorization'] = localStorage.getItem('jwtToken'); + axios + .delete('/routes/api/userDynamicForms/investorDeleteForm/' + Mongoose.Types.ObjectId(formId), { + headers: { Authorization: localStorage.getItem('jwtToken') } + }) + .then((res) => { + //document.getElementById('Flip').flipOnClick = false; + alert('This case has been deleted successfully!!'); + document.location.href = '/investorInProgressform'; + }) + .catch((err) => { + console.log(err); + }); + }; + + render() { + + return ( +
+ + + + + + Are you sure you want to delete this form? + + + + + + + +
+ ) + } +} + +export default Delete; diff --git a/client/src/components/pages/GetCaseReviewer.js b/client/src/components/pages/GetCaseReviewer.js index 68f415a..2bbd453 100644 --- a/client/src/components/pages/GetCaseReviewer.js +++ b/client/src/components/pages/GetCaseReviewer.js @@ -10,6 +10,7 @@ import GetAllReviewerForms from "../form/GetAllReviewerForms"; import { Dropdown } from "react-bootstrap"; import { blue200 } from "material-ui/styles/colors"; import trans from '../translations/getReviewerTranslation' +import swal from "sweetalert"; const mongoose = require('mongoose') var $ = require("jquery")(window); @@ -27,9 +28,12 @@ class Companies extends Component { { headers: { Authorization: localStorage.getItem("jwtToken") } } ) .then(res => { - if (Array.isArray(res.data.data)) { + if (Array.isArray(res.data.data)&&res.data.data.length>0) { this.setState({ companies: res.data.data }); } + else{ + swal('You do not have any In Progress Cases yet!') + } }); } diff --git a/client/src/components/pages/assignToReviewer.js b/client/src/components/pages/assignToReviewer.js index 50edbc4..c0bbcc4 100644 --- a/client/src/components/pages/assignToReviewer.js +++ b/client/src/components/pages/assignToReviewer.js @@ -5,6 +5,7 @@ import 'mdbreact/dist/css/mdb.css'; import { Button } from 'react-bootstrap'; import Flippy, { FrontSide, BackSide } from 'react-flippy'; import trans from '../translations/unassignedRevTranslation'; +import swal from 'sweetalert'; const Mongoose = require('mongoose'); class assignToReviewer extends Component { state = { @@ -17,9 +18,12 @@ class assignToReviewer extends Component { headers: { Authorization: localStorage.getItem('jwtToken') } }) .then((res) => { - if (Array.isArray(res.data.data)) { + if (Array.isArray(res.data.data)&&res.data.data.length>0) { this.setState({ certainFormType: res.data.data }); } + else{ + swal('There are no cases to pick right now!') + } }); } AssignReviewer = (formId) => { diff --git a/client/src/components/pages/getCaseLawyer.js b/client/src/components/pages/getCaseLawyer.js index 72d4287..72c8e52 100644 --- a/client/src/components/pages/getCaseLawyer.js +++ b/client/src/components/pages/getCaseLawyer.js @@ -10,6 +10,7 @@ import GetAllUserForms from '../form/GetAllUserForms'; import { Dropdown, Card } from 'react-bootstrap'; import { MDBProgress } from 'mdbreact'; import { blue200 } from 'material-ui/styles/colors'; +import swal from 'sweetalert'; import trans from '../translations/getCaseLawyerTranslation' const mongoose = require('mongoose'); var $ = require('jquery')(window); @@ -39,9 +40,12 @@ class Companies extends Component { headers: { Authorization: localStorage.getItem('jwtToken') } }) .then((res) => { - if (Array.isArray(res.data.data)) { + if (Array.isArray(res.data.data)&&res.data.data.length>0) { this.setState({ companies: res.data.data }); } + else{ + swal('You do not have any In Progress Cases yet!') + } console.log(this.state.companies); }) .catch((err) => { diff --git a/client/src/components/pages/inProgressInvestorCases.js b/client/src/components/pages/inProgressInvestorCases.js index 110dcb3..794b3b9 100644 --- a/client/src/components/pages/inProgressInvestorCases.js +++ b/client/src/components/pages/inProgressInvestorCases.js @@ -5,12 +5,16 @@ import Flippy, { FrontSide, BackSide } from 'react-flippy'; import 'mdbreact/dist/css/mdb.css'; import Mongoose from 'mongoose'; import { MDBProgress } from 'mdbreact'; -import { Button } from 'react-bootstrap'; +import { Button ,ButtonToolbar} from 'react-bootstrap'; import trans from '../translations/inProgressInvestorTranslation'; +import swal from 'sweetalert'; +import Delete from './Delete'; +import { fromRenderProps } from 'recompose'; class InProgressInvestorCases extends Component { state = { certainFormType: [], - isFlipped: true + isFlipped: true , + modalShow: false }; componentDidMount() { axios.defaults.headers.common['Authorization'] = 'Bearer ' + localStorage.getItem('jwtToken'); @@ -20,9 +24,12 @@ class InProgressInvestorCases extends Component { }) .then((res) => { console.log(res); - if (Array.isArray(res.data.data)) { + if (Array.isArray(res.data.data)&& res.data.data.length>0) { this.setState({ certainFormType: res.data.data }); } + else{ + swal('You do not have any In Progress Companies yet!') + } }) .catch((err) => console.log(err)); } @@ -40,21 +47,7 @@ class InProgressInvestorCases extends Component { console.log(err); }); }; - DeleteForm = (formId) => { - axios.defaults.headers.common['Authorization'] = localStorage.getItem('jwtToken'); - axios - .delete('/routes/api/userDynamicForms/investorDeleteForm/' + Mongoose.Types.ObjectId(formId), { - headers: { Authorization: localStorage.getItem('jwtToken') } - }) - .then((res) => { - //document.getElementById('Flip').flipOnClick = false; - alert('This case has been deleted successfully!'); - document.location.href = '/investorInProgressform'; - }) - .catch((err) => { - console.log(err); - }); - }; + redirectEdit(formId, formType) { console.log(formType); localStorage.setItem('formId', formId); @@ -62,6 +55,7 @@ class InProgressInvestorCases extends Component { document.location.href = '/editinvcompany'; } getAttributes = () => { + let modalClose = () => this.setState({ modalShow: false }); return this.state.certainFormType.map((Form, index) => { var KEYS = []; for (var key in Form) { @@ -76,6 +70,8 @@ class InProgressInvestorCases extends Component { ref={(r) => (this.flippy = r)} style={{ width: '100%', height: '970px' }} > + +

- {trans.reviewerP}
95% + {trans.reviewerP}
85%

+ ) : null} + {Form.status === 'Reviewer accepted' ? ( + +

+ {trans.reviewerA}
99% +

+
+ + ) : null} {Form.status === 'Approved' ? ( @@ -160,19 +165,27 @@ class InProgressInvestorCases extends Component { + + + ) : null} {Form.status === 'Lawyer rejected' ? ( @@ -201,7 +214,8 @@ class InProgressInvestorCases extends Component { paddingLeft: '60px' }} > -
+ +
{KEYS.map((key, index) => { if ( key !== '_proto' && @@ -219,7 +233,6 @@ class InProgressInvestorCases extends Component { for (var att in constraints['0']) { keys.push(att); } - if (key === 'lawyerComments') { return (
@@ -254,7 +267,9 @@ class InProgressInvestorCases extends Component { })}
); - } else { + } + + else { return (
{' '} @@ -266,7 +281,7 @@ class InProgressInvestorCases extends Component { return (
{att} : - {constraints['0'][att]} + {constraints['0'][att] }
); })} diff --git a/client/src/components/pages/unassignedForm.js b/client/src/components/pages/unassignedForm.js index 98faf2c..d342950 100644 --- a/client/src/components/pages/unassignedForm.js +++ b/client/src/components/pages/unassignedForm.js @@ -5,6 +5,7 @@ import '../../App.scss'; import { Button } from 'react-bootstrap'; import 'mdbreact/dist/css/mdb.css'; import Flippy, { FrontSide, BackSide } from 'react-flippy'; +import swal from 'sweetalert'; import trans from '../translations/unassignedTranslation'; const mongoose = require('mongoose'); class unassignedForm extends Component { @@ -18,9 +19,12 @@ class unassignedForm extends Component { headers: { Authorization: localStorage.getItem('jwtToken') } }) .then((res) => { - if (Array.isArray(res.data.data)) { + if (Array.isArray(res.data.data)&&res.data.data.length>0) { this.setState({ certainFormType: res.data.data }); } + else{ + swal('There are no cases to pick right now!') + } }); } AssignCase = (formId) => { diff --git a/client/src/components/translations/inProgressInvestorTranslation.js b/client/src/components/translations/inProgressInvestorTranslation.js index 4e835ee..d2782f7 100644 --- a/client/src/components/translations/inProgressInvestorTranslation.js +++ b/client/src/components/translations/inProgressInvestorTranslation.js @@ -8,6 +8,7 @@ let strings = new LocalizedStrings({ lawyerR:"Lawyer Rejected", lawyerA:"Lawyer Accepted", reviewerP:"In Progress Reviewer", + reviewerA:"Reviewer Accepted", approved:"Approved", edit:"Edit Form", delete:"Delete Form" @@ -19,6 +20,7 @@ let strings = new LocalizedStrings({ lawyerR:"المحامي رفضها", lawyerA:"المحامي وافق عليها", reviewerP:"المتابع يعمل عليها", + reviewerA:"المتابع قد وافق", approved:"تم الموافقة", edit:"تعديل", delete:"حذف" diff --git a/controllers/userController.js b/controllers/userController.js index b5600cd..cd7033a 100644 --- a/controllers/userController.js +++ b/controllers/userController.js @@ -23,7 +23,7 @@ exports.registerInvestor = async function registerInvestor(body) { // const user = await User.findOne({body:email}) if (user) return { error: 'Account already exists' }; - + body.financialBalance = 0 const newUser = await User.create(body) .then((res) => { return res; diff --git a/models/DynamicForm.js b/models/DynamicForm.js index efe78db..6343127 100644 --- a/models/DynamicForm.js +++ b/models/DynamicForm.js @@ -3,7 +3,7 @@ const Schema = mongoose.Schema; var ObjectId = mongoose.Schema.Types.ObjectId; const DynamicForm = new Schema({ - status:{type: String,enum:['Unassigned','In progress Lawyer','Laywer rejected','Lawyer accepted','In progress Reviewer','Reviewer rejected','Approved','Rejected']}, + status:{type: String,enum:['Unassigned','In progress Lawyer','Laywer rejected','Lawyer accepted','In progress Reviewer','Reviewer accepted','Reviewer rejected','Approved','Rejected']}, creationDate:{type: Date,required: true}, lawyerComments:{type:[String]}, reviewerComments:{type:[String]}, diff --git a/routes/api/userDynamicForms.js b/routes/api/userDynamicForms.js index 1931596..d456675 100644 --- a/routes/api/userDynamicForms.js +++ b/routes/api/userDynamicForms.js @@ -320,7 +320,7 @@ router.put( form.status === "In progress Reviewer" && form.reviewerId.equals(req.user.id) ) { - form.status = "Approved"; + form.status = "Reviewer accepted"; const returnedForm = await dynamicFormController.update( "_id", formid, @@ -328,13 +328,13 @@ router.put( ); if (returnedForm.error) return res.status(400).json({ error: form.error }); - const investor = await userController.search("_id".form.investor_id); + const investor = await userController.search('_id',returnedForm.investorId); if(investor!==null){ if (investor.error) return res.status(400).json({ error: investor.error }); const updatedFinancialBalance = form.fees + investor.financialBalance; const returnedInvestor = await userController.update( - "_id", + '_id', investor._id, { financialBalance: updatedFinancialBalance } ); diff --git a/routes/api/users.js b/routes/api/users.js index 3e74890..3e5df1c 100644 --- a/routes/api/users.js +++ b/routes/api/users.js @@ -65,7 +65,8 @@ router.get('/CertainAttributes', passport.authenticate('jwt', { session: false } Email: searchUsers.email, Password: searchUsers.password, Telephone: searchUsers.telephone, - Fax: searchUsers.fax + Fax: searchUsers.fax, + FinancialBalance:searchUsers.financialBalance }); }); @@ -110,9 +111,7 @@ router.post('/register', async (req, res) => { if (newUser.userType === 'Investor') { newUser.resetPasswordToken = null; newUser.resetPasswordExpires = null; - newUser.financialBalance = 0; returnedUser = await userController.update('_id', newUser._id, { - financialBalance: newUser.financialBalance, resetPasswordToken: newUser.resetPasswordToken, resetPasswordExpires: newUser.resetPasswordExpires }); diff --git a/validations/userValidations.js b/validations/userValidations.js index dec75a4..7317fac 100644 --- a/validations/userValidations.js +++ b/validations/userValidations.js @@ -105,7 +105,9 @@ module.exports = { telephone: Joi.string().max(15).min(4), fax: Joi.string().min(5).max(20), investorType: Joi.string(), - financialBalance: Joi.number() + financialBalance: Joi.number(), + resetPasswordToken: Joi.string(), + resetPasswordExpires: Joi.date() }; return Joi.validate(request, updateSchema);