Skip to content

The country value of Profile page get from lookup data #2332

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
Apr 25, 2019
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
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ exports[`renders a full Profile correctly 1`] = `
>
<ProfileHeader
copilot={true}
country="United States"
country=""
info={
Object {
"competitionCountryCode": "USA",
Expand Down Expand Up @@ -631,7 +631,7 @@ exports[`renders an empty Profile correctly 1`] = `
>
<ProfileHeader
copilot={false}
country="United States"
country=""
info={
Object {
"competitionCountryCode": "USA",
Expand Down
15 changes: 13 additions & 2 deletions src/shared/components/ProfilePage/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,12 @@ class ProfilePage extends React.Component {
const {
achievements,
copilot,
country,
externalAccounts,
externalLinks,
info,
skills: propSkills,
stats,
lookupData,
} = this.props;

const {
Expand All @@ -126,6 +126,17 @@ class ProfilePage extends React.Component {
skillsExpanded,
} = this.state;

// get country
let country = '';
if (_.has(lookupData, 'countries') && lookupData.countries.length > 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;
Expand Down Expand Up @@ -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;
5 changes: 5 additions & 0 deletions src/shared/containers/Profile.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ ProfileContainer.propTypes = {
profileForHandle: PT.string,
skills: PT.shape(),
stats: PT.shape(),
lookupData: PT.shape().isRequired,
};

const mapStateToProps = (state, ownProps) => ({
Expand All @@ -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());
Expand All @@ -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());
},
};
}
Expand Down