diff --git a/src/components/UserProfile/Bio.jsx b/src/components/UserProfile/Bio.jsx new file mode 100644 index 0000000..7e12985 --- /dev/null +++ b/src/components/UserProfile/Bio.jsx @@ -0,0 +1,88 @@ +import React from 'react'; +import PropTypes from 'prop-types'; +import { Input } from 'reactstrap'; + +import EditControls from './elements/EditControls'; +import EditableItemHeader from './elements/EditableItemHeader'; +import EmptyContent from './elements/EmptyContent'; +import SwitchContent from './elements/SwitchContent'; + + +function Bio({ + bio, + editMode, + onEdit, + onChange, + onSave, + onCancel, + onVisibilityChange, + saveState, +}) { + return ( + + + onChange('bio', e.target.value)} + /> + onCancel('bio')} + onSave={() => onSave('bio')} + saveState={saveState} + visibility="Everyone" + onVisibilityChange={e => onVisibilityChange('bio', e.target.value)} + /> + + ), + editable: ( + + onEdit('bio')} + showVisibility={Boolean(bio)} + visibility="Everyone" + /> +

{bio}

+
+ ), + empty: ( + onEdit('bio')}>Add a short bio + ), + static: ( + + +

{bio}

, +
+ ), + }} + /> + ); +} + +Bio.propTypes = { + editMode: PropTypes.string, + onEdit: PropTypes.func.isRequired, + onChange: PropTypes.func.isRequired, + onSave: PropTypes.func.isRequired, + onCancel: PropTypes.func.isRequired, + onVisibilityChange: PropTypes.func.isRequired, + saveState: PropTypes.string, + bio: PropTypes.string, +}; + +Bio.defaultProps = { + editMode: 'static', + saveState: null, + bio: null, +}; + + +export default Bio; diff --git a/src/components/UserProfile/Education.jsx b/src/components/UserProfile/Education.jsx new file mode 100644 index 0000000..1f090d1 --- /dev/null +++ b/src/components/UserProfile/Education.jsx @@ -0,0 +1,95 @@ +import React from 'react'; +import PropTypes from 'prop-types'; +import { Input } from 'reactstrap'; + +import EditControls from './elements/EditControls'; +import EditableItemHeader from './elements/EditableItemHeader'; +import EmptyContent from './elements/EmptyContent'; +import SwitchContent from './elements/SwitchContent'; + +import EDUCATION from '../../constants/education'; + + +function Education({ + education, + editMode, + onEdit, + onChange, + onSave, + onCancel, + onVisibilityChange, + saveState, +}) { + return ( + + + onChange('education', e.target.value)} + > + {Object.keys(EDUCATION).map(key => ( + + ))} + + onCancel('education')} + onSave={() => onSave('education')} + saveState={saveState} + visibility="Everyone" + onVisibilityChange={e => onVisibilityChange('education', e.target.value)} + /> + + ), + editable: ( + + onEdit('education')} + showVisibility={Boolean(education)} + visibility="Everyone" + /> +
{EDUCATION[education]}
+
+ ), + empty: ( + onEdit('education')}>Add education + ), + static: ( + + +
{EDUCATION[education]}
+
+ ), + }} + /> + ); +} + +Education.propTypes = { + editMode: PropTypes.string, + onEdit: PropTypes.func.isRequired, + onChange: PropTypes.func.isRequired, + onSave: PropTypes.func.isRequired, + onCancel: PropTypes.func.isRequired, + onVisibilityChange: PropTypes.func.isRequired, + saveState: PropTypes.string, + education: PropTypes.string, +}; + +Education.defaultProps = { + editMode: 'static', + saveState: null, + education: null, +}; + + +export default Education; diff --git a/src/components/UserProfile/FullName.jsx b/src/components/UserProfile/FullName.jsx new file mode 100644 index 0000000..5e2d346 --- /dev/null +++ b/src/components/UserProfile/FullName.jsx @@ -0,0 +1,89 @@ +import React from 'react'; +import PropTypes from 'prop-types'; +import { Input } from 'reactstrap'; + +import EditControls from './elements/EditControls'; +import EditableItemHeader from './elements/EditableItemHeader'; +import EmptyContent from './elements/EmptyContent'; +import SwitchContent from './elements/SwitchContent'; + + +function FullName({ + fullName, + editMode, + onEdit, + onChange, + onSave, + onCancel, + onVisibilityChange, + saveState, +}) { + return ( + + + onChange('fullName', e.target.value)} + /> + onCancel('fullName')} + onSave={() => onSave('fullName')} + saveState={saveState} + visibility="Everyone" + onVisibilityChange={e => onVisibilityChange('fullName', e.target.value)} + /> + + ), + editable: ( + + onEdit('fullName')} + showVisibility={Boolean(fullName)} + visibility="Everyone" + /> +
{fullName}
+
+ ), + empty: ( + onEdit('fullName')}>Add name + ), + static: ( + + +
{fullName}
+
+ ), + }} + /> + ); +} + + +FullName.propTypes = { + editMode: PropTypes.string, + onEdit: PropTypes.func.isRequired, + onChange: PropTypes.func.isRequired, + onSave: PropTypes.func.isRequired, + onCancel: PropTypes.func.isRequired, + onVisibilityChange: PropTypes.func.isRequired, + saveState: PropTypes.string, + fullName: PropTypes.string, +}; + +FullName.defaultProps = { + editMode: 'static', + saveState: null, + fullName: null, +}; + + +export default FullName; diff --git a/src/components/UserProfile/MyCertificates.jsx b/src/components/UserProfile/MyCertificates.jsx new file mode 100644 index 0000000..3ee1ded --- /dev/null +++ b/src/components/UserProfile/MyCertificates.jsx @@ -0,0 +1,102 @@ +import React from 'react'; +import PropTypes from 'prop-types'; +import { Row, Col, Card, CardBody, CardTitle } from 'reactstrap'; + +import EditControls from './elements/EditControls'; +import EditableItemHeader from './elements/EditableItemHeader'; +import SwitchContent from './elements/SwitchContent'; + +function MyCertificates({ + certificates, + editMode, + onEdit, + onSave, + onCancel, + onVisibilityChange, + saveState, +}) { + const renderCertificates = () => { + if (!certificates) return null; + + return ( + + {certificates.map(({ title }) => ( + + + + {title} + + + + ))} + + ); + }; + + return ( + + + {renderCertificates()} + onCancel('certificates')} + onSave={() => onSave('certificates')} + saveState={saveState} + visibility="Everyone" + onVisibilityChange={e => onVisibilityChange('certificates', e.target.value)} + /> + + ), + editable: ( + + onEdit('certificates')} + showVisibility={Boolean(certificates)} + visibility="Everyone" + /> + {renderCertificates()} + + ), + empty: ( +
+ You don’t have any certificates yet. Find a course. +
+ ), + static: ( + + + {renderCertificates()} + + ), + }} + /> + ); +} + + +MyCertificates.propTypes = { + editMode: PropTypes.string, + onEdit: PropTypes.func.isRequired, + onSave: PropTypes.func.isRequired, + onCancel: PropTypes.func.isRequired, + onVisibilityChange: PropTypes.func.isRequired, + saveState: PropTypes.string, + certificates: PropTypes.arrayOf(PropTypes.shape({ + title: PropTypes.string, + })), +}; + +MyCertificates.defaultProps = { + editMode: 'static', + saveState: null, + certificates: null, +}; + + +export default MyCertificates; diff --git a/src/components/UserProfile/UserLocation.jsx b/src/components/UserProfile/UserLocation.jsx new file mode 100644 index 0000000..41b5929 --- /dev/null +++ b/src/components/UserProfile/UserLocation.jsx @@ -0,0 +1,95 @@ +import React from 'react'; +import PropTypes from 'prop-types'; +import { Input } from 'reactstrap'; + +import EditControls from './elements/EditControls'; +import EditableItemHeader from './elements/EditableItemHeader'; +import EmptyContent from './elements/EmptyContent'; +import SwitchContent from './elements/SwitchContent'; + +import { ALL_COUNTRIES } from '../../constants/countries'; + + +function UserLocation({ + userLocation, + editMode, + onEdit, + onChange, + onSave, + onCancel, + onVisibilityChange, + saveState, +}) { + return ( + + + onChange('userLocation', e.target.value)} + > + {Object.keys(ALL_COUNTRIES).map(key => ( + + ))} + + onCancel('userLocation')} + onSave={() => onSave('userLocation')} + saveState={saveState} + visibility="Everyone" + onVisibilityChange={e => onVisibilityChange('userLocation', e.target.value)} + /> + + ), + editable: ( + + onEdit('userLocation')} + showVisibility={Boolean(userLocation)} + visibility="Everyone" + /> +
{ALL_COUNTRIES[userLocation]}
+
+ ), + empty: ( + onEdit('userLocation')}>Add location + ), + static: ( + + +
{ALL_COUNTRIES[userLocation]}
+
+ ), + }} + /> + ); +} + +UserLocation.propTypes = { + editMode: PropTypes.string, + onEdit: PropTypes.func.isRequired, + onChange: PropTypes.func.isRequired, + onSave: PropTypes.func.isRequired, + onCancel: PropTypes.func.isRequired, + onVisibilityChange: PropTypes.func.isRequired, + saveState: PropTypes.string, + userLocation: PropTypes.string, +}; + +UserLocation.defaultProps = { + editMode: 'static', + saveState: null, + userLocation: null, +}; + + +export default UserLocation; diff --git a/src/components/UserProfile/index.jsx b/src/components/UserProfile/index.jsx index f4438ce..7149849 100644 --- a/src/components/UserProfile/index.jsx +++ b/src/components/UserProfile/index.jsx @@ -1,16 +1,14 @@ import React from 'react'; import PropTypes from 'prop-types'; -import { Container, Row, Col, Input, Card, CardBody, CardTitle } from 'reactstrap'; +import { Container, Row, Col } from 'reactstrap'; -import EditControls from './elements/EditControls'; -import EditableItemHeader from './elements/EditableItemHeader'; -import EmptyContent from './elements/EmptyContent'; -import SwitchContent from './elements/SwitchContent'; import ProfileAvatar from './ProfileAvatar'; +import FullName from './FullName'; +import UserLocation from './UserLocation'; +import Education from './Education'; import SocialLinks from './SocialLinks'; - -import { ALL_COUNTRIES } from '../../constants/countries'; -import EDUCATION from '../../constants/education'; +import Bio from './Bio'; +import MyCertificates from './MyCertificates'; class UserProfile extends React.Component { @@ -204,395 +202,3 @@ UserProfile.defaultProps = { certificates: null, saveUserProfile: null, }; - - -const sectionPropTypes = { - editMode: PropTypes.string, - onEdit: PropTypes.func.isRequired, - onChange: PropTypes.func.isRequired, - onSave: PropTypes.func.isRequired, - onCancel: PropTypes.func.isRequired, - onVisibilityChange: PropTypes.func.isRequired, - saveState: PropTypes.string, -}; - -const sectionDefaultProps = { - editMode: 'static', - saveState: null, -}; - - -function FullName({ - fullName, - editMode, - onEdit, - onChange, - onSave, - onCancel, - onVisibilityChange, - saveState, -}) { - return ( - - - onChange('fullName', e.target.value)} - /> - onCancel('fullName')} - onSave={() => onSave('fullName')} - saveState={saveState} - visibility="Everyone" - onVisibilityChange={e => onVisibilityChange('fullName', e.target.value)} - /> - - ), - editable: ( - - onEdit('fullName')} - showVisibility={Boolean(fullName)} - visibility="Everyone" - /> -
{fullName}
-
- ), - empty: ( - onEdit('fullName')}>Add name - ), - static: ( - - -
{fullName}
-
- ), - }} - /> - ); -} - -FullName.propTypes = { - ...sectionPropTypes, - fullName: PropTypes.string, -}; - -FullName.defaultProps = { - ...sectionDefaultProps, - fullName: null, -}; - - -function UserLocation({ - userLocation, - editMode, - onEdit, - onChange, - onSave, - onCancel, - onVisibilityChange, - saveState, -}) { - return ( - - - onChange('userLocation', e.target.value)} - > - {Object.keys(ALL_COUNTRIES).map(key => ( - - ))} - - onCancel('userLocation')} - onSave={() => onSave('userLocation')} - saveState={saveState} - visibility="Everyone" - onVisibilityChange={e => onVisibilityChange('userLocation', e.target.value)} - /> - - ), - editable: ( - - onEdit('userLocation')} - showVisibility={Boolean(userLocation)} - visibility="Everyone" - /> -
{ALL_COUNTRIES[userLocation]}
-
- ), - empty: ( - onEdit('userLocation')}>Add location - ), - static: ( - - -
{ALL_COUNTRIES[userLocation]}
-
- ), - }} - /> - ); -} - -UserLocation.propTypes = { - ...sectionPropTypes, - userLocation: PropTypes.string, -}; - -UserLocation.defaultProps = { - ...sectionDefaultProps, - userLocation: null, -}; - - -function Education({ - education, - editMode, - onEdit, - onChange, - onSave, - onCancel, - onVisibilityChange, - saveState, -}) { - return ( - - - onChange('education', e.target.value)} - > - {Object.keys(EDUCATION).map(key => ( - - ))} - - onCancel('education')} - onSave={() => onSave('education')} - saveState={saveState} - visibility="Everyone" - onVisibilityChange={e => onVisibilityChange('education', e.target.value)} - /> - - ), - editable: ( - - onEdit('education')} - showVisibility={Boolean(education)} - visibility="Everyone" - /> -
{EDUCATION[education]}
-
- ), - empty: ( - onEdit('education')}>Add education - ), - static: ( - - -
{EDUCATION[education]}
-
- ), - }} - /> - ); -} - -Education.propTypes = { - ...sectionPropTypes, - education: PropTypes.string, -}; - -Education.defaultProps = { - ...sectionDefaultProps, - education: null, -}; - - -function Bio({ - bio, - editMode, - onEdit, - onChange, - onSave, - onCancel, - onVisibilityChange, - saveState, -}) { - return ( - - - onChange('bio', e.target.value)} - /> - onCancel('bio')} - onSave={() => onSave('bio')} - saveState={saveState} - visibility="Everyone" - onVisibilityChange={e => onVisibilityChange('bio', e.target.value)} - /> - - ), - editable: ( - - onEdit('bio')} - showVisibility={Boolean(bio)} - visibility="Everyone" - /> -

