Skip to content

Commit

Permalink
refactor(actions/user): Address PR comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
binh-dam-ibigroup committed Oct 2, 2020
1 parent 714d795 commit 45a2057
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions lib/actions/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,18 +205,17 @@ export function requestPhoneVerificationSms (originalUserData, newPhoneNumber) {
// and cache the previous value and verification state so they can be reverted.
// The full user record will be updated upon the user clicking Finish/Save preferences.
// TODO: Figure out what should happen if the user refreshes the browser at this stage.
const previousPhoneNumber = originalUserData.phoneNumber
const previousIsPhoneNumberVerified = originalUserData.isPhoneNumberVerified

// Make a clone of the original userData object.
// Make a clone of the original userData object and persist it (temporarily).
const newUserData = clone(originalUserData)
const previousPhoneNumber = newUserData.phoneNumber
const previousIsPhoneNumberVerified = newUserData.isPhoneNumberVerified

newUserData.phoneNumber = newPhoneNumber
newUserData.isPhoneNumberVerified = false

const userUpdateResult = await updateUser(otpMiddleware, accessToken, newUserData)

if (userUpdateResult.status === 'success' && userUpdateResult.data) {
// With the user's record updated, send the SMS request.
const sendSmsResult = await sendPhoneVerificationSms(otpMiddleware, accessToken, newUserData.id)
if (sendSmsResult.status === 'success') {
// Update application state on success.
Expand Down Expand Up @@ -248,21 +247,22 @@ export function verifyPhoneNumber (originalUserData, code) {
if (otpMiddleware) {
const { accessToken } = user
const sendResult = await validatePhoneVerificationCode(otpMiddleware, accessToken, originalUserData.id, code)

// If the check is successful, status in the returned data will be "approved".
if (sendResult.status === 'success' && sendResult.data) {
if (sendResult.data.status === 'approved') {
// Make a clone of the original userData object.
const newUserData = clone(originalUserData)

// Update phone number and verification in database record.
// FIXME: The call to updateUer below assumes the middleware requires saving the user's phone number prior to verification.
// FIXME: The call to updateUser below assumes the middleware requires saving the user's phone number prior to verification.
newUserData.isPhoneNumberVerified = true
newUserData.notificationChannel = 'sms'
const userUpdateResult = await updateUser(otpMiddleware, accessToken, newUserData)

if (userUpdateResult.status === 'success' && userUpdateResult.data) {
alert('Your phone is now verified and set to receive trip notifications.')

// Update application state
// Update application state.
// The new phone verification status will be shown underneath the phone number.
dispatch(setCurrentUser({ accessToken, user: userUpdateResult.data }))
} else {
alert(`Error updating your phone's verified status:\n${JSON.stringify(sendResult)}`)
Expand Down

0 comments on commit 45a2057

Please sign in to comment.