modified th api's for bin, contract and task to have as passed in as a prop and not get it ffrom the global state directly in the api
This commit is contained in:
parent
4bcac4e346
commit
e2f5eb0557
31 changed files with 155 additions and 507 deletions
|
|
@ -39,6 +39,7 @@ import { Label, Pie, PieChart, ResponsiveContainer, Text } from "recharts";
|
|||
import { stringToMaterialColour } from "utils";
|
||||
import { makeStyles } from "@mui/styles";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import { useGlobalState } from "providers";
|
||||
|
||||
interface Props {
|
||||
contracts: Contract[];
|
||||
|
|
@ -59,6 +60,7 @@ const useStyles = makeStyles((theme: Theme) => ({
|
|||
export default function ContractsList(props: Props) {
|
||||
const { contracts, contractPermissions, updateList } = props;
|
||||
const theme = useTheme();
|
||||
const [{as}] = useGlobalState();
|
||||
//will need map for contracts that have supported grain types
|
||||
const [supportedTypes, setSupportedTypes] = useState<Map<pond.Grain, Contract[]>>(new Map());
|
||||
//will need need map for custom contracts
|
||||
|
|
@ -115,7 +117,7 @@ export default function ContractsList(props: Props) {
|
|||
const deleteContract = () => {
|
||||
if (currentContract) {
|
||||
contractAPI
|
||||
.removeContract(currentContract.key())
|
||||
.removeContract(currentContract.key(), as)
|
||||
.then(resp => {
|
||||
let c = contracts;
|
||||
contracts.splice(c.indexOf(currentContract), 1);
|
||||
|
|
|
|||
|
|
@ -45,6 +45,7 @@ export default function ContractSettings(props: Props) {
|
|||
const { open, close, contract } = props;
|
||||
const contractAPI = useContractAPI();
|
||||
const [name, setName] = useState("");
|
||||
const [{as}] = useGlobalState();
|
||||
const [contractID, setContractID] = useState(""); //id
|
||||
const [holder, setHolder] = useState(""); //holder
|
||||
const [deliveryStart, setDeliveryStart] = useState(moment().format("YYYY-MM-DD")); //deliverystart
|
||||
|
|
@ -136,7 +137,7 @@ export default function ContractSettings(props: Props) {
|
|||
});
|
||||
|
||||
taskAPI
|
||||
.addTask(task)
|
||||
.addTask(task, as)
|
||||
.then(resp => {
|
||||
console.log("Task Created");
|
||||
})
|
||||
|
|
@ -171,7 +172,7 @@ export default function ContractSettings(props: Props) {
|
|||
settings.contractDate = contractDate;
|
||||
|
||||
contractAPI
|
||||
.updateContract(contract.key(), name, settings)
|
||||
.updateContract(contract.key(), name, settings, as)
|
||||
.then(resp => {
|
||||
console.log("Updated Contract");
|
||||
close();
|
||||
|
|
@ -198,7 +199,7 @@ export default function ContractSettings(props: Props) {
|
|||
settings.contractDate = contractDate;
|
||||
|
||||
contractAPI
|
||||
.addContract(name, settings)
|
||||
.addContract(name, settings, as)
|
||||
.then(resp => {
|
||||
if (createDeliveryTask) {
|
||||
createTask(resp.data.key);
|
||||
|
|
@ -214,7 +215,7 @@ export default function ContractSettings(props: Props) {
|
|||
const deleteContract = () => {
|
||||
if (contract) {
|
||||
contractAPI
|
||||
.removeContract(contract.key())
|
||||
.removeContract(contract.key(), as)
|
||||
.then(resp => {
|
||||
console.log("contract deleted");
|
||||
close();
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ import moment from "moment";
|
|||
import ObjectDescriber from "objects/ObjectDescriber";
|
||||
import DeleteIcon from "products/AgIcons/Delete";
|
||||
import { pond } from "protobuf-ts/pond";
|
||||
import { useBinAPI, useGrainBagAPI, useSnackbar, useTransactionAPI, useUserAPI } from "providers";
|
||||
import { useBinAPI, useGlobalState, useGrainBagAPI, useSnackbar, useTransactionAPI, useUserAPI } from "providers";
|
||||
import React, { useEffect, useState } from "react";
|
||||
import TransactionDataDisplay from "transactions/transactionDataDisplay";
|
||||
import ContractTransactionFile from "./contractTransactionFile";
|
||||
|
|
@ -51,6 +51,7 @@ export default function ContractTransactionTable(props: Props) {
|
|||
const [displayData, setDisplayData] = useState<Transaction[]>([]);
|
||||
const [tablePage, setTablePage] = useState(0)
|
||||
const [pageSize, setPageSize] = useState(10)
|
||||
const [{as}] = useGlobalState();
|
||||
const userAPI = useUserAPI();
|
||||
const [userProfiles, setUserProfiles] = useState<Map<string, pond.UserProfile>>(new Map());
|
||||
const [openRevokeDialog, setOpenRevokeDialog] = useState(false);
|
||||
|
|
@ -97,7 +98,7 @@ export default function ContractTransactionTable(props: Props) {
|
|||
setTransactionSource(undefined);
|
||||
switch (transaction.transaction.fromObject) {
|
||||
case pond.ObjectType.OBJECT_TYPE_BIN:
|
||||
binAPI.getBin(transaction.transaction.fromKey).then(resp => {
|
||||
binAPI.getBin(transaction.transaction.fromKey, as).then(resp => {
|
||||
let bin = Bin.create(resp.data);
|
||||
setTransactionSource(bin);
|
||||
});
|
||||
|
|
@ -366,8 +367,8 @@ export default function ContractTransactionTable(props: Props) {
|
|||
rows={displayData}
|
||||
columns={columns}
|
||||
total={tableData.length}
|
||||
handleRowsPerPageChange={()=>{}}
|
||||
setPage={()=>{}}
|
||||
handleRowsPerPageChange={(e)=>{setPageSize(e.target.value)}}
|
||||
setPage={(page)=>{setTablePage(page)}}
|
||||
/>
|
||||
{/* <MaterialTable
|
||||
title={"Deliveries"}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue