Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,11 @@ export default function ChallengeDetailsView(props) {
setSpecsTabState,
specsTabState,
updateChallenge,
auth,
} = props;

const isLoggedIn = !_.isEmpty(auth && auth.tokenV3);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[💡 readability]
The expression auth && auth.tokenV3 is used to check if auth is defined before accessing auth.tokenV3. This is correct, but it could be simplified by using optional chaining: auth?.tokenV3. This would improve readability and reduce potential errors if auth is undefined.


const {
groups,
description,
Expand Down Expand Up @@ -371,7 +374,7 @@ export default function ChallengeDetailsView(props) {
isDevelop={(getTrackName(track) || '').toLowerCase() === 'development'}
eventDetail={_.isEmpty(events) ? null : events[0]}
isMM={isMM(challenge)}
terms={terms}
terms={isLoggedIn ? terms : []}
// shareable={_.isEmpty(groups)}
environment={environment}
codeRepo={codeRepo}
Expand All @@ -387,6 +390,7 @@ export default function ChallengeDetailsView(props) {
}

ChallengeDetailsView.defaultProps = {
auth: {},
terms: [],
challenge: {
description: undefined,
Expand All @@ -405,6 +409,7 @@ ChallengeDetailsView.defaultProps = {
};

ChallengeDetailsView.propTypes = {
auth: PT.shape(),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[⚠️ maintainability]
The auth prop type is defined as PT.shape(), which does not specify any expected shape for the auth object. Consider defining the expected structure of the auth object to improve type safety and maintainability.

terms: PT.arrayOf(PT.shape()),
challenge: PT.shape({
description: PT.string,
Expand Down
8 changes: 6 additions & 2 deletions src/shared/containers/Terms.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ class TermsPageContainer extends React.Component {
loadTerms, authTokens, entity, termsForEntity,
} = this.props;

if (!_.isEqual(entity, termsForEntity)) {
// Only load terms for authenticated users
const isLoggedIn = !_.isEmpty(authTokens.tokenV3);
if (isLoggedIn && !_.isEqual(entity, termsForEntity)) {
loadTerms(authTokens, entity);
}
}
Expand All @@ -31,7 +33,9 @@ class TermsPageContainer extends React.Component {
// this is currently never happens that we have mounted Terms component
// which persist without unmounting during entity is changed
// but just in case better to support such case to avoid hidden unexpected behavior
if (!_.isEqual(nextProps.entity, entity)) {
// Only load terms for authenticated users
const isLoggedIn = !_.isEmpty(authTokens.tokenV3);
if (isLoggedIn && !_.isEqual(nextProps.entity, entity)) {
loadTerms(authTokens, nextProps.entity);
}
}
Expand Down
21 changes: 12 additions & 9 deletions src/shared/containers/challenge-detail/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,7 @@ class ChallengeDetailPageContainer extends React.Component {
!isEmpty && selectedTab === DETAIL_TABS.DETAILS
&& (
<ChallengeDetailsView
auth={auth}
challenge={challenge}
challengesUrl={challengesUrl}
communitiesList={communitiesList.data}
Expand Down Expand Up @@ -738,15 +739,17 @@ class ChallengeDetailPageContainer extends React.Component {
}
</div>

<Terms
defaultTitle="Challenge Prerequisites"
entity={{ type: 'challenge', id: challengeId.toString(), terms: challenge.terms }}
instanceId={this.instanceId}
description="You are seeing these Terms & Conditions because you have registered to a challenge and you have to respect the terms below in order to be able to submit."
register={() => {
registerForChallenge(auth, challengeId);
}}
/>
{isLoggedIn && (

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[❗❗ correctness]
The Terms component is now conditionally rendered based on the isLoggedIn flag. Ensure that isLoggedIn is correctly set to avoid unintended behavior where terms are not displayed to logged-in users.

<Terms
defaultTitle="Challenge Prerequisites"
entity={{ type: 'challenge', id: challengeId.toString(), terms: challenge.terms }}
instanceId={this.instanceId}
description="You are seeing these Terms & Conditions because you have registered to a challenge and you have to respect the terms below in order to be able to submit."
register={() => {
registerForChallenge(auth, challengeId);
}}
/>
)}

{showSecurityReminder && (
<SecurityReminder
Expand Down
Loading