Skip to content

Commit

Permalink
[CLD-349] Fix undefined on submit address history and declaration and… (
Browse files Browse the repository at this point in the history
#60)

* [CLD-349] Fix undefined on submit address history and declaration and risk

* [CLD-349] fix cannot submit on primary id and secondary
  • Loading branch information
duong-se authored Oct 24, 2019
1 parent 4e6e5de commit df98e19
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 37 deletions.
6 changes: 3 additions & 3 deletions src/components/ui/forms/identification.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ import { oc } from 'ts-optchain'
export type IdentificationFormValues = {
typeId: string
details: string
expiry?: Date
expiry?: Date | null
fileUrl?: string
}

export const IDENTIFICATION_FORM_DEFAULT_VALUES: IdentificationFormValues = {
typeId: '',
details: '',
expiry: undefined,
fileUrl: undefined
expiry: null,
fileUrl: ''
}

export type IdentificationProps = {
Expand Down
2 changes: 1 addition & 1 deletion src/components/ui/profile-toggle.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState } from 'react'
import React from 'react'
import { MdCheck, MdClose, MdKeyboardArrowDown } from 'react-icons/md'
import styles from '@/styles/ui/profile-toggle.scss?mod'

Expand Down
41 changes: 20 additions & 21 deletions src/sagas/checklist-detail.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { selectUserCode } from '@/selectors/auth'
import { selectCheckListDetailContact, selectCheckListDetailIdCheck } from '@/selectors/checklist-detail'
import { fetcher } from '@reapit/elements'
import { fetcher, isBase64 } from '@reapit/elements'
import { put, fork, takeLatest, all, call, select } from '@redux-saga/core/effects'
import { oc } from 'ts-optchain'
import { Action } from '@/types/core'
import ActionTypes from '@/constants/action-types'
import { URLS, REAPIT_API_BASE_URL, UPLOAD_FILE_BASE_URL } from '@/constants/api'
import { initAuthorizedRequestHeaders, isBase64 } from '@/utils/api'
import { initAuthorizedRequestHeaders } from '@/utils/api'
import { errorThrownServer } from '../actions/error'
import {
checklistDetailLoading,
Expand Down Expand Up @@ -121,7 +121,7 @@ export const mapArrAddressToUploadImageFunc = ({ addresses, headers, addressesMe
return []
}
return addresses.map((address: AddressModel, index) => {
if (!isBase64(addressesMeta[index].documentImage)) {
if (!isBase64(addressesMeta && addressesMeta[index] && addressesMeta[index].documentImage)) {
return null
}
return call(uploadImage, {
Expand Down Expand Up @@ -270,14 +270,14 @@ export const updateSecondaryId = function*({ data }: Action<any>) {
const idCheck: IdentityCheckModel | null = yield select(selectCheckListDetailIdCheck)
const contact: ContactModel = yield select(selectCheckListDetailContact)
const secondaryIdUrl = data.fileUrl
const uploaderDocument: FileUploaderResponse = isBase64(data.fileUrl)
? yield call(uploadImage, {
headers,
name: `${contact.id}-${data.details}`,
imageData: data.fileUrl
})
: null

let uploaderDocument: FileUploaderResponse | null = null
if (isBase64(data.fileUrl)) {
uploaderDocument = yield call(uploadImage, {
headers,
name: `${contact.id}-${data.details}`,
imageData: data.fileUrl
})
}
const currentPrimaryIdUrl = oc(idCheck).metadata.primaryIdUrl()
const documents = oc(idCheck).documents([])
if (documents.length <= 1) {
Expand Down Expand Up @@ -335,20 +335,19 @@ export const updateSecondaryId = function*({ data }: Action<any>) {

export const updatePrimaryId = function*({ data }: Action<any>) {
yield put(checkListDetailSubmitForm(true))

try {
const headers = yield call(initAuthorizedRequestHeaders)
const idCheck: IdentityCheckModel | null = yield select(selectCheckListDetailIdCheck)
const contact: ContactModel = yield select(selectCheckListDetailContact)
const primaryIdUrl = data.fileUrl
const uploaderDocument: FileUploaderResponse = isBase64(data.fileUrl)
? yield call(uploadImage, {
headers,
name: `${contact.id}-${data.details}`,
imageData: data.fileUrl
})
: null

let uploaderDocument: FileUploaderResponse | null = null
if (isBase64(data.fileUrl)) {
uploaderDocument = yield call(uploadImage, {
headers,
name: `${contact.id}-${data.details}`,
imageData: data.fileUrl
})
}
const currentSecondaryIdUrl = oc(idCheck).metadata.secondaryIdUrl()
const documents = oc(idCheck).documents([])
if (documents.length === 0) {
Expand All @@ -360,12 +359,12 @@ export const updatePrimaryId = function*({ data }: Action<any>) {

const baseValues = {
metadata: {
// @ts-ignore
primaryIdUrl: uploaderDocument ? uploaderDocument.Url : primaryIdUrl,
secondaryIdUrl: currentSecondaryIdUrl
},
documents
} as IdentityCheckModel

if (idCheck) {
yield call(updateIdentityCheck, {
contactId: contact.id,
Expand Down
12 changes: 0 additions & 12 deletions src/utils/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,3 @@ export const initAuthorizedRequestHeaders = async () => ({
...CONTACTS_HEADERS,
Authorization: `Bearer ${await getAccessToken()}`
})

const base64Regex = new RegExp('^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{4})$')

export const isBase64 = base64Str => {
const base64Value = base64Str.split(';base64,')[1]

if (!base64Regex.test(base64Value)) {
return false
}

return true
}

0 comments on commit df98e19

Please sign in to comment.