ef20839f99
Phase 1-2: Setup, SQL schema, enums, queue constants, base entities
Phase 3 (US1): ReviewTeam, ReviewTeamMember, ReviewTask, TaskCreationService
Phase 4 (US2): ResponseCode, ResponseCodeRule, ImplicationsService, NotificationTriggerService
Phase 5 (US3): Delegation entity, CircularDetectionService, DelegationService/Controller/Module
Phase 6 (US4): ReminderRule, SchedulerService, EscalationService, ReminderProcessor, ReminderModule
Phase 7 (US5): DistributionMatrix, DistributionRecipient, ApprovalListenerService (Strangler),
TransmittalCreatorService, DistributionProcessor, DistributionModule
Phase 8 (US6): MatrixManagementService, InheritanceService (global→project override)
Phase 9 (Polish): AggregateStatusService, ConsensusService, VetoOverrideService,
ParallelGatewayHandler, review-validators, optimistic locking in completeReview,
test stubs (unit/integration/e2e), jest.config.js updated for tests/ directory
Frontend: ReviewTaskInbox, ParallelProgress, VetoOverrideDialog, DelegationForm,
DelegatedBadge, MatrixEditor, ProjectOverrideManager, DistributionStatus,
ReminderHistory, ResponseCodeSelector, CodeImplications, CompleteReviewForm,
ReviewTeamForm, ReviewTeamSelector, TeamMemberManager
Closes #1
83 lines
2.2 KiB
TypeScript
83 lines
2.2 KiB
TypeScript
// File: hooks/use-delegation.ts
|
|
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
|
|
import { toast } from 'sonner';
|
|
import apiClient from '@/lib/api/client';
|
|
import { getApiErrorMessage } from '@/types/api-error';
|
|
import { DelegationScope } from '@/types/review-team';
|
|
|
|
export interface Delegation {
|
|
publicId: string;
|
|
delegatorUserId?: number;
|
|
delegateUserId?: number;
|
|
scope: DelegationScope;
|
|
projectId?: number;
|
|
startDate: string;
|
|
endDate: string;
|
|
reason?: string;
|
|
isActive: boolean;
|
|
createdAt: string;
|
|
delegate?: {
|
|
publicId: string;
|
|
fullName?: string;
|
|
email?: string;
|
|
};
|
|
}
|
|
|
|
export interface CreateDelegationDto {
|
|
delegateUserPublicId: string;
|
|
scope: DelegationScope;
|
|
projectPublicId?: string;
|
|
startDate: string;
|
|
endDate: string;
|
|
reason?: string;
|
|
}
|
|
|
|
export const delegationKeys = {
|
|
all: ['delegations'] as const,
|
|
mine: () => [...delegationKeys.all, 'mine'] as const,
|
|
};
|
|
|
|
export function useMyDelegations() {
|
|
return useQuery({
|
|
queryKey: delegationKeys.mine(),
|
|
queryFn: async (): Promise<Delegation[]> => {
|
|
const res = await apiClient.get('/delegations');
|
|
return res.data;
|
|
},
|
|
});
|
|
}
|
|
|
|
export function useCreateDelegation() {
|
|
const queryClient = useQueryClient();
|
|
|
|
return useMutation({
|
|
mutationFn: (data: CreateDelegationDto) => apiClient.post('/delegations', data),
|
|
onSuccess: () => {
|
|
toast.success('Delegation created successfully');
|
|
queryClient.invalidateQueries({ queryKey: delegationKeys.mine() });
|
|
},
|
|
onError: (error: unknown) => {
|
|
toast.error('Failed to create delegation', {
|
|
description: getApiErrorMessage(error, 'Something went wrong'),
|
|
});
|
|
},
|
|
});
|
|
}
|
|
|
|
export function useRevokeDelegation() {
|
|
const queryClient = useQueryClient();
|
|
|
|
return useMutation({
|
|
mutationFn: (publicId: string) => apiClient.delete(`/delegations/${publicId}`),
|
|
onSuccess: () => {
|
|
toast.success('Delegation revoked');
|
|
queryClient.invalidateQueries({ queryKey: delegationKeys.mine() });
|
|
},
|
|
onError: (error: unknown) => {
|
|
toast.error('Failed to revoke delegation', {
|
|
description: getApiErrorMessage(error, 'Something went wrong'),
|
|
});
|
|
},
|
|
});
|
|
}
|