feat(rfa): complete RFA Approval Refactor - all 9 phases (T001-T080)

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
This commit is contained in:
Nattanin
2026-05-12 16:17:27 +07:00
parent 3df8707b7f
commit ef20839f99
82 changed files with 7052 additions and 104 deletions
+82
View File
@@ -0,0 +1,82 @@
// 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'),
});
},
});
}
+45
View File
@@ -0,0 +1,45 @@
// File: hooks/use-response-codes.ts
import { useQuery } from '@tanstack/react-query';
import apiClient from '@/lib/api/client';
import { ResponseCode, ResponseCodeCategory } from '@/types/review-team';
export const responseCodeKeys = {
all: ['responseCodes'] as const,
byCategory: (cat: ResponseCodeCategory) => [...responseCodeKeys.all, 'category', cat] as const,
byDocType: (docTypeId: number, projectId?: number) =>
[...responseCodeKeys.all, 'docType', docTypeId, projectId] as const,
};
export function useResponseCodes() {
return useQuery({
queryKey: responseCodeKeys.all,
queryFn: async (): Promise<ResponseCode[]> => {
const res = await apiClient.get('/response-codes');
return res.data;
},
});
}
export function useResponseCodesByCategory(category: ResponseCodeCategory) {
return useQuery({
queryKey: responseCodeKeys.byCategory(category),
queryFn: async (): Promise<ResponseCode[]> => {
const res = await apiClient.get(`/response-codes/category/${category}`);
return res.data;
},
enabled: !!category,
});
}
export function useResponseCodesByDocType(documentTypeId: number, projectId?: number) {
return useQuery({
queryKey: responseCodeKeys.byDocType(documentTypeId, projectId),
queryFn: async (): Promise<ResponseCode[]> => {
const res = await apiClient.get(`/response-codes/document-type/${documentTypeId}`, {
params: projectId ? { projectId } : undefined,
});
return res.data;
},
enabled: !!documentTypeId,
});
}
+118
View File
@@ -0,0 +1,118 @@
// File: hooks/use-review-teams.ts
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
import { toast } from 'sonner';
import { getApiErrorMessage } from '@/types/api-error';
import {
reviewTeamService,
CreateReviewTeamDto,
UpdateReviewTeamDto,
AddTeamMemberDto,
SearchReviewTeamDto,
} from '@/lib/services/review-team.service';
// ─── Query Keys ───────────────────────────────────────────────────────────────
export const reviewTeamKeys = {
all: ['reviewTeams'] as const,
lists: () => [...reviewTeamKeys.all, 'list'] as const,
list: (params: SearchReviewTeamDto) => [...reviewTeamKeys.lists(), params] as const,
details: () => [...reviewTeamKeys.all, 'detail'] as const,
detail: (publicId: string) => [...reviewTeamKeys.details(), publicId] as const,
};
// ─── Queries ──────────────────────────────────────────────────────────────────
export function useReviewTeams(params?: SearchReviewTeamDto) {
return useQuery({
queryKey: reviewTeamKeys.list(params ?? {}),
queryFn: () => reviewTeamService.getAll(params),
placeholderData: (prev: unknown) => prev,
});
}
export function useReviewTeam(publicId: string) {
return useQuery({
queryKey: reviewTeamKeys.detail(publicId),
queryFn: () => reviewTeamService.getByPublicId(publicId),
enabled: !!publicId,
});
}
// ─── Mutations ────────────────────────────────────────────────────────────────
export function useCreateReviewTeam() {
const queryClient = useQueryClient();
return useMutation({
mutationFn: (data: CreateReviewTeamDto) => reviewTeamService.create(data),
onSuccess: () => {
toast.success('Review Team created successfully');
queryClient.invalidateQueries({ queryKey: reviewTeamKeys.lists() });
},
onError: (error: unknown) => {
toast.error('Failed to create Review Team', {
description: getApiErrorMessage(error, 'Something went wrong'),
});
},
});
}
export function useUpdateReviewTeam() {
const queryClient = useQueryClient();
return useMutation({
mutationFn: ({ publicId, data }: { publicId: string; data: UpdateReviewTeamDto }) =>
reviewTeamService.update(publicId, data),
onSuccess: (_: unknown, { publicId }: { publicId: string; data: UpdateReviewTeamDto }) => {
toast.success('Review Team updated');
queryClient.invalidateQueries({ queryKey: reviewTeamKeys.detail(publicId) });
queryClient.invalidateQueries({ queryKey: reviewTeamKeys.lists() });
},
onError: (error: unknown) => {
toast.error('Failed to update Review Team', {
description: getApiErrorMessage(error, 'Something went wrong'),
});
},
});
}
export function useAddTeamMember() {
const queryClient = useQueryClient();
return useMutation({
mutationFn: ({ teamPublicId, data }: { teamPublicId: string; data: AddTeamMemberDto }) =>
reviewTeamService.addMember(teamPublicId, data),
onSuccess: (_: unknown, { teamPublicId }: { teamPublicId: string; data: AddTeamMemberDto }) => {
toast.success('Member added to team');
queryClient.invalidateQueries({ queryKey: reviewTeamKeys.detail(teamPublicId) });
},
onError: (error: unknown) => {
toast.error('Failed to add member', {
description: getApiErrorMessage(error, 'Something went wrong'),
});
},
});
}
export function useRemoveTeamMember() {
const queryClient = useQueryClient();
return useMutation({
mutationFn: ({
teamPublicId,
memberPublicId,
}: {
teamPublicId: string;
memberPublicId: string;
}) => reviewTeamService.removeMember(teamPublicId, memberPublicId),
onSuccess: (_: unknown, { teamPublicId }: { teamPublicId: string; memberPublicId: string }) => {
toast.success('Member removed from team');
queryClient.invalidateQueries({ queryKey: reviewTeamKeys.detail(teamPublicId) });
},
onError: (error: unknown) => {
toast.error('Failed to remove member', {
description: getApiErrorMessage(error, 'Something went wrong'),
});
},
});
}