Merge branch 'hybrid_inventory_control' into staging_environment

This commit is contained in:
csawatzky 2025-06-09 14:55:26 -06:00
commit cb7bf64c68
15 changed files with 729 additions and 38 deletions

View file

@ -4,6 +4,7 @@ import { pond } from "protobuf-ts/pond";
import { pondURL } from "./pond";
import { AxiosResponse } from "axios";
import { useGlobalState } from "providers";
import { or } from "utils";
export interface ITransactionAPIContext {
addTransaction: (
@ -25,12 +26,22 @@ export interface ITransactionAPIContext {
toKey?: string,
otherTeam?: string
) => Promise<AxiosResponse<pond.ListTransactionsResponse>>;
listTransactionsFor: (
limit: number,
offset: number,
order: "asc" | "desc",
objectKey: string,
state?: pond.TransactionState,
otherTeam?: string
) => Promise<AxiosResponse<pond.ListTransactionsForResponse>>
revokeTransaction: (key: string, otherTeam?: string) => Promise<AxiosResponse<pond.RevokeTransactionResponse>>;
updateTransaction: (
key: string,
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>(
@ -41,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) => {
@ -88,6 +99,35 @@ export default function TransactionProvider(props: PropsWithChildren<Props>) {
);
};
const listTransactionsFor = (
limit: number,
offset: number,
order: "asc" | "desc",
objectKey: string,
state?: pond.TransactionState,
otherTeam?: string
) => {
const view = otherTeam ? otherTeam : as
const url = "/transactionsFor" +
"?limit=" +
limit +
"&offset=" +
offset +
("&order=" + or(order, "asc")) +
"&object=" + objectKey +
(state ? "&state=" + state : "") +
(view ? "&as=" + view : "")
return new Promise<AxiosResponse<pond.ListTransactionsForResponse>>((resolve, reject)=>{
get<pond.ListTransactionsForResponse>(pondURL(url)).then(resp => {
resp.data = pond.ListTransactionsForResponse.fromObject(resp.data)
return resolve(resp)
}).catch(err => {
return reject(err)
})
})
}
const updateTransaction = (key: string, data: pond.TransactionData, otherTeam?: string) => {
const view = otherTeam ? otherTeam : as
if (view)
@ -120,14 +160,35 @@ 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>(pondURL(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>(pondURL(url))
}
return (
<TransactionAPIContext.Provider
value={{
addTransaction,
listTransactions,
listTransactionsFor,
updateTransaction,
transactionPageData,
revokeTransaction
revokeTransaction,
submitApproval,
removeTransaction
}}>
{children}
</TransactionAPIContext.Provider>