Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 11 additions & 62 deletions apps/site-main/src/components/assetManagement/machine-dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import {
import { DateTimePicker } from '@mui/x-date-pickers';
import { useEffect, useState } from 'react';

const options = ['operating', 'not operating'];
const user = JSON.parse(localStorage.getItem('user'));
const organisationId = user.organisation.id;

Expand All @@ -50,7 +49,7 @@ import {
lastServiced: machine ? machine.lastServiced : '',
remarks: machine ? machine.remarks : '',
productionLineId: machine ? machine.productionLine : '',
isOperating: machine ? machine.isOperating : "not operating" ,
isOperating: machine ? machine.isOperating : true ,
};

let schema = {
Expand All @@ -59,10 +58,7 @@ import {
make: Yup.string(),
model: Yup.string(),
year: Yup.string(),
// lastServiced: Yup.date(),
remarks: Yup.string(),
// productionLineId: Yup.string(),
// status: Yup.boolean().required('Status is required'),
};

const handleOnSubmit = async () => {
Expand All @@ -81,9 +77,7 @@ import {
year: formik.values.year,
lastServiced: selectedDate,
remarks: formik.values.remarks,
productionLineId: selectedProductionLines,
isOperating: formik.values.isOperating,
// lastStopped: selectedDate.toJSON()
}),
});

Expand All @@ -100,7 +94,6 @@ import {
}
} else if (action === 'PATCH') {
console.log(machine)
console.log(selectedProductionLines)
const response = await fetch(`http://localhost:3000/api/factory-machines/${machine.id}`, {
method: 'PATCH',
headers: {
Expand All @@ -114,7 +107,6 @@ import {
year: formik.values.year,
lastServiced: selectedDate,
remarks: formik.values.remarks,
productionLineId: selectedProductionLines,
isOperating: formik.values.isOperating,
}),
});
Expand Down Expand Up @@ -143,6 +135,7 @@ import {
formik.resetForm();
handleClose();
};

const [dateTime, setDateTime] = useState([]);

const [selectedDate, handleDateChange] = useState([]);
Expand All @@ -156,34 +149,7 @@ import {
if(action=="PATCH") {
const selectedDate = machine?.lastServiced;
}
},[open]);

const [productionLineOptions, setProductionLineOptions] = useState([]);
const [selectedProductionLines, setSelectedProductionLines] = useState([]);

const fetchData = async () => {
const productionLines = await fetchProductionLines(user.organisation.id);
setProductionLineOptions(productionLines);
};

useEffect(() => {
fetchData();
if(action=="POST") {
setSelectedProductionLines('')
}else if(action=="PATCH") {
setSelectedProductionLines(machine?.productionLineId)
}
},[open]);

const handleChange = (event) => {
const {
target: { value },
} = event;
setSelectedProductionLines(
// On autofill we get a stringified value.
typeof value === 'string' ? value.split(',') : value,
);
};


return (
Expand Down Expand Up @@ -226,7 +192,6 @@ import {
variant="outlined"
multiline
minRows={4}
autoFocus={action === 'PATCH'}
/>
<TextField
required
Expand All @@ -240,6 +205,7 @@ import {
onChange={formik.handleChange}
value={formik.values.make}
variant="outlined"
disabled={action === 'PATCH'}
/>
<TextField
required
Expand All @@ -253,6 +219,7 @@ import {
onChange={formik.handleChange}
value={formik.values.model}
variant="outlined"
disabled={action === 'PATCH'}

/>
<TextField
Expand All @@ -267,6 +234,7 @@ import {
onChange={formik.handleChange}
value={formik.values.year}
variant="outlined"
disabled={action === 'PATCH'}

/>
<TextField
Expand Down Expand Up @@ -294,29 +262,8 @@ import {
disableFuture={true}
/>
</Stack>
<Stack direction="row" spacing={1} alignItems="center">
<Typography>Production Line :</Typography>
<FormControl sx={{ m: 1, width: 300 }}>
<InputLabel id="productionLineNamesLabel">Production Lines</InputLabel>
<Select
labelId="productionLineNamesLabel"
id="productionLineNames"
value={selectedProductionLines}
onChange={handleChange}
input={<OutlinedInput label="Production Line Name" />}
>
{productionLineOptions.map((option) => (
<MenuItem
key={option.id}
value={option.id}
>
{option.name}
</MenuItem>
))}
</Select>
</FormControl>
</Stack>
<Stack direction="row" spacing={1} alignItems="center">

{/* <Stack direction="row" spacing={1} alignItems="center">
<Typography>Status :</Typography>
<RadioGroup
label="isOperating"
Expand All @@ -325,7 +272,7 @@ import {
onBlur={formik.handleBlur}
onChange={formik.handleChange}
value={formik.values.isOperating}
defaultValue={formik.values.isOperating}
defaultValue={options[0]}
row
>
{options.map((option) => (
Expand All @@ -334,11 +281,13 @@ import {
value={option}
control={<Radio />}
label={option}
disabled={action === 'POST'}

/>
))}
</RadioGroup>
</Stack>
</Stack> */}

</DialogContent>
<DialogActions>
<Button
Expand Down
Loading