feat: prompt vehicle selection on login after auto-downgrade (#60) #62
@@ -1,8 +1,9 @@
|
||||
import { apiClient } from '../../../core/api/client';
|
||||
import type { CheckoutRequest, PaymentMethodUpdateRequest, DowngradeRequest } from '../types/subscription.types';
|
||||
import type { CheckoutRequest, PaymentMethodUpdateRequest, DowngradeRequest, NeedsVehicleSelectionResponse } from '../types/subscription.types';
|
||||
|
||||
export const subscriptionApi = {
|
||||
getSubscription: () => apiClient.get('/subscriptions'),
|
||||
needsVehicleSelection: () => apiClient.get<NeedsVehicleSelectionResponse>('/subscriptions/needs-vehicle-selection'),
|
||||
checkout: (data: CheckoutRequest) => apiClient.post('/subscriptions/checkout', data),
|
||||
cancel: () => apiClient.post('/subscriptions/cancel'),
|
||||
reactivate: () => apiClient.post('/subscriptions/reactivate'),
|
||||
|
||||
@@ -19,6 +19,17 @@ export const useSubscription = () => {
|
||||
});
|
||||
};
|
||||
|
||||
export const useNeedsVehicleSelection = () => {
|
||||
const { isAuthenticated, isLoading } = useAuth0();
|
||||
|
||||
return useQuery({
|
||||
queryKey: ['needs-vehicle-selection'],
|
||||
queryFn: () => subscriptionApi.needsVehicleSelection(),
|
||||
enabled: isAuthenticated && !isLoading,
|
||||
staleTime: 0, // Always fetch fresh on login
|
||||
});
|
||||
};
|
||||
|
||||
export const useCheckout = () => {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
|
||||
@@ -41,3 +41,9 @@ export interface DowngradeRequest {
|
||||
targetTier: SubscriptionTier;
|
||||
vehicleIdsToKeep: string[];
|
||||
}
|
||||
|
||||
export interface NeedsVehicleSelectionResponse {
|
||||
needsSelection: boolean;
|
||||
vehicleCount: number;
|
||||
maxAllowed: number;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user