Skip to content

Commit

Permalink
avoid overwriting function argument
Browse files Browse the repository at this point in the history
  • Loading branch information
paolodamico committed Feb 5, 2021
1 parent a366662 commit 7580545
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions frontend/src/scenes/persons/personsLogic.ts
Expand Up @@ -48,13 +48,15 @@ export const personsLogic = kea<personsLogicType<PersonPaginatedResponse>>({
editProperty: async ({ key, newValue }) => {
const person = values.person
if (person) {
if (typeof person.properties[key] === 'number') {
const parsedNumber = Number(newValue)
if (!Number.isNaN(parsedNumber)) {
newValue = parsedNumber
}
let parsedValue = newValue

// If the property is a number, store it as a number
const attemptedParsedNumber = Number(newValue)
if (!Number.isNaN(attemptedParsedNumber)) {
parsedValue = attemptedParsedNumber
}
person.properties[key] = newValue

person.properties[key] = parsedValue
actions.setPerson(person) // To update the UI immediately while the request is being processed
const response = await api.update(`api/person/${person.id}`, person)
actions.setPerson(response)
Expand Down

0 comments on commit 7580545

Please sign in to comment.