Skip to content

Commit fdeb72a

Browse files
feat: fixed displaying field and visibility forms
1 parent 20c9595 commit fdeb72a

File tree

5 files changed

+254
-81
lines changed

5 files changed

+254
-81
lines changed

src/profile/ProfilePage.jsx

+70-43
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ class ProfilePage extends React.Component {
178178
visibilityLearningGoal,
179179
languageProficiencies,
180180
visibilityLanguageProficiencies,
181+
courseCertificates,
181182
visibilityCourseCertificates,
182183
bio,
183184
visibilityBio,
@@ -196,6 +197,17 @@ class ProfilePage extends React.Component {
196197
changeHandler: this.handleChange,
197198
};
198199

200+
const isBlockVisible = (blockInfo) => this.isAuthenticatedUserProfile()
201+
|| (!this.isAuthenticatedUserProfile() && Boolean(blockInfo));
202+
203+
const isLanguageBlockVisible = isBlockVisible(languageProficiencies.length);
204+
const isEducationBlockVisible = isBlockVisible(levelOfEducation);
205+
const isSocialLinksBLockVisible = isBlockVisible(socialLinks.some((link) => link.socialLink !== null));
206+
const isBioBlockVisible = isBlockVisible(bio);
207+
const isCertificatesBlockVisible = isBlockVisible(courseCertificates.length);
208+
const isNameBlockVisible = isBlockVisible(name);
209+
const isLocationBlockVisible = isBlockVisible(country);
210+
199211
return (
200212
<div className="container-fluid">
201213
<div className="row align-items-center pt-4 mb-4 pt-md-0 mb-md-0">
@@ -230,46 +242,58 @@ class ProfilePage extends React.Component {
230242
<div className="d-md-none mb-4">
231243
{this.renderViewMyRecordsButton()}
232244
</div>
233-
<Name
234-
name={name}
235-
visibilityName={visibilityName}
236-
formId="name"
237-
{...commonFormProps}
238-
/>
239-
<Country
240-
country={country}
241-
visibilityCountry={visibilityCountry}
242-
formId="country"
243-
{...commonFormProps}
244-
/>
245-
<PreferredLanguage
246-
languageProficiencies={languageProficiencies}
247-
visibilityLanguageProficiencies={visibilityLanguageProficiencies}
248-
formId="languageProficiencies"
249-
{...commonFormProps}
250-
/>
251-
<Education
252-
levelOfEducation={levelOfEducation}
253-
visibilityLevelOfEducation={visibilityLevelOfEducation}
254-
formId="levelOfEducation"
255-
{...commonFormProps}
256-
/>
257-
<SocialLinks
258-
socialLinks={socialLinks}
259-
draftSocialLinksByPlatform={draftSocialLinksByPlatform}
260-
visibilitySocialLinks={visibilitySocialLinks}
261-
formId="socialLinks"
262-
{...commonFormProps}
263-
/>
245+
{isNameBlockVisible && (
246+
<Name
247+
name={name}
248+
visibilityName={visibilityName}
249+
formId="name"
250+
{...commonFormProps}
251+
/>
252+
)}
253+
{isLocationBlockVisible && (
254+
<Country
255+
country={country}
256+
visibilityCountry={visibilityCountry}
257+
formId="country"
258+
{...commonFormProps}
259+
/>
260+
)}
261+
{isLanguageBlockVisible && (
262+
<PreferredLanguage
263+
languageProficiencies={languageProficiencies}
264+
visibilityLanguageProficiencies={visibilityLanguageProficiencies}
265+
formId="languageProficiencies"
266+
{...commonFormProps}
267+
/>
268+
)}
269+
{isEducationBlockVisible && (
270+
<Education
271+
levelOfEducation={levelOfEducation}
272+
visibilityLevelOfEducation={visibilityLevelOfEducation}
273+
formId="levelOfEducation"
274+
{...commonFormProps}
275+
/>
276+
)}
277+
{isSocialLinksBLockVisible && (
278+
<SocialLinks
279+
socialLinks={socialLinks}
280+
draftSocialLinksByPlatform={draftSocialLinksByPlatform}
281+
visibilitySocialLinks={visibilitySocialLinks}
282+
formId="socialLinks"
283+
{...commonFormProps}
284+
/>
285+
)}
264286
</div>
265287
<div className="pt-md-3 col-md-8 col-lg-7 offset-lg-1">
266288
{!this.isYOBDisabled() && this.renderAgeMessage()}
267-
<Bio
268-
bio={bio}
269-
visibilityBio={visibilityBio}
270-
formId="bio"
271-
{...commonFormProps}
272-
/>
289+
{isBioBlockVisible && (
290+
<Bio
291+
bio={bio}
292+
visibilityBio={visibilityBio}
293+
formId="bio"
294+
{...commonFormProps}
295+
/>
296+
)}
273297
{getConfig().ENABLE_SKILLS_BUILDER_PROFILE && (
274298
<LearningGoal
275299
learningGoal={learningGoal}
@@ -278,11 +302,13 @@ class ProfilePage extends React.Component {
278302
{...commonFormProps}
279303
/>
280304
)}
281-
<Certificates
282-
visibilityCourseCertificates={visibilityCourseCertificates}
283-
formId="certificates"
284-
{...commonFormProps}
285-
/>
305+
{isCertificatesBlockVisible && (
306+
<Certificates
307+
visibilityCourseCertificates={visibilityCourseCertificates}
308+
formId="certificates"
309+
{...commonFormProps}
310+
/>
311+
)}
286312
</div>
287313
</div>
288314
</div>
@@ -348,7 +374,7 @@ ProfilePage.propTypes = {
348374

349375
// Learning Goal form data
350376
learningGoal: PropTypes.string,
351-
visibilityLearningGoal: PropTypes.string.isRequired,
377+
visibilityLearningGoal: PropTypes.string,
352378

353379
// Other data we need
354380
profileImage: PropTypes.shape({
@@ -397,6 +423,7 @@ ProfilePage.defaultProps = {
397423
courseCertificates: null,
398424
requiresParentalConsent: null,
399425
dateJoined: null,
426+
visibilityLearningGoal: null,
400427
};
401428

402429
export default connect(

src/profile/ProfilePage.test.jsx

+28-9
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const requiredProfilePageProps = {
2929
deleteProfilePhoto: () => {},
3030
openField: () => {},
3131
closeField: () => {},
32-
params: { username: 'staff' },
32+
match: { params: { username: 'staff' } },
3333
};
3434

3535
// Mock language cookie
@@ -67,28 +67,29 @@ beforeEach(() => {
6767
});
6868

6969
const ProfilePageWrapper = ({
70-
contextValue, store, params, requiresParentalConsent,
70+
contextValue, store, match, requiresParentalConsent,
7171
}) => (
7272
<AppContext.Provider
7373
value={contextValue}
7474
>
7575
<IntlProvider locale="en">
7676
<Provider store={store}>
77-
<ProfilePage {...requiredProfilePageProps} params={params} requiresParentalConsent={requiresParentalConsent} />
77+
<ProfilePage {...requiredProfilePageProps} match={match} requiresParentalConsent={requiresParentalConsent} />
7878
</Provider>
7979
</IntlProvider>
8080
</AppContext.Provider>
8181
);
8282

8383
ProfilePageWrapper.defaultProps = {
84-
params: { username: 'staff' },
84+
match: { params: { username: 'staff' } },
8585
requiresParentalConsent: null,
86+
8687
};
8788

8889
ProfilePageWrapper.propTypes = {
8990
contextValue: PropTypes.shape({}).isRequired,
9091
store: PropTypes.shape({}).isRequired,
91-
params: PropTypes.shape({}),
92+
match: PropTypes.shape({}),
9293
requiresParentalConsent: PropTypes.bool,
9394
};
9495

@@ -114,16 +115,34 @@ describe('<ProfilePage />', () => {
114115
expect(tree).toMatchSnapshot();
115116
});
116117

117-
it('viewing other profile', () => {
118+
it('viewing other profile with all fields', () => {
118119
const contextValue = {
119120
authenticatedUser: { userId: 123, username: 'staff', administrator: true },
120121
config: getConfig(),
121122
};
123+
122124
const component = (
123125
<ProfilePageWrapper
124126
contextValue={contextValue}
125-
store={mockStore(storeMocks.viewOtherProfile)}
126-
params={{ username: 'verified' }} // Override default params
127+
store={mockStore({
128+
...storeMocks.viewOtherProfile,
129+
profilePage: {
130+
...storeMocks.viewOtherProfile.profilePage,
131+
account: {
132+
...storeMocks.viewOtherProfile.profilePage.account,
133+
name: 'user',
134+
country: 'EN',
135+
bio: 'bio',
136+
courseCertificates: ['course certificates'],
137+
levelOfEducation: 'some level',
138+
languageProficiencies: ['some lang'],
139+
socialLinks: ['twitter'],
140+
timeZone: 'time zone',
141+
accountPrivacy: 'all_users',
142+
},
143+
},
144+
})}
145+
match={{ params: { username: 'verified' } }} // Override default match
127146
/>
128147
);
129148
const tree = renderer.create(component).toJSON();
@@ -278,7 +297,7 @@ describe('<ProfilePage />', () => {
278297
<ProfilePageWrapper
279298
contextValue={contextValue}
280299
store={mockStore(storeMocks.loadingApp)}
281-
params={{ username: 'test-username' }}
300+
match={{ params: { username: 'test-username' } }}
282301
/>
283302
);
284303
const wrapper = mount(component);

0 commit comments

Comments
 (0)