diff --git a/src/App.js b/src/App.js index d83eb6ab..65b58a45 100644 --- a/src/App.js +++ b/src/App.js @@ -4,15 +4,17 @@ import "./App.css"; import { Provider } from "react-redux"; import store from "./store"; import jwt_decode from "jwt-decode"; -import { setAuthToken } from "./utils/setAuthToken"; +import { allowCredentialsInHeader } from "./utils/allowCredentialsInHeader"; import { setCurrentUser, logoutUser } from "./actions/authAction"; import "./css/main.scss"; import ReactGA from "react-ga"; +allowCredentialsInHeader() + function App() { useEffect(() => { ReactGA.initialize("UA-173245995-1"); - setAuthToken() + }); return ( diff --git a/src/actions/adminAction.js b/src/actions/adminAction.js index 70026728..9d441ba1 100644 --- a/src/actions/adminAction.js +++ b/src/actions/adminAction.js @@ -2,7 +2,6 @@ import axios from 'axios' import { errorHandler } from '../utils/errorHandler' import { setRequestStatus } from '../utils/setRequestStatus' import { SET_ADMIN, GET_ADMIN } from './types' -import { setAuthToken } from '../utils/setAuthToken' import jwt_decode from 'jwt-decode'; import { setCurrentUser } from './authAction' import { BASE_URL } from './baseApi' @@ -27,31 +26,27 @@ export const createAdmin = (adminInfo) => async (dispatch) => { export const loginAdmin = (adminInfo, history) => async (dispatch) => { try { const res = await axios.post(`${BASE_URL}/auth/login/`, adminInfo) - dispatch(setRequestStatus(false)); - if (res.status === 200) { + dispatch(setRequestStatus(false)); + if (res.status === 200) { + dispatch(setRequestStatus(true)); - const token = res.data.token; - dispatch(setRequestStatus(true)); + // update state with user + localStorage.setItem('userId', res.data.user) + dispatch(setCurrentUser(res.data.user._id)); - localStorage.setItem("jwtToken", (token)); - setAuthToken(token); + // update localStorage with admin status + localStorage.setItem('username', `${res.data.user.name.firstName} ${res.data.user.name.lastName}`) + localStorage.setItem('admin', res.data.user.isAdmin) + localStorage.setItem('ticketModerator', res.data.user.isTicketsModerator) + localStorage.setItem('orgId', res.data.user.orgId); - // update state with user - const decodedData = await jwt_decode(token); - localStorage.setItem('userId', decodedData._id) - dispatch(setCurrentUser(decodedData)); - - // update localStorage with admin status - localStorage.setItem('admin', true) - - dispatch({ - type: SET_ADMIN, - payload: true - }) - - history.push("/dashboard"); + dispatch({ + type: SET_ADMIN, + payload: res.data.user.isAdmin + }) + history.push("/dashboard"); } } catch (error) { dispatch(errorHandler(error)) } -} \ No newline at end of file +} diff --git a/src/actions/authAction.js b/src/actions/authAction.js index 53f93f12..2312cc5a 100644 --- a/src/actions/authAction.js +++ b/src/actions/authAction.js @@ -1,6 +1,5 @@ import { SET_CURRENT_USER, GET_USER_PROFILE, PASSWORD_SUCCESSFULLY_CHANGED, PASSWORD_CHANGE_REQUEST_SUCCESS, SET_ADMIN } from './types'; import axios from 'axios'; -import { setAuthToken } from '../utils/setAuthToken'; import { errorHandler } from '../utils/errorHandler'; import { setRequestStatus } from '../utils/setRequestStatus'; import { BASE_URL } from './baseApi'; @@ -146,8 +145,6 @@ export const logoutUser = () => async (dispatch) => { const orgId = localStorage.getItem('orgId'); localStorage.clear() localStorage.setItem('orgId', orgId) - // delete authorization from the header - setAuthToken(false); // set user to {} setCurrentUser({}); // move to home diff --git a/src/css/components/_modals.scss b/src/css/components/_modals.scss index 3a4275f7..7662444a 100644 --- a/src/css/components/_modals.scss +++ b/src/css/components/_modals.scss @@ -35,12 +35,10 @@ padding-top: 5px; } .search_btn { - width: 6vw; - height: 5vh; background: rgb(250, 251, 252); border-radius: 100px; color: #1a73e8; - padding: 0.3em; + padding: 0 1rem; margin-left: 1em; } .edit__post__option { diff --git a/src/user/dashboard/Community/components/Toggle/ToggleSwitch.js b/src/user/dashboard/Community/components/Toggle/ToggleSwitch.js index de46a5e6..0a51d840 100644 --- a/src/user/dashboard/Community/components/Toggle/ToggleSwitch.js +++ b/src/user/dashboard/Community/components/Toggle/ToggleSwitch.js @@ -21,6 +21,7 @@ function ToggleSwitch(props) { let handleClose = () => { console.log('close clicked!') + setCheck(!checked) setModalShow(false) } @@ -99,4 +100,4 @@ const mapStateToProps = (state) => ({ error: state.error }) -export default connect(mapStateToProps)(withRouter(ToggleSwitch)); \ No newline at end of file +export default connect(mapStateToProps)(withRouter(ToggleSwitch)); diff --git a/src/user/dashboard/news-feed/popups/AddEventModal.js b/src/user/dashboard/news-feed/popups/AddEventModal.js index c21bf050..bfe06389 100644 --- a/src/user/dashboard/news-feed/popups/AddEventModal.js +++ b/src/user/dashboard/news-feed/popups/AddEventModal.js @@ -103,7 +103,7 @@ const AddEventModal = (props) => { > Date @@ -116,7 +116,7 @@ const AddEventModal = (props) => { > Time diff --git a/src/user/organization/popups/Admins.js b/src/user/organization/popups/Admins.js index 88f13081..2f76ad59 100644 --- a/src/user/organization/popups/Admins.js +++ b/src/user/organization/popups/Admins.js @@ -56,7 +56,7 @@ class Admins extends Component { mapHelper = (allAdmins) => { let adminInfo = [] - if (allAdmins.length > 0) { + if (allAdmins && allAdmins.length > 0) { allAdmins.forEach((admin) => { adminInfo.push({ name: admin.name.firstName + ' ' + admin.name.lastName, desc: admin.info.about?.designation, _id: admin._id, isRemoved: admin?.isRemoved || false }) }) @@ -100,6 +100,15 @@ class Admins extends Component { const { onHide, show } = this.props const { inviteLink, whoCanSendInvite } = this.state const adminList = [...this.state.admins] + + const handleModalHide = () => { + this.setState({ + query: '' + }, () => { + onHide() + }) + } + let admins = adminList.map((item) => (
@@ -123,7 +132,7 @@ class Admins extends Component { )); return ( ({ org: state.org }) -export default connect(mapStateToProps, { removeAdmin, getMember, getInviteLink, getOrgProfile })(Admins) \ No newline at end of file +export default connect(mapStateToProps, { removeAdmin, getMember, getInviteLink, getOrgProfile })(Admins) diff --git a/src/user/organization/popups/Members.js b/src/user/organization/popups/Members.js index 3c719e55..32cd5e11 100644 --- a/src/user/organization/popups/Members.js +++ b/src/user/organization/popups/Members.js @@ -83,7 +83,7 @@ class Members extends Component { mapHelper = (allMembers) => { let membersInfo = [] - if(allMembers.length > 0) { + if(allMembers && allMembers.length > 0) { allMembers.forEach((member) => { membersInfo.push({ name: member.name.firstName + ' ' + member.name.lastName, @@ -113,6 +113,15 @@ class Members extends Component { const { onHide, show } = this.props const { isAdmin, inviteLink, whoCanSendInvite } = this.state const membersList = [ ...this.state.members] + + const handleModalHide = () => { + this.setState({ + query: '' + }, () => { + onHide() + }) + } + let members = membersList.map((item) => (
@@ -142,7 +151,7 @@ class Members extends Component { )); return ( { + setProposalId(props.idContent) + }, [props.idContent]) const onDrop = useCallback((acceptedFiles) => { let formData = new FormData(); @@ -53,7 +57,7 @@ function StyledDropzone(props) { .catch((err) => { console.log(err); }); - }, []); + }, [proposalId]); const { getRootProps, diff --git a/src/user/proposals/ProposalEditor/EditorContent/EditorContent.js b/src/user/proposals/ProposalEditor/EditorContent/EditorContent.js index 587cc2d5..b686f1da 100644 --- a/src/user/proposals/ProposalEditor/EditorContent/EditorContent.js +++ b/src/user/proposals/ProposalEditor/EditorContent/EditorContent.js @@ -268,7 +268,7 @@ class EditorContent extends Component {
{!this.state.newProposal ? ( ) : (
diff --git a/src/utils/allowCredentialsInHeader.js b/src/utils/allowCredentialsInHeader.js new file mode 100644 index 00000000..40cbe676 --- /dev/null +++ b/src/utils/allowCredentialsInHeader.js @@ -0,0 +1,5 @@ +import axios from "axios"; + +export const allowCredentialsInHeader = () => { + axios.defaults.withCredentials = true; +} diff --git a/src/utils/setAuthToken.js b/src/utils/setAuthToken.js deleted file mode 100644 index 14fcec74..00000000 --- a/src/utils/setAuthToken.js +++ /dev/null @@ -1,12 +0,0 @@ -import axios from "axios"; - -export const setAuthToken = (token) => { - axios.defaults.withCredentials = true; - if(token){ - // set AUTHORIZATION in headers of all request - axios.defaults.headers.common['Authorization'] = token || localStorage.getItem("jwtToken"); - } else { - // delete from the headers - delete axios.defaults.headers.common['Authorization']; - } -}