feat: add needsVehicleSelection frontend hook (refs #60)

- Add NeedsVehicleSelectionResponse type
- Add needsVehicleSelection API method
- Add useNeedsVehicleSelection hook with staleTime: 0

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Eric Gullickson
2026-01-24 11:27:02 -06:00
parent 684615a8a2
commit baf576f5cb
3 changed files with 19 additions and 1 deletions

View File

@@ -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'),

View File

@@ -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({

View File

@@ -41,3 +41,9 @@ export interface DowngradeRequest {
targetTier: SubscriptionTier;
vehicleIdsToKeep: string[];
}
export interface NeedsVehicleSelectionResponse {
needsSelection: boolean;
vehicleCount: number;
maxAllowed: number;
}