From db7a0316101341cdbb8cb58e8cd790da68ed6ab3 Mon Sep 17 00:00:00 2001 From: Leonardo Galindo Date: Wed, 5 May 2021 18:09:36 -0500 Subject: [PATCH] Add Members UI (#70) * add button for new user * add user created on frontend * add user created on frontend * formatting * linting * fixed add members * linting * comments * comments * linting * add required fields * removed css * linting * fixed year validation * generalized digit regex --- api/src/api/members.js | 2 + api/src/utils/user-utils.js | 4 +- .../EditableAttribute/DateAttribute.js | 3 + .../EditableAttribute/TextAttribute.js | 3 + client/src/components/navbar/Navbar.js | 7 +- client/src/css/Navbar.css | 1 + client/src/pages/Profile.js | 76 ++++++++++++++----- client/src/utils/apiWrapper.js | 13 ++++ client/src/utils/consts.js | 20 +++++ 9 files changed, 105 insertions(+), 24 deletions(-) create mode 100644 client/src/utils/consts.js diff --git a/api/src/api/members.js b/api/src/api/members.js index 1bdf1ab..ea31023 100644 --- a/api/src/api/members.js +++ b/api/src/api/members.js @@ -68,6 +68,8 @@ router.get( }), ); +// Create a new member +// Requires Director Level router.post( '/', requireDirector, diff --git a/api/src/utils/user-utils.js b/api/src/utils/user-utils.js index d56fbc1..6afbc0d 100644 --- a/api/src/utils/user-utils.js +++ b/api/src/utils/user-utils.js @@ -28,8 +28,8 @@ const nonEditableFields = [ const validationFields = { email: /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/, phone: /^[0-9]{10}$/, - gradYear: /^\d{4}/, - generationYear: /^\d{4}/, + gradYear: /^\d{4}$/, + generationYear: /^\d{4}$/, }; const getViewableFields = (currentUser, memberId) => { diff --git a/client/src/components/EditableAttribute/DateAttribute.js b/client/src/components/EditableAttribute/DateAttribute.js index 5918f54..0277435 100644 --- a/client/src/components/EditableAttribute/DateAttribute.js +++ b/client/src/components/EditableAttribute/DateAttribute.js @@ -11,6 +11,7 @@ const DateAttribute = ({ isDisabled = false, className = '', onChange, + isRequired = false, }) => { const onValueChange = (date) => { onChange(date, attributeLabel); @@ -24,6 +25,7 @@ const DateAttribute = ({ onChange={onValueChange} selected={value} disabled={isDisabled} + required={isRequired} /> ); @@ -35,6 +37,7 @@ DateAttribute.propTypes = { isDisabled: PropTypes.bool, className: PropTypes.string, onChange: PropTypes.func.isRequired, + isRequired: PropTypes.bool, }; export default DateAttribute; diff --git a/client/src/components/EditableAttribute/TextAttribute.js b/client/src/components/EditableAttribute/TextAttribute.js index 0d7b563..e69afc9 100644 --- a/client/src/components/EditableAttribute/TextAttribute.js +++ b/client/src/components/EditableAttribute/TextAttribute.js @@ -10,6 +10,7 @@ const TextAttribute = ({ isDisabled = false, className = '', onChange, + isRequired = false, }) => { const onValueChange = (e) => { onChange(e.target.value, attributeLabel); @@ -23,6 +24,7 @@ const TextAttribute = ({ value={value} onChange={onValueChange} disabled={isDisabled} + required={isRequired} /> ); @@ -33,6 +35,7 @@ TextAttribute.propTypes = { type: PropTypes.string, attributeLabel: PropTypes.string, isDisabled: PropTypes.bool, + isRequired: PropTypes.bool, className: PropTypes.string, onChange: PropTypes.func.isRequired, }; diff --git a/client/src/components/navbar/Navbar.js b/client/src/components/navbar/Navbar.js index 44c2002..2cc0cf0 100644 --- a/client/src/components/navbar/Navbar.js +++ b/client/src/components/navbar/Navbar.js @@ -3,8 +3,8 @@ import { Link, NavLink } from 'react-router-dom'; import PropTypes from 'prop-types'; import '../../css/Navbar.css'; - import ProfileDropdown from '../ProfileDropdown/ProfileDropdown'; +import { levelEnum } from '../../utils/consts'; import * as Routes from '../../routes'; /** @@ -19,6 +19,11 @@ const Navbar = ({ user }) => (