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 19, 2024
1 parent 3467534 commit 716426b
Show file tree
Hide file tree
Showing 13 changed files with 791 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
90 changes: 78 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 @@ -150,6 +151,7 @@ class AccountSettingsPage extends React.Component {
}));

handleEditableFieldChange = (name, value) => {
console.log('handleEditableFieldChange', { name, value });

Check warning on line 154 in src/account-settings/AccountSettingsPage.jsx

View workflow job for this annotation

GitHub Actions / tests (lint)

Unexpected console statement
this.props.updateDraft(name, value);
};

Expand All @@ -167,6 +169,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 +582,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 +936,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 716426b

Please sign in to comment.