From de4bcc8be047d9e74c62d92a2a9ab8be22572b30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=9E=C3=B3rey=20J=C3=B3na?= Date: Wed, 13 Nov 2024 04:24:17 +0000 Subject: [PATCH] feat(native-app): Revert "feat: update vehicleList endpoint to V2" (#16823) This reverts commit 036f952acbe8f0849e5830a47a26f1e22ed6ea39. Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> --- .../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 | 14 +++---- .../app/src/screens/vehicles/vehicles.tsx | 28 ++++++------- 6 files changed, 68 insertions(+), 37 deletions(-) diff --git a/apps/native/app/src/graphql/fragments/vehicle.fragment.graphql b/apps/native/app/src/graphql/fragments/vehicle.fragment.graphql index ba48326227e9..244ad841d50a 100644 --- a/apps/native/app/src/graphql/fragments/vehicle.fragment.graphql +++ b/apps/native/app/src/graphql/fragments/vehicle.fragment.graphql @@ -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 } diff --git a/apps/native/app/src/graphql/queries/vehicles.graphql b/apps/native/app/src/graphql/queries/vehicles.graphql index a88bb380e3b7..da2ad3c69212 100644 --- a/apps/native/app/src/graphql/queries/vehicles.graphql +++ b/apps/native/app/src/graphql/queries/vehicles.graphql @@ -1,5 +1,5 @@ -query ListVehiclesV2($input: GetVehiclesListV2Input!) { - vehiclesListV2(input: $input) { +query ListVehicles($input: GetVehiclesForUserInput!) { + vehiclesList(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 f228c0843a88..057b658de585 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 { - useListVehiclesV2Query, + useListVehiclesQuery, validateVehiclesInitialData, VehiclesModule, } from './vehicles-module' @@ -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, diff --git a/apps/native/app/src/screens/home/vehicles-module.tsx b/apps/native/app/src/screens/home/vehicles-module.tsx index 34c5c709c86d..02975f50a8e2 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 { - ListVehiclesV2Query, - useListVehiclesV2Query, + ListVehiclesQuery, + useListVehiclesQuery, } from '../../graphql/types/schema' import { screenWidth } from '../../utils/dimensions' @@ -30,7 +30,7 @@ const validateVehiclesInitialData = ({ data, loading, }: { - data: ListVehiclesV2Query | undefined + data: ListVehiclesQuery | 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?.vehiclesListV2?.vehicleList?.some( + data?.vehiclesList?.vehicleList?.some( (vehicle) => vehicle.requiresMileageRegistration, ) ) { @@ -49,7 +49,7 @@ const validateVehiclesInitialData = ({ } interface VehiclesModuleProps { - data: ListVehiclesV2Query | undefined + data: ListVehiclesQuery | undefined loading: boolean error?: ApolloError | undefined } @@ -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( @@ -170,4 +170,4 @@ const VehiclesModule = React.memo( }, ) -export { VehiclesModule, validateVehiclesInitialData, useListVehiclesV2Query } +export { VehiclesModule, validateVehiclesInitialData, useListVehiclesQuery } 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 afe6b8c607a5..100dc377366b 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 { ListVehiclesV2Query } from '../../../graphql/types/schema' +import { ListVehiclesQuery } 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?.nextMainInspection - ? new Date(item?.nextMainInspection) + const nextInspection = item?.nextInspection?.nextInspectionDate + ? new Date(item?.nextInspection.nextInspectionDate) : null const isInspectionDeadline = @@ -51,14 +51,14 @@ export const VehicleItem = React.memo( onPress={() => { navigateTo(`/vehicle/`, { id: item.permno, - title: item.make, + title: item.type, }) }} > ['vehicleList'] + NonNullable['vehicleList'] >[0] type ListItem = @@ -61,6 +61,8 @@ const Empty = () => ( const input = { page: 1, pageSize: 10, + showDeregeristered: false, + showHistory: false, } export const VehiclesScreen: NavigationFunctionComponent = ({ @@ -75,7 +77,7 @@ export const VehiclesScreen: NavigationFunctionComponent = ({ const scrollY = useRef(new Animated.Value(0)).current const loadingTimeout = useRef>() - const res = useListVehiclesV2Query({ + const res = useListVehiclesQuery({ variables: { input, }, @@ -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}`, [], ) @@ -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 ( @@ -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 } @@ -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 ?? []), ], }, }