Commit d9214454 authored by Rafael's avatar Rafael

Corrige bugs com obter referências e veículos.

parent c5e9603f
{
"API_URL": "http://192.168.0.65:8080",
"API_URL": "http://192.168.0.34:8080",
"APP_NAME_BROKER": "@agiliza-dev/agente",
"APP_NAME_CUSTOMER": "@agiliza-dev/cliente",
"SESSION_KEY_BROKER": "@agiliza-dev/agente",
"SESSION_KEY_CUSTOMER": "@agiliza-dev/cliente"
}
\ No newline at end of file
}
......@@ -68,7 +68,12 @@ export class AddInvolvedPersonIdentification implements ApiAdapter<InvolvedPerso
nome: domain.name,
cpfcnpj: extractNumbers(domain.cpfcnpj),
sexo: domain.gender,
tipo: domain.type === INVOLVED_PERSON_NAMES['2'] ? INVOLVED_PERSON_TYPES['CUSTOMER'] : '',
tipo:
domain.type === INVOLVED_PERSON_NAMES['2']
? INVOLVED_PERSON_TYPES['CUSTOMER']
: domain.type === INVOLVED_PERSON_TYPES['CUSTOMER']
? domain.type
: '',
contaBanestes: domain.account ? this.mapBanestesAccountToApi(domain.account) : undefined,
dadosTipo: domain.dataType ? this.mapDateTypeToApi(domain.dataType) : undefined,
})
......
......@@ -11,6 +11,7 @@ import {
Vehicle,
Workplace
} from '@agiliza/api/domain'
import { INVOLVED_PERSON_NAMES, INVOLVED_PERSON_TYPES } from '@agiliza/constants/involvedPeople'
import {
EnderecoApiModel,
ProjetoPessoaEnvolvidaConjugeApiModel,
......@@ -61,7 +62,7 @@ export class CDIdentificationAdapter implements DomainAdapter<ProjetoPessoaEnvol
name: pessoa.nome,
cpfcnpj: pessoa.cpfcnpj,
gender: pessoa.sexo,
type: pessoa.tipo,
type: pessoa.tipo === INVOLVED_PERSON_NAMES[INVOLVED_PERSON_TYPES.CUSTOMER] ? INVOLVED_PERSON_TYPES.CUSTOMER : '',
account: pessoa.contaBanestes ? this.mapContaBanestesToDomain(pessoa.contaBanestes) : undefined,
dataType: pessoa.dadosTipo ? this.mapDadosTipoToDomain(pessoa.dadosTipo) : undefined,
})
......
......@@ -17,7 +17,7 @@ import {
UpdateCDVehicle
} from '@agiliza/api/domain'
import { DadosCliente } from '@agiliza/api/mappers/domain/proposalData'
import { INVOLVED_PERSON_NAMES, INVOLVED_PERSON_TYPES } from '@agiliza/constants/involvedPeople'
import { INVOLVED_PERSON_TYPES } from '@agiliza/constants/involvedPeople'
import { ClienteApi, Configuration } from '@microcredito/client'
import { ErrorMappers, ProposalDataApiMappers, ProposalDataMappers } from '../../mappers'
......@@ -106,8 +106,7 @@ export class PDCustomerDataRepositoryImpl implements PDCustomerDataDataRepositor
try {
const pessoasEnvolvidas = await this.api.obterPessoasEnvolvidas({ projetoId: input.projectId })
const involvedPeople = pessoasEnvolvidas.map(this.cdIdentificationMapper.mapApiModelToDomain)
console.log(involvedPeople)
const identification = involvedPeople.find((pE) => pE.type === INVOLVED_PERSON_NAMES[INVOLVED_PERSON_TYPES['CUSTOMER']])
const identification = involvedPeople.find((pE) => pE.type === INVOLVED_PERSON_TYPES['CUSTOMER'])
return identification
} catch (e) {
const result = await this.errorAdapter.mapApiModelToDomain(e)
......@@ -141,6 +140,7 @@ export class PDCustomerDataRepositoryImpl implements PDCustomerDataDataRepositor
public updateIdentification = async (input: UpdateCDIdentification['Input']): Promise<UpdateCDIdentification['Output']> => {
try {
console.log(this.cdUpdateIdentificationApiMapper.mapDomainToApiModel(input))
const response = await this.api.atualizarIdentificacaoPessoaEnvolvida(this.cdUpdateIdentificationApiMapper.mapDomainToApiModel(input))
return this.cdIdentificationMapper.mapApiModelToDomain(response)
} catch (e) {
......
......@@ -50,6 +50,17 @@ const updateVehiclesReferences = (state: Store, pds: Vehicle[] = [], rfs: Refere
state.references.byId = references
state.references.allIds = keys(references)
}
const updateReferences = (state: Store, rfs: Reference[]) => {
const { references } = normalizeCustomerData([], rfs)
state.references.byId = references
state.references.allIds = keys(references)
}
const updateVehicles = (state: Store, vhs: Vehicle[]) => {
const { vehicles } = normalizeCustomerData(vhs, [])
state.vehicles.byId = vehicles
state.vehicles.allIds = keys(vehicles)
}
export default createSlice({
name: `${PROPOSAL_DATA_PREFIX}/customerData`,
......@@ -69,27 +80,27 @@ export default createSlice({
},
[customerDataTypes.getVehicles.fulfilled]: (state, action: PayloadAction<GetCDVehicles['Output']>) => {
const { payload } = action
updateVehiclesReferences(state, payload)
updateVehicles(state, payload)
},
[customerDataTypes.updateReference.fulfilled]: (state, action: PayloadAction<UpdateCDVehicle['Output']>) => {
[customerDataTypes.updateVehicle.fulfilled]: (state, action: PayloadAction<UpdateCDVehicle['Output']>) => {
const { payload } = action
updateVehiclesReferences(state, payload)
updateVehicles(state, payload)
},
[customerDataTypes.addReference.fulfilled]: (state, action: PayloadAction<AddCDVehicle['Output']>) => {
[customerDataTypes.addVehicle.fulfilled]: (state, action: PayloadAction<AddCDVehicle['Output']>) => {
const { payload } = action
updateVehiclesReferences(state, payload)
updateVehicles(state, payload)
},
[customerDataTypes.getReferences.fulfilled]: (state, action: PayloadAction<GetCDReferences['Output']>) => {
const { payload } = action
updateVehiclesReferences(state, [], payload)
updateReferences(state, payload)
},
[customerDataTypes.updateReference.fulfilled]: (state, action: PayloadAction<UpdateCDReference['Output']>) => {
const { payload } = action
updateVehiclesReferences(state, [], payload)
updateReferences(state, payload)
},
[customerDataTypes.addReference.fulfilled]: (state, action: PayloadAction<AddCDReference['Output']>) => {
const { payload } = action
updateVehiclesReferences(state, [], payload)
updateReferences(state, payload)
},
},
})
......@@ -38,7 +38,6 @@ export default createSlice({
state.personId = action.payload.id
},
[customerDataTypes.getIdentification.fulfilled]: (state, action: PayloadAction<Identification>) => {
console.log(action.payload)
state.personId = action.payload?.id
},
},
......
......@@ -2,3 +2,5 @@ import { State } from './slice'
export const isFetching = (state: State) => state.fetching
export const isGettingCustomerData = (state: State) => state.gettingCustomerData
export const isGettingReferences = (state: State) => state.gettingReferences
export const isGettingVehicles = (state: State) => state.gettingVehicles
......@@ -7,6 +7,7 @@ import {
GetCDReferences,
GetCDVehicles,
GetCustomerData,
InvolvedPerson,
UpdateCDAddress,
UpdateCDHome,
UpdateCDIdentification,
......@@ -33,11 +34,15 @@ const prefix = 'useCases/customerData'
export interface State {
fetching: boolean
gettingCustomerData: boolean
gettingReferences: boolean
gettingVehicles: boolean
}
export const initialState: State = {
fetching: false,
gettingCustomerData: false,
gettingReferences: false,
gettingVehicles: false,
}
export const actions = {
......@@ -181,16 +186,19 @@ export const actions = {
return thunkApi.rejectWithValue(e)
}
}),
getCustomerData: createAsyncThunk(`${prefix}/getCustomerData`, async (input: WithSuccess<GetCustomerData['Input']>, thunkApi) => {
const useCase = PDCustomerDataRepositoryImplFactory.create(appPlatform)
try {
const response = await useCase.getCustomerData(input)
input.onSuccess && input.onSuccess()
return response
} catch (e) {
return thunkApi.rejectWithValue(e)
getCustomerData: createAsyncThunk(
`${prefix}/getCustomerData`,
async (input: WithSuccess<GetCustomerData['Input'], Omit<InvolvedPerson, 'id'>>, thunkApi) => {
const useCase = PDCustomerDataRepositoryImplFactory.create(appPlatform)
try {
const response = await useCase.getCustomerData(input)
input.onSuccess && input.onSuccess(response)
return response
} catch (e) {
return thunkApi.rejectWithValue(e)
}
}
}),
),
getIdentification: createAsyncThunk(`${prefix}/getIdentification`, async (input: WithSuccess<GetCDIdentification['Input'], string>, thunkApi) => {
const useCase = PDCustomerDataRepositoryImplFactory.create(appPlatform)
try {
......@@ -211,6 +219,8 @@ const login = createSlice({
extraReducers: {
...values(types).reduce((reducers, type) => ({ ...reducers, ...createAsyncReducers(type) }), {}),
...createAsyncReducers(types.getCustomerData, 'gettingCustomerData'),
...createAsyncReducers(types.getReferences, 'gettingReferences'),
...createAsyncReducers(types.getVehicles, 'gettingVehicles'),
},
})
......
......@@ -7,25 +7,13 @@ export interface CDIdentificationState extends ExtendedState {
hasAccount: boolean
}
export const initialState: CDIdentificationState =
process.env.NODE_ENV === 'development'
? {
id: '',
name: 'TEST',
cpfcnpj: '80.162.745/0001-96',
gender: '1',
type: INVOLVED_PERSON_TYPES['CUSTOMER'],
hasAccount: false,
account: { agencyNumber: '', number: '', cardPicture: '' },
dataType: { doesWithdrawal: false, framework: '1' },
}
: {
id: '',
name: '',
cpfcnpj: '',
gender: '',
type: INVOLVED_PERSON_TYPES['CUSTOMER'],
hasAccount: false,
account: { agencyNumber: '', number: '', cardPicture: '' },
dataType: { doesWithdrawal: false, framework: '' },
}
export const initialState: CDIdentificationState = {
id: '',
name: '',
cpfcnpj: '',
gender: '',
type: INVOLVED_PERSON_TYPES['CUSTOMER'],
hasAccount: false,
account: { agencyNumber: '', number: '', cardPicture: '' },
dataType: { doesWithdrawal: false, framework: '' },
}
......@@ -11,7 +11,7 @@ export interface ConnectedProps {
}
type StateProps = Pick<ConnectedProps, 'fetching' | 'context'>
// type DispatchProps = Pick<ConnectedProps, 'updateIndentification'>
// type DispatchProps = Pick<ConnectedProps, 'getReferences'>
const mapStateToProps = (state: StoreState): StateProps => ({
fetching: ucProposalDataContext.selectors.isFetching(state.ui.login),
......@@ -21,6 +21,7 @@ const mapStateToProps = (state: StoreState): StateProps => ({
// const mapDispatchToProps = (dispatch: Dispatch): DispatchProps =>
// bindActionCreators(
// {
// getReferences: ucProposalData.actions.getReferences,
// },
// dispatch
// )
......
......@@ -2,7 +2,14 @@ import React, { useEffect, useState } from 'react'
import { Reference } from '@agiliza/api/domain/proposalData/involvedPeople/reference'
import { ActionType } from '@agiliza/utils/hooks/state'
import { Avatar, List, ListItem, ListItemAvatar, ListItemText } from '@material-ui/core'
import {
Avatar,
CircularProgress,
List,
ListItem,
ListItemAvatar,
ListItemText
} from '@material-ui/core'
import { withStyles, WithStyles } from '@material-ui/core/styles'
import { Add as AddIcon, EmojiEmotions as EmojiEmotionsIcon } from '@material-ui/icons'
......@@ -23,14 +30,12 @@ interface Props extends ExtendedProps {
const References = (props: Props) => {
const { classes, fetching, context, state, actions, references, projectId, personId } = props
console.log(personId)
const [selectedReference, setSelectedReference] = useState<Reference | undefined>()
const [open, setOpen] = useState(false)
useEffect(() => {
props.getReferences({ personId, projectId })
props.getReferences({ projectId, personId })
}, [])
const handleClickListItem = (reference: Reference) => () => {
......@@ -49,8 +54,8 @@ const References = (props: Props) => {
const handleSave = (reference: Reference, add: boolean) => () => {
const onSuccess = () => {
setOpen(false)
setSelectedReference(reference)
// setOpen(false)
// setSelectedReference(reference)
}
if (add)
props.addReference({
......@@ -69,6 +74,8 @@ const References = (props: Props) => {
})
}
if (fetching) return <CircularProgress className={classes.circularProgress} />
return (
<>
<div className={classes.contentContainer}>
......
......@@ -20,7 +20,7 @@ type StateProps = Pick<ConnectedProps, 'fetching' | 'context' | 'references'>
type DispatchProps = Pick<ConnectedProps, 'getReferences' | 'addReference' | 'updateReference'>
const mapStateToProps = (state: StoreState): StateProps => ({
fetching: ucProposalData.selectors.isFetching(state.useCases.proposalData.customerData),
fetching: ucProposalData.selectors.isGettingReferences(state.useCases.proposalData.customerData),
context: entProposalDataContext.selectors.getContext(state.entities.proposalData.context),
references: entCustomerData.selectors.getReferences(state.entities.proposalData.customerData),
})
......
import React, { useState } from 'react'
import React, { useEffect, useState } from 'react'
import { Vehicle } from '@agiliza/api/domain'
import { ActionType } from '@agiliza/utils/hooks/state'
import { Avatar, List, ListItem, ListItemAvatar, ListItemText } from '@material-ui/core'
import {
Avatar,
CircularProgress,
List,
ListItem,
ListItemAvatar,
ListItemText
} from '@material-ui/core'
import { withStyles, WithStyles } from '@material-ui/core/styles'
import { Add as AddIcon, DriveEta as DriveEtaIcon } from '@material-ui/icons'
......@@ -26,6 +33,9 @@ const Vehicles = (props: Props) => {
const [selectedVehicle, setSelectedVehicle] = useState<Vehicle | undefined>()
const [open, setOpen] = useState(false)
useEffect(() => {
props.getVehicles({ personId, projectId })
}, [])
const handleClickListItem = (vehicle: Vehicle) => () => {
setOpen(true)
......@@ -64,6 +74,8 @@ const Vehicles = (props: Props) => {
})
}
if (fetching) return <CircularProgress className={classes.circularProgress} />
return (
<>
<div className={classes.contentContainer}>
......
......@@ -20,7 +20,7 @@ type StateProps = Pick<ConnectedProps, 'fetching' | 'context' | 'vehicles'>
type DispatchProps = Pick<ConnectedProps, 'getVehicles' | 'addVehicle' | 'updateVehicle'>
const mapStateToProps = (state: StoreState): StateProps => ({
fetching: ucProposalData.selectors.isFetching(state.useCases.proposalData.customerData),
fetching: ucProposalData.selectors.isGettingVehicles(state.useCases.proposalData.customerData),
context: entProposalDataContext.selectors.getContext(state.entities.proposalData.context),
vehicles: entCustomerData.selectors.getVehicles(state.entities.proposalData.customerData),
})
......
......@@ -88,7 +88,12 @@ const ProposalData = (props: Props) => {
props.getCDIdentification({
projectId: proposalId,
onSuccess: (pID) => {
if (pID) props.getCustomerData({ projectId: proposalId, personId: pID })
if (pID)
props.getCustomerData({
projectId: proposalId,
personId: pID,
onSuccess: (cD) => {},
})
},
})
}, [])
......@@ -137,20 +142,18 @@ const ProposalData = (props: Props) => {
else return idn
}, {})
)
}, [customerData])
useEffect(() => {
const { identification, address, stockSalesCosts } = businessData
if (identification)
const { identification: bdIdentification, address: bdAddress, stockSalesCosts } = businessData
if (bdIdentification)
bdIdentificationState.actions.update(
entries(identification).reduce((idn, [k, v]) => {
entries(bdIdentification).reduce((idn, [k, v]) => {
if (v !== undefined) return { ...idn, [k]: v }
else return idn
}, {})
)
if (address)
if (bdAddress)
bdAddressState.actions.update(
entries(address).reduce((idn, [k, v]) => {
entries(bdAddress).reduce((idn, [k, v]) => {
if (v !== undefined) return { ...idn, [k]: v }
else return idn
}, {})
......@@ -162,7 +165,7 @@ const ProposalData = (props: Props) => {
else return idn
}, {})
)
}, [businessData])
}, [customerData, businessData])
const customerDataItems = useMemo(
() => [
......@@ -171,7 +174,11 @@ const ProposalData = (props: Props) => {
icon: <AccountBoxIcon />,
component: <Identification state={cdIdentification.state} actions={cdIdentification.actions} />,
},
{ label: 'Dados Pessoais', icon: <ListIcon />, component: <PersonalData state={cdPersonalData.state} actions={cdPersonalData.actions} /> },
{
label: 'Dados Pessoais',
icon: <ListIcon />,
component: <PersonalData state={cdPersonalData.state} actions={cdPersonalData.actions} />,
},
{ label: 'Endereço', icon: <ContactMailIcon />, component: <Address state={cdAddress.state} actions={cdAddress.actions} /> },
{ label: 'Fonte de renda', icon: <LocalAtmIcon />, component: <SourceIncome state={cdSourceIncome.state} actions={cdSourceIncome.actions} /> },
{ label: 'Cônjuge - Ident.', icon: <ForumIcon />, component: <SpouseData state={cdSpouseData.state} actions={cdSpouseData.actions} /> },
......@@ -192,7 +199,7 @@ const ProposalData = (props: Props) => {
component: <Vehicles state={cdVehicleState.state} actions={cdVehicleState.actions} projectId={proposalId} personId={personId} />,
},
],
[cdIdentification, cdPersonalData, cdAddress, cdSpouseData, cdReference, cdHomeState, cdVehicleState]
[cdIdentification, cdPersonalData, cdAddress, cdSourceIncome, cdSpouseData, cdReference, cdHomeState, cdVehicleState]
)
const businessDataItems = useMemo(
......
......@@ -36,6 +36,7 @@ export interface ConnectedProps {
getCDIdentification: typeof ucProposalDataCD.actions.getIdentification
getCustomerData: typeof ucProposalDataCD.actions.getCustomerData
getBusinessData: typeof ucProposalDataBD.actions.getBusinessData
getReferences: typeof ucProposalDataCD.actions.getReferences
}
type StateProps = Pick<ConnectedProps, 'fetching' | 'proposalId' | 'personId' | 'businessData' | 'customerData'>
......@@ -58,6 +59,7 @@ type DispatchProps = Pick<
| 'getCDIdentification'
| 'getCustomerData'
| 'getBusinessData'
| 'getReferences'
>
const isFetching = createSelector(
......@@ -99,6 +101,7 @@ const mapDispatchToProps = (dispatch: Dispatch): DispatchProps =>
getBusinessData: ucProposalDataBD.actions.getBusinessData,
getCustomerData: ucProposalDataCD.actions.getCustomerData,
getCDIdentification: ucProposalDataCD.actions.getIdentification,
getReferences: ucProposalDataCD.actions.getReferences,
},
dispatch
)
......
......@@ -11,7 +11,7 @@ export default (theme: Theme) => {
padding: theme.spacing(2),
display: 'flex',
flexDirection: 'column',
overflowY: 'hidden',
overflowY: 'auto',
},
title: {
flexGrow: 1,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment