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

feat: add first and last name to settings page #1002

Open
wants to merge 1 commit into
base: split-fullname
Choose a base branch
from
Open
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
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 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 @@
this.props.saveSettings(formId, values, extendedProfileObject);
};

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

if (Object.keys(this.props.drafts).includes('useVerifiedNameForCerts')) {
settingsToBeSaved.push({

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

View check run for this annotation

Codecov / codecov/patch

src/account-settings/AccountSettingsPage.jsx#L175

Added line #L175 was not covered by tests
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 @@
isEditable={false}
{...editableFieldProps}
/>
<EditableField
name="name"
type="text"
value={
{(this.props.formValues?.are_first_and_last_name_required_in_registration === true) ? (
<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()

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

View check run for this annotation

Codecov / codecov/patch

src/account-settings/AccountSettingsPage.jsx#L597

Added line #L597 was not covered by tests
}
helpText={
verifiedName
? this.renderFullNameHelpText(verifiedName.status, verifiedName.proctored_exam_attempt_id)

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

View check run for this annotation

Codecov / codecov/patch

src/account-settings/AccountSettingsPage.jsx#L601

Added line #L601 was not covered by tests
: 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,10 +935,13 @@
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,
year_of_birth: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
are_first_and_last_name_required_in_registration: PropTypes.bool,
country: PropTypes.string,
level_of_education: PropTypes.string,
gender: PropTypes.string,
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
Loading