@@ -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'
2223import { PrimaryButton , OutlineButton } from '../Buttons'
2324import 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