Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#1487: replaced usage of type any with specific types #2130

Merged
merged 9 commits into from
Mar 18, 2024
88 changes: 66 additions & 22 deletions src/frontend/src/hooks/change-requests.hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,22 @@ export const useSingleChangeRequest = (id: number) => {
});
};

export interface ReviewPayload {
reviewerId: number;
crId: number;
accepted: boolean;
reviewNotes: string;
psId: string;
}

/**
* Custom React Hook to review a change request.
*/
export const useReviewChangeRequest = () => {
const queryClient = useQueryClient();
return useMutation<{ message: string }, Error, any>(
return useMutation<{ message: string }, Error, ReviewPayload>(
['change requests', 'review'],
async (reviewPayload: any) => {
async (reviewPayload: ReviewPayload) => {
const { data } = await reviewChangeRequest(
reviewPayload.reviewerId,
reviewPayload.crId,
Expand All @@ -69,7 +77,7 @@ export const useReviewChangeRequest = () => {
*/
export const useDeleteChangeRequest = () => {
const queryClient = useQueryClient();
return useMutation<{ message: string }, Error, any>(
return useMutation<{ message: string }, Error, number>(
['change requests', 'delete'],
async (id: number) => {
const { data } = await deleteChangeRequest(id);
Expand Down Expand Up @@ -103,41 +111,73 @@ export const useCreateStandardChangeRequest = () => {
);
};

export interface CreateActivationChangeRequestPayload {
submitterId: number;
wbsNum: WbsNumber;
projectLeadId: number;
projectManagerId: number;
startDate: string;
confirmDetails: boolean;
type: string;
}

export interface CreateStageGateChangeRequestPayload {
submitterId: number;
wbsNum: WbsNumber;
confirmDone: boolean;
type: string;
}

export interface CreateProposeSolutionPayload {
submitterId: number;
crId: number;
description: string;
scopeImpact: string;
timelineImpact: number;
budgetImpact: number;
}

/**
* Custom React Hook to create an activation change request.
*/
export const useCreateActivationChangeRequest = () => {
return useMutation<{ message: string }, Error, any>(['change requests', 'create', 'activation'], async (payload: any) => {
const { data } = await createActivationChangeRequest(
payload.submitterId,
payload.wbsNum,
payload.projectLeadId,
payload.projectManagerId,
payload.startDate,
payload.confirmDetails
);
return data;
});
return useMutation<{ message: string }, Error, CreateActivationChangeRequestPayload>(
['change requests', 'create', 'activation'],
async (payload: CreateActivationChangeRequestPayload) => {
const { data } = await createActivationChangeRequest(
payload.submitterId,
payload.wbsNum,
payload.projectLeadId,
payload.projectManagerId,
payload.startDate,
payload.confirmDetails
);
return data;
}
);
};

/**
* Custom React Hook to create a stage gate change request.
*/
export const useCreateStageGateChangeRequest = () => {
return useMutation<{ message: string }, Error, any>(['change requests', 'create', 'stage gate'], async (payload: any) => {
const { data } = await createStageGateChangeRequest(payload.submitterId, payload.wbsNum, payload.confirmDone);
return data;
});
return useMutation<{ message: string }, Error, CreateStageGateChangeRequestPayload>(
['change requests', 'create', 'stage gate'],
async (payload: CreateStageGateChangeRequestPayload) => {
const { data } = await createStageGateChangeRequest(payload.submitterId, payload.wbsNum, payload.confirmDone);
return data;
}
);
};

/**
* Custom React Hook to create a proposed solution
*/
export const useCreateProposeSolution = () => {
const queryClient = useQueryClient();
return useMutation<{ message: string }, Error, any>(
return useMutation<{ message: string }, Error, CreateProposeSolutionPayload>(
['change requests', 'create', 'propose solution'],
async (payload: any) => {
async (payload: CreateProposeSolutionPayload) => {
const { data } = await addProposedSolution(
payload.submitterId,
payload.crId,
Expand All @@ -156,14 +196,18 @@ export const useCreateProposeSolution = () => {
);
};

export interface CRReviewPayload {
userIds: number[];
}

/**
* Custom React hook to request cr reviewers
*/
export const useRequestCRReview = (crId: string) => {
const queryClient = useQueryClient();
return useMutation<{ message: string }, Error, any>(
return useMutation<{ message: string }, Error, CRReviewPayload>(
['change requests', 'review'],
async (crReviewPayload: { userIds: number[] }) => {
async (crReviewPayload: CRReviewPayload) => {
const { data } = await requestCRReview(crId, crReviewPayload);
return data;
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,20 @@ const ActivateWorkPackageModalContainer: React.FC<ActivateWorkPackageModalContai
const handleConfirm = async ({ projectLeadId, projectManagerId, startDate, confirmDetails }: FormInput) => {
handleClose();
if (auth.user?.userId === undefined) throw new Error('Cannot create activation change request without being logged in');
if (projectLeadId === undefined) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can just use the shorthand of !projectLeadId instead of projectLeadId === undefined

throw new Error('Project Lead Id must be defined to create an activation change request');
}
if (projectManagerId === undefined) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same thing

throw new Error('Project Manager Id must be defined to create an activation change request');
}
try {
await mutateAsync({
submitterId: auth.user?.userId,
wbsNum,
type: ChangeRequestType.Activation,
projectLeadId,
projectManagerId,
startDate,
startDate: startDate.toISOString(),
confirmDetails
});
history.push(routes.CHANGE_REQUESTS);
Expand Down
Loading