replaced uses of getGrainUnit to the users grainUnit function to pull form logged in users settings rather than local storage

This commit is contained in:
csawatzky 2026-03-26 12:47:16 -06:00
parent dc54f99abd
commit cabc0146ed
22 changed files with 146 additions and 250 deletions

View file

@ -2,8 +2,7 @@ import {MenuItem, TextField } from "@mui/material"
import { cloneDeep } from "lodash"
import { pond } from "protobuf-ts/pond"
import React, { useEffect, useRef, useState } from "react"
import { getGrainUnit } from "utils"
import { useGlobalState } from "providers";
interface Props {
grainSettings?: pond.GrainSettings
onGrainSettingsChange: (settings: pond.GrainSettings, formValid: boolean) => void
@ -11,6 +10,7 @@ interface Props {
export default function CustomGrainForm(props: Props) {
const {grainSettings, onGrainSettingsChange} = props
const [{ user }] = useGlobalState();
const [newGrainSettings, setNewGrainSettings] = useState(pond.GrainSettings.create())
const [name, setName] = useState("")
const [group, setGroup] = useState("")
@ -204,7 +204,7 @@ export default function CustomGrainForm(props: Props) {
valid.current = validate(name, group, constantA, constantB, constantC, kgPerBushel, val)
let settings = cloneDeep(newGrainSettings)
if(!isNaN(parseFloat(val))){
if(getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TON){
if(user.grainUnit() === pond.GrainUnit.GRAIN_UNIT_TON){
settings.bushelsPerTonne = parseFloat(val)/0.907
}else{
settings.bushelsPerTonne = parseFloat(val)
@ -212,7 +212,7 @@ export default function CustomGrainForm(props: Props) {
}
settingsChanged(settings)
}}
label={"Bushels per " + (getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE ? " Tonne" : "Ton")}/>
label={"Bushels per " + (user.grainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE ? " Tonne" : "Ton")}/>
</React.Fragment>
)
}

View file

@ -29,7 +29,6 @@ import {
useTransactionAPI
} from "providers";
import { useState, useEffect } from "react";
import { getGrainUnit } from "utils";
interface Props {
mainObject: Bin | GrainBag | Field | Contract;
@ -451,7 +450,7 @@ export default function GrainTransaction(props: Props) {
};
const grainUnitDisplay = () => {
switch (getGrainUnit()){
switch (user.grainUnit()){
case pond.GrainUnit.GRAIN_UNIT_TONNE:
return "mT"
case pond.GrainUnit.GRAIN_UNIT_TON:
@ -525,7 +524,7 @@ export default function GrainTransaction(props: Props) {
onChange={e => {
//if the user is viewing the grain in weight
let grainVal = e.target.value;
if (getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE) {
if (user.grainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE) {
//need to convert what the user input (weight) into what is actually stored (bushels)
//use source of the conversion value if it was selected, otherwise use the destination
if (!isNaN(parseFloat(e.target.value))) {
@ -535,7 +534,7 @@ export default function GrainTransaction(props: Props) {
grainVal = (+grainVal * selectedDestination.value.bushelsPerTonne()).toFixed(2);
}
}
}else if (getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TON) {
}else if (user.grainUnit() === pond.GrainUnit.GRAIN_UNIT_TON) {
if (!isNaN(parseFloat(e.target.value))) {
if (selectedSource) {
if(selectedSource.value.bushelsPerTonne){