{bio}

-
- ), - empty: ( - onEdit('bio')}>Add a short bio - ), - static: ( - - -

{bio}

, -
- ), - }} - /> - ); -} - -Bio.propTypes = { - ...sectionPropTypes, - bio: PropTypes.string, -}; - -Bio.defaultProps = { - ...sectionDefaultProps, - bio: null, -}; - - -function MyCertificates({ - certificates, - editMode, - onEdit, - onSave, - onCancel, - onVisibilityChange, - saveState, -}) { - const renderCertificates = () => { - if (!certificates) return null; - - return ( - - {certificates.map(({ title }) => ( - - - - {title} - - - - ))} - - ); - }; - - return ( - - - {renderCertificates()} - onCancel('certificates')} - onSave={() => onSave('certificates')} - saveState={saveState} - visibility="Everyone" - onVisibilityChange={e => onVisibilityChange('certificates', e.target.value)} - /> - - ), - editable: ( - - onEdit('certificates')} - showVisibility={Boolean(certificates)} - visibility="Everyone" - /> - {renderCertificates()} - - ), - empty: ( -
- You don’t have any certificates yet. Find a course. -
- ), - static: ( - - - {renderCertificates()} - - ), - }} - /> - ); -} - -MyCertificates.propTypes = { - ...sectionPropTypes, - certificates: PropTypes.arrayOf(PropTypes.shape({ - title: PropTypes.string, - })), -}; - -MyCertificates.defaultProps = { - ...sectionDefaultProps, - certificates: null, -};