Skip to content

Commit

Permalink
feat(native-app): Revert "feat: update vehicleList endpoint to V2" (#…
Browse files Browse the repository at this point in the history
…16823)

This reverts commit 036f952.

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
thoreyjona and kodiakhq[bot] authored Nov 13, 2024
1 parent 378ee5f commit de4bcc8
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 37 deletions.
39 changes: 34 additions & 5 deletions apps/native/app/src/graphql/fragments/vehicle.fragment.graphql
Original file line number Diff line number Diff line change
@@ -1,10 +1,39 @@
fragment VehicleFragment on VehicleListed {
fragment VehicleFragment on VehiclesVehicle {
isCurrent
permno
regno
make
colorName
vin
type
color
firstRegDate
modelYear
productYear
registrationType
role
operatorStartDate
operatorEndDate
outOfUse
otherOwners
termination
buyerPersidno
ownerPersidno
vehicleStatus
useGroup
vehGroup
plateStatus
nextInspection {
nextInspectionDate
nextInspectionDateIfPassedInspectionToday
}
operatorNumber
primaryOperator
ownerSsid
ownerName
lastInspectionResult
lastInspectionDate
lastInspectionType
nextInspectionDate
nextAvailableMileageReadDate
requiresMileageRegistration
canRegisterMilage
nextMainInspection
canRegisterMileage
}
4 changes: 2 additions & 2 deletions apps/native/app/src/graphql/queries/vehicles.graphql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
query ListVehiclesV2($input: GetVehiclesListV2Input!) {
vehiclesListV2(input: $input) {
query ListVehicles($input: GetVehiclesForUserInput!) {
vehiclesList(input: $input) {
vehicleList {
...VehicleFragment
}
Expand Down
6 changes: 4 additions & 2 deletions apps/native/app/src/screens/home/home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ import {
} from './licenses-module'
import { OnboardingModule } from './onboarding-module'
import {
useListVehiclesV2Query,
useListVehiclesQuery,
validateVehiclesInitialData,
VehiclesModule,
} from './vehicles-module'
Expand Down Expand Up @@ -174,11 +174,13 @@ export const MainHomeScreen: NavigationFunctionComponent = ({
skip: !airDiscountWidgetEnabled,
})

const vehiclesRes = useListVehiclesV2Query({
const vehiclesRes = useListVehiclesQuery({
variables: {
input: {
page: 1,
pageSize: 15,
showDeregeristered: false,
showHistory: false,
},
},
skip: !vehiclesWidgetEnabled,
Expand Down
14 changes: 7 additions & 7 deletions apps/native/app/src/screens/home/vehicles-module.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import illustrationSrc from '../../assets/illustrations/le-moving-s4.png'
import { navigateTo } from '../../lib/deep-linking'
import { VehicleItem } from '../vehicles/components/vehicle-item'
import {
ListVehiclesV2Query,
useListVehiclesV2Query,
ListVehiclesQuery,
useListVehiclesQuery,
} from '../../graphql/types/schema'
import { screenWidth } from '../../utils/dimensions'

Expand All @@ -30,15 +30,15 @@ const validateVehiclesInitialData = ({
data,
loading,
}: {
data: ListVehiclesV2Query | undefined
data: ListVehiclesQuery | undefined
loading: boolean
}) => {
if (loading) {
return true
}
// Only show widget initially if there are vehicles that require mileage registration
if (
data?.vehiclesListV2?.vehicleList?.some(
data?.vehiclesList?.vehicleList?.some(
(vehicle) => vehicle.requiresMileageRegistration,
)
) {
Expand All @@ -49,7 +49,7 @@ const validateVehiclesInitialData = ({
}

interface VehiclesModuleProps {
data: ListVehiclesV2Query | undefined
data: ListVehiclesQuery | undefined
loading: boolean
error?: ApolloError | undefined
}
Expand All @@ -59,7 +59,7 @@ const VehiclesModule = React.memo(
const theme = useTheme()
const intl = useIntl()

const vehicles = data?.vehiclesListV2?.vehicleList
const vehicles = data?.vehiclesList?.vehicleList

// Reorder vehicles so vehicles that require mileage registration are shown first
const reorderedVehicles = useMemo(
Expand Down Expand Up @@ -170,4 +170,4 @@ const VehiclesModule = React.memo(
},
)

export { VehiclesModule, validateVehiclesInitialData, useListVehiclesV2Query }
export { VehiclesModule, validateVehiclesInitialData, useListVehiclesQuery }
14 changes: 7 additions & 7 deletions apps/native/app/src/screens/vehicles/components/vehicle-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import React from 'react'
import { FormattedDate, FormattedMessage } from 'react-intl'
import { SafeAreaView, TouchableHighlight, View, ViewStyle } from 'react-native'
import styled, { useTheme } from 'styled-components/native'
import { ListVehiclesV2Query } from '../../../graphql/types/schema'
import { ListVehiclesQuery } from '../../../graphql/types/schema'
import { navigateTo } from '../../../lib/deep-linking'

function differenceInMonths(a: Date, b: Date) {
return a.getMonth() - b.getMonth() + 12 * (a.getFullYear() - b.getFullYear())
}

type VehicleListItem = NonNullable<
NonNullable<ListVehiclesV2Query['vehiclesListV2']>['vehicleList']
NonNullable<ListVehiclesQuery['vehiclesList']>['vehicleList']
>[0]

const Cell = styled(TouchableHighlight)`
Expand All @@ -31,8 +31,8 @@ export const VehicleItem = React.memo(
style?: ViewStyle
}) => {
const theme = useTheme()
const nextInspection = item?.nextMainInspection
? new Date(item?.nextMainInspection)
const nextInspection = item?.nextInspection?.nextInspectionDate
? new Date(item?.nextInspection.nextInspectionDate)
: null

const isInspectionDeadline =
Expand All @@ -51,14 +51,14 @@ export const VehicleItem = React.memo(
onPress={() => {
navigateTo(`/vehicle/`, {
id: item.permno,
title: item.make,
title: item.type,
})
}}
>
<SafeAreaView>
<VehicleCard
title={item.make}
color={item.colorName}
title={item.type}
color={item.color}
number={item.regno}
minHeight={minHeight}
label={
Expand Down
28 changes: 14 additions & 14 deletions apps/native/app/src/screens/vehicles/vehicles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import { useTheme } from 'styled-components/native'
import illustrationSrc from '../../assets/illustrations/le-moving-s4.png'
import { BottomTabsIndicator } from '../../components/bottom-tabs-indicator/bottom-tabs-indicator'
import {
ListVehiclesV2Query,
useListVehiclesV2Query,
ListVehiclesQuery,
useListVehiclesQuery,
} from '../../graphql/types/schema'
import { createNavigationOptionHooks } from '../../hooks/create-navigation-option-hooks'
import { useConnectivityIndicator } from '../../hooks/use-connectivity-indicator'
Expand All @@ -32,7 +32,7 @@ const { useNavigationOptions, getNavigationOptions } =
}))

type VehicleListItem = NonNullable<
NonNullable<ListVehiclesV2Query['vehiclesListV2']>['vehicleList']
NonNullable<ListVehiclesQuery['vehiclesList']>['vehicleList']
>[0]

type ListItem =
Expand Down Expand Up @@ -61,6 +61,8 @@ const Empty = () => (
const input = {
page: 1,
pageSize: 10,
showDeregeristered: false,
showHistory: false,
}

export const VehiclesScreen: NavigationFunctionComponent = ({
Expand All @@ -75,7 +77,7 @@ export const VehiclesScreen: NavigationFunctionComponent = ({
const scrollY = useRef(new Animated.Value(0)).current
const loadingTimeout = useRef<ReturnType<typeof setTimeout>>()

const res = useListVehiclesV2Query({
const res = useListVehiclesQuery({
variables: {
input,
},
Expand Down Expand Up @@ -133,9 +135,7 @@ export const VehiclesScreen: NavigationFunctionComponent = ({
// Extract key of data
const keyExtractor = useCallback(
(item: ListItem, index: number) =>
item.__typename === 'Skeleton'
? String(item.id)
: `${item.permno}${index}`,
item.__typename === 'Skeleton' ? String(item.id) : `${item.vin}${index}`,
[],
)

Expand All @@ -147,7 +147,7 @@ export const VehiclesScreen: NavigationFunctionComponent = ({
__typename: 'Skeleton',
}))
}
return res?.data?.vehiclesListV2?.vehicleList || []
return res?.data?.vehiclesList?.vehicleList || []
}, [res.data, res.loading])

return (
Expand Down Expand Up @@ -184,8 +184,8 @@ export const VehiclesScreen: NavigationFunctionComponent = ({
if (res.loading) {
return
}
const pageNumber = res.data?.vehiclesListV2?.paging?.pageNumber ?? 1
const totalPages = res.data?.vehiclesListV2?.paging?.totalPages ?? 1
const pageNumber = res.data?.vehiclesList?.paging?.pageNumber ?? 1
const totalPages = res.data?.vehiclesList?.paging?.totalPages ?? 1
if (pageNumber >= totalPages) {
return
}
Expand All @@ -200,11 +200,11 @@ export const VehiclesScreen: NavigationFunctionComponent = ({
},
updateQuery(prev, { fetchMoreResult }) {
return {
vehiclesListV2: {
...fetchMoreResult.vehiclesListV2,
vehiclesList: {
...fetchMoreResult.vehiclesList,
vehicleList: [
...(prev.vehiclesListV2?.vehicleList ?? []),
...(fetchMoreResult.vehiclesListV2?.vehicleList ?? []),
...(prev.vehiclesList?.vehicleList ?? []),
...(fetchMoreResult.vehiclesList?.vehicleList ?? []),
],
},
}
Expand Down

0 comments on commit de4bcc8

Please sign in to comment.