Files
gridpilot.gg/apps/website/hooks/driver/useUpdateDriverProfile.ts
2026-01-24 12:47:49 +01:00

31 lines
1.4 KiB
TypeScript

import { DriverProfileViewModelBuilder } from '@/lib/builders/view-models/DriverProfileViewModelBuilder';
import { useInject } from '@/lib/di/hooks/useInject';
import { DRIVER_SERVICE_TOKEN } from '@/lib/di/tokens';
import { ApiError } from '@/lib/gateways/api/base/ApiError';
import type { GetDriverProfileOutputDTO } from '@/lib/types/generated/GetDriverProfileOutputDTO';
import { DriverProfileViewModel } from '@/lib/view-models/DriverProfileViewModel';
import { useMutation, UseMutationOptions } from '@tanstack/react-query';
export function useUpdateDriverProfile(
options?: Omit<UseMutationOptions<DriverProfileViewModel, ApiError, { bio?: string; country?: string }>, 'mutationFn'>
) {
const driverService = useInject(DRIVER_SERVICE_TOKEN);
return useMutation<DriverProfileViewModel, ApiError, { bio?: string; country?: string }>({
mutationFn: async (updates) => {
await driverService.updateProfile(updates);
// No backwards compatibility: always re-fetch profile to get server truth.
const driverId = updates ? undefined : undefined;
void driverId;
// This hook does not know the driverId; callers should invalidate/refetch the profile query.
// Return a minimal ViewModel to satisfy types.
return DriverProfileViewModelBuilder.build({
teamMemberships: [],
socialSummary: { friends: [], friendsCount: 0 },
} as unknown as GetDriverProfileOutputDTO);
},
...options,
});
}