Skip to content

Commit d7d8769

Browse files
committed
feat: Segment Profile Information by User Role
ref issue #4103
1 parent cc879c1 commit d7d8769

File tree

5 files changed

+93
-35
lines changed

5 files changed

+93
-35
lines changed

src/config/constants.js

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,38 +1039,21 @@ export const PROJECT_CATEGORY_TAAS = 'talent-as-a-service'
10391039
* - if field is not on the list means it should not be shown
10401040
*/
10411041
export const PROFILE_FIELDS_CONFIG = {
1042-
// this config is used to show any user profile
1043-
DEFAULT: {
1044-
// required fields
1045-
firstName: true,
1046-
lastName: true,
1047-
country: true,
1048-
title: true,
1049-
timeZone: true,
1050-
businessPhone: true,
1051-
companyName: true,
1052-
1053-
// optional fields
1054-
avatar: false,
1055-
workingHourStart: false,
1056-
workingHourEnd: false,
1057-
},
1058-
1059-
// configs below are used when we ask users to fill missing fields (progressive registration)
10601042
TOPCODER: {
10611043
// required fields
10621044
firstName: true,
10631045
lastName: true,
1046+
title: true,
10641047
country: true,
10651048
timeZone: true,
10661049
workingHourStart: true,
10671050
workingHourEnd: true,
10681051

10691052
// optional fields
10701053
avatar: false,
1071-
title: false,
1072-
companyName: false,
1073-
businessPhone: false,
1054+
// companyName: false,
1055+
// companyURL: false,
1056+
// businessPhone: false,
10741057
},
10751058
CUSTOMER: {
10761059
// required fields
@@ -1079,13 +1062,30 @@ export const PROFILE_FIELDS_CONFIG = {
10791062
country: true,
10801063
title: true,
10811064
companyName: true,
1065+
companyURL: true,
10821066
businessPhone: true,
1067+
businessEmail: true,
10831068

10841069
// optional fields
1085-
businessEmail: false,
10861070
avatar: false,
10871071
timeZone: false,
10881072
workingHourStart: false,
10891073
workingHourEnd: false,
1074+
},
1075+
COPILOT: {
1076+
// required fields
1077+
firstName: true,
1078+
lastName: true,
1079+
country: true,
1080+
timeZone: true,
1081+
workingHourStart: true,
1082+
workingHourEnd: true,
1083+
1084+
// optional fields
1085+
avatar: false,
1086+
// title: false,
1087+
// companyName: false,
1088+
// companyURL: true,
1089+
// businessPhone: false,
10901090
}
10911091
}

src/config/permissions.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,43 @@ export default {
331331
],
332332
},
333333

