From f5486cc1c048e4531a44048771673ad87933e5f2 Mon Sep 17 00:00:00 2001 From: Huan Li Date: Thu, 25 Apr 2019 16:32:43 +0800 Subject: [PATCH] The country value of Profile page get from lookup data --- .../ProfilePage/__snapshots__/index.jsx.snap | 4 ++-- src/shared/components/ProfilePage/index.jsx | 15 +++++++++++++-- src/shared/containers/Profile.jsx | 5 +++++ 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/__tests__/shared/components/ProfilePage/__snapshots__/index.jsx.snap b/__tests__/shared/components/ProfilePage/__snapshots__/index.jsx.snap index a2770cdecd..054508c19b 100644 --- a/__tests__/shared/components/ProfilePage/__snapshots__/index.jsx.snap +++ b/__tests__/shared/components/ProfilePage/__snapshots__/index.jsx.snap @@ -28,7 +28,7 @@ exports[`renders a full Profile correctly 1`] = ` > 0) { + const countryCode = _.isEmpty(_.get(info, 'homeCountryCode')) + ? _.get(info, 'competitionCountryCode') : _.get(info, 'homeCountryCode'); + + const result = _.find(lookupData.countries, + c => c.countryCode === countryCode.toUpperCase()); + country = _.isEmpty(result) ? '' : result.country; + } + // Convert skills from object to an array for easier iteration let skills = propSkills ? _.map(propSkills, (skill, tagId) => ({ tagId, ...skill })) : []; const showMoreButton = skills.length > MAX_SKILLS; @@ -286,12 +297,12 @@ ProfilePage.defaultProps = { ProfilePage.propTypes = { achievements: PT.arrayOf(PT.shape()), copilot: PT.bool.isRequired, - country: PT.string.isRequired, externalAccounts: PT.shape().isRequired, externalLinks: PT.arrayOf(PT.shape()).isRequired, info: PT.shape().isRequired, skills: PT.shape(), stats: PT.shape(), + lookupData: PT.shape().isRequired, }; export default ProfilePage; diff --git a/src/shared/containers/Profile.jsx b/src/shared/containers/Profile.jsx index 631ec4c77e..bbf8981b48 100644 --- a/src/shared/containers/Profile.jsx +++ b/src/shared/containers/Profile.jsx @@ -93,6 +93,7 @@ ProfileContainer.propTypes = { profileForHandle: PT.string, skills: PT.shape(), stats: PT.shape(), + lookupData: PT.shape().isRequired, }; const mapStateToProps = (state, ownProps) => ({ @@ -107,10 +108,12 @@ const mapStateToProps = (state, ownProps) => ({ profileForHandle: state.profile.profileForHandle, skills: state.profile.skills, stats: state.profile.stats, + lookupData: state.lookup, }); function mapDispatchToProps(dispatch) { const a = actions.profile; + const lookupActions = actions.lookup; return { loadProfile: (handle) => { dispatch(a.clearProfile()); @@ -121,12 +124,14 @@ function mapDispatchToProps(dispatch) { dispatch(a.getInfoInit()); dispatch(a.getSkillsInit()); dispatch(a.getStatsInit()); + dispatch(lookupActions.getCountriesInit()); dispatch(a.getAchievementsV3Done(handle)); dispatch(a.getExternalAccountsDone(handle)); dispatch(a.getExternalLinksDone(handle)); dispatch(a.getInfoDone(handle)); dispatch(a.getSkillsDone(handle)); dispatch(a.getStatsDone(handle)); + dispatch(lookupActions.getCountriesDone()); }, }; }