Files
gridpilot.gg/apps/website/hooks/driver/useUpdateDriverProfile.ts
Marc Mintel 09632d004d
Some checks failed
CI / lint-typecheck (pull_request) Failing after 12s
CI / tests (pull_request) Has been skipped
CI / contract-tests (pull_request) Has been skipped
CI / e2e-tests (pull_request) Has been skipped
CI / comment-pr (pull_request) Has been skipped
CI / commit-types (pull_request) Has been skipped
code quality
2026-01-26 22:16:33 +01:00

31 lines
1.4 KiB
TypeScript

import { DriverProfileViewDataBuilder } from '@/lib/builders/view-data/DriverProfileViewDataBuilder';
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 type { DriverProfileViewData } from '@/lib/view-data/DriverProfileViewData';
import { useMutation, UseMutationOptions } from '@tanstack/react-query';
export function useUpdateDriverProfile(
options?: Omit<UseMutationOptions<DriverProfileViewData, ApiError, { bio?: string; country?: string }>, 'mutationFn'>
) {
const driverService = useInject(DRIVER_SERVICE_TOKEN);
return useMutation<DriverProfileViewData, 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 DriverProfileViewDataBuilder.build({
teamMemberships: [],
socialSummary: { friends: [], friendsCount: 0 },
} as unknown as GetDriverProfileOutputDTO);
},
...options,
});
}