@@ -17,7 +17,8 @@ import {
17
17
DEFAULT_NDA_UUID ,
18
18
SUBMITTER_ROLE_UUID ,
19
19
CREATE_FORUM_TYPE_IDS ,
20
- MESSAGE
20
+ MESSAGE ,
21
+ COMMUNITY_APP_URL
21
22
} from '../../config/constants'
22
23
import { PrimaryButton , OutlineButton } from '../Buttons'
23
24
import TrackField from './Track-Field'
@@ -962,12 +963,41 @@ class ChallengeEditor extends Component {
962
963
challenge : newChallenge ,
963
964
isSaving : false } , cb )
964
965
} 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 } `
966
967
this . setState ( { isSaving : false , error } , cb )
967
968
}
968
969
} )
969
970
}
970
971
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
+
971
1001
async onActiveChallenge ( ) {
972
1002
this . updateAllChallengeInfo ( 'Active' )
973
1003
}
0 commit comments