diff --git a/frontend/app/src/domains/production/ProductionController.tsx b/frontend/app/src/domains/production/ProductionController.tsx new file mode 100644 index 0000000..6237b4c --- /dev/null +++ b/frontend/app/src/domains/production/ProductionController.tsx @@ -0,0 +1,24 @@ +import React from 'react' +import { useState } from 'react' +import BeefProductionCreator from './views/beefProductionCreator/BeefProductionCreator.tsx' +import PackageLotsCreator from './views/PackageLotsCreator.js' +import ProductionsList from './views/ProductionsList.tsx' + +export default function ProductionController() { + + const BEEF_PRODUCTION_CREATION = 'BEEF_PRODUCTION_CREATION' + const BEEF_PRODUCTION_PACKAGE_MODIFICATION = 'BEEF_PRODUCTION_PACKAGE_MODIFICATION' + const PRODUCTIONS_LIST = 'PRODUCTIONS_LIST' + + const [currentAction, setCurrentAction] = useState(PRODUCTIONS_LIST) + + return <>{getContent()} + + function getContent() { + switch (currentAction) { + case PRODUCTIONS_LIST: return setCurrentAction(BEEF_PRODUCTION_CREATION)}> + case BEEF_PRODUCTION_CREATION: return {setCurrentAction(action)}} /> + case BEEF_PRODUCTION_PACKAGE_MODIFICATION: return + } + } +} \ No newline at end of file diff --git a/frontend/app/src/domains/production/components/PackageLotConfigurator.tsx b/frontend/app/src/domains/production/components/PackageLotConfigurator.tsx new file mode 100644 index 0000000..fd1aa9e --- /dev/null +++ b/frontend/app/src/domains/production/components/PackageLotConfigurator.tsx @@ -0,0 +1,122 @@ +import React from 'react' +import { useState } from "react" +import EditIcon from '@mui/icons-material/Edit'; +import { Button, Dialog, DialogActions, DialogContent, DialogTitle } from "@mui/material" +import { FormContainer, TextFieldElement, useForm } from 'react-hook-form-mui'; + +/** + * + * @param {PackageLot} lot + * @returns + */ +export default function PackageLotConfigurator({packageLot: packageLot, changeCallback: changeCallback}) { + const [quantity, setQuantity] = useState(packageLot.quantity) + const [editionPopinOpen, setEditionPopinOpen] = useState(false) + const form = useForm({defaultValues: packageLot}) + + return
+
+
+
{packageLot.label}
+
{packageLot.description}
+
{packageLot.netWeight} kg
+
{packageLot.unitPrice} € TTC/kg
+
+
+ + +
+
+
{quantity}
+
colis mis en vente
+
{quantity * packageLot.netWeight} kg
+
{quantity * packageLot.netWeight * packageLot.unitPrice} € TTC
+
+
+ + +
+
+ + Modification du colis + + + + + + + + + + + + + +
+ + /** + * @param {number} quantity + */ + function addPackages(quantity) { + packageLot.quantity += quantity + setQuantity(packageLot.quantity) + changeCallback(packageLot) + } + + /** + * @param {number} quantity + */ + function removePackages(quantity) { + packageLot.quantity -= Math.min(quantity, packageLot.quantity) + setQuantity(packageLot.quantity) + changeCallback(packageLot) + } + + function openEditionPopin() { + setEditionPopinOpen(true) + } + + function closeEditionPopin() { + setEditionPopinOpen(false) + } + + function validForm(formData) { + packageLot.label = formData.label + packageLot.description = formData.description + packageLot.unitPrice = formData.unitPrice + packageLot.netWeight = formData.netWeight + closeEditionPopin() + } + +} \ No newline at end of file