added to transaction api and built the submit function

This commit is contained in:
csawatzky 2025-05-30 14:50:21 -06:00
parent 49bd146de6
commit a083f7d8ed
3 changed files with 97 additions and 16 deletions

View file

@ -40,6 +40,8 @@ export interface ITransactionAPIContext {
data: pond.TransactionData,
otherTeam?: string
) => Promise<AxiosResponse<pond.UpdateTransactionResponse>>;
submitApproval: (key: string, approved: boolean, updatedData: pond.Transaction, otherTeam?: string) => Promise<AxiosResponse<pond.SubmitTransactionApprovalResponse>>;
removeTransaction: (key: string, otherTeam?: string) => Promise<AxiosResponse<pond.RemoveTransactionResponse>>
}
export const TransactionAPIContext = createContext<ITransactionAPIContext>(
@ -50,7 +52,7 @@ interface Props {}
export default function TransactionProvider(props: PropsWithChildren<Props>) {
const { children } = props;
const { get, post, put } = useHTTP();
const { get, post, put, del } = useHTTP();
const [{ as }] = useGlobalState();
const addTransaction = (transaction: pond.Transaction, fileIDs?: string[], otherTeam?: string) => {
@ -158,6 +160,24 @@ export default function TransactionProvider(props: PropsWithChildren<Props>) {
return put<pond.TransactionPageDataResponse>(pondURL("/transactions/" + key + "/revoke"));
};
const submitApproval = (key: string, approval: boolean, updatedData: pond.Transaction, otherTeam?: string) => {
const view = otherTeam ? otherTeam : as
let url = "/transactions/" + key + "/approval?approve=" + approval.toString()
if(view){
url = url + "&as=" + view
}
return post<pond.SubmitTransactionApprovalResponse>(url, updatedData)
}
const removeTransaction = (key: string, otherTeam?: string) => {
const view = otherTeam ? otherTeam : as
let url = "/transactions/" + key + "/remove"
if(view){
url = url + "&as=" + view
}
return del<pond.RemoveTransactionResponse>(url)
}
return (
<TransactionAPIContext.Provider
value={{
@ -166,7 +186,9 @@ export default function TransactionProvider(props: PropsWithChildren<Props>) {
listTransactionsFor,
updateTransaction,
transactionPageData,
revokeTransaction
revokeTransaction,
submitApproval,
removeTransaction
}}>
{children}
</TransactionAPIContext.Provider>