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 28d80a7
Show file tree
Hide file tree
Showing 12 changed files with 633 additions and 24 deletions.
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({

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 @@ 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()

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,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 28d80a7

Please sign in to comment.