diff --git a/src/lib/api/adapters/crew.adapter.ts b/src/lib/api/adapters/crew.adapter.ts index 21a54114..4d5ca4e9 100644 --- a/src/lib/api/adapters/crew.adapter.ts +++ b/src/lib/api/adapters/crew.adapter.ts @@ -292,6 +292,33 @@ export class CrewAdapter extends BaseAdapter { this.clearCache('/crew/members') return response.phantom_player } + + /** + * Decline claim of a phantom player (by the assigned user) + */ + async declinePhantomClaim(crewId: string, phantomId: string, options?: RequestOptions): Promise { + const response = await this.request<{ phantom_player: PhantomPlayer }>( + `/crews/${crewId}/phantom_players/${phantomId}/decline_claim`, + { + ...options, + method: 'POST' + } + ) + this.clearCache('/crew/members') + this.clearCache('/pending_phantom_claims') + return response.phantom_player + } + + /** + * Get pending phantom claims for current user (phantoms assigned but not yet confirmed) + */ + async getPendingPhantomClaims(options?: RequestOptions): Promise { + const response = await this.request<{ phantom_claims: PhantomPlayer[] }>( + '/pending_phantom_claims', + options + ) + return response.phantom_claims + } } export const crewAdapter = new CrewAdapter(DEFAULT_ADAPTER_CONFIG) diff --git a/src/lib/api/mutations/crew.mutations.ts b/src/lib/api/mutations/crew.mutations.ts index 899cc09f..9dec5fe5 100644 --- a/src/lib/api/mutations/crew.mutations.ts +++ b/src/lib/api/mutations/crew.mutations.ts @@ -268,6 +268,23 @@ export function useConfirmPhantomClaim() { crewAdapter.confirmPhantomClaim(crewId, phantomId), onSuccess: () => { queryClient.invalidateQueries({ queryKey: crewKeys.membersAll() }) + queryClient.invalidateQueries({ queryKey: crewKeys.phantomClaims.pending() }) + } + })) +} + +/** + * Decline phantom claim mutation + */ +export function useDeclinePhantomClaim() { + const queryClient = useQueryClient() + + return createMutation(() => ({ + mutationFn: ({ crewId, phantomId }: { crewId: string; phantomId: string }) => + crewAdapter.declinePhantomClaim(crewId, phantomId), + onSuccess: () => { + queryClient.invalidateQueries({ queryKey: crewKeys.membersAll() }) + queryClient.invalidateQueries({ queryKey: crewKeys.phantomClaims.pending() }) } })) } diff --git a/src/lib/api/queries/crew.queries.ts b/src/lib/api/queries/crew.queries.ts index 2fc574c1..c768226f 100644 --- a/src/lib/api/queries/crew.queries.ts +++ b/src/lib/api/queries/crew.queries.ts @@ -84,6 +84,18 @@ export const crewQueries = { queryFn: () => crewAdapter.getPendingInvitations(), staleTime: 1000 * 60 * 2, // 2 minutes gcTime: 1000 * 60 * 15 // 15 minutes + }), + + /** + * Current user's pending phantom claims query options + * Returns phantoms assigned to the user that need to be accepted or declined + */ + pendingPhantomClaims: () => + queryOptions({ + queryKey: ['phantom_claims', 'pending'] as const, + queryFn: () => crewAdapter.getPendingPhantomClaims(), + staleTime: 1000 * 60 * 2, // 2 minutes + gcTime: 1000 * 60 * 15 // 15 minutes }) } @@ -113,5 +125,9 @@ export const crewKeys = { invitations: { all: ['invitations'] as const, pending: () => ['invitations', 'pending'] as const + }, + phantomClaims: { + all: ['phantom_claims'] as const, + pending: () => ['phantom_claims', 'pending'] as const } } diff --git a/src/lib/types/api/crew.ts b/src/lib/types/api/crew.ts index 5e798a1e..a122c513 100644 --- a/src/lib/types/api/crew.ts +++ b/src/lib/types/api/crew.ts @@ -65,6 +65,8 @@ export interface PhantomPlayer { // From :with_scores view totalScore?: number scoreCount?: number + // From :with_crew view + crew?: CrewMinimal } // CrewInvitation from CrewInvitationBlueprint