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

Remove sending phone number if not present #37

Merged

Conversation

tarunkumar2
Copy link
Contributor

The application is sending the phone number as empty value if the phone number is added by the user. Have fixed the application to prevent sending the phone number if the user doesn't enter the phone number.

@MasterXen
Copy link
Contributor

All these changes can be simplified since empty string are falsy. Alternately you could use Typescript's nullish coalescing functionality. So this:

phoneNumber: this.formData.phoneNumber !== '' ? this.formData.phoneNumber : undefined

can become

phoneNumber: this.formData.phoneNumber || undefined

Do you have an easy way to test the API input being generated locally?

@tarunkumar2
Copy link
Contributor Author

No @MasterXen . I am currently using the chrome inspect tool to test the API calls and the params sent.

@kristinfritsch
Copy link
Contributor

@MasterXen @tarunkumar2 I’d prefer to have that logic on api layer, so we can actually write tests for it and the views don't need care about it.

@timmy-circle
Copy link
Contributor

Nothing related to this PR. But I have a little suggestion on the UI/UX part for phone number. While testing on sample app, I had issue with not having proper format of my phone number that failed the api request. One little suggestion would be maybe have two separate box on phone number, one for country code and one for actual phone number. Wdyt?
68747470733a2f2f7261772e6769746875622e636f6d2f6a61636b6f636e722f696e746c2d74656c2d696e7075742f6d61737465722f73637265656e73686f74732f76616e696c6c612e706e67

@tarunkumar2
Copy link
Contributor Author

Thank you for the suggestion @timmy-circle . Yeah providing this kind of UI is better since it can avoid the API due to the improper phone number format. I will try to implement this kind of UI option along or provide the placeholder that will help the user determining the format.

lib/cardsApi.ts Outdated
@@ -71,6 +71,22 @@ instance.interceptors.response.use(
}
)

function checkNullInMetaData(metaData: MetaData) {
const nullIfEmpty = (prop: string | undefined) => {
if (prop === '') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably a good idea to do prop.trim() === '' to also cover whitespace in a string

lib/cardsApi.ts Outdated
sessionId: metaData.sessionId,
ipAddress: metaData.ipAddress
}
return updateMetaObj
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This replaces the actual metaData object. If there are new properties added, they will be stripped out without noticing.

Best here is to copy the existing obj and only overwrite the properties we want to change.

const updateMetaObj = {
    ...metaData
    email: nullIfEmpty(metaData.email),
    phoneNumber: nullIfEmpty(metaData.phoneNumber),
  }

lib/cardsApi.ts Outdated
@@ -71,6 +71,22 @@ instance.interceptors.response.use(
}
)

function checkNullInMetaData(metaData: MetaData) {
const nullIfEmpty = (prop: string | undefined) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to have nullIfEmpty reusable across this file. Can we move it out of this function please.

lib/cardsApi.ts Outdated
payload.metadata = checkNullInMetaData(payload.metadata)

return instance.post(url, payload)
const modifiedPayload = Object.assign({}, payload)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this fixes the issue. Try to use payload:

 {
    email: 'my-email@xyz.com',
    phoneNumber: '+491777777',
    sessionId: 'xyz',
    ipAddress: '10.0.2.1',
    newProp: 'my-prop'
  }

newProp will be omitted. That's why I suggested the spread syntax.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for not understanding the previous comment. I have updated the code now

lib/cardsApi.ts Outdated
return instance.put(url, payload)
payload.metadata.email = nullIfEmpty(payload.metadata.email)
payload.metadata.phoneNumber = nullIfEmpty(payload.metadata.phoneNumber)
return instance.post(url, payload)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why did that change to post instead of put?

lib/cardsApi.ts Outdated
@@ -133,7 +141,8 @@ function createCard(payload: CreateCardPayload) {
*/
function updateCard(cardId: string, payload: UpdateCardPayload) {
const url = `/v1/cards/${cardId}`

payload.metadata.email = nullIfEmpty(payload.metadata.email)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we just have a small check if metadata prop is not undefined. Otherwise i think looks good

Copy link
Contributor

@kristinfritsch kristinfritsch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@kristinfritsch kristinfritsch merged commit 96eb0c7 into circlefin:master Apr 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants