From f0517563b2b4836a739c36e8a92b6e9c19d71786 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=BCbra=20Aksu?= Date: Fri, 22 Dec 2023 21:18:54 +0300 Subject: [PATCH] resource selection implementation revised. --- .../components/Resource/ResourceDetail1.js | 170 +++++------------- 1 file changed, 43 insertions(+), 127 deletions(-) diff --git a/resq/frontend/src/components/Resource/ResourceDetail1.js b/resq/frontend/src/components/Resource/ResourceDetail1.js index ea220516..a50ef334 100644 --- a/resq/frontend/src/components/Resource/ResourceDetail1.js +++ b/resq/frontend/src/components/Resource/ResourceDetail1.js @@ -5,86 +5,34 @@ import { FormControlLabel, Checkbox, FormControl, - InputLabel, - Select, - MenuItem, - OutlinedInput + Autocomplete, + TextField } from '@mui/material'; -import { useTheme } from '@mui/material/styles'; import { useQuery } from "@tanstack/react-query"; import { getCategoryTree } from "../../AppService"; -const materialResources = [ - 'Food', - 'Diapers', - 'Hygene Products', - 'Water', - 'Shelter', - 'Tent', - 'Clothing', -]; -const humanResources = [ - 'Doctor', - 'Nurse', - 'Translator', - 'Rescue Team', - 'Lorry Driver', - 'Food Service', - 'District Responsible', -]; - export default function ResourceDetails1({ resourceData, setResourceData }) { + const [isMaterialResourceChecked, setIsMaterialResourceChecked] = useState(false); + const [isHumanResourceChecked, setIsHumanResourceChecked] = useState(false); + const [selectedResource, setSelectedResource] = useState(null); - const ITEM_HEIGHT = 48; - const ITEM_PADDING_TOP = 8; - const MenuProps = { - PaperProps: { - style: { - maxHeight: ITEM_HEIGHT * 4.5 + ITEM_PADDING_TOP, - width: 250, - }, - }, - }; - - const { data: categoryTreeData, isLoading: isLoadingCategoryTree } = useQuery({ + const { data: categoryTreeData, isLoading } = useQuery({ queryKey: ['categoryTree'], queryFn: getCategoryTree }); - const [isMaterialResourceChecked, setIsMaterialResourceChecked] = useState(false); - const [isHumanResourceChecked, setIsHumanResourceChecked] = useState(false); - - const [selectedMaterialValue, setSelectedMaterial] = useState(null); - const [selectedHumanValues, setSelectedHumanValues] = useState([]); - - const getStyles = (item, selectedItems, theme) => { - return { - fontWeight: - selectedItems.indexOf(item) === -1 - ? theme.typography.fontWeightRegular - : theme.typography.fontWeightMedium, - }; - }; - - const handleHumanChange = (event) => { - setSelectedHumanValues(event.target.value); - }; - - const theme = useTheme(); useEffect(() => { - if (!isMaterialResourceChecked && !isHumanResourceChecked) { - setSelectedResource(''); - } - - const updatedResourceData = { ...resourceData }; - if (isMaterialResourceChecked || isHumanResourceChecked) { - updatedResourceData.resourceType = selectedResource; - } - setResourceData(updatedResourceData); + const description = { + resourceType: isMaterialResourceChecked ? 'material' : 'human', + resourceId: selectedResource?.id || '' + }; + setResourceData({ ...resourceData, ...description }); }, [isMaterialResourceChecked, isHumanResourceChecked, selectedResource, setResourceData, resourceData]); - const handleResourceChange = (event) => { - setSelectedResource(event.target.value); + const filterCategoryItems = (type) => { + return categoryTreeData?.filter(cat => cat.type === type) + .map(cat => ({ label: cat.data, id: cat.id })) + .sort((a, b) => a.label.localeCompare(b.label)) || []; }; return ( @@ -95,76 +43,44 @@ export default function ResourceDetails1({ resourceData, setResourceData }) { { setIsMaterialResourceChecked(e.target.checked); setIsHumanResourceChecked(!e.target.checked); - }} - /> - } + setSelectedResource(null); + }} />} label="Material Resource" /> - {isMaterialResourceChecked && ( - - Material Resource - - - )} - - setIsHumanResourceChecked(e.target.checked)} />} + control={ { + setIsHumanResourceChecked(e.target.checked); + setIsMaterialResourceChecked(!e.target.checked); + setSelectedResource(null); + }} />} label="Human Resource" /> - {isHumanResourceChecked && ( - <> - - - - + + + {(isMaterialResourceChecked || isHumanResourceChecked) && ( + + { + setSelectedResource(newValue); + }} + sx={{ width: 300 }} + renderInput={(params) => ( + + )} + /> + )} - + ); }