Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: sync 2u-main with master #1123

Merged
merged 7 commits into from
Sep 24, 2024
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
71 changes: 43 additions & 28 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"@tensorflow/tfjs-core": "3.21.0",
"bowser": "2.11.0",
"classnames": "2.5.1",
"core-js": "3.38.0",
"core-js": "3.38.1",
"font-awesome": "4.7.0",
"form-urlencoded": "6.1.5",
"formdata-polyfill": "4.0.10",
Expand Down Expand Up @@ -85,7 +85,7 @@
"devDependencies": {
"@edx/browserslist-config": "1.2.0",
"@edx/reactifex": "1.1.0",
"@openedx/frontend-build": "14.1.2",
"@openedx/frontend-build": "14.1.4",
"@testing-library/jest-dom": "6.4.8",
"@testing-library/react": "12.1.5",
"react-test-renderer": "17.0.2",
Expand Down
39 changes: 37 additions & 2 deletions src/account-settings/AccountSettingsPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,15 @@ class AccountSettingsPage extends React.Component {
countryOptions: [{
value: '',
label: this.props.intl.formatMessage(messages['account.settings.field.country.options.empty']),
}].concat(getCountryList(locale).map(({ code, name }) => ({ value: code, label: name }))),
}].concat(
this.removeDisabledCountries(
getCountryList(locale).map(({ code, name }) => ({
value: code,
label: name,
disabled: this.isDisabledCountry(code),
})),
),
),
stateOptions: [{
value: '',
label: this.props.intl.formatMessage(messages['account.settings.field.state.options.empty']),
Expand All @@ -147,11 +155,28 @@ class AccountSettingsPage extends React.Component {
})),
}));

removeDisabledCountries = (countryList) => {
const { disabledCountries, committedValues } = this.props;

if (!disabledCountries.length) {
return countryList;
}

return countryList.filter(({ value, disabled }) => {
const isUserCountry = value === committedValues.country;
return !disabled || isUserCountry;
});
};

handleEditableFieldChange = (name, value) => {
this.props.updateDraft(name, value);
};

handleSubmit = (formId, values) => {
if (formId === 'country' && this.isDisabledCountry(values)) {
return;
}

const { formValues } = this.props;
let extendedProfileObject = {};

Expand Down Expand Up @@ -193,6 +218,11 @@ class AccountSettingsPage extends React.Component {
}
};

isDisabledCountry = (country) => {
const { disabledCountries } = this.props;
return disabledCountries.includes(country);
};

isEditable(fieldName) {
return !this.props.staticFields.includes(fieldName);
}
Expand Down Expand Up @@ -476,7 +506,8 @@ class AccountSettingsPage extends React.Component {
} = this.getLocalizedOptions(this.context.locale, this.props.formValues.country);

// Show State field only if the country is US (could include Canada later)
const showState = this.props.formValues.country === COUNTRY_WITH_STATES;
const { country } = this.props.formValues;
const showState = country === COUNTRY_WITH_STATES && !this.isDisabledCountry(country);
const { verifiedName } = this.props;

const hasWorkExperience = !!this.props.formValues?.extended_profile?.find(field => field.field_name === 'work_experience');
Expand Down Expand Up @@ -880,6 +911,7 @@ AccountSettingsPage.propTypes = {
name: PropTypes.string,
useVerifiedNameForCerts: PropTypes.bool,
verified_name: PropTypes.string,
country: PropTypes.string,
}),
drafts: PropTypes.shape({}),
formErrors: PropTypes.shape({
Expand Down Expand Up @@ -938,6 +970,7 @@ AccountSettingsPage.propTypes = {
),
navigate: PropTypes.func.isRequired,
location: PropTypes.string.isRequired,
disabledCountries: PropTypes.arrayOf(PropTypes.string),
};

AccountSettingsPage.defaultProps = {
Expand All @@ -947,6 +980,7 @@ AccountSettingsPage.defaultProps = {
committedValues: {
useVerifiedNameForCerts: false,
verified_name: null,
country: '',
},
drafts: {},
formErrors: {},
Expand All @@ -963,6 +997,7 @@ AccountSettingsPage.defaultProps = {
verifiedName: null,
mostRecentVerifiedName: {},
verifiedNameHistory: [],
disabledCountries: [],
};

export default withLocation(withNavigate(connect(accountSettingsPageSelector, {
Expand Down
3 changes: 2 additions & 1 deletion src/account-settings/EditableSelectField.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ const EditableSelectField = (props) => {
<option
value={subOption.value}
key={`${subOption.value}-${subOption.label}`}
disabled={subOption?.disabled}
>
{subOption.label}
</option>
Expand All @@ -115,7 +116,7 @@ const EditableSelectField = (props) => {
);
}
return (
<option value={option.value} key={`${option.value}-${option.label}`}>
<option value={option.value} key={`${option.value}-${option.label}`} disabled={option?.disabled}>
{option.label}
</option>
);
Expand Down
1 change: 1 addition & 0 deletions src/account-settings/data/reducers.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export const defaultState = {
verifiedName: null,
mostRecentVerifiedName: {},
verifiedNameHistory: {},
disabledCountries: ['RU'],
};

const reducer = (state = defaultState, action = {}) => {
Expand Down
8 changes: 8 additions & 0 deletions src/account-settings/data/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,11 @@ const activeAccountSelector = createSelector(
accountSettings => accountSettings.values.is_active,
);

const disabledCountriesSelector = createSelector(
accountSettingsSelector,
accountSettings => accountSettings.disabledCountries,
);

export const siteLanguageSelector = createSelector(
previousSiteLanguageSelector,
draftsSelector,
Expand Down Expand Up @@ -237,6 +242,7 @@ export const accountSettingsPageSelector = createSelector(
mostRecentApprovedVerifiedNameValueSelector,
mostRecentVerifiedNameSelector,
sortedVerifiedNameHistorySelector,
disabledCountriesSelector,
(
accountSettings,
siteLanguageOptions,
Expand All @@ -254,6 +260,7 @@ export const accountSettingsPageSelector = createSelector(
verifiedName,
mostRecentVerifiedName,
verifiedNameHistory,
disabledCountries,
) => ({
siteLanguageOptions,
siteLanguage,
Expand All @@ -274,6 +281,7 @@ export const accountSettingsPageSelector = createSelector(
verifiedName,
mostRecentVerifiedName,
verifiedNameHistory,
disabledCountries,
}),
);

Expand Down
1 change: 1 addition & 0 deletions src/notification-preferences/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const messages = defineMessages({
contentReported {Reported content}
courseUpdates {Course updates}
oraStaffNotification {ORA new submissions}
oraGradeAssigned {ORA grade received}
other {{text}}
}`,
description: 'Display text for Notification Types',
Expand Down