Skip to content

Commit 88b4779

Browse files
authored
Merge pull request #2053 from Northeastern-Electric-Racing/#690-Remove-any-types-from-work-packages.hooks
#690 Removed any types from work-packages.hooks.tsx
2 parents aeb1e41 + c393014 commit 88b4779

4 files changed

Lines changed: 23 additions & 17 deletions

File tree

src/frontend/src/apis/work-packages.api.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ import { wbsPipe } from '../utils/pipes';
99
import { apiUrls } from '../utils/urls';
1010
import { workPackageTransformer } from './transformers/work-packages.transformers';
1111

12-
interface WorkPackageApiInputs {
12+
export interface WorkPackageApiInputs {
1313
name: string;
14-
startDate: Date;
14+
startDate: String;
1515
duration: number;
1616
crId: number;
1717
stage: WorkPackageStage | null;
@@ -53,7 +53,7 @@ export const getSingleWorkPackage = (wbsNum: WbsNumber) => {
5353
*
5454
* @param payload Payload containing all the necessary data to create a work package.
5555
*/
56-
export const createSingleWorkPackage = (payload: CreateWorkPackageApiInputs) => {
56+
export const createSingleWorkPackage = (payload: WorkPackageApiInputs) => {
5757
return axios.post<{ message: string }>(apiUrls.workPackagesCreate(), {
5858
...payload
5959
});

src/frontend/src/hooks/work-packages.hooks.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ import {
1313
getAllWorkPackages,
1414
getSingleWorkPackage,
1515
slackUpcomingDeadlines,
16-
getManyWorkPackages
16+
getManyWorkPackages,
17+
WorkPackageApiInputs
1718
} from '../apis/work-packages.api';
1819

1920
/**
@@ -44,10 +45,13 @@ export const useSingleWorkPackage = (wbsNum: WbsNumber) => {
4445
* @param wpPayload Payload containing all information needed to create a work package.
4546
*/
4647
export const useCreateSingleWorkPackage = () => {
47-
return useMutation<{ message: string }, Error, any>(['work packages', 'create'], async (wpPayload: any) => {
48-
const { data } = await createSingleWorkPackage(wpPayload);
49-
return data;
50-
});
48+
return useMutation<{ message: string }, Error, WorkPackageApiInputs>(
49+
['work packages', 'create'],
50+
async (wpPayload: WorkPackageApiInputs) => {
51+
const { data } = await createSingleWorkPackage(wpPayload);
52+
return data;
53+
}
54+
);
5155
};
5256

5357
/**
@@ -57,9 +61,9 @@ export const useCreateSingleWorkPackage = () => {
5761
*/
5862
export const useEditWorkPackage = (wbsNum: WbsNumber) => {
5963
const queryClient = useQueryClient();
60-
return useMutation<{ message: string }, Error, any>(
64+
return useMutation<{ message: string }, Error, WorkPackageApiInputs>(
6165
['work packages', 'edit'],
62-
async (wpPayload: any) => {
66+
async (wpPayload: WorkPackageApiInputs) => {
6367
const { data } = await editWorkPackage(wpPayload);
6468
return data;
6569
},
@@ -76,7 +80,7 @@ export const useEditWorkPackage = (wbsNum: WbsNumber) => {
7680
*/
7781
export const useDeleteWorkPackage = () => {
7882
const queryClient = useQueryClient();
79-
return useMutation<{ message: string }, Error, any>(
83+
return useMutation<{ message: string }, Error, WbsNumber>(
8084
['work packages', 'delete'],
8185
async (wbsNum: WbsNumber) => {
8286
const { data } = await deleteWorkPackage(wbsNum);
@@ -114,7 +118,7 @@ export const useGetManyWorkPackages = (wbsNums: WbsNumber[]) => {
114118
* Custom React Hook to slack upcoming deadlines.
115119
*/
116120
export const useSlackUpcomingDeadlines = () => {
117-
return useMutation<{ message: string }, Error, any>(['slack upcoming deadlines'], async (deadline: Date) => {
121+
return useMutation<{ message: string }, Error, Date>(['slack upcoming deadlines'], async (deadline: Date) => {
118122
const { data } = await slackUpcomingDeadlines(deadline);
119123
return data;
120124
});

src/frontend/src/pages/WorkPackageForm/WorkPackageForm.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { UseMutateAsyncFunction } from 'react-query';
21
import { WbsNumber, WorkPackage, isGuest, wbsPipe } from 'shared';
32
import WorkPackageFormView, { WorkPackageFormViewPayload } from './WorkPackageFormView';
43
import { bulletsToObject } from '../../utils/form';
@@ -8,12 +7,13 @@ import ErrorPage from '../ErrorPage';
87
import { useAllUsers } from '../../hooks/users.hooks';
98
import { useSingleProject } from '../../hooks/projects.hooks';
109
import { useQuery } from '../../hooks/utils.hooks';
10+
import { WorkPackageApiInputs } from '../../apis/work-packages.api';
1111

1212
interface WorkPackageFormProps {
1313
wbsNum: WbsNumber;
1414
exitActiveMode: () => void;
1515
crId?: string;
16-
mutateAsync: UseMutateAsyncFunction<unknown, unknown, unknown>;
16+
mutateAsync: (data: WorkPackageApiInputs) => void;
1717
createForm?: boolean;
1818
}
1919

src/frontend/src/pages/WorkPackageForm/WorkPackageFormView.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import { yupResolver } from '@hookform/resolvers/yup';
99
import * as yup from 'yup';
1010
import { Box, TextField, Autocomplete, FormControl, Typography } from '@mui/material';
1111
import { useState } from 'react';
12-
import { UseMutateAsyncFunction } from 'react-query';
1312
import WorkPackageFormDetails from './WorkPackageFormDetails';
1413
import NERFailButton from '../../components/NERFailButton';
1514
import NERSuccessButton from '../../components/NERSuccessButton';
@@ -22,6 +21,8 @@ import { projectWbsNamePipe, projectWbsPipe } from '../../utils/pipes';
2221
import { routes } from '../../utils/routes';
2322
import { getMonday } from '../GanttPage/GanttPackage/helpers/date-helper';
2423
import PageBreadcrumbs from '../../layouts/PageTitle/PageBreadcrumbs';
24+
import { WorkPackageApiInputs } from '../../apis/work-packages.api';
25+
import { WorkPackageStage } from 'shared';
2526

2627
const schema = yup.object().shape({
2728
name: yup.string().required('Name is required!'),
@@ -40,7 +41,7 @@ const schema = yup.object().shape({
4041

4142
interface WorkPackageFormViewProps {
4243
exitActiveMode: () => void;
43-
mutateAsync: UseMutateAsyncFunction<unknown, unknown, unknown>;
44+
mutateAsync: (data: WorkPackageApiInputs) => void;
4445
defaultValues?: WorkPackageFormViewPayload;
4546
wbsElement: WbsElement;
4647
leadOrManagerOptions: User[];
@@ -121,6 +122,7 @@ const WorkPackageFormView: React.FC<WorkPackageFormViewProps> = ({
121122
const day = date.getDate() < 10 ? `0${date.getDate()}` : date.getDate().toString();
122123
return `${date.getFullYear().toString()}-${month}-${day}`;
123124
};
125+
124126
const onSubmit = async (data: WorkPackageFormViewPayload) => {
125127
const { name, startDate, duration, blockedBy, crId, stage } = data;
126128
const expectedActivities = mapBulletsToPayload(data.expectedActivities);
@@ -139,7 +141,7 @@ const WorkPackageFormView: React.FC<WorkPackageFormViewProps> = ({
139141
blockedBy: blockedByWbsNums,
140142
expectedActivities: createForm ? expectedActivities.map((activity) => activity.detail) : expectedActivities,
141143
deliverables: createForm ? deliverables.map((deliverable) => deliverable.detail) : deliverables,
142-
stage
144+
stage: stage as WorkPackageStage
143145
};
144146
await mutateAsync(payload);
145147
exitActiveMode();

0 commit comments

Comments
 (0)