Files
sgeUpdated/sge-frontend/src/components/main-data-tables-waste-update/solid-waste.js
Khaled Elagamy 85f1847070 Add 'sge-frontend/' from commit '5fa787e054b25ac53edc7ff0275ea7960a709401'
git-subtree-dir: sge-frontend
git-subtree-mainline: 876c278ac4
git-subtree-split: 5fa787e054
2025-08-04 00:27:23 +03:00

138 lines
4.2 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import React, { useState, useEffect } from "react";
import { useDispatch, useSelector } from "react-redux";
import { Label, Input } from "reactstrap";
import Select from "react-select";
import { useTranslation } from "react-i18next";
import { getMcfTypes } from "../../redux/actions/datas";
const DataUpdateSolidWaste = ({ editingDataInput, setEditingDataInput }) => {
const { t } = useTranslation();
const dispatch = useDispatch();
const datasStore = useSelector((state) => state.datas);
const [mcfTypesOptions, setMcfTypesOptions] = useState([]);
useEffect(() => {
setMcfTypesOptions(
datasStore?.mcfTypes?.map((mcfType) => {
return {
value: mcfType?.id,
label: `${mcfType?.typeName} (${mcfType?.value})`,
};
})
);
}, [datasStore?.mcfTypes]);
useEffect(() => {
dispatch(getMcfTypes());
}, []);
let solidWasteTypes = [
{ label: "Evsel", value: "domestic" },
{ label: "Bahçe", value: "garden" },
{ label: "Kağıt", value: "paper" },
{ label: "Ağaç", value: "tree" },
{ label: "Tekstil", value: "textile" },
{ label: "Endüstriyel", value: "industrial" },
];
return (
<>
<div className="mb-2">
<Label className="form-label" for="solid-waste-types">
Atık Türü:
</Label>
{solidWasteTypes.map((type, index) => (
<div className="d-flex flex-md-row flex-column" key={index}>
<div className="mb-2 col-3">
<Label className="form-label" for="solid-waste-type">
{type.label}:
</Label>
</div>
<div className="mb-2 col-6">
<Input
id="solid-waste-type"
placeholder="0-100"
type="text"
value={editingDataInput?.[type.value]?.inputValue || ""}
onChange={(e) => {
const inputValue = e.target.value;
const onlyNumbers = inputValue.replace(/[^0-9]/g, "");
const parsedNumber = Math.min(
100,
Math.max(0, parseInt(onlyNumbers, 10))
);
setEditingDataInput({
...editingDataInput,
[type.value]: {
...editingDataInput?.[type.value],
inputValue: parsedNumber,
},
});
}}
onKeyDown={(e) => {
if (e.key === "e" || e.key === "E") {
e.preventDefault();
}
}}
/>
</div>
</div>
))}
</div>
<div className="mb-2">
<Label className="form-label" for="mcfType">
MCF:
</Label>
<Select
id="mcfType"
isClearable={false}
closeMenuOnSelect={true}
maxMenuHeight={150}
menuPlacement="auto"
className="react-select"
placeholder=""
options={mcfTypesOptions}
value={editingDataInput?.mcfType || ""}
onChange={(value) => {
setEditingDataInput({
...editingDataInput,
mcfType: value,
});
}}
/>
</div>
<div className="mb-2">
<Label className="form-label" for="frec">
Metan Yakalama Oranı %:
</Label>
<Input
id="frec"
placeholder="0-100"
type="text"
value={editingDataInput?.frec || ""}
onChange={(e) => {
const inputValue = e.target.value;
const onlyNumbers = inputValue.replace(/[^0-9]/g, "");
const parsedNumber = Math.min(
100,
Math.max(0, parseInt(onlyNumbers, 10))
);
setEditingDataInput({
...editingDataInput,
frec: parsedNumber,
});
}}
onKeyDown={(e) => {
if (e.key === "e" || e.key === "E") {
e.preventDefault();
}
}}
/>
</div>
</>
);
};
export default DataUpdateSolidWaste;