Skip to content

Commit 25f705b

Browse files
authored
Merge pull request #1199 from yoution/issue-1174
fix: issue #1174
2 parents 879b8bf + 59bab10 commit 25f705b

File tree

5 files changed

+37
-20
lines changed

5 files changed

+37
-20
lines changed

src/components/ChallengeEditor/Cancel-Dropdown/Cancel-DropDown.module.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
box-shadow: 0 1px 5px #ccc;
1313
background-clip: padding-box;
1414
border: 1px solid #ccc;
15+
cursor: pointer;
1516

1617
.menu {
1718
height: 30px;
@@ -23,6 +24,10 @@
2324
}
2425
}
2526

27+
.pop-container {
28+
height: 100%;
29+
}
30+
2631
.modalContainer {
2732
padding: 0;
2833
position: fixed;
Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,26 @@
1-
import React, { useState } from 'react'
1+
import React, { useState, useRef } from 'react'
22
import PropTypes from 'prop-types'
3-
import { withRouter } from 'react-router-dom'
43
import Dropdown from 'rc-dropdown'
54
import styles from './Cancel-DropDown.module.scss'
65
import { CANCEL_REASONS } from '../../../config/constants'
76
import cn from 'classnames'
87
import 'rc-dropdown/assets/index.css'
98
import { PrimaryButton } from '../../Buttons'
109
import ConfirmationModal from '../../Modal/ConfirmationModal'
11-
import { patchChallenge } from '../../../services/challenges'
1210
import _ from 'lodash'
1311

1412
const theme = {
1513
container: styles.modalContainer
1614
}
17-
const CancelDropDown = ({ challenge, history }) => {
15+
const CancelDropDown = ({ challenge, onSelectMenu }) => {
1816
const [cancelReason, setCancelReason] = useState('')
1917
const [showModal, setShowModal] = useState(false)
18+
const popupContainerEl = useRef(null)
2019

2120
const onSelect = v => {
2221
setCancelReason(v)
2322
setShowModal(true)
2423
}
25-
const onConfirm = async () => {
26-
await patchChallenge(challenge.id, {
27-
status: cancelReason
28-
})
29-
30-
history.push(`/projects/${challenge.projectId}/challenges`)
31-
}
3224

3325
const menu = (
3426
<div className={cn(styles['menus'])}>
@@ -49,20 +41,23 @@ const CancelDropDown = ({ challenge, history }) => {
4941

5042
return (
5143
<>
52-
<Dropdown trigger={['click']} overlay={menu} animation='slide-up'>
53-
<PrimaryButton text={'Cancel'} type={'danger'} />
44+
<Dropdown trigger={['click']} overlay={menu} animation='slide-up' getPopupContainer={() => {
45+
return popupContainerEl.current
46+
}}>
47+
<div ref={popupContainerEl} className={styles['pop-container']}>
48+
<PrimaryButton text={'Cancel'} type={'danger'} />
49+
</div>
5450
</Dropdown>
5551
{showModal && (
5652
<ConfirmationModal
57-
// title='Reminder'
5853
message={'Do you want to cancel the challenge ?'}
5954
theme={theme}
6055
cancelText='Cancel'
6156
confirmText='Continue'
6257
onCancel={() => {
6358
setShowModal(false)
6459
}}
65-
onConfirm={onConfirm}
60+
onConfirm={() => { onSelectMenu(challenge, cancelReason) }}
6661
/>
6762
)}
6863
</>
@@ -73,7 +68,7 @@ CancelDropDown.defaultProps = {}
7368

7469
CancelDropDown.propTypes = {
7570
challenge: PropTypes.shape().isRequired,
76-
history: PropTypes.shape()
71+
onSelectMenu: PropTypes.func.isRequired
7772
}
7873

79-
export default withRouter(CancelDropDown)
74+
export default CancelDropDown

src/components/ChallengeEditor/ChallengeViewTabs/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ const ChallengeViewTabs = ({
4040
assignedMemberDetails,
4141
enableEdit,
4242
onLaunchChallenge,
43+
cancelChallenge,
4344
onCloseTask
4445
}) => {
4546
const [selectedTab, setSelectedTab] = useState(0)
@@ -99,7 +100,7 @@ const ChallengeViewTabs = ({
99100
styles.actionButtonsRight
100101
)}
101102
>
102-
{(challenge.status === 'Draft' || challenge.status === 'New') && <div className={styles['cancel-button']}><CancelDropDown challenge={challenge} /></div>}
103+
{(challenge.status === 'Draft' || challenge.status === 'New') && <div className={styles['cancel-button']}><CancelDropDown challenge={challenge} onSelectMenu={cancelChallenge} /></div>}
103104
{challenge.status === 'Draft' && (
104105
<div className={styles.button}>
105106
{challenge.legacyId || isTask ? (
@@ -232,6 +233,7 @@ ChallengeViewTabs.propTypes = {
232233
assignedMemberDetails: PropTypes.shape(),
233234
enableEdit: PropTypes.bool,
234235
onLaunchChallenge: PropTypes.func,
236+
cancelChallenge: PropTypes.func.isRequired,
235237
onCloseTask: PropTypes.func
236238
}
237239

src/components/ChallengeEditor/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1204,6 +1204,7 @@ class ChallengeEditor extends Component {
12041204
uploadAttachments,
12051205
token,
12061206
removeAttachment,
1207+
cancelChallenge,
12071208
failedToLoad,
12081209
errorMessage,
12091210
projectDetail,
@@ -1408,7 +1409,7 @@ class ChallengeEditor extends Component {
14081409
</div>
14091410
)}
14101411
<div className={styles.button}>
1411-
<CancelDropDown challenge={challenge} />
1412+
<CancelDropDown challenge={challenge} onSelectMenu={cancelChallenge} />
14121413
</div>
14131414
</div>}
14141415
{!isLoading && isActive && <div className={styles.buttonContainer}>
@@ -1639,6 +1640,7 @@ ChallengeEditor.propTypes = {
16391640
metadata: PropTypes.object.isRequired,
16401641
isLoading: PropTypes.bool.isRequired,
16411642
uploadAttachments: PropTypes.func.isRequired,
1643+
cancelChallenge: PropTypes.func.isRequired,
16421644
removeAttachment: PropTypes.func.isRequired,
16431645
attachments: PropTypes.arrayOf(PropTypes.shape()),
16441646
token: PropTypes.string.isRequired,

src/containers/ChallengeEditor/index.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ class ChallengeEditor extends Component {
5757
}
5858

5959
this.onLaunchChallenge = this.onLaunchChallenge.bind(this)
60+
this.cancelChallenge = this.cancelChallenge.bind(this)
6061
this.activateChallenge = this.activateChallenge.bind(this)
6162
this.closeLaunchModal = this.closeLaunchModal.bind(this)
6263
this.closeCloseTaskModal = this.closeCloseTaskModal.bind(this)
@@ -190,6 +191,15 @@ class ChallengeEditor extends Component {
190191
}
191192
}
192193

194+
async cancelChallenge (challenge, cancelReason) {
195+
const { partiallyUpdateChallengeDetails, history } = this.props
196+
197+
await partiallyUpdateChallengeDetails(challenge.id, {
198+
status: cancelReason
199+
})
200+
history.push(`/projects/${challenge.projectId}/challenges`)
201+
}
202+
193203
onCloseTask () {
194204
this.setState({ showCloseTaskModal: true })
195205
}
@@ -395,6 +405,7 @@ class ChallengeEditor extends Component {
395405
isBillingAccountExpired={isBillingAccountExpired}
396406
challengeResources={challengeResources}
397407
metadata={metadata}
408+
cancelChallenge={this.cancelChallenge}
398409
projectId={_.get(match.params, 'projectId', null)}
399410
challengeId={challengeId}
400411
isNew={!_.has(match.params, 'challengeId')}
@@ -429,6 +440,7 @@ class ChallengeEditor extends Component {
429440
challengeDetails={challengeDetails}
430441
challengeResources={challengeResources}
431442
metadata={metadata}
443+
cancelChallenge={this.cancelChallenge}
432444
projectId={_.get(match.params, 'projectId', null)}
433445
challengeId={challengeId}
434446
isNew={!_.has(match.params, 'challengeId')}
@@ -461,6 +473,7 @@ class ChallengeEditor extends Component {
461473
projectDetail={projectDetail}
462474
challengeSubmissions={challengeSubmissions}
463475
challenge={challengeDetails}
476+
cancelChallenge={this.cancelChallenge}
464477
attachments={attachments}
465478
challengeResources={challengeResources}
466479
token={token}
@@ -503,7 +516,7 @@ ChallengeEditor.propTypes = {
503516
isProjectLoading: PropTypes.bool,
504517
hasProjectAccess: PropTypes.bool,
505518
projectDetail: PropTypes.object,
506-
// history: PropTypes.object,
519+
history: PropTypes.object,
507520
metadata: PropTypes.shape({
508521
challengeTypes: PropTypes.array
509522
}),

0 commit comments

Comments
 (0)