Skip to content
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

feat: add bio component to profile page #54285

Merged
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions client/i18n/locales/english/translations.json
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@
"tweet": "I just earned the {{certTitle}} certification @freeCodeCamp! Check it out here: {{certURL}}",
"avatar": "{{username}}'s avatar",
"joined": "Joined {{date}}",
"from": "From {{location}}",
"total-points": "Total Points:",
"points": "{{count}} point on {{date}}",
"points_plural": "{{count}} points on {{date}}",
Expand Down
486 changes: 270 additions & 216 deletions client/src/components/profile/__snapshots__/profile.test.tsx.snap

Large diffs are not rendered by default.

67 changes: 67 additions & 0 deletions client/src/components/profile/components/bio.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import React from 'react';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faCalendar, faLocationDot } from '@fortawesome/free-solid-svg-icons';
import { useTranslation } from 'react-i18next';
import { useSelector } from 'react-redux';
import { userSelector } from '../../../redux/selectors';
import { User } from '../../../redux/prop-types';
import { AvatarRenderer, FullWidthRow, Spacer } from '../../helpers';
import { parseDate } from './utils';
import SocialIcons from './social-icons';

const Bio = () => {
const { t } = useTranslation();
const {
joinDate,
location,
username,
name,
about,
githubProfile,
linkedin,
twitter,
website,
isDonating,
yearsTopContributor,
picture
} = useSelector(userSelector) as User;

return (
<FullWidthRow>
<div className='avatar-camper'>
<AvatarRenderer
isDonating={isDonating}
isTopContributor={yearsTopContributor.length > 0}
picture={picture}
/>
</div>
<h1>@{username}</h1>
{name && <h2>{name}</h2>}
<Spacer size={'small'} />
{about && <p>{about}</p>}
<div className='profile-meta-container'>
{joinDate && (
<div>
<FontAwesomeIcon icon={faCalendar} />
<span>{parseDate(joinDate, t)}</span>
</div>
)}
{location && (
<div>
<FontAwesomeIcon icon={faLocationDot} />
<span>{t('profile.from', { location })}</span>
</div>
)}
</div>
<SocialIcons
githubProfile={githubProfile}
linkedin={linkedin}
twitter={twitter}
username={username}
website={website}
/>
<hr />
</FullWidthRow>
);
};
export default Bio;
26 changes: 25 additions & 1 deletion client/src/components/profile/components/camper.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

.avatar-camper {
display: flex;
justify-content: center;
}

.avatar-camper .avatar {
Expand All @@ -29,3 +28,28 @@
width: auto;
margin: 0 0.2em -0.3em 0.2em;
}

.profile-meta-container {
display: flex;
flex-direction: row;
margin-bottom: 2rem;
color: var(--quaternary-color);
}

.profile-meta-container div {
margin-inline-end: 12px;
}

.profile-meta-container svg {
margin-inline-end: 4px;
}

.social-icons-row a {
display: inline-block;
margin-inline-end: 12px;
color: var(--quaternary-color);
}

.bio-container h2 {
color: var(--quaternary-color);
}
59 changes: 6 additions & 53 deletions client/src/components/profile/components/camper.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import { faAward, faCalendar } from '@fortawesome/free-solid-svg-icons';
import { faAward } from '@fortawesome/free-solid-svg-icons';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import React from 'react';
import { useTranslation } from 'react-i18next';
import { Col, Row } from '@freecodecamp/ui';
import type { User } from '../../../redux/prop-types';
import { AvatarRenderer } from '../../helpers';
import Link from '../../helpers/link';
import SupporterBadge from '../../../assets/icons/supporter-badge';
import SocialIcons from './social-icons';
import { formatYears, parseDate } from './utils';
import { formatYears } from './utils';
import './camper.css';
import Bio from './bio';

export type CamperProps = Pick<
User,
Expand All @@ -27,56 +24,12 @@ export type CamperProps = Pick<
| 'joinDate'
>;

function Camper({
name,
username,
location,
picture,
about,
yearsTopContributor,
githubProfile,
isDonating,
joinDate,
linkedin,
twitter,
website
}: CamperProps): JSX.Element {
function Camper({ yearsTopContributor }: CamperProps): JSX.Element {
const { t } = useTranslation();

return (
<div>
<Row>
<Col className='avatar-camper' xs={12}>
<AvatarRenderer
isDonating={isDonating}
isTopContributor={yearsTopContributor.length > 0}
picture={picture}
/>
</Col>
</Row>
<SocialIcons
githubProfile={githubProfile}
linkedin={linkedin}
twitter={twitter}
username={username}
website={website}
/>
<br />
<h2 className='text-center username'>@{username}</h2>
{name && <p className='text-center name'>{name}</p>}
{location && <p className='text-center location'>{location}</p>}
{isDonating && (
<p className='text-center supporter'>
<SupporterBadge />
{t('profile.supporter')}
</p>
)}
{about && <p className='bio text-center'>{about}</p>}
{joinDate && (
<p className='bio text-center'>
<FontAwesomeIcon icon={faCalendar} /> {parseDate(joinDate, t)}
</p>
)}
<div className='bio-container'>
<Bio />
{yearsTopContributor.filter(Boolean).length > 0 && (
<div>
<br />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ function SocialIcons(props: SocialIconsProps): JSX.Element | null {

return (
<Row>
<Col className='text-center social-media-icons' sm={6} smOffset={3}>
<Col className='social-icons-row'>
{linkedin ? LinkedInIcon(linkedin, username) : null}
{githubProfile ? GitHubIcon(githubProfile, username) : null}
{website ? WebsiteIcon(website, username) : null}
Expand Down
18 changes: 14 additions & 4 deletions client/src/components/profile/profile.test.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { render, screen } from '@testing-library/react';
import React from 'react';
import { Provider } from 'react-redux';
import { createStore } from 'redux';
import { Themes } from '../settings/theme';

import Profile from './profile';

jest.mock('../../analytics');
//workaround to avoid some strange gatsby error:
window.___loader = { enqueue: () => {}, hovering: () => {} };

const userProps = {
user: {
Expand Down Expand Up @@ -77,17 +80,24 @@ const notMyProfileProps = {
isSessionUser: false,
...userProps
};

function reducer() {
return {
app: { appUsername: 'vasili', user: { vasili: userProps.user } }
};
}
function renderWithRedux(ui: JSX.Element) {
return render(<Provider store={createStore(reducer)}>{ui}</Provider>);
}
describe('<Profile/>', () => {
it('renders the report button on another persons profile', () => {
render(<Profile {...notMyProfileProps} />);
renderWithRedux(<Profile {...notMyProfileProps} />);

const reportButton: HTMLElement = screen.getByText('buttons.flag-user');
expect(reportButton).toHaveAttribute('href', '/user/string/report-user');
});

it('renders correctly', () => {
const { container } = render(<Profile {...notMyProfileProps} />);
const { container } = renderWithRedux(<Profile {...notMyProfileProps} />);

expect(container).toMatchSnapshot();
});
Expand Down