Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 56 additions & 4 deletions src/frontend/src/apis/finance.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
* This file is part of NER's FinishLine and licensed under GNU AGPLv3.
* See the LICENSE file in the repository root folder for details.
*/
import { sponsorTaskTranformer, sponsorTransformer } from '../../../backend/src/transformers/finance.transformer';
import {
CreateReimbursementRequestPayload,
EditReimbursementRequestPayload,
EditVendorPayload,
AccountCodePayload,
RefundPayload,
MarkDeliveredRequestPayload
MarkDeliveredRequestPayload,
EditSponsorTaskPayload
} from '../hooks/finance.hooks';
import axios from '../utils/axios';
import { apiUrls } from '../utils/urls';
Expand All @@ -19,7 +21,7 @@ import {
} from './transformers/reimbursement-requests.transformer';
import { saveAs } from 'file-saver';
import { PDFDocument, PDFImage } from 'pdf-lib';
import { IndexCode, AccountCode, ReimbursementRequest, OtherProductReason } from 'shared';
import { IndexCode, AccountCode, ReimbursementRequest, OtherProductReason, Sponsor, SponsorTask } from 'shared';

enum AllowedFileType {
JPEG = 'image/jpeg',
Expand Down Expand Up @@ -390,7 +392,7 @@ export const requestReimbursementRequestChanges = async (id: string) => {
*/
export const getAllIndexCodes = () => {
return axios.get<IndexCode[]>(apiUrls.getAllIndexCodes(), {
transformResponse: (data) => JSON.parse(data) as IndexCode[]
transformResponse: (data) => JSON.parse(data)
});
};

Expand All @@ -401,6 +403,56 @@ export const getAllIndexCodes = () => {
*/
export const getAllOtherProductReason = () => {
return axios.get<OtherProductReason[]>(apiUrls.getAllOtherProductReasons(), {
transformResponse: (data) => JSON.parse(data) as OtherProductReason[]
transformResponse: (data) => JSON.parse(data)
});
};

/**
* API call to get the list of all sponsors
*
* @returns the list of all sponsors
*/

export const getAllSponsors = () => {
return axios.get<Sponsor[]>(apiUrls.getAllSponsors(), {
transformResponse: (data) => JSON.parse(data).map(sponsorTransformer)
});
};

/**
* API call to the sponsor tasks for a given sponsor
*
* @param sponsorId the id of the sponsor which tasks are retrieved
*
* @returns the list of tasks for a given sponsor
*/

export const getSponsorTasks = (sponsorId: string) => {
return axios.get<SponsorTask[]>(apiUrls.getSponsorTasks(sponsorId), {
transformResponse: (data) => JSON.parse(data).map(sponsorTaskTranformer)
});
};

/**
* API call to delete a given sponsor
*
* @param sponsorId the id of the sponsor to delete
*
* @returns the deleted sponsor
*/

export const deleteSponsor = (sponsorId: string) => {
return axios.delete(apiUrls.deleteSponsor(sponsorId));
};

/**
* API call to edit a sponsor task
*
* @param sponsorTaskData the edited data of the sponsor task
* @param sponsorTaskId the id of the sponsor task to be edited
*
* @returns the edited sponosor task
*/
export const editSponsorTask = (sponsorTaskId: string, sponsorTaskData: EditSponsorTaskPayload) => {
return axios.post(apiUrls.editSponsorTask(sponsorTaskId), sponsorTaskData);
};
82 changes: 80 additions & 2 deletions src/frontend/src/hooks/finance.hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ import {
requestReimbursementRequestChanges,
markPendingFinance,
getAllIndexCodes,
getAllOtherProductReason
getAllOtherProductReason,
getAllSponsors,
getSponsorTasks,
editSponsorTask,
deleteSponsor
} from '../apis/finance.api';
import {
IndexCode,
Expand All @@ -47,7 +51,9 @@ import {
OtherReimbursementProductCreateArgs,
WbsReimbursementProductCreateArgs,
ReimbursementStatusType,
OtherProductReason
OtherProductReason,
Sponsor,
SponsorTask
} from 'shared';
import { fullNamePipe } from '../utils/pipes';

Expand Down Expand Up @@ -96,6 +102,13 @@ export interface IndexCodePayload {
name: string;
}

export interface EditSponsorTaskPayload {
dueDate: Date;
notes: string;
notifyDate?: Date;
asigneeId?: string;
}

/**
* Custom React Hook to upload a new picture.
*/
Expand Down Expand Up @@ -621,3 +634,68 @@ export const useGetAllOtherProductReason = () => {
return data;
});
};

/**
* custom React Hook to get all the sponsors
*
* @returns the list of all of the sponsors
*/
export const useGetAllSponsors = () => {
return useQuery<Sponsor[], Error>(['sponsor'], async () => {
const { data } = await getAllSponsors();
return data;
});
};

/**
* custom react hook to get all of the sponsor tasks for a given sponsor
*
* @returns the list of all of the sponsor tasks for a given sponsor
*/
export const useGetSponsorTasks = (sponsorId: string) => {
return useQuery<SponsorTask[], Error>(['sponsor-task'], async () => {
const { data } = await getSponsorTasks(sponsorId);
return data;
});
};

/**
* Custom React Hook to edit a sponsor task
*
* @param sponsorTaskId the id of the sponsor task to be edited
*
* @returns the edited sponosor task
*/
export const useEditSponsorTask = (sponsorTaskId: string) => {
const queryClient = useQueryClient();
return useMutation<SponsorTask, Error, EditSponsorTaskPayload>(
['sponsor-task', 'edit'],
async (formData: EditSponsorTaskPayload) => {
const { data } = await editSponsorTask(sponsorTaskId, formData);
queryClient.invalidateQueries(['sponsor-task']);
return data;
}
);
};

/**
* Custom React Hook to delete a sponsor
*
* @param sponsorId the id of the sponsor to be deleted
* @returns the deleted sponsor
*/
export const useDeleteSponsor = (sponsorId: string) => {
const queryClient = useQueryClient();
return useMutation<Sponsor, Error>(
['sponsor', 'delete'],
async () => {
const { data } = await deleteSponsor(sponsorId);
return data;
},
{
onSuccess: () => {
queryClient.invalidateQueries(['sponsor']);
}
}
);
};
9 changes: 9 additions & 0 deletions src/frontend/src/utils/urls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,11 @@ const financeEditVendor = (vendorId: string) => `${financeEndpoints()}/${vendorI
const financeLeadershipApprove = (id: string) => `${financeEndpoints()}/${id}/leadership-approve`;
const getAllIndexCodes = () => `${financeEndpoints()}/index-codes`;
const getAllOtherProductReasons = () => `${financeEndpoints()}/other-reimbursement-product-reasons`;
const financeRoutesEndpoints = () => `${API_URL}/finance`;
const getAllSponsors = () => `${financeRoutesEndpoints()}/sponsors`;
const getSponsorTasks = (sponsorId: string) => `${financeRoutesEndpoints()}/sponsors/${sponsorId}/tasks`;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

route should end with '/sponsorTasks'

const deleteSponsor = (sponsorId: string) => `${financeRoutesEndpoints()}/sponsors/${sponsorId}/delete`;
const editSponsorTask = (sponsorTaskId: string) => `${financeRoutesEndpoints()}/sponsorTask/${sponsorTaskId}/edit`;

/**************** Bill of Material Endpoints **************************/
const bomEndpoints = () => `${API_URL}/projects/bom`;
Expand Down Expand Up @@ -370,6 +375,10 @@ export const apiUrls = {
financeLeadershipApprove,
getAllIndexCodes,
getAllOtherProductReasons,
getAllSponsors,
getSponsorTasks,
deleteSponsor,
editSponsorTask,

bomEndpoints,
bomGetMaterialsByWbsNum,
Expand Down