Skip to content

Commit

Permalink
feat: 🎨 list user hydrometers on personal consumption select
Browse files Browse the repository at this point in the history
  • Loading branch information
Vini7Dev committed Jun 25, 2023
1 parent 0adcf87 commit a86a141
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
30 changes: 25 additions & 5 deletions mobile/src/screens/PersonalConsumption/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useCallback, useState } from 'react'
import React, { useCallback, useEffect, useState } from 'react'
import { format } from 'date-fns'
import { LineChart } from 'react-native-gifted-charts'

Expand All @@ -18,6 +18,7 @@ import { NavigationHeader } from '../../components/NavigationHeader'
import { CompareByOptions } from '../../components/CompareByOptions'
import { MOCK_CONSUMPTIONS } from './MOCK_CONSUMPTIONS'
import { Select } from '../../components/Select'
import { api } from '../../services/api'

interface ConsumptionProps {
id: string
Expand All @@ -26,6 +27,11 @@ interface ConsumptionProps {
created_at: string
}

interface HydrometerProps {
id: string
name: string
}

const ChartComponent: React.FC = () => {
const {
pastGroup,
Expand Down Expand Up @@ -123,6 +129,20 @@ const ChartComponent: React.FC = () => {
export const PersonalConsumption: React.FC = () => {
const [selectedHydrometerId, setSelectedHydrometerId] = useState<string>()

const [userHydrometerList, setUserHydrometerList] = useState<HydrometerProps[]>([])

const handleGetUserHydrometerList = async () => {
const {
data: userHydrometerListResponse
} = await api.get<HydrometerProps[]>('/user-hydrometers')

setUserHydrometerList(userHydrometerListResponse)
}

useEffect(() => {
handleGetUserHydrometerList()
}, [])

const handleSelectHydrometer = useCallback((value?: string) => {
setSelectedHydrometerId(value)
}, [])
Expand All @@ -135,10 +155,10 @@ export const PersonalConsumption: React.FC = () => {
<ScreenContent>
<Select
placeholder="Selecione um hidrômetro"
options={[
{ label: 'Casa 1', value: '1' },
{ label: 'Casa 2', value: '2' },
]}
options={userHydrometerList.map(hydrometer => ({
value: hydrometer.id,
label: hydrometer.name,
}))}
onSelect={handleSelectHydrometer}
/>

Expand Down
2 changes: 1 addition & 1 deletion mobile/src/screens/PersonalHydrometersList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ const HydrometerItem: React.FC<HydrometerItemProps> = ({
</HydrometerName>

<HydrometerAddress>
{address.street} - {address.number ?? 'S/N'}
{address?.street ?? 'Sem endereço'} - {address?.number ?? 'S/N'}
</HydrometerAddress>
</>
</HydrometerNameContainer>
Expand Down

0 comments on commit a86a141

Please sign in to comment.