Skip to content

Commit 0959f0d

Browse files
authored
Merge pull request #78 from topcoder-platform/develop
Adds confirm modal to Join Community button
2 parents fbacbec + b2bb7b4 commit 0959f0d

File tree

7 files changed

+124
-24
lines changed

7 files changed

+124
-24
lines changed
6.76 KB
Loading

src/server/tc-communities/wipro/metadata.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
}],
2121
"leaderboardApiUrl": "https://api.topcoder.com/v4/looks/0/run/json/",
2222
"logos": [
23-
"https://upload.wikimedia.org/wikipedia/commons/thumb/0/0e/Wipro_Logo_RGB.png/480px-Wipro_Logo_RGB.png",
23+
"/themes/wipro/wipro-logo.png",
2424
"/themes/wipro/logo_topcoder_with_name.svg"
2525
],
2626
"menuItems": [

src/shared/actions/tc-communities/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,7 @@ export default createActions({
1818
HIDE_JOIN_BUTTON: _.noop,
1919
JOIN_INIT: _.noop,
2020
JOIN_DONE: joinDone,
21+
RESET_JOIN_BUTTON: _.noop,
22+
SHOW_JOIN_CONFIRM_MODAL: _.noop,
2123
},
2224
});

src/shared/components/tc-communities/JoinCommunity/index.jsx

Lines changed: 43 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,48 +7,62 @@
77

88
/* global window */
99

10+
import _ from 'lodash';
1011
import config from 'utils/config';
1112
import LoadingIndicator from 'components/LoadingIndicator';
1213
import Modal from 'components/Modal';
1314
import PT from 'prop-types';
1415
import React from 'react';
1516
import style from './style.scss';
1617

