api 호출 제거
This commit is contained in:
parent
a1f80b0752
commit
70ebb63fa7
@ -1,128 +0,0 @@
|
|||||||
'use client'
|
|
||||||
|
|
||||||
import { Select, SelectItem } from '@nextui-org/react'
|
|
||||||
import { useEffect, useState } from 'react'
|
|
||||||
import { useAxios } from '@/hooks/useAxios'
|
|
||||||
|
|
||||||
export default function RoofSelect() {
|
|
||||||
const [roofMaterials, setRoofMaterials] = useState([])
|
|
||||||
const [manufacturers, setManufacturers] = useState([])
|
|
||||||
const [trestles, setTrestles] = useState([])
|
|
||||||
const [modules, setModules] = useState([])
|
|
||||||
const [originTrestles, setOriginTrestles] = useState([])
|
|
||||||
|
|
||||||
const [roofMaterialId, setRoofMaterialId] = useState(null)
|
|
||||||
const [manufacturerId, setManufacturerId] = useState(null)
|
|
||||||
const [trestleId, setTrestleId] = useState(null)
|
|
||||||
|
|
||||||
const { get } = useAxios()
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
get({ url: '/api/roof-material/roof-material-infos' }).then((res) => {
|
|
||||||
//TODO: error handling
|
|
||||||
if (!res) return
|
|
||||||
|
|
||||||
setRoofMaterials(res)
|
|
||||||
})
|
|
||||||
}, [])
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (!roofMaterialId) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
get({ url: `/api/roof-material/roof-material-infos/${roofMaterialId}/trestles` }).then((res) => {
|
|
||||||
if (res.length === 0) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
setOriginTrestles(res)
|
|
||||||
const manufactural = res.map((trestle) => {
|
|
||||||
return { id: trestle.manufacturerId, name: trestle.manufacturerName }
|
|
||||||
})
|
|
||||||
// Remove duplicates
|
|
||||||
const uniqueManufactural = Array.from(new Set(manufactural.map((a) => a.id))).map((id) => {
|
|
||||||
return manufactural.find((a) => a.id === id)
|
|
||||||
})
|
|
||||||
|
|
||||||
setManufacturers(uniqueManufactural)
|
|
||||||
})
|
|
||||||
}, [roofMaterialId])
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (!manufacturerId) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
const trestles = originTrestles.filter((trestle) => trestle.manufacturerId === manufacturerId)
|
|
||||||
setTrestles(trestles)
|
|
||||||
}, [manufacturerId])
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (!trestleId) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
get({ url: `/api/module/module-infos?roofMaterialId=${roofMaterialId}&trestleId=${trestleId}` }).then((res) => {
|
|
||||||
if (res.length === 0) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
setModules(res)
|
|
||||||
})
|
|
||||||
}, [trestleId])
|
|
||||||
|
|
||||||
const handleRoofMaterialOnChange = (e) => {
|
|
||||||
const roofMaterialId = e.target.value
|
|
||||||
setRoofMaterialId(roofMaterialId)
|
|
||||||
setManufacturers([])
|
|
||||||
setManufacturerId(null)
|
|
||||||
setTrestleId(null)
|
|
||||||
setTrestles([])
|
|
||||||
setModules([])
|
|
||||||
}
|
|
||||||
|
|
||||||
const handleManufacturersOnChange = (e) => {
|
|
||||||
const manufacturerId = Number(e.target.value)
|
|
||||||
setTrestles([])
|
|
||||||
setManufacturerId(manufacturerId)
|
|
||||||
setTrestleId(null)
|
|
||||||
setModules([])
|
|
||||||
}
|
|
||||||
|
|
||||||
const handleTrestlesOnChange = (e) => {
|
|
||||||
const trestleId = Number(e.target.value)
|
|
||||||
setTrestleId(trestleId)
|
|
||||||
setModules([])
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className="flex w-full flex-wrap md:flex-nowrap gap-4">
|
|
||||||
{roofMaterials.length > 0 && (
|
|
||||||
<Select label="지붕재" className="max-w-xs" onChange={handleRoofMaterialOnChange}>
|
|
||||||
{roofMaterials.map((roofMaterial) => (
|
|
||||||
<SelectItem key={roofMaterial.id}>{roofMaterial.name}</SelectItem>
|
|
||||||
))}
|
|
||||||
</Select>
|
|
||||||
)}
|
|
||||||
{manufacturers.length > 0 && (
|
|
||||||
<Select label="제조 회사" className="max-w-xs" onChange={handleManufacturersOnChange}>
|
|
||||||
{manufacturers.map((manufacturer) => (
|
|
||||||
<SelectItem key={manufacturer.id}>{manufacturer.name}</SelectItem>
|
|
||||||
))}
|
|
||||||
</Select>
|
|
||||||
)}
|
|
||||||
{trestles.length > 0 && (
|
|
||||||
<Select label="가대" className="max-w-xs" onChange={handleTrestlesOnChange}>
|
|
||||||
{trestles.map((trestle) => (
|
|
||||||
<SelectItem key={trestle.id}>{trestle.name}</SelectItem>
|
|
||||||
))}
|
|
||||||
</Select>
|
|
||||||
)}
|
|
||||||
{modules.length > 0 && (
|
|
||||||
<Select label="설치가능 모듈" className="max-w-xs">
|
|
||||||
{modules.map((module) => (
|
|
||||||
<SelectItem key={module.id}>{module.name}</SelectItem>
|
|
||||||
))}
|
|
||||||
</Select>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
@ -1,14 +1,8 @@
|
|||||||
import Roof2 from '@/components/Roof2'
|
import Roof2 from '@/components/Roof2'
|
||||||
import RoofSelect from '@/app/roof2/RoofSelect'
|
|
||||||
|
|
||||||
export default async function Roof2Page() {
|
export default async function Roof2Page() {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div>
|
|
||||||
<div className="m-2">
|
|
||||||
<RoofSelect />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div className="flex flex-col justify-center my-8 pt-20">
|
<div className="flex flex-col justify-center my-8 pt-20">
|
||||||
<Roof2 />
|
<Roof2 />
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -29,13 +29,6 @@ export default function InitSettingsModal(props) {
|
|||||||
//const { get, post } = useAxios()
|
//const { get, post } = useAxios()
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
get({ url: '/api/roof-material/roof-material-infos' }).then((res) => {
|
|
||||||
//TODO: error handling
|
|
||||||
if (!res) return
|
|
||||||
|
|
||||||
setRoofMaterials(res)
|
|
||||||
})
|
|
||||||
|
|
||||||
get({ url: `/api/canvas-management/canvas-basic-settings/by-object/${objectNo}` }).then((res) => {
|
get({ url: `/api/canvas-management/canvas-basic-settings/by-object/${objectNo}` }).then((res) => {
|
||||||
if (res.length == 0) return
|
if (res.length == 0) return
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user