Skip to content

Revert "fixes - #927" #1033

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 0 additions & 24 deletions src/actions/challenges.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
fetchChallengeTracks,
updateChallenge,
patchChallenge,
deleteChallenge as deleteChallengeAPI,
createChallenge as createChallengeAPI,
createResource as createResourceAPI,
deleteResource as deleteResourceAPI
Expand All @@ -39,9 +38,6 @@ import {
CREATE_CHALLENGE_PENDING,
CREATE_CHALLENGE_SUCCESS,
CREATE_CHALLENGE_FAILURE,
DELETE_CHALLENGE_PENDING,
DELETE_CHALLENGE_SUCCESS,
DELETE_CHALLENGE_FAILURE,
LOAD_CHALLENGE_RESOURCES
} from '../config/constants'
import { loadProject } from './projects'
Expand Down Expand Up @@ -271,26 +267,6 @@ export function partiallyUpdateChallengeDetails (challengeId, partialChallengeDe
}
}

export function deleteChallenge (challengeId) {
return async (dispatch) => {
dispatch({
type: DELETE_CHALLENGE_PENDING
})

return deleteChallengeAPI(challengeId).then((challenge) => {
return dispatch({
type: DELETE_CHALLENGE_SUCCESS,
challengeDetails: challenge
})
}).catch((error) => {
dispatch({
type: DELETE_CHALLENGE_FAILURE
})
throw error
})
}
}

export function loadTimelineTemplates () {
return async (dispatch) => {
const timelineTemplates = await fetchTimelineTemplates()
Expand Down
8 changes: 1 addition & 7 deletions src/components/ChallengeEditor/ChallengeEditor.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@
.actionButtons {
position: absolute;
top: 30px;
a,button {
a {
height: 40px;
}
}
Expand All @@ -251,13 +251,7 @@
}

.actionButtonsRight {
display: flex;
align-items: center;
right: 20px;

button {
margin-right: 20px;
}
}

.buttonContainer {
Expand Down
43 changes: 2 additions & 41 deletions src/components/ChallengeEditor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ class ChallengeEditor extends Component {
super(props)
this.state = {
isLaunch: false,
isDeleteLaunch: false,
isConfirm: false,
isClose: false,
isOpenAdvanceSettings: false,
Expand Down Expand Up @@ -122,8 +121,6 @@ class ChallengeEditor extends Component {
this.getAvailableTimelineTemplates = this.getAvailableTimelineTemplates.bind(this)
this.autoUpdateChallengeThrottled = _.throttle(this.validateAndAutoUpdateChallenge.bind(this), 3000) // 3s
this.updateResource = this.updateResource.bind(this)
this.onDeleteChallenge = this.onDeleteChallenge.bind(this)
this.deleteModalLaunch = this.deleteModalLaunch.bind(this)
}

componentDidMount () {
Expand All @@ -134,27 +131,6 @@ class ChallengeEditor extends Component {
this.resetChallengeData(this.setState.bind(this))
}

deleteModalLaunch () {
if (!this.state.isDeleteLaunch) {
this.setState({ isDeleteLaunch: true })
}
}

async onDeleteChallenge () {
const { deleteChallenge, challengeDetails, history } = this.props
try {
this.setState({ isSaving: true })
// Call action to delete the challenge
await deleteChallenge(challengeDetails.id)
this.setState({ isSaving: false })
this.resetModal()
history.push(`/projects/${challengeDetails.projectId}/challenges`)
} catch (e) {
const error = _.get(e, 'response.data.message', 'Unable to Delete the challenge')
this.setState({ isSaving: false, error })
}
}

/**
* Validates challenge and if its valid calling an autosave method
*
Expand Down Expand Up @@ -230,7 +206,7 @@ class ChallengeEditor extends Component {
}

resetModal () {
this.setState({ isLoading: false, isConfirm: false, isLaunch: false, error: null, isCloseTask: false, isDeleteLaunch: false })
this.setState({ isLoading: false, isConfirm: false, isLaunch: false, error: null, isCloseTask: false })
}

/**
Expand Down Expand Up @@ -1397,19 +1373,6 @@ class ChallengeEditor extends Component {
/>
</div>
}
{
this.state.isDeleteLaunch && !this.state.isConfirm && (
<ConfirmationModal
title='Confirm Delete'
message={`Do you want to delete "${challenge.name}"?`}
theme={theme}
isProcessing={isSaving}
errorMessage={this.state.error}
onCancel={this.resetModal}
onConfirm={this.onDeleteChallenge}
/>
)
}
{ showTimeline && (
<ChallengeScheduleField
templates={this.getAvailableTimelineTemplates()}
Expand Down Expand Up @@ -1463,7 +1426,6 @@ class ChallengeEditor extends Component {
</div>
<div className={styles.title}>{getTitle(isNew)}</div>
<div className={cn(styles.actionButtons, styles.actionButtonsRight)}>
{this.props.challengeDetails.status === 'New' && <PrimaryButton text={'Delete'} type={'danger'} onClick={this.deleteModalLaunch} />}
<PrimaryButton text={'Back'} type={'info'} submit link={`/projects/${projectDetail.id}/challenges`} />
</div>
<div className={styles.textRequired}>* Required</div>
Expand Down Expand Up @@ -1507,8 +1469,7 @@ ChallengeEditor.propTypes = {
updateChallengeDetails: PropTypes.func.isRequired,
createChallenge: PropTypes.func,
replaceResourceInRole: PropTypes.func,
partiallyUpdateChallengeDetails: PropTypes.func.isRequired,
deleteChallenge: PropTypes.func.isRequired
partiallyUpdateChallengeDetails: PropTypes.func.isRequired
}

export default withRouter(ChallengeEditor)
Original file line number Diff line number Diff line change
Expand Up @@ -257,31 +257,6 @@
}
}

.deleteButton {
height: 22px;
width: 86px;
border-radius: 11.5px;
display: flex;
justify-content: center;
align-items: center;
background-color: $tc-red;
border-color: $tc-red;
cursor: pointer;

span {
@include roboto;

font-size: 14px;
font-weight: 400;
line-height: 17px;
color: $white;
text-transform: capitalize;
display: flex;
justify-content: center;
align-items: center;
}
}

.icon {
vertical-align: bottom;
}
Expand Down
57 changes: 8 additions & 49 deletions src/components/ChallengesComponent/ChallengeCard/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,20 +96,14 @@ const getPhaseInfo = (c) => {
* @param onUpdateLaunch
* @returns {*}
*/
const hoverComponents = (challenge, onUpdateLaunch, deleteModalLaunch) => {
const hoverComponents = (challenge, onUpdateLaunch) => {
const communityAppUrl = `${COMMUNITY_APP_URL}/challenges/${challenge.id}`
const directUrl = `${DIRECT_PROJECT_URL}/contest/detail?projectId=${challenge.legacyId}`
const orUrl = `${ONLINE_REVIEW_URL}/review/actions/ViewProjectDetails?pid=${challenge.legacyId}`

// NEW projects never have Legacy challenge created, so don't show links and "Activate" button for them at all
if (challenge.status.toUpperCase() === CHALLENGE_STATUS.NEW) {
if (challenge.status.toUpperCase() === CHALLENGE_STATUS.NEW) {
return (
<button className={styles.deleteButton} onClick={deleteModalLaunch}>
<span>Delete</span>
</button>
)
}
return null
}

return challenge.legacyId ? (
Expand Down Expand Up @@ -183,13 +177,10 @@ class ChallengeCard extends React.Component {
this.state = {
isConfirm: false,
isLaunch: false,
isDeleteLaunch: false,
isSaving: false
}
this.onUpdateConfirm = this.onUpdateConfirm.bind(this)
this.onUpdateLaunch = this.onUpdateLaunch.bind(this)
this.onDeleteChallenge = this.onDeleteChallenge.bind(this)
this.deleteModalLaunch = this.deleteModalLaunch.bind(this)
this.resetModal = this.resetModal.bind(this)
this.onLaunchChallenge = this.onLaunchChallenge.bind(this)
}
Expand All @@ -204,14 +195,8 @@ class ChallengeCard extends React.Component {
}
}

deleteModalLaunch () {
if (!this.state.isDeleteLaunch) {
this.setState({ isDeleteLaunch: true })
}
}

resetModal () {
this.setState({ isConfirm: false, isLaunch: false, isDeleteLaunch: false })
this.setState({ isConfirm: false, isLaunch: false })
}

async onLaunchChallenge () {
Expand All @@ -231,39 +216,12 @@ class ChallengeCard extends React.Component {
}
}

async onDeleteChallenge () {
const { deleteChallenge, challenge } = this.props
try {
this.setState({ isSaving: true })
// Call action to delete the challenge
await deleteChallenge(challenge.id)
this.setState({ isSaving: false })
this.resetModal()
} catch (e) {
const error = _.get(e, 'response.data.message', 'Unable to Delete the challenge')
this.setState({ isSaving: false, error })
}
}

render () {
const { isLaunch, isConfirm, isSaving, isDeleteLaunch } = this.state
const { isLaunch, isConfirm, isSaving } = this.state
const { challenge, shouldShowCurrentPhase, reloadChallengeList } = this.props
const { phaseMessage, endTime } = getPhaseInfo(challenge)
return (
<div className={styles.item}>
{
isDeleteLaunch && !isConfirm && (
<ConfirmationModal
title='Confirm Delete'
message={`Do you want to delete "${challenge.name}"?`}
theme={theme}
isProcessing={isSaving}
errorMessage={this.state.error}
onCancel={this.resetModal}
onConfirm={this.onDeleteChallenge}
/>
)
}
{ isLaunch && !isConfirm && (
<ConfirmationModal
title='Confirm Launch'
Expand Down Expand Up @@ -305,7 +263,7 @@ class ChallengeCard extends React.Component {
<span className='block light-text'>{endTime}</span>
</Link>)}
<div className={cn(styles.col4, styles.editingContainer)}>
{hoverComponents(challenge, this.onUpdateLaunch, this.deleteModalLaunch)}
{hoverComponents(challenge, this.onUpdateLaunch, this.props.showError)}
</div>
<div className={cn(styles.col4, styles.iconsContainer)}>
<div className={styles.faIconContainer}>
Expand All @@ -324,15 +282,16 @@ class ChallengeCard extends React.Component {

ChallengeCard.defaultPrps = {
shouldShowCurrentPhase: true,
showError: () => {},
reloadChallengeList: () => {}
}

ChallengeCard.propTypes = {
challenge: PropTypes.object,
shouldShowCurrentPhase: PropTypes.bool,
showError: PropTypes.func,
reloadChallengeList: PropTypes.func,
partiallyUpdateChallengeDetails: PropTypes.func.isRequired,
deleteChallenge: PropTypes.func.isRequired
partiallyUpdateChallengeDetails: PropTypes.func.isRequired
}

export default withRouter(ChallengeCard)
8 changes: 3 additions & 5 deletions src/components/ChallengesComponent/ChallengeList/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,7 @@ class ChallengeList extends Component {
page,
perPage,
totalChallenges,
partiallyUpdateChallengeDetails,
deleteChallenge
partiallyUpdateChallengeDetails
} = this.props
if (warnMessage) {
return <Message warnMessage={warnMessage} />
Expand Down Expand Up @@ -212,9 +211,9 @@ class ChallengeList extends Component {
<ChallengeCard
shouldShowCurrentPhase={selectedTab === 0}
challenge={c}
showError={this.showError}
reloadChallengeList={this.reloadChallengeList}
partiallyUpdateChallengeDetails={partiallyUpdateChallengeDetails}
deleteChallenge={deleteChallenge}
/>
</li>
)
Expand Down Expand Up @@ -257,8 +256,7 @@ ChallengeList.propTypes = {
page: PropTypes.number.isRequired,
perPage: PropTypes.number.isRequired,
totalChallenges: PropTypes.number.isRequired,
partiallyUpdateChallengeDetails: PropTypes.func.isRequired,
deleteChallenge: PropTypes.func.isRequired
partiallyUpdateChallengeDetails: PropTypes.func.isRequired
}

export default ChallengeList
7 changes: 2 additions & 5 deletions src/components/ChallengesComponent/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ const ChallengesComponent = ({
page,
perPage,
totalChallenges,
partiallyUpdateChallengeDetails,
deleteChallenge
partiallyUpdateChallengeDetails
}) => {
return (
<Sticky top={10}>
Expand Down Expand Up @@ -87,7 +86,6 @@ const ChallengesComponent = ({
perPage={perPage}
totalChallenges={totalChallenges}
partiallyUpdateChallengeDetails={partiallyUpdateChallengeDetails}
deleteChallenge={deleteChallenge}
/>
)}
</div>
Expand All @@ -111,8 +109,7 @@ ChallengesComponent.propTypes = {
page: PropTypes.number.isRequired,
perPage: PropTypes.number.isRequired,
totalChallenges: PropTypes.number.isRequired,
partiallyUpdateChallengeDetails: PropTypes.func.isRequired,
deleteChallenge: PropTypes.func.isRequired
partiallyUpdateChallengeDetails: PropTypes.func.isRequired
}

ChallengesComponent.defaultProps = {
Expand Down
4 changes: 0 additions & 4 deletions src/config/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,6 @@ export const CREATE_CHALLENGE_SUCCESS = 'CREATE_CHALLENGE_SUCCESS'
export const CREATE_CHALLENGE_PENDING = 'CREATE_CHALLENGE_PENDING'
export const CREATE_CHALLENGE_FAILURE = 'CREATE_CHALLENGE_FAILURE'

export const DELETE_CHALLENGE_SUCCESS = 'DELETE_CHALLENGE_SUCCESS'
export const DELETE_CHALLENGE_PENDING = 'DELETE_CHALLENGE_PENDING'
export const DELETE_CHALLENGE_FAILURE = 'DELETE_CHALLENGE_FAILURE'

export const LOAD_PROJECT_DETAILS = 'LOAD_PROJECT_DETAILS'
export const LOAD_PROJECT_DETAILS_SUCCESS = 'LOAD_PROJECT_DETAILS_SUCCESS'
export const LOAD_PROJECT_DETAILS_PENDING = 'LOAD_PROJECT_DETAILS_PENDING'
Expand Down
Loading