Skip to content

Commit

Permalink
feat: add first and last name to settings page
Browse files Browse the repository at this point in the history
  • Loading branch information
syedsajjadkazmii committed Feb 20, 2024
1 parent 3467534 commit 13cbebc
Show file tree
Hide file tree
Showing 12 changed files with 786 additions and 48 deletions.
314 changes: 290 additions & 24 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"@edx/brand": "npm:@openedx/brand-openedx@^1.2.2",
"@edx/frontend-component-footer": "13.0.2",
"@edx/frontend-component-header": "5.0.2",
"@edx/frontend-component-header-edx": "^8.1.0",
"@edx/frontend-platform": "7.1.0",
"@edx/openedx-atlas": "^0.6.0",
"@fortawesome/fontawesome-svg-core": "1.2.36",
Expand Down
89 changes: 77 additions & 12 deletions src/account-settings/AccountSettingsPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import { fetchSiteLanguages } from './site-language';
import DemographicsSection from './demographics/DemographicsSection';
import { fetchCourseList } from '../notification-preferences/data/thunks';
import { withLocation, withNavigate } from './hoc';
import NameField from './NameField';

class AccountSettingsPage extends React.Component {
constructor(props, context) {
Expand Down Expand Up @@ -167,6 +168,34 @@ class AccountSettingsPage extends React.Component {
this.props.saveSettings(formId, values, extendedProfileObject);
};

handleSubmitFirstAndLastName = (formId, fullName, firstName, lastName) => {
const settingsToBeSaved = [];

if (Object.keys(this.props.drafts).includes('useVerifiedNameForCerts')) {
settingsToBeSaved.push({
formId: 'useVerifiedNameForCerts',
commitValues: this.props.formValues.useVerifiedNameForCerts,
});
}

settingsToBeSaved.push({
formId: 'first_name',
commitValues: firstName,
});

settingsToBeSaved.push({
formId: 'last_name',
commitValues: lastName,
});

settingsToBeSaved.push({
formId: 'name',
commitValues: fullName,
});

this.props.saveMultipleSettings(settingsToBeSaved, formId, false);
};

handleSubmitProfileName = (formId, values) => {
if (Object.keys(this.props.drafts).includes('useVerifiedNameForCerts')) {
this.props.saveMultipleSettings([
Expand Down Expand Up @@ -552,37 +581,71 @@ class AccountSettingsPage extends React.Component {
isEditable={false}
{...editableFieldProps}
/>
<EditableField
name="name"
type="text"
value={
{(this.props.formValues?.first_name !== undefined && this.props.formValues?.last_name !== undefined) ? (
<NameField
name="name"
type="text"
verifiedName={verifiedName}
pendingNameChange={this.props.formValues.pending_name_change}
fullNameValue={this.props.formValues.name}
firstNameValue={this.props.formValues.first_name}
lastNameValue={this.props.formValues.last_name}
label={this.props.intl.formatMessage(messages['account.settings.field.full.name'])}
emptyLabel={
this.isEditable('name')
? this.props.intl.formatMessage(messages['account.settings.field.full.name.empty'])
: this.renderEmptyStaticFieldMessage()
}
helpText={
verifiedName
? this.renderFullNameHelpText(verifiedName.status, verifiedName.proctored_exam_attempt_id)
: this.props.intl.formatMessage(messages['account.settings.field.full.name.help.text'])
}
isEditable={
verifiedName
? this.isEditable('verifiedName') && this.isEditable('name')
: this.isEditable('name')
}
isGrayedOut={
verifiedName && !this.isEditable('verifiedName')
}
onChange={this.handleEditableFieldChange}
onSubmit={this.handleSubmitFirstAndLastName}
/>
) : (
<EditableField
name="name"
type="text"
value={
verifiedName?.status === 'submitted'
&& this.props.formValues.pending_name_change
? this.props.formValues.pending_name_change
: this.props.formValues.name
}
label={this.props.intl.formatMessage(messages['account.settings.field.full.name'])}
emptyLabel={
label={this.props.intl.formatMessage(messages['account.settings.field.full.name'])}
emptyLabel={
this.isEditable('name')
? this.props.intl.formatMessage(messages['account.settings.field.full.name.empty'])
: this.renderEmptyStaticFieldMessage()
}
helpText={
helpText={
verifiedName
? this.renderFullNameHelpText(verifiedName.status, verifiedName.proctored_exam_attempt_id)
: this.props.intl.formatMessage(messages['account.settings.field.full.name.help.text'])
}
isEditable={
isEditable={
verifiedName
? this.isEditable('verifiedName') && this.isEditable('name')
: this.isEditable('name')
}
isGrayedOut={
isGrayedOut={
verifiedName && !this.isEditable('verifiedName')
}
onChange={this.handleEditableFieldChange}
onSubmit={this.handleSubmitProfileName}
/>
onChange={this.handleEditableFieldChange}
onSubmit={this.handleSubmitProfileName}
/>
)}

{verifiedName
&& (
<EditableField
Expand Down Expand Up @@ -872,6 +935,8 @@ AccountSettingsPage.propTypes = {
formValues: PropTypes.shape({
username: PropTypes.string,
name: PropTypes.string,
first_name: PropTypes.string,
last_name: PropTypes.string,
email: PropTypes.string,
secondary_email: PropTypes.string,
secondary_email_enabled: PropTypes.bool,
Expand Down
10 changes: 10 additions & 0 deletions src/account-settings/AccountSettingsPage.messages.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,16 @@ const messages = defineMessages({
defaultMessage: 'Full name',
description: 'Label for account settings name field.',
},
'account.settings.field.first.name': {
id: 'account.settings.field.first.name',
defaultMessage: 'First name',
description: 'Label for account settings first name field.',
},
'account.settings.field.last.name': {
id: 'account.settings.field.last.name',
defaultMessage: 'Last name',
description: 'Label for account settings last name field.',
},
'account.settings.field.full.name.empty': {
id: 'account.settings.field.full.name.empty',
defaultMessage: 'Add name',
Expand Down
Loading

0 comments on commit 13cbebc

Please sign in to comment.