Skip to content

Commit

Permalink
Move the toMilitaryName util method to Person
Browse files Browse the repository at this point in the history
  • Loading branch information
jlnat committed Nov 27, 2024
1 parent 77417a0 commit 67d7fa6
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 19 deletions.
2 changes: 1 addition & 1 deletion client/src/components/SecurityBanner.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ const SecurityBanner = ({ onLogout, handleSecurityBannerBottom }) => {
width={25}
height={25}
/>{" "}
{utils.toMilitaryName(currentUser.name)}
{Person.formattedMilitaryName(currentUser.name)}
</LinkTo>
{Settings.keycloakConfiguration.showLogoutLink && (
<Dropdown.Toggle
Expand Down
2 changes: 1 addition & 1 deletion client/src/components/previews/PersonPreview.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ const PersonPreview = ({ className, uuid }) => {
return (
<div className={`${className} preview-content-scroll`}>
<div className="preview-sticky-title">
<h4 className="ellipsized-text">{`${person.rank} ${utils.toMilitaryName(person.name)}`}</h4>
<h4 className="ellipsized-text">{`${person.rank} ${Person.formattedMilitaryName(person.name)}`}</h4>
</div>
<div className="preview-section">
<Row>
Expand Down
16 changes: 15 additions & 1 deletion client/src/models/Person.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ export default class Person extends Model {
}

toString() {
const militaryName = utils.toMilitaryName(this.name)
const militaryName = Person.formattedMilitaryName(this.name)
if (this.rank) {
return this.rank + " " + militaryName
} else {
Expand Down Expand Up @@ -376,6 +376,20 @@ export default class Person extends Model {
}
}

static formattedMilitaryName(name) {
const delimiter = name.indexOf(Person.delimiter)
let lastName = name
let firstName = ""

if (delimiter > -1) {
lastName = name.substring(0, delimiter)
firstName = name.substring(delimiter + 1, name.length)
return `${lastName.toUpperCase()}, ${firstName}`
}

return lastName.toUpperCase()
}

getNumberOfFieldsInLeftColumn() {
return Settings.fields[this.user ? "advisor" : "regular"].person
.numberOfFieldsInLeftColumn
Expand Down
2 changes: 1 addition & 1 deletion client/src/pages/people/Edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ const PersonEdit = ({ pageDispatchers }) => {
const person = new Person(data ? data.person : {})
const isPending =
person.isPendingVerification() && Person.isEqual(currentUser, person)
const legendText = isPending ? "Create your account" : `Edit ${utils.toMilitaryName(person.name)}`
const legendText = isPending ? "Create your account" : `Edit ${Person.formattedMilitaryName(person.name)}`
const saveText = isPending ? "Update profile" : "Save Person"

// mutates the object
Expand Down
2 changes: 1 addition & 1 deletion client/src/pages/people/Show.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ const PersonShow = ({ pageDispatchers }) => {
persistent
/>
}{" "}
{person.rank} {utils.toMilitaryName(person.name)}
{person.rank} {Person.formattedMilitaryName(person.name)}
</>
}
action={action}
Expand Down
14 changes: 0 additions & 14 deletions client/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -400,20 +400,6 @@ export default {
value,
label
}))
},

toMilitaryName: function(name) {
const delimiter = name.indexOf(",")
let lastName = name
let firstName = ""

if (delimiter > -1) {
lastName = name.substring(0, delimiter)
firstName = name.substring(delimiter + 1, name.length)
return `${lastName.toUpperCase()}, ${firstName}`
}

return lastName.toUpperCase()
}
}

Expand Down

0 comments on commit 67d7fa6

Please sign in to comment.