Skip to content

Commit

Permalink
beef production creation form full with business controls
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminpochat committed Feb 18, 2024
1 parent 9eb993d commit adcf92d
Show file tree
Hide file tree
Showing 15 changed files with 2,397 additions and 1,577 deletions.
3,361 changes: 1,960 additions & 1,401 deletions frontend/app/package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion frontend/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"react-cookie": "^7.0.2",
"react-dom": "^18.2.0",
"react-hook-form": "^7.46.1",
"react-hook-form-mui": "^6.5.2",
"react-hook-form-mui": "^6.8.0",
"react-scripts": "5.0.1",
"typescript": "^5.2.2",
"viandeendirect_eu": "file:../gen",
Expand Down
4 changes: 4 additions & 0 deletions frontend/app/src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
margin: 1rem;
}

.form-select-list {
width: 10rem;
}

.card-clickable > *:hover {
background-color: lightgrey;
cursor: pointer;
Expand Down
6 changes: 5 additions & 1 deletion frontend/app/src/App.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { ThemeProvider } from '@mui/material';
import { createTheme } from '@mui/material/styles';
import { frFR } from '@mui/material/locale';
import { LocalizationProvider } from "@mui/x-date-pickers"
import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs'

import { ReactKeycloakProvider } from '@react-keycloak/web'
import Keycloak from 'keycloak-js'
Expand Down Expand Up @@ -69,7 +71,9 @@ function App() {
<CookiesProvider>
<ReactKeycloakProvider authClient={keycloakClient} initOptions={keycloakInitOptions}>
<ThemeProvider theme={theme}>
{getLayoutWrapper()}
<LocalizationProvider dateAdapter={AdapterDayjs} adapterLocale="fr">
{getLayoutWrapper()}
</LocalizationProvider>
</ThemeProvider>
</ReactKeycloakProvider>
</CookiesProvider>
Expand Down
4 changes: 2 additions & 2 deletions frontend/app/src/domains/production/ProductionController.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useState } from 'react'
import BeefProductionForm from './views/BeefProductionForm.tsx'
import BeefProductionCreator from './views/beefProductionCreator/BeefProductionCreator.tsx'
import PackageLotsCreator from './views/PackageLotsCreator'
import ProductionsList from './views/ProductionsList.tsx'

Expand All @@ -16,7 +16,7 @@ export default function ProductionController() {
function getContent() {
switch (currentAction) {
case PRODUCTIONS_LIST: return <ProductionsList createBeefProductionCallback={() => setCurrentAction(BEEF_PRODUCTION_CREATION)}></ProductionsList>
case BEEF_PRODUCTION_CREATION: return <BeefProductionForm callback={(action) => {setCurrentAction(action)}} />
case BEEF_PRODUCTION_CREATION: return <BeefProductionCreator callback={(action) => {setCurrentAction(action)}} />
case BEEF_PRODUCTION_PACKAGE_MODIFICATION: return <PackageLotsCreator></PackageLotsCreator>
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Button } from "@mui/material"
* @param {PackageLot} lot
* @returns
*/
export default function PackageLotsConfigurator({packageLot: packageLot}) {
export default function PackageLotsConfigurator({packageLot: packageLot, changeCallback: changeCallback}) {
const [quantity, setQuantity] = useState(packageLot.quantity)

return <div>
Expand Down Expand Up @@ -41,6 +41,7 @@ export default function PackageLotsConfigurator({packageLot: packageLot}) {
function addPackages(quantity) {
packageLot.quantity += quantity
setQuantity(packageLot.quantity)
changeCallback(packageLot)
}

/**
Expand All @@ -49,6 +50,7 @@ export default function PackageLotsConfigurator({packageLot: packageLot}) {
function removePackages(quantity) {
packageLot.quantity -= Math.min(quantity, packageLot.quantity)
setQuantity(packageLot.quantity)
changeCallback(packageLot)
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export class BeefProductionService {
static getMeatWeight(warmCarcassWeight: number): number {
return Math.round(warmCarcassWeight / 0.55 * 0.36 || 0 )
}

static getLiveWeight(warmCarcassWeight: number): number {
return Math.round(warmCarcassWeight / 0.55 || 0 )
}
}
122 changes: 0 additions & 122 deletions frontend/app/src/domains/production/views/BeefProductionForm.tsx

This file was deleted.

58 changes: 31 additions & 27 deletions frontend/app/src/domains/production/views/PackageLotsCreator.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,40 +6,44 @@ import PackageLot from "viandeendirect_eu/dist/model/PackageLot"
import PackageLotsConfigurator from "../components/PackageLotConfigurator"


export default function PackageLotsCreator() {
export default function PackageLotsCreator({ production: production, changeProductionCallback: changeProductionCallback }) {

const { keycloak, initialized } = useKeycloak()
const [packageLots, setPackageLots] = useState([])
const { keycloak } = useKeycloak()
const apiBuilder = new ApiBuilder()

useEffect(() => {
apiBuilder.getAuthenticatedApi(keycloak).then(api => {
apiBuilder.invokeAuthenticatedApi(() => {
api.getPackageTemplates((error, data, response) => {
if (error) {
console.error(error);
} else {
console.log('api.getPackageTemplates called successfully. Returned data: ' + data);
const lots = []
data.map(template => {
let lot = new PackageLot()
lot.label = template.label
lot.description = template.description
lot.unitPrice = template.unitPrice
lot.netWeight = template.netWeight
lot.quantity = 0
lot.quantitySold = 0
lots.push(lot)
})
setPackageLots(lots)
}
})
}, keycloak)
})
if (!production.lots) {
apiBuilder.getAuthenticatedApi(keycloak).then(api => {
apiBuilder.invokeAuthenticatedApi(() => {
api.getPackageTemplates((error, data, response) => {
if (error) {
console.error(error);
} else {
console.log('api.getPackageTemplates called successfully. Returned data: ' + data);
const lots = []
data.map(template => {
let lot = new PackageLot()
lot.label = template.label
lot.description = template.description
lot.unitPrice = template.unitPrice
lot.netWeight = template.netWeight
lot.quantity = 0
lot.quantitySold = 0
lots.push(lot)
})
changeProductionCallback({ ...production, lots: lots })
}
})
}, keycloak)
})
}
}, [keycloak])

return <>
{packageLots.map(lot => <PackageLotsConfigurator packageLot={lot}></PackageLotsConfigurator>)}
{production.lots?.map(lot => <PackageLotsConfigurator packageLot={lot} changeCallback={changeLotConfiguration}></PackageLotsConfigurator>)}
</>

function changeLotConfiguration(lot) {
changeProductionCallback({ ...production })
}
}
Loading

0 comments on commit adcf92d

Please sign in to comment.