From a083f7d8ed8f8b8ad30e8719e2dcdd0ed50bdf98 Mon Sep 17 00:00:00 2001 From: csawatzky Date: Fri, 30 May 2025 14:50:21 -0600 Subject: [PATCH] added to transaction api and built the submit function --- package-lock.json | 2 +- src/bin/BinTransactions.tsx | 85 +++++++++++++++++++++++---- src/providers/pond/transactionAPI.tsx | 26 +++++++- 3 files changed, 97 insertions(+), 16 deletions(-) diff --git a/package-lock.json b/package-lock.json index d9db3c8..5d02369 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10864,7 +10864,7 @@ }, "node_modules/protobuf-ts": { "version": "1.0.0", - "resolved": "git+https://gitlab+deploy-token-50627:hv8mB4WkyvtjBpJKU1rN@gitlab.com/brandx/protobuf-ts.git#6bf3baa3e9db19f0d7031dda1c3045f6f64c515b", + "resolved": "git+https://gitlab+deploy-token-50627:hv8mB4WkyvtjBpJKU1rN@gitlab.com/brandx/protobuf-ts.git#8269078a53ebd9089b32bc7861c3e53698ba4166", "dependencies": { "protobufjs": "^6.8.8" } diff --git a/src/bin/BinTransactions.tsx b/src/bin/BinTransactions.tsx index ba551b1..6b06fe8 100644 --- a/src/bin/BinTransactions.tsx +++ b/src/bin/BinTransactions.tsx @@ -1,3 +1,4 @@ +import { CheckOutlined } from "@mui/icons-material"; import { Autocomplete, Box, Button, Card, DialogActions, DialogContent, DialogTitle, TextField, Typography } from "@mui/material"; import ResponsiveDialog from "common/ResponsiveDialog"; import ResponsiveTable from "common/ResponsiveTable"; @@ -9,7 +10,7 @@ import { Transaction } from "models/Transaction"; import moment from "moment"; import ObjectDescriber from "objects/ObjectDescriber"; import { pond } from "protobuf-ts/pond"; -import { useBinAPI, useContractAPI, useFieldAPI, useGrainBagAPI, useTransactionAPI } from "providers"; +import { useBinAPI, useContractAPI, useFieldAPI, useGrainBagAPI, useSnackbar, useTransactionAPI } from "providers"; import React from "react"; import { useCallback, useEffect, useState } from "react"; import TransactionDataDisplay from "transactions/transactionDataDisplay"; @@ -31,6 +32,7 @@ export default function BinTransactions(props: Props){ const [possibleTransactionMatches, setPossibleTransactionMatches] = useState([]) const [tablePage, setTablePage] = useState(0) const [tablePageSize, setTablePageSize] = useState(10) + const { openSnack } = useSnackbar(); const [total, setTotal] = useState(0) const [binOptions, setBinOptions] = useState([]) @@ -106,8 +108,32 @@ export default function BinTransactions(props: Props){ },[state, bin, loadTransactionsFor]) const submit = () => { - //submit approval - //in the response if it succeeded remove (not reject but fully delete it) the matched transaction + let transaction = cloneDeep(selectedTransaction) + if(transaction){ + if(selectedMatch){ + if (transaction.transaction.fromKey === ""){ + transaction.transaction.fromObject = selectedMatch.transaction.fromObject + transaction.transaction.fromKey = selectedMatch.transaction.fromKey + } + if (transaction.transaction.toKey === ""){ + transaction.transaction.toObject = selectedMatch.transaction.toObject + transaction.transaction.toKey = selectedMatch.transaction.toKey + } + } + //submit approval + transactionAPI.submitApproval(transaction.transaction.key, true, transaction.transaction).then(resp => { + //in the response if it succeeded remove (not reject but fully delete it) the matched transaction + if(selectedMatch){ + transactionAPI.removeTransaction(selectedMatch.transaction.key).then(resp => { + openSnack("Updated and matched transactions") + }).catch(err => { + + }) + }else{ + openSnack("Updated Transaction") + } + }) + } } const reject = () => { @@ -145,9 +171,10 @@ export default function BinTransactions(props: Props){ {getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_WEIGHT ? weight + " mT" : bushels + " bushels"} of {grainTransaction.subtype} {grainDisplay} moved - From + From: {/*Object type selection*/} ObjectDescriber(option).name} fullWidth - onChange={(e, val) => { + onChange={(_, val) => { setFromType(val ?? pond.ObjectType.OBJECT_TYPE_UNKNOWN) //based on what it is changed to need to load data if it is not already loaded if(val === pond.ObjectType.OBJECT_TYPE_BIN){ @@ -175,13 +202,14 @@ export default function BinTransactions(props: Props){ /> {/* object selection */} option.label} fullWidth - onChange={(e, val) => { + onChange={(_, val) => { setFromOption(val ?? undefined) //once one is selected get the transactions for it that are requiring approval transactionAPI.listTransactionsFor(0, 0, "asc", val?.value, pond.TransactionState.TRANSACTION_STATE_APPROVAL_REQUIRED).then(resp => { @@ -197,8 +225,9 @@ export default function BinTransactions(props: Props){ }} renderInput={params => } /> - To + To: ObjectDescriber(option).name} fullWidth - onChange={(e, val) => { + onChange={(_, val) => { setToType(val ?? pond.ObjectType.OBJECT_TYPE_UNKNOWN) //based on what it is changed to need to load data if it is not already loaded if(val === pond.ObjectType.OBJECT_TYPE_BIN){ @@ -225,13 +254,14 @@ export default function BinTransactions(props: Props){ renderInput={params => } /> option.label} fullWidth - onChange={(e, val) => { + onChange={(_, val) => { //once one is selected get the transactions for it that are requiring approval transactionAPI.listTransactionsFor(0, 0, "asc", val?.value, pond.TransactionState.TRANSACTION_STATE_APPROVAL_REQUIRED).then(resp => { let matches: Transaction[] = [] @@ -248,12 +278,41 @@ export default function BinTransactions(props: Props){ renderInput={params => } /> - + + Possible matching Transactions + Pick a transaction below if you want to match them together {possibleTransactionMatches.map(t => { + // get the display information for the transaction + const grainTransaction = t.transaction.transaction?.grainTransaction ?? pond.GrainTransaction.create() + const bushels = grainTransaction.bushels ?? 0 + const weight = bushels / grainTransaction.bushelsPerTonne + let graintype = grainTransaction.grainType ?? pond.Grain.GRAIN_INVALID + const grainDisplay = graintype === pond.Grain.GRAIN_CUSTOM + ? grainTransaction.customGrain + : GrainDescriber(grainTransaction.grainType).name return ( - - {t.transaction.timestamp} - + + + + {moment(t.transaction.timestamp).fromNow()} + + + {selectedMatch?.transaction.key === t.transaction.key && } + + + + {getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_WEIGHT ? weight + " mT" : bushels + " bushels"} of {grainTransaction.subtype} {grainDisplay} moved + + + ) })} diff --git a/src/providers/pond/transactionAPI.tsx b/src/providers/pond/transactionAPI.tsx index 635b063..d0e1a2d 100644 --- a/src/providers/pond/transactionAPI.tsx +++ b/src/providers/pond/transactionAPI.tsx @@ -40,6 +40,8 @@ export interface ITransactionAPIContext { data: pond.TransactionData, otherTeam?: string ) => Promise>; + submitApproval: (key: string, approved: boolean, updatedData: pond.Transaction, otherTeam?: string) => Promise>; + removeTransaction: (key: string, otherTeam?: string) => Promise> } export const TransactionAPIContext = createContext( @@ -50,7 +52,7 @@ interface Props {} export default function TransactionProvider(props: PropsWithChildren) { 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) { return put(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(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(url) + } + return ( ) { listTransactionsFor, updateTransaction, transactionPageData, - revokeTransaction + revokeTransaction, + submitApproval, + removeTransaction }}> {children}