From 036f952acbe8f0849e5830a47a26f1e22ed6ea39 Mon Sep 17 00:00:00 2001 From: thoreyjona Date: Fri, 8 Nov 2024 10:21:31 +0000 Subject: [PATCH 1/2] feat: update vehicleList endpoint to V2 --- .../fragments/vehicle.fragment.graphql | 39 +++---------------- .../app/src/graphql/queries/vehicles.graphql | 4 +- apps/native/app/src/screens/home/home.tsx | 6 +-- .../app/src/screens/home/vehicles-module.tsx | 14 +++---- .../vehicles/components/vehicle-item.tsx | 16 ++++---- .../app/src/screens/vehicles/vehicles.tsx | 28 ++++++------- 6 files changed, 39 insertions(+), 68 deletions(-) diff --git a/apps/native/app/src/graphql/fragments/vehicle.fragment.graphql b/apps/native/app/src/graphql/fragments/vehicle.fragment.graphql index 244ad841d50a..ba48326227e9 100644 --- a/apps/native/app/src/graphql/fragments/vehicle.fragment.graphql +++ b/apps/native/app/src/graphql/fragments/vehicle.fragment.graphql @@ -1,39 +1,10 @@ -fragment VehicleFragment on VehiclesVehicle { - isCurrent +fragment VehicleFragment on VehicleListed { permno regno - vin - type - color - firstRegDate + make + colorName 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 - canRegisterMileage + canRegisterMilage + nextMainInspection } diff --git a/apps/native/app/src/graphql/queries/vehicles.graphql b/apps/native/app/src/graphql/queries/vehicles.graphql index da2ad3c69212..a88bb380e3b7 100644 --- a/apps/native/app/src/graphql/queries/vehicles.graphql +++ b/apps/native/app/src/graphql/queries/vehicles.graphql @@ -1,5 +1,5 @@ -query ListVehicles($input: GetVehiclesForUserInput!) { - vehiclesList(input: $input) { +query ListVehiclesV2($input: GetVehiclesListV2Input!) { + vehiclesListV2(input: $input) { vehicleList { ...VehicleFragment } diff --git a/apps/native/app/src/screens/home/home.tsx b/apps/native/app/src/screens/home/home.tsx index 057b658de585..f228c0843a88 100644 --- a/apps/native/app/src/screens/home/home.tsx +++ b/apps/native/app/src/screens/home/home.tsx @@ -55,7 +55,7 @@ import { } from './licenses-module' import { OnboardingModule } from './onboarding-module' import { - useListVehiclesQuery, + useListVehiclesV2Query, validateVehiclesInitialData, VehiclesModule, } from './vehicles-module' @@ -174,13 +174,11 @@ export const MainHomeScreen: NavigationFunctionComponent = ({ skip: !airDiscountWidgetEnabled, }) - const vehiclesRes = useListVehiclesQuery({ + const vehiclesRes = useListVehiclesV2Query({ variables: { input: { page: 1, pageSize: 15, - showDeregeristered: false, - showHistory: false, }, }, skip: !vehiclesWidgetEnabled, diff --git a/apps/native/app/src/screens/home/vehicles-module.tsx b/apps/native/app/src/screens/home/vehicles-module.tsx index 02975f50a8e2..34c5c709c86d 100644 --- a/apps/native/app/src/screens/home/vehicles-module.tsx +++ b/apps/native/app/src/screens/home/vehicles-module.tsx @@ -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 { - ListVehiclesQuery, - useListVehiclesQuery, + ListVehiclesV2Query, + useListVehiclesV2Query, } from '../../graphql/types/schema' import { screenWidth } from '../../utils/dimensions' @@ -30,7 +30,7 @@ const validateVehiclesInitialData = ({ data, loading, }: { - data: ListVehiclesQuery | undefined + data: ListVehiclesV2Query | undefined loading: boolean }) => { if (loading) { @@ -38,7 +38,7 @@ const validateVehiclesInitialData = ({ } // Only show widget initially if there are vehicles that require mileage registration if ( - data?.vehiclesList?.vehicleList?.some( + data?.vehiclesListV2?.vehicleList?.some( (vehicle) => vehicle.requiresMileageRegistration, ) ) { @@ -49,7 +49,7 @@ const validateVehiclesInitialData = ({ } interface VehiclesModuleProps { - data: ListVehiclesQuery | undefined + data: ListVehiclesV2Query | undefined loading: boolean error?: ApolloError | undefined } @@ -59,7 +59,7 @@ const VehiclesModule = React.memo( const theme = useTheme() const intl = useIntl() - const vehicles = data?.vehiclesList?.vehicleList + const vehicles = data?.vehiclesListV2?.vehicleList // Reorder vehicles so vehicles that require mileage registration are shown first const reorderedVehicles = useMemo( @@ -170,4 +170,4 @@ const VehiclesModule = React.memo( }, ) -export { VehiclesModule, validateVehiclesInitialData, useListVehiclesQuery } +export { VehiclesModule, validateVehiclesInitialData, useListVehiclesV2Query } diff --git a/apps/native/app/src/screens/vehicles/components/vehicle-item.tsx b/apps/native/app/src/screens/vehicles/components/vehicle-item.tsx index 100dc377366b..ea07af195556 100644 --- a/apps/native/app/src/screens/vehicles/components/vehicle-item.tsx +++ b/apps/native/app/src/screens/vehicles/components/vehicle-item.tsx @@ -3,7 +3,7 @@ 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 { ListVehiclesQuery } from '../../../graphql/types/schema' +import { ListVehiclesV2Query } from '../../../graphql/types/schema' import { navigateTo } from '../../../lib/deep-linking' function differenceInMonths(a: Date, b: Date) { @@ -11,7 +11,7 @@ function differenceInMonths(a: Date, b: Date) { } type VehicleListItem = NonNullable< - NonNullable['vehicleList'] + NonNullable['vehicleList'] >[0] const Cell = styled(TouchableHighlight)` @@ -31,8 +31,8 @@ export const VehicleItem = React.memo( style?: ViewStyle }) => { const theme = useTheme() - const nextInspection = item?.nextInspection?.nextInspectionDate - ? new Date(item?.nextInspection.nextInspectionDate) + const nextInspection = item?.nextMainInspection + ? new Date(item?.nextMainInspection) : null const isInspectionDeadline = @@ -42,6 +42,8 @@ export const VehicleItem = React.memo( const isMileageRequired = item.requiresMileageRegistration + // type - permno - regno - color + return ( { navigateTo(`/vehicle/`, { id: item.permno, - title: item.type, + title: item.make, }) }} > ['vehicleList'] + NonNullable['vehicleList'] >[0] type ListItem = @@ -61,8 +61,6 @@ const Empty = () => ( const input = { page: 1, pageSize: 10, - showDeregeristered: false, - showHistory: false, } export const VehiclesScreen: NavigationFunctionComponent = ({ @@ -77,7 +75,7 @@ export const VehiclesScreen: NavigationFunctionComponent = ({ const scrollY = useRef(new Animated.Value(0)).current const loadingTimeout = useRef>() - const res = useListVehiclesQuery({ + const res = useListVehiclesV2Query({ variables: { input, }, @@ -135,7 +133,9 @@ export const VehiclesScreen: NavigationFunctionComponent = ({ // Extract key of data const keyExtractor = useCallback( (item: ListItem, index: number) => - item.__typename === 'Skeleton' ? String(item.id) : `${item.vin}${index}`, + item.__typename === 'Skeleton' + ? String(item.id) + : `${item.permno}${index}`, [], ) @@ -147,7 +147,7 @@ export const VehiclesScreen: NavigationFunctionComponent = ({ __typename: 'Skeleton', })) } - return res?.data?.vehiclesList?.vehicleList || [] + return res?.data?.vehiclesListV2?.vehicleList || [] }, [res.data, res.loading]) return ( @@ -184,8 +184,8 @@ export const VehiclesScreen: NavigationFunctionComponent = ({ if (res.loading) { return } - const pageNumber = res.data?.vehiclesList?.paging?.pageNumber ?? 1 - const totalPages = res.data?.vehiclesList?.paging?.totalPages ?? 1 + const pageNumber = res.data?.vehiclesListV2?.paging?.pageNumber ?? 1 + const totalPages = res.data?.vehiclesListV2?.paging?.totalPages ?? 1 if (pageNumber >= totalPages) { return } @@ -200,11 +200,11 @@ export const VehiclesScreen: NavigationFunctionComponent = ({ }, updateQuery(prev, { fetchMoreResult }) { return { - vehiclesList: { - ...fetchMoreResult.vehiclesList, + vehiclesListV2: { + ...fetchMoreResult.vehiclesListV2, vehicleList: [ - ...(prev.vehiclesList?.vehicleList ?? []), - ...(fetchMoreResult.vehiclesList?.vehicleList ?? []), + ...(prev.vehiclesListV2?.vehicleList ?? []), + ...(fetchMoreResult.vehiclesListV2?.vehicleList ?? []), ], }, } From 17089b3b238d012763b42d3a14c4796954050d53 Mon Sep 17 00:00:00 2001 From: thoreyjona Date: Fri, 8 Nov 2024 10:23:52 +0000 Subject: [PATCH 2/2] fix: remove comment --- .../native/app/src/screens/vehicles/components/vehicle-item.tsx | 2 -- 1 file changed, 2 deletions(-) diff --git a/apps/native/app/src/screens/vehicles/components/vehicle-item.tsx b/apps/native/app/src/screens/vehicles/components/vehicle-item.tsx index ea07af195556..afe6b8c607a5 100644 --- a/apps/native/app/src/screens/vehicles/components/vehicle-item.tsx +++ b/apps/native/app/src/screens/vehicles/components/vehicle-item.tsx @@ -42,8 +42,6 @@ export const VehicleItem = React.memo( const isMileageRequired = item.requiresMileageRegistration - // type - permno - regno - color - return (