18+
export const STATE = {
19+
CONFIRM_JOIN: 'confirm-join',
20+
DEFAULT: 'default',
21+
HIDDEN: 'hidden',
22+
JOINED: 'joined',
23+
JOINING: 'joining',
24+
};
25+
1726
export default function JoinCommunity({
18-
canJoin,
1927
communityName,
2028
groupId,
2129
hideJoinButton,
2230
join,
23-
joined,
24-
joining,
31+
resetJoinButton,
32+
showJoinConfirmModal,
33+
state,
2534
token,
2635
userId,
2736
}) {
28-
if (!canJoin) return <div styleName="placeholder" />;
37+
if (state === STATE.HIDDEN) return <div styleName="placeholder" />;
2938
return (
3039
<div>
3140
<button
3241
onClick={() => {
33-
if (joining || joined) return;
34-
if (token) join(token, groupId, userId);
42+
switch (state) {
43+
case STATE.JOINED:
44+
case STATE.JOINING:
45+
return;
46+
default:
47+
}
48+
if (token) showJoinConfirmModal();
3549
else {
3650
/* If our visitor is not authenticated, the button redirects to
3751
* login page, with return URL set back to this page. */
3852
const url = encodeURIComponent(window.location.href);
3953
window.location = `${config.URL.AUTH}?retUrl=${url}`;
4054
}
4155
}}
42-
styleName={`link ${joining ? 'joining' : ''}`}
56+
styleName={`link ${state === STATE.JOINING ? 'joining' : ''}`}
4357
>
44-
{ joining ? (
58+
{ state === STATE.JOINING ? (
4559
<div>
4660
<p>Joining...</p>
4761
<LoadingIndicator theme={{ style: style.loadingIndicator }} />
4862
</div>
4963
) : 'Join Community'}
5064
</button>
51-
{ joined ? (
65+
{ state === STATE.JOINED ? (
5266
<Modal onCancel={hideJoinButton}>
5367
<h1 styleName="modalTitle">Congratulations!</h1>
5468
<p styleName="modalMsg">You have joined {communityName}!</p>
@@ -58,6 +72,23 @@ export default function JoinCommunity({
5872
>Return to the Community</button>
5973
</Modal>
6074
) : null}
75+
{ state === STATE.CONFIRM_JOIN ? (
76+
<Modal onCancel={resetJoinButton}>
77+
<p styleName="confirmMsg">
78+
Are you sure you want to join {communityName}?
79+
</p>
80+
<div styleName="buttons">
81+
<button
82+
onClick={() => join(token, groupId, userId)}
83+
styleName="btnConfirm"
84+
>Join</button>
85+
<button
86+
onClick={resetJoinButton}
87+
styleName="btnCancel"
88+
>Cancel</button>
89+
</div>
90+
</Modal>
91+
) : null}
6192
</div>
6293
);
6394
}
@@ -69,13 +100,13 @@ JoinCommunity.defaultProps = {
69100
};
70101

71102
JoinCommunity.propTypes = {
72-
canJoin: PT.bool.isRequired,
73103
communityName: PT.string.isRequired,
74104
groupId: PT.string,
75105
hideJoinButton: PT.func.isRequired,
76106
join: PT.func.isRequired,
77-
joined: PT.bool.isRequired,
78-
joining: PT.bool.isRequired,
107+
resetJoinButton: PT.func.isRequired,
108+
showJoinConfirmModal: PT.func.isRequired,
109+
state: PT.oneOf(_.values(STATE)).isRequired,
79110
token: PT.string,
80111
userId: PT.string,
81112
};

src/shared/components/tc-communities/JoinCommunity/style.scss

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,58 @@
11
@import "~styles/tc-styles";
22

3+
@mixin button($color, $highlight-color) {
4+
color: $color;
5+
display: block;
6+
background: $tc-white;
7+
border: 1px solid $color;
8+
border-radius: 20px;
9+
font: 700 14px/40px 'Open Sans';
10+
margin: 24px auto;
11+
height: 40px;
12+
text-align: center;
13+
text-transform: uppercase;
14+
width: 171px;
15+
16+
&:hover,
17+
&:active,
18+
&:focus,
19+
&:visited {
20+
color: $color;
21+
outline: none;
22+
text-decoration: none;
23+
}
24+
25+
&:hover {
26+
background: $highlight-color;
27+
}
28+
}
29+
30+
.confirmMsg {
31+
@include tc-body;
32+
33+
text-align: center;
34+
}
35+
36+
.btnCancel {
37+
@include button($tc-light-blue, $tc-light-blue-10);
38+
39+
display: inline-block;
40+
margin: 24px 0 0 12px;
41+
width: 100px;
42+
}
43+
44+
.btnConfirm {
45+
@include button($tc-green, $tc-green-10);
46+
47+
display: inline-block;
48+
margin: 24px 12px 0 0;
49+
width: 100px;
50+
}
51+
52+
.buttons {
53+
text-align: center;
54+
}
55+
356
.done {
457
color: $tc-light-blue;
558
display: block;

src/shared/containers/tc-communities/JoinCommunity.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import _ from 'lodash';
22
import actions from 'actions/tc-communities';
3-
import JoinCommunity from 'components/tc-communities/JoinCommunity';
3+
import JoinCommunity, {
4+
STATE as JOIN_COMMUNITY,
5+
} from 'components/tc-communities/JoinCommunity';
46
import { connect } from 'react-redux';
57

68
function mapStateToProps(state) {
@@ -11,13 +13,14 @@ function mapStateToProps(state) {
1113
item.id === state.tcCommunities.meta.challengeGroupId);
1214
if (state.tcCommunities.hideJoinButton) canJoin = false;
1315

16+
if (canJoin) canJoin = state.tcCommunities.joinCommunityButton;
17+
else canJoin = JOIN_COMMUNITY.HIDDEN;
18+
1419
return {
15-
canJoin,
1620
communityName: state.tcCommunities.meta.communityName,
1721
groupId: state.tcCommunities.meta.challengeGroupId,
18-
joined: state.tcCommunities.joined,
19-
joining: state.tcCommunities.joining,
2022
token: state.auth.tokenV3,
23+
state: canJoin,
2124
userId: _.get(state.auth.user, 'userId'),
2225
};
2326
}
@@ -30,6 +33,8 @@ function mapDispatchToProps(dispatch) {
3033
dispatch(a.joinInit());
3134
dispatch(a.joinDone(...args));
3235
},
36+
resetJoinButton: () => dispatch(a.resetJoinButton()),
37+
showJoinConfirmModal: () => dispatch(a.showJoinConfirmModal()),
3338
};
3439
}
3540

src/shared/reducers/tc-communities/index.js

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import actions from 'actions/tc-communities';
99
import logger from 'utils/logger';
1010
import { handleActions } from 'redux-actions';
1111
import { combine, resolveReducers } from 'utils/redux';
12+
import { STATE as JOIN_COMMUNITY } from 'components/tc-communities/JoinCommunity';
1213

1314
import { factory as metaFactory } from './meta';
1415
import { factory as newsFactory } from './news';
@@ -22,21 +23,29 @@ function onJoinDone(state, action) {
2223
* to see it normally. */
2324
alert('Failed to join the group!'); // eslint-disable-line no-alert
2425

25-
return { ...state, joined: false, joining: false };
26+
return { ...state, joinCommunityButton: JOIN_COMMUNITY.DEFAULT };
2627
}
27-
return { ...state, joined: true };
28+
return { ...state, joinCommunityButton: JOIN_COMMUNITY.JOINED };
2829
}
2930

3031
function create(initialState = {}) {
3132
const a = actions.tcCommunity;
3233
return handleActions({
33-
[a.hideJoinButton]: state => ({ ...state, hideJoinButton: true }),
34-
[a.joinInit]: state => ({ ...state, joining: true }),
34+
[a.hideJoinButton]: state => ({
35+
...state, joinCommunityButton: JOIN_COMMUNITY.HIDDEN,
36+
}),
37+
[a.joinInit]: state => ({
38+
...state, joinCommunityButton: JOIN_COMMUNITY.JOINING,
39+
}),
3540
[a.joinDone]: onJoinDone,
41+
[a.resetJoinButton]: state => ({
42+
...state, joinCommunityButton: JOIN_COMMUNITY.DEFAULT,
43+
}),
44+
[a.showJoinConfirmModal]: state => ({
45+
...state, joinCommunityButton: JOIN_COMMUNITY.CONFIRM_JOIN,
46+
}),
3647
}, _.defaults(_.clone(initialState), {
37-
hideJoinButton: false,
38-
joined: false,
39-
joining: false,
48+
joinCommunityButton: JOIN_COMMUNITY.DEFAULT,
4049
}));
4150
}
4251

0 commit comments

Comments
 (0)