From aaf1c5f1ead983508845632c02806e7ae7455982 Mon Sep 17 00:00:00 2001 From: Adam Butterworth Date: Thu, 14 Feb 2019 17:08:10 -0500 Subject: [PATCH] Add empty state cases for each section. Update SwitchContent to handle forwarding of cases. --- src/components/UserProfile/SocialLinks.jsx | 33 ++++---- .../UserProfile/elements/EmptyContent.jsx | 4 +- .../UserProfile/elements/SwitchContent.jsx | 18 ++++- src/components/UserProfile/index.jsx | 75 +++++++++---------- src/containers/UserProfile/index.jsx | 4 +- 5 files changed, 72 insertions(+), 62 deletions(-) diff --git a/src/components/UserProfile/SocialLinks.jsx b/src/components/UserProfile/SocialLinks.jsx index e442952..33966a2 100644 --- a/src/components/UserProfile/SocialLinks.jsx +++ b/src/components/UserProfile/SocialLinks.jsx @@ -1,12 +1,11 @@ import React from 'react'; import PropTypes from 'prop-types'; import { Input } from 'reactstrap'; -import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; -import { faPencilAlt } from '@fortawesome/free-solid-svg-icons'; import EditControls from './elements/EditControls'; import EditableItemHeader from './elements/EditableItemHeader'; import SwitchContent from './elements/SwitchContent'; +import EmptyContent from './elements/EmptyContent'; class SocialLinks extends React.Component { @@ -35,13 +34,13 @@ class SocialLinks extends React.Component { saveState, } = this.props; - if (socialLinks === null) return null; - const socialLinksObj = {}; - socialLinks.forEach(({ platform, socialLink }) => { - socialLinksObj[platform] = socialLink; - }); + if (socialLinks !== null) { + socialLinks.forEach(({ platform, socialLink }) => { + socialLinksObj[platform] = socialLink; + }); + } return ( @@ -83,7 +82,7 @@ class SocialLinks extends React.Component { content="Social Links" showEditButton onClickEdit={() => onEdit('socialLinks')} - showVisibility={Boolean(socialLinks.length)} + showVisibility={Boolean(socialLinks && socialLinks.length)} visibility="Everyone" /> ), + empty: ( + + ), static: ( diff --git a/src/components/UserProfile/elements/EmptyContent.jsx b/src/components/UserProfile/elements/EmptyContent.jsx index e32ea55..8a381af 100644 --- a/src/components/UserProfile/elements/EmptyContent.jsx +++ b/src/components/UserProfile/elements/EmptyContent.jsx @@ -2,7 +2,7 @@ import React from 'react'; import PropTypes from 'prop-types'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; -import { faPencilAlt } from '@fortawesome/free-solid-svg-icons'; +import { faPlus } from '@fortawesome/free-solid-svg-icons'; function EmptyContent({ children, onClick, showPlusIcon }) { const onKeyDown = (e) => { if (e.key === 'Enter') onClick(); }; @@ -34,7 +34,7 @@ function EmptyContent({ children, onClick, showPlusIcon }) { return (
- {showPlusIcon ? : null} + {showPlusIcon ? : null} {children}
); diff --git a/src/components/UserProfile/elements/SwitchContent.jsx b/src/components/UserProfile/elements/SwitchContent.jsx index c6d947d..a0a5c80 100644 --- a/src/components/UserProfile/elements/SwitchContent.jsx +++ b/src/components/UserProfile/elements/SwitchContent.jsx @@ -18,9 +18,21 @@ const onChildExit = (htmlNode) => { function SwitchContent({ expression, cases, className }) { - if (!cases[expression] && !cases.default) { + const getContent = (caseKey) => { + if (cases[caseKey]) { + if (typeof cases[caseKey] === 'string') { + return getContent(cases[caseKey]); + } + return React.cloneElement(cases[caseKey], { key: caseKey }); + } else if (cases.default) { + if (typeof cases.default === 'string') { + return getContent(cases.default); + } + React.cloneElement(cases.default, { key: 'default' }); + } + return null; - } + }; return ( - {expression ? React.cloneElement(cases[expression], { key: expression }) : React.cloneElement(cases.default, { key: 'default' })} + {getContent(expression)} ); } diff --git a/src/components/UserProfile/index.jsx b/src/components/UserProfile/index.jsx index 293b185..f4438ce 100644 --- a/src/components/UserProfile/index.jsx +++ b/src/components/UserProfile/index.jsx @@ -89,9 +89,9 @@ class UserProfile extends React.Component { error, }; - - const getEditMode = (name) => { + const getMode = (name) => { if (name === this.props.currentlyEditingField) return 'editing'; + if (!this.props[name] || !this.props[name].length) return 'empty'; return 'editable'; }; @@ -119,25 +119,25 @@ class UserProfile extends React.Component { @@ -146,13 +146,13 @@ class UserProfile extends React.Component { @@ -193,15 +193,15 @@ UserProfile.defaultProps = { currentlyEditingField: null, saveState: null, error: null, - profileImage: 'https://source.unsplash.com/featured/200x200/?face', - fullName: 'Hermione Granger', - username: 'itslevioooosa20', - userLocation: 'London, UK', + profileImage: null, + fullName: null, + username: null, + userLocation: null, education: null, socialLinks: [], - aboutMe: 'These are some words about me and who I am as a person.', - bio: 'These are some words about me and who I am as a person.', - certificates: [{ title: 'Certificate 1' }, { title: 'Certificate 2' }, { title: 'Certificate 3' }], + aboutMe: null, + bio: null, + certificates: null, saveUserProfile: null, }; @@ -264,13 +264,12 @@ function FullName({ showVisibility={Boolean(fullName)} visibility="Everyone" /> - {fullName ? ( -
{fullName}
- ) : ( - onEdit('fullName')}>Add name - )} +
{fullName}
), + empty: ( + onEdit('fullName')}>Add name + ), static: ( @@ -340,13 +339,12 @@ function UserLocation({ showVisibility={Boolean(userLocation)} visibility="Everyone" /> - {userLocation ? ( -
{ALL_COUNTRIES[userLocation]}
- ) : ( - onEdit('userLocation')}>Add location - )} +
{ALL_COUNTRIES[userLocation]}
), + empty: ( + onEdit('userLocation')}>Add location + ), static: ( @@ -416,13 +414,12 @@ function Education({ showVisibility={Boolean(education)} visibility="Everyone" /> - {education ? ( -
{EDUCATION[education]}
- ) : ( - onEdit('education')}>Add education - )} +
{EDUCATION[education]}
), + empty: ( + onEdit('education')}>Add education + ), static: ( @@ -487,13 +484,12 @@ function Bio({ showVisibility={Boolean(bio)} visibility="Everyone" /> - {bio ? ( -

{bio}

- ) : ( - onEdit('bio')}>Tell other learners a little about yourself... - )} +

{bio}

), + empty: ( + onEdit('bio')}>Add a short bio + ), static: ( @@ -526,9 +522,7 @@ function MyCertificates({ saveState, }) { const renderCertificates = () => { - if (!certificates) { - return onEdit('certificates')}>You don"t have any certificates yet.; - } + if (!certificates) return null; return ( @@ -575,6 +569,11 @@ function MyCertificates({ {renderCertificates()} ), + empty: ( +
+ You don’t have any certificates yet. Find a course. +
+ ), static: ( diff --git a/src/containers/UserProfile/index.jsx b/src/containers/UserProfile/index.jsx index 8283435..6971226 100644 --- a/src/containers/UserProfile/index.jsx +++ b/src/containers/UserProfile/index.jsx @@ -11,7 +11,6 @@ const mapStateToProps = state => ({ currentlyEditingField: state.profile.currentlyEditingField, saveState: state.profile.saveState, error: state.profile.error, - bannerImage: 'https://source.unsplash.com/featured/1000x200/?colored,pattern', profileImage: state.userAccount.profileImage.imageUrlLarge, fullName: state.userAccount.name, username: state.userAccount.username, @@ -19,8 +18,7 @@ const mapStateToProps = state => ({ education: state.userAccount.levelOfEducation, socialLinks: state.userAccount.socialLinks, bio: state.userAccount.bio, - certificates: [{ title: 'Certificate 1' }, { title: 'Certificate 2' }, { title: 'Certificate 3' }], - courses: [{ title: 'Course ' }, { title: 'Course 2' }, { title: 'Course 3' }], + certificates: null, }); export default connect(mapStateToProps, {