334+
VIEW_USER_PROFILE_AS_COPILOT: {
335+
_meta: {
336+
group: 'User Profile',
337+
title: 'View User Profile as Copilot',
338+
},
339+
topcoderRoles: [
340+
ROLE_CONNECT_COPILOT
341+
],
342+
},
343+
344+
VIEW_USER_PROFILE_AS_TOPCODER_EMPLOYEE: {
345+
_meta: {
346+
group: 'User Profile',
347+
title: 'View User Profile as Topcoder Employee',
348+
},
349+
topcoderRoles: [
350+
..._.difference(TOPCODER_ALL, [ROLE_TOPCODER_USER, ROLE_CONNECT_COPILOT])
351+
],
352+
},
353+
354+
VIEW_USER_PROFILE_AS_CUSTOMER: {
355+
_meta: {
356+
group: 'User Profile',
357+
title: 'View User Profile as Customer',
358+
},
359+
allowRule: {
360+
topcoderRoles: [
361+
ROLE_TOPCODER_USER
362+
]
363+
},
364+
denyRule: {
365+
topcoderRoles: [
366+
..._.difference(TOPCODER_ALL, [ROLE_TOPCODER_USER])
367+
],
368+
}
369+
},
370+
334371
SEE_MEMBER_SUGGESTIONS: {
335372
_meta: {
336373
group: 'View Member Suggestions',

src/helpers/tcHelpers.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import {
99
NON_CUSTOMER_ROLES,
1010
PROFILE_FIELDS_CONFIG,
1111
} from '../config/constants'
12+
import { hasPermission } from './permissions'
13+
import PERMISSIONS from '../config/permissions'
1214

1315
/**
1416
* Check if a user is a special system user
@@ -73,3 +75,22 @@ export const isUserProfileComplete = (user, profileSettings) => {
7375

7476
return !isMissingUserInfo
7577
}
78+
79+
/**
80+
* Get User Profile fields config based on the current user roles.
81+
*
82+
* @returns {Object} fields config
83+
*/
84+
export const getUserProfileFieldsConfig = () => {
85+
if (hasPermission(PERMISSIONS.VIEW_USER_PROFILE_AS_TOPCODER_EMPLOYEE)) {
86+
return PROFILE_FIELDS_CONFIG.TOPCODER
87+
}
88+
89+
if (hasPermission(PERMISSIONS.VIEW_USER_PROFILE_AS_COPILOT)) {
90+
return PROFILE_FIELDS_CONFIG.COPILOT
91+
}
92+
93+
if (hasPermission(PERMISSIONS.VIEW_USER_PROFILE_AS_CUSTOMER)) {
94+
return PROFILE_FIELDS_CONFIG.CUSTOMER
95+
}
96+
}

src/routes/settings/routes/profile/components/ProfileSettingsForm.jsx

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import ISOCountries from '../../../../../helpers/ISOCountries'
1515
import { formatPhone } from '../../../../../helpers/utils'
1616
import { hasPermission } from '../../../../../helpers/permissions'
1717
import PERMISSIONS from '../../../../../config/permissions'
18-
import { PROFILE_FIELDS_CONFIG } from '../../../../../config/constants'
1918
import './ProfileSettingsForm.scss'
2019

2120
const countries = _.orderBy(ISOCountries, ['name'], ['asc']).map((country) => ({
@@ -137,6 +136,11 @@ class ProfileSettingsForm extends Component {
137136
validationErrors.isEmail = 'Please, enter correct email'
138137
}
139138

139+
if (name === 'companyURL') {
140+
validations.isRelaxedUrl = true
141+
validationErrors.isRelaxedUrl = 'Please, enter correct URL'
142+
}
143+
140144
return (
141145
<div className="field">
142146
<div className="label">
@@ -235,13 +239,11 @@ class ProfileSettingsForm extends Component {
235239
{!_.isUndefined(fieldsConfig.firstName) && this.getField('First Name', 'firstName', fieldsConfig.firstName)}
236240
{!_.isUndefined(fieldsConfig.lastName) && this.getField('Last Name', 'lastName', fieldsConfig.lastName)}
237241
{!_.isUndefined(fieldsConfig.title) && this.getField('Title', 'title', fieldsConfig.title)}
238-
{!_.isUndefined(fieldsConfig.businessEmail) &&
239-
this.getField('Business Email', 'businessEmail', fieldsConfig.businessEmail, true)}
240242
{!_.isUndefined(fieldsConfig.businessPhone) && (
241243
<div className="field">
242244
<div className="label">
243245
<span styleName="fieldLabelText">Business Phone</span>&nbsp;
244-
<sup styleName="requiredMarker">*</sup>
246+
{fieldsConfig.businessPhone && <sup styleName="requiredMarker">*</sup>}
245247
</div>
246248
<div className="input-field">
247249
<PhoneInput
@@ -275,13 +277,9 @@ class ProfileSettingsForm extends Component {
275277
</div>
276278
</div>
277279
)}
278-
{!_.isUndefined(fieldsConfig.companyName) &&
279-
this.getField(
280-
'Company Name',
281-
'companyName',
282-
fieldsConfig.companyName,
283-
disableCompanyInput
284-
)}
280+
{!_.isUndefined(fieldsConfig.businessEmail) && this.getField('Business Email', 'businessEmail', fieldsConfig.businessEmail, true)}
281+
{!_.isUndefined(fieldsConfig.companyName) && this.getField('Company Name', 'companyName', fieldsConfig.companyName, disableCompanyInput)}
282+
{!_.isUndefined(fieldsConfig.companyURL) && this.getField('Company URL', 'companyURL', fieldsConfig.companyURL)}
285283
{!_.isUndefined(fieldsConfig.country) && (
286284
<div className="field">
287285
{fieldsConfig.country ? (
@@ -414,8 +412,6 @@ class ProfileSettingsForm extends Component {
414412
}
415413

416414
ProfileSettingsForm.defaultProps = {
417-
// default config is same for user profile for any kind of users
418-
fieldsConfig: PROFILE_FIELDS_CONFIG.DEFAULT,
419415
showBackButton: false,
420416
submitButton: 'Save settings',
421417
onBack: () => {},
@@ -434,6 +430,7 @@ ProfileSettingsForm.propTypes = {
434430
lastName: PropTypes.bool,
435431
title: PropTypes.bool,
436432
companyName: PropTypes.bool,
433+
companyURL: PropTypes.bool,
437434
businessPhone: PropTypes.bool,
438435
businessEmail: PropTypes.bool,
439436
country: PropTypes.bool,

src/routes/settings/routes/profile/containers/ProfileSettingsContainer.jsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import spinnerWhileLoading from '../../../../../components/LoadingSpinner'
1010
import { requiresAuthentication } from '../../../../../components/AuthenticatedComponent'
1111
import { getProfileSettings, saveProfileSettings, uploadProfilePhoto } from '../../../actions/index'
1212
import { formatProfileSettings } from '../../../helpers/settings'
13+
import { getUserProfileFieldsConfig } from '../../../../../helpers/tcHelpers'
1314

1415
const enhance = spinnerWhileLoading(props => !props.values.isLoading)
1516
const ProfileSettingsFormEnhanced = enhance(ProfileSettingsForm)
@@ -20,6 +21,7 @@ class ProfileSettingsContainer extends Component {
2021

2122
render() {
2223
const { profileSettings, saveProfileSettings, uploadProfilePhoto, user } = this.props
24+
const fieldsConfig = getUserProfileFieldsConfig()
2325

2426
return (
2527
<SettingsPanel
@@ -31,6 +33,7 @@ class ProfileSettingsContainer extends Component {
3133
values={profileSettings}
3234
saveSettings={saveProfileSettings}
3335
uploadPhoto={uploadProfilePhoto}
36+
fieldsConfig={fieldsConfig}
3437
/>
3538
</SettingsPanel>
3639
)

0 commit comments

Comments
 (0)