Skip to content

Commit b73a906

Browse files
committed
pagination, login control, name control
1 parent 818073c commit b73a906

File tree

12 files changed

+146
-53
lines changed

12 files changed

+146
-53
lines changed

src/actions/eventAction.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,20 @@ import { errorHandler } from '../utils/errorHandler';
33
import { setRequestStatus } from '../utils/setRequestStatus';
44
import { GET_ALL_EVENTS, GET_EVENT_BY_ID } from './types';
55
import { BASE_URL } from './baseApi'
6+
import { customErrorHandler } from '../utils/customErrorHandler';
67

78
// DELETE EVENT REQUEST
89
export const deleteEvent = (eventId) => async (dispatch) => {
910
try {
1011
const res = await axios.delete(`${BASE_URL}/event/${eventId}`)
11-
dispatch(setRequestStatus(false));
1212
if(res.status === 200){
13-
dispatch(setRequestStatus(true));
1413
dispatch(getAllEvents())
1514
}
1615
} catch(error) {
17-
dispatch(errorHandler(error))
16+
const msg = {
17+
error: error?.response?.msg
18+
}
19+
dispatch(customErrorHandler(msg))
1820
}
1921
}
2022

src/actions/orgAction.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ import {
66
UPDATE_ORG_PROFILE,
77
DEACTIVATE_ORG,
88
GET_ALL_MEMBERS,
9-
TRIGGER_MAINTENANCE
9+
TRIGGER_MAINTENANCE,
10+
GET_LOGIN_OPTIONS
1011
} from './types'
1112

1213
import { BASE_URL } from './baseApi'
@@ -149,4 +150,20 @@ export const TriggerMaintenance = () => async (dispatch) => {
149150
} catch (error) {
150151
dispatch(errorHandler(error))
151152
}
153+
}
154+
155+
// GET LOGIN OPTIONS
156+
export const getLoginOptions = () => async (dispatch) => {
157+
try {
158+
const res = await axios.get(`${BASE_URL}/org/login/options`)
159+
if(res.status === 200) {
160+
console.log('fetched login options ', res.data)
161+
dispatch({
162+
type: GET_LOGIN_OPTIONS,
163+
payload: res.data.methods
164+
})
165+
}
166+
} catch(error) {
167+
dispatch(errorHandler(error))
168+
}
152169
}

src/actions/types.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,5 @@ export const GET_DEVICE_ANALYTICS ="GET_DEVICE_ANALYTICS"
5151
export const GET_MOSTVIEWED_ANALYTICS ="GET_MOSTVIEWED_ANALYTICS"
5252
export const GET_PROPOSALVIEW_ANALYTICS="GET_PROPOSALVIEW_ANALYTICS"
5353
export const ACTIVATE_DEACTIVATE_ACCOUNT_TOGGLER = "ACTIVATE_DEACTIVATE_ACCOUNT_TOGGLER";
54-
export const CLEAR_INVITE_LINK = "CLEAR_INVITE_LINK"
54+
export const CLEAR_INVITE_LINK = "CLEAR_INVITE_LINK";
55+
export const GET_LOGIN_OPTIONS = "GET_LOGIN_OPTIONS";

src/actions/usersAction.js

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,12 @@ export const getProfile = (id) => async (dispatch)=> {
3131
// FOLLOW USER
3232
export const followUser = (userId) => async (dispatch) => {
3333
try {
34-
let followObj = {
35-
followId: userId
36-
}
37-
console.log('followObj ', followObj)
38-
const res = await axios.patch(`${BASE_URL}/user/follow`, followObj)
34+
console.log('followuser ', userId)
35+
const res = await axios.patch(`${BASE_URL}/user/follow/${userId}`)
3936
dispatch(setRequestStatus(false))
4037
if (res.status === 200) {
4138
dispatch(setRequestStatus(true))
42-
console.log('started following ', followObj)
39+
console.log('started following ', userId)
4340
dispatch({
4441
type: GET_USER_PROFILE,
4542
payload: res.data.user,
@@ -53,15 +50,12 @@ export const followUser = (userId) => async (dispatch) => {
5350
// UnFOLLOW USER
5451
export const unFollowUser = (userId) => async (dispatch) => {
5552
try {
56-
let unFollowObj = {
57-
followId: userId
58-
}
59-
console.log('unfollowObj ', unFollowObj)
60-
const res = await axios.patch(`${BASE_URL}/user/unfollow`, unFollowObj)
53+
console.log('unfollowObj ', userId)
54+
const res = await axios.patch(`${BASE_URL}/user/unfollow/${userId}`)
6155
dispatch(setRequestStatus(false))
6256
if (res.status === 200) {
6357
dispatch(setRequestStatus(true))
64-
console.log('unfollowed ', unFollowObj)
58+
console.log('unfollowed ', userId)
6559
dispatch({
6660
type: GET_USER_PROFILE,
6761
payload: res.data.user,

src/reducers/orgReducer.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import { GET_ORG_PROFILE, UPDATE_ORG_PROFILE, DEACTIVATE_ORG, TRIGGER_MAINTENANCE } from '../actions/types'
1+
import { GET_ORG_PROFILE, UPDATE_ORG_PROFILE, DEACTIVATE_ORG, TRIGGER_MAINTENANCE, GET_LOGIN_OPTIONS } from '../actions/types'
22
const initialState = {
33
isDeactivated: false,
44
isMaintenance: false,
5-
org: {}
5+
org: {},
6+
loginOptions: {}
67
}
78

89
export default (state = initialState, action) => {
@@ -31,6 +32,12 @@ export default (state = initialState, action) => {
3132
isDeactivated: action.payload
3233
}
3334
}
35+
case GET_LOGIN_OPTIONS: {
36+
return {
37+
...state,
38+
loginOptions: action.payload
39+
}
40+
}
3441
default: {
3542
return state
3643
}

src/user/Activity/Users.js

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { connect } from 'react-redux';
77
import Moment from 'react-moment'
88
import { Pagination } from 'antd'
99
import { withRouter } from 'react-router-dom'
10+
import Img from '../../assets/images/userIcon2.jpg'
1011

1112
class Users extends Component {
1213
constructor(props) {
@@ -55,13 +56,18 @@ class Users extends Component {
5556
key={index}
5657
onClick={() => this.props.history.push(`/activity/${user._id}`)}
5758
>
58-
<p className="activity__link">
59-
{user.name.firstName + " " + user.name.lastName}
60-
</p>
61-
<p className="joined__on">
62-
Joined on:{" "}
63-
<Moment format="DD MMM YYYY">{user.createdAt}</Moment>
64-
</p>
59+
<div className="user__wrapper">
60+
<img src={Img} alt="user_image" className="user__image mr-2"/>
61+
<div className="name_wrapper">
62+
<p className="activity__link">
63+
{user.name.firstName + " " + user.name.lastName}
64+
</p>
65+
<p className="joined__on">
66+
Joined on:{" "}
67+
<Moment format="DD MMM YYYY">{user.createdAt}</Moment>
68+
</p>
69+
</div>
70+
</div>
6571
</Timeline.Item>
6672
))}
6773
</Timeline>

src/user/Activity/users.scss

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,37 @@
2929
display: flex;
3030
flex-direction: row;
3131
flex-wrap: wrap;
32-
.activity__link {
33-
color: #1a73ed;
34-
font-family: "Inter";
35-
font-size: 14px;
36-
cursor: pointer;
37-
&:hover {
38-
text-decoration: underline;
39-
}
40-
}
41-
.joined__on {
42-
margin-top: -14px;
43-
color: #cccccc;
44-
}
4532
.pagination__container {
4633
position: fixed;
4734
margin-top: 78vh;
4835
}
36+
.user__wrapper {
37+
display: flex;
38+
flex-direction: row;
39+
max-height: 52px;
40+
.user__image {
41+
border-radius: 50%;
42+
height: 37px;
43+
width: 36px;
44+
}
45+
.name_wrapper {
46+
.activity__link {
47+
color: #1a73ed;
48+
font-family: "Inter";
49+
font-size: 14px;
50+
cursor: pointer;
51+
52+
&:hover {
53+
text-decoration: underline;
54+
}
55+
}
56+
.joined__on {
57+
color: #cccccc;
58+
margin-top: -15px;
59+
&:hover {
60+
text-decoration: underline;
61+
}
62+
}
63+
}
64+
}
4965
}

src/user/auth/login/login.js

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,40 @@ import { DonutTitle } from "../../../donutTitle/donutTitle";
66
import multipleDonuts from "../../../assets/images/extra-donuts.png";
77
import GoogleLogin from "../../../assets/images/icons8-google-48.png";
88
import { FaGithub } from 'react-icons/fa'
9+
import { connect } from 'react-redux';
10+
import { getLoginOptions } from '../../../actions/orgAction'
911
import "./login.scss";
1012

1113
class Login extends Component {
1214
constructor(props) {
1315
super(props);
1416
this.state = {
1517
activeForm: "login",
18+
loginOptions: {}
1619
};
1720
}
21+
22+
// get login options
23+
componentDidMount() {
24+
this.props.getLoginOptions()
25+
}
26+
27+
componentDidUpdate(prevProps, prevState) {
28+
if(prevState.loginOptions != this.props.org?.loginOptions){
29+
this.setState({
30+
loginOptions: this.props.org?.loginOptions
31+
})
32+
}
33+
}
34+
1835
handleSelectorClick = (formItem) => {
1936
this.setState({
2037
activeForm: formItem,
2138
});
2239
};
2340

2441
render() {
42+
const { loginOptions } = this.state
2543
return (
2644
<div className="login-page">
2745
<div className="welcome-text">
@@ -58,7 +76,8 @@ class Login extends Component {
5876
: "Or SignUp with"}
5977
</p>
6078
<Row>
61-
<Col className = "button-column">
79+
{Boolean(loginOptions?.google === true) ? (
80+
<Col className = "button-column">
6281
<a
6382
href="http://localhost:5000/auth/google"
6483
style={{ padding: "1vh" }}
@@ -76,7 +95,9 @@ class Login extends Component {
7695
</Button>
7796
</a>
7897
</Col>
79-
<Col className="button-column" >
98+
) : null }
99+
{Boolean(loginOptions?.github === true) ? (
100+
<Col className="button-column" >
80101
<a
81102
href="http://localhost:5000/auth/google"
82103
style={{ padding: "1vh" }}
@@ -94,6 +115,7 @@ class Login extends Component {
94115
</Button>
95116
</a>
96117
</Col>
118+
) : null }
97119
</Row>
98120
<p className="login-text-selector">
99121
{this.state.activeForm === "login"
@@ -123,4 +145,9 @@ class Login extends Component {
123145
}
124146
}
125147

126-
export default Login;
148+
// map state to props
149+
const mapStateToProps = (state) => ({
150+
org: state.org
151+
})
152+
153+
export default connect(mapStateToProps, { getLoginOptions })(Login);

src/user/dashboard/Community/CommunitySetting.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class CommunitySetting extends Component {
4040
return (
4141
<div className="overall_container">
4242
<div className="main_navigation">
43-
<Navigation orgSettings={this.state.org} />
43+
<Navigation orgSettings={this.state.org} user={this.props.user} />
4444
</div>
4545
<div className="org_settings_view">
4646
<div className="main_section">
@@ -71,6 +71,7 @@ class CommunitySetting extends Component {
7171
const mapStateToProps = (state) => ({
7272
auth: state.auth,
7373
error: state.error,
74+
user: state.user,
7475
org: state.org
7576
})
7677
export default connect(mapStateToProps)(CommunitySetting);

src/user/dashboard/Community/components/OrgPermission.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class OrgPermission extends Component {
2424
}
2525

2626
toggleRadio = (e) => {
27-
this.setState({ [e.target.name]: e.target.checked }, () => {
27+
this.setState({ [e.target.name]: !e.target.checked }, () => {
2828
console.log("state ", this.state);
2929
});
3030
};
@@ -124,7 +124,7 @@ class OrgPermission extends Component {
124124
<Form.Check
125125
type="checkbox"
126126
label="Prevent users from changing their name"
127-
checked={canChangeName}
127+
checked={canChangeName === false}
128128
name="canChangeName"
129129
onChange={this.toggleRadio}
130130
/>
@@ -133,7 +133,7 @@ class OrgPermission extends Component {
133133
<Form.Check
134134
type="checkbox"
135135
label="Prevent users from changing their email address "
136-
checked={canChangeEmail}
136+
checked={canChangeEmail === false}
137137
name="canChangeEmail"
138138
onChange={this.toggleRadio}
139139
/>

src/user/dashboard/navigation/navigation.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ class Navigation extends Component {
2828
userId: nextProps.user.userProfile?._id
2929
})
3030
}
31+
32+
3133
render() {
3234
const ListItem = (props) => {
3335
const item = props.isMobile ? (
@@ -108,7 +110,7 @@ class Navigation extends Component {
108110
<ListItem
109111
name="Account"
110112
className={this.props.profile ? "active" : "inactive"}
111-
link={`/profile/${this.state.userId}`}
113+
link={`/profile/${this.state.userId || this.props.user.userProfile._id}`}
112114
/>
113115
<ListItem
114116
name="Settings"

0 commit comments

Comments
 (0)