Skip to content

Commit 82c5747

Browse files
author
vikasrohit
authored
Merge pull request #980 from topcoder-platform/develop
Prod update - Terms link in error
2 parents 6da9e25 + e3de054 commit 82c5747

File tree

2 files changed

+48
-2
lines changed

2 files changed

+48
-2
lines changed

src/components/ChallengeEditor/ChallengeEditor.module.scss

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,3 +403,19 @@
403403
}
404404
}
405405

406+
ul.linkList {
407+
display: inline;
408+
margin: 0;
409+
padding: 0;
410+
411+
> li {
412+
display: inline;
413+
list-style: none;
414+
margin: 0;
415+
padding: 0;
416+
}
417+
418+
> li + li:before {
419+
content:',\0000a0'; /* Non-breaking space */
420+
}
421+
}

src/components/ChallengeEditor/index.js

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ import {
1717
DEFAULT_NDA_UUID,
1818
SUBMITTER_ROLE_UUID,
1919
CREATE_FORUM_TYPE_IDS,
20-
MESSAGE
20+
MESSAGE,
21+
COMMUNITY_APP_URL
2122
} from '../../config/constants'
2223
import { PrimaryButton, OutlineButton } from '../Buttons'
2324
import TrackField from './Track-Field'
@@ -962,12 +963,41 @@ class ChallengeEditor extends Component {
962963
challenge: newChallenge,
963964
isSaving: false }, cb)
964965
} catch (e) {
965-
const error = _.get(e, 'response.data.message', `Unable to update the challenge to status ${status}`)
966+
const error = this.formatResponseError(e) || `Unable to update the challenge to status ${status}`
966967
this.setState({ isSaving: false, error }, cb)
967968
}
968969
})
969970
}
970971

972+
/**
973+
* Format the error we might get from some API endpoint.
974+
*
975+
* @param {Error} error error
976+
*
977+
* @returns {import('react').ReactNode}
978+
*/
979+
formatResponseError (error) {
980+
const errorMessage = _.get(error, 'response.data.message')
981+
const errorMetadata = _.get(error, 'response.data.metadata')
982+
983+
if (errorMetadata.missingTerms && errorMetadata.missingTerms.length > 0) {
984+
return <>
985+
{errorMessage}
986+
<ul className={styles.linkList}>{' '}
987+
{errorMetadata.missingTerms.map((terms, index) => {
988+
const termsNumber = errorMetadata.missingTerms.length > 1 ? ` ${index + 1}` : ''
989+
return (
990+
<li key={index}><a href={`${COMMUNITY_APP_URL}/challenges/terms/detail/${terms.termId}`} target='_blank'>link to terms{termsNumber}</a></li>
991+
)
992+
})}
993+
</ul>
994+
</>
995+
}
996+
997+
// if no special error data, just use message
998+
return errorMessage
999+
}
1000+
9711001
async onActiveChallenge () {
9721002
this.updateAllChallengeInfo('Active')
9731003
}

0 commit comments

Comments
 (0)