Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
56 changes: 54 additions & 2 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,
EditSponsorTierPayload
} 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 @@ -404,3 +406,53 @@ export const getAllOtherProductReason = () => {
transformResponse: (data) => JSON.parse(data) as OtherProductReason[]
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.

i know you didn't do this but can you remove the as OtherProductReason[], I think its redundant here

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.

same with as IndexCode above

});
};

/**
* 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) => {
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.

should be 'getSponsorTasks'

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 tier
*
* @param sponsorTierData the edited data of the sponsor tier
* @param sponsorTierId the id of the sponsor tier to be edited
*
* @returns the edited sponosor tier
*/
export const editSponsorTier = (sponsorTierId: string, sponsorTierData: EditSponsorTierPayload) => {
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.

we don't have this endpoint, it should be calling an api to editSponsorTask. That is totally my bad, i miswrote the ticket. Should be a quick change tho

return axios.post(apiUrls.editSponsorTier(sponsorTierId), sponsorTierData);
};
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,
editSponsorTier,
deleteSponsor
} from '../apis/finance.api';
import {
IndexCode,
Expand All @@ -47,7 +51,10 @@ import {
OtherReimbursementProductCreateArgs,
WbsReimbursementProductCreateArgs,
ReimbursementStatusType,
OtherProductReason
OtherProductReason,
Sponsor,
SponsorTask,
SponsorTier
} from 'shared';
import { fullNamePipe } from '../utils/pipes';

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

export interface EditSponsorTierPayload {
name: string;
colorHexCode: string;
}

/**
* Custom React Hook to upload a new picture.
*/
Expand Down Expand Up @@ -621,3 +633,69 @@ 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 tier
*
* @param sponsorTierData the edited data of the sponsor tier
* @param sponsorTierId the id of the sponsor tier to be edited
*
* @returns the edited sponosor tier
*/
export const useEditSponsorTier = (sponsorTierId: string) => {
const queryClient = useQueryClient();
return useMutation<SponsorTier, Error, EditSponsorTierPayload>(
['sponsor-tier', 'edit'],
async (formData: EditSponsorTierPayload) => {
const { data } = await editSponsorTier(sponsorTierId, formData);
queryClient.invalidateQueries(['sponsor-tier']);
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 editSponsorTier = (sponsorTierId: string) => `${financeRoutesEndpoints()}/sponsorTier/${sponsorTierId}/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,
editSponsorTier,

bomEndpoints,
bomGetMaterialsByWbsNum,
Expand Down
Loading