-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
frontend : beef production modification form
- Loading branch information
1 parent
82c1dec
commit 45355ee
Showing
9 changed files
with
264 additions
and
173 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 0 additions & 51 deletions
51
frontend/app/src/domains/production/views/BeefProductionView.tsx
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
126 changes: 126 additions & 0 deletions
126
frontend/app/src/domains/production/views/beefProduction/BeefProductionView.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
import { Typography, ButtonGroup, Button, Tab, Tabs } from '@mui/material' | ||
import React from 'react' | ||
import { useState } from 'react' | ||
import BreedingPropertiesForm, { mapBreedingFormDataToBeefProduction } from './forms/BreedingPropertiesForm.tsx' | ||
import SlaughterPropertiesForm, { mapSlaughterFormDataToBeefProduction } from './forms/SlaughterPropertiesForm.tsx' | ||
import CuttingPropertiesForm, { mapCuttingFormDataToBeefProduction } from './forms/CuttingPropertiesForm.tsx' | ||
import { useForm } from 'react-hook-form' | ||
import dayjs from 'dayjs' | ||
import BeefProduction from "viandeendirect_eu/dist/model/BeefProduction.js" | ||
|
||
export default function BeefProductionView({ beefProduction: beefProduction, backCallback: backCallback }) { | ||
|
||
const BREEDING_PROPERTIES_TAB = 0 | ||
const SLAUGHTER_PROPERTIES_TAB = 1 | ||
const CUTTING_PROPERTIES_TAB = 2 | ||
const PRODUCTS_TAB = 3 | ||
|
||
const [currentTab, setCurrentTab] = useState<number>(BREEDING_PROPERTIES_TAB); | ||
const [readOnly, setReadOnly] = useState<boolean>(true) | ||
const [production, setProduction] = useState<BeefProduction>(beefProduction) | ||
|
||
const changeTab = (event: React.SyntheticEvent, newValue: number) => { | ||
setCurrentTab(newValue); | ||
}; | ||
|
||
const breedingPropertiesForm = useForm<BeefProduction>({defaultValues: { | ||
...beefProduction, | ||
birthDate: beefProduction.birthDate ? dayjs(beefProduction.birthDate) : undefined | ||
}}) | ||
|
||
const slaughterPropertiesForm = useForm<BeefProduction>({defaultValues: { | ||
...beefProduction, | ||
slaughterDate: beefProduction.slaughterDate ? dayjs(beefProduction.slaughterDate) : undefined | ||
}}) | ||
|
||
const cuttingPropertiesForm = useForm<BeefProduction>({defaultValues: { | ||
...beefProduction, | ||
cuttingDate: beefProduction.cuttingDate ? dayjs(beefProduction.cuttingDate) : undefined | ||
}}) | ||
|
||
return <> | ||
<Typography variant="h6">Abattage bovin</Typography> | ||
<Tabs value={currentTab} onChange={changeTab} variant='scrollable' allowScrollButtonsMobile > | ||
<Tab label="Elevage" disabled={!readOnly}/> | ||
<Tab label="Abattage" disabled={!readOnly}/> | ||
<Tab label="Découpe" disabled={!readOnly}/> | ||
<Tab label="Colis" disabled={!readOnly}/> | ||
</Tabs> | ||
<div hidden={currentTab !== 0}> | ||
<BreedingPropertiesForm | ||
form={breedingPropertiesForm} | ||
disabled={readOnly} | ||
maxBirthDate={production.slaughterDate}/> | ||
</div> | ||
<div hidden={currentTab !== 1}> | ||
<SlaughterPropertiesForm | ||
form={slaughterPropertiesForm} | ||
disabled={readOnly} | ||
minSlaughterDate={production.birthDate} | ||
maxSlaughterDate={production.cuttingDate} | ||
initialWarmCarcassWeight={production.warmCarcassWeight}/> | ||
</div> | ||
<div hidden={currentTab !== 2}> | ||
<CuttingPropertiesForm | ||
form={cuttingPropertiesForm} | ||
disabled={readOnly} | ||
minCuttingDate={production.slaughterDate} /> | ||
</div> | ||
<div hidden={currentTab !== 3}> | ||
</div> | ||
{getButtons()} | ||
</> | ||
|
||
function getButtons() { | ||
if (readOnly) { | ||
return <ButtonGroup> | ||
<Button variant="contained" size="small" onClick={() => backCallback()} >Retour</Button> | ||
<Button variant="outlined" size="small" onClick={() => setReadOnly(false)} >Modifier</Button> | ||
</ButtonGroup> | ||
} | ||
return <ButtonGroup> | ||
<Button variant="contained" size="small" onClick={saveUpdate()} >Sauvegarder</Button> | ||
<Button variant="outlined" size="small" onClick={cancelUpdate} >Abandonner</Button> | ||
</ButtonGroup> | ||
} | ||
|
||
function saveUpdate() { | ||
switch (currentTab) { | ||
case BREEDING_PROPERTIES_TAB: | ||
return breedingPropertiesForm.handleSubmit((breedingFormData) => { | ||
setProduction(mapBreedingFormDataToBeefProduction(breedingFormData, production)) | ||
setReadOnly(true) | ||
}) | ||
case SLAUGHTER_PROPERTIES_TAB: | ||
return slaughterPropertiesForm.handleSubmit((slaughterFormData) => { | ||
setProduction(mapSlaughterFormDataToBeefProduction(slaughterFormData, production)) | ||
setReadOnly(true) | ||
}) | ||
case CUTTING_PROPERTIES_TAB: | ||
return cuttingPropertiesForm.handleSubmit((cuttingFormData) => { | ||
setProduction(mapCuttingFormDataToBeefProduction(cuttingFormData, production)) | ||
setReadOnly(true) | ||
}) | ||
} | ||
} | ||
|
||
function cancelUpdate() { | ||
switch (currentTab) { | ||
case BREEDING_PROPERTIES_TAB: | ||
return breedingPropertiesForm.reset(() => { | ||
setProduction(beefProduction) | ||
setReadOnly(true) | ||
}) | ||
case SLAUGHTER_PROPERTIES_TAB: | ||
return slaughterPropertiesForm.reset(() => { | ||
setProduction(beefProduction) | ||
setReadOnly(true) | ||
}) | ||
case CUTTING_PROPERTIES_TAB: | ||
return cuttingPropertiesForm.reset(() => { | ||
setProduction(beefProduction) | ||
setReadOnly(true) | ||
}) | ||
} | ||
} | ||
} |
Oops, something went wrong.