fetching error: TypeError: Cannot read properties of undefined (reading 'planNo')

at eval (useRoofAllocationSetting.js:179:26)
    at async fetchBasicSettings (useRoofAllocationSetting.js:112:7)
This commit is contained in:
ysCha 2025-09-12 16:45:53 +09:00
parent d37b191139
commit f912a8474e
3 changed files with 24 additions and 15 deletions

View File

@ -86,7 +86,7 @@ export default function ContextRoofAllocationSetting(props) {
return (
<div className="grid-option-box" key={index}>
<div className="d-check-radio pop no-text">
<input type="radio" name="radio01" checked={roof.selected && 'checked'} readOnly={true} />
<input type="radio" name="radio01" checked={!!roof.selected} readOnly={true} />
<label
htmlFor="ra01"
onClick={(e) => {
@ -189,7 +189,7 @@ export default function ContextRoofAllocationSetting(props) {
<input
type="text"
className="input-origin block"
value={roof.hajebichi === '' ? '0' : roof.hajebichi}
value={roof.hajebichi ?? ''}
readOnly={roof.roofPchAuth === 'R'}
onChange={(e) => {
e.target.value = normalizeDigits(e.target.value)
@ -211,8 +211,7 @@ export default function ContextRoofAllocationSetting(props) {
e.target.value = normalizeDecimalLimit(e.target.value, 2)
handleChangePitch(e, index)
}}
value={currentAngleType === 'slope' ? (roof.pitch || '0') : (roof.angle || '0')}
defaultValue={currentAngleType === 'slope' ? (roof.pitch || '0') : (roof.angle || '0')}
value={currentAngleType === 'slope' ? (roof.pitch ?? '') : (roof.angle ?? '')}
/>
</div>
<span className="absol">{pitchText}</span>

View File

@ -86,7 +86,7 @@ export default function RoofAllocationSetting(props) {
return (
<div className="grid-option-box" key={index}>
<div className="d-check-radio pop no-text">
<input type="radio" name="radio01" checked={roof.selected} readOnly />
<input type="radio" name="radio01" checked={!!roof.selected} readOnly />
<label
htmlFor="ra01"
onClick={(e) => {
@ -194,7 +194,7 @@ export default function RoofAllocationSetting(props) {
e.target.value = normalizeDigits(e.target.value)
handleChangeInput(e, 'hajebichi', index)
}}
value={parseInt(roof.hajebichi)}
value={roof.hajebichi ?? ''}
readOnly={roof.roofPchAuth === 'R'}
/>
</div>
@ -212,7 +212,7 @@ export default function RoofAllocationSetting(props) {
e.target.value = normalizeDecimalLimit(e.target.value, 2)
handleChangePitch(e, index)
}}
value={currentAngleType === 'slope' ? roof.pitch : roof.angle}
value={currentAngleType === 'slope' ? (roof.pitch ?? '') : (roof.angle ?? '')}
/>
</div>
<span className="absol">{pitchText}</span>

View File

@ -174,22 +174,32 @@ export function useRoofAllocationSetting(id) {
})
}
const firstRes = Array.isArray(res) && res.length > 0 ? res[0] : null
setBasicSetting({
...basicSetting,
planNo: res[0].planNo,
roofSizeSet: res[0].roofSizeSet,
roofAngleSet: res[0].roofAngleSet,
planNo: firstRes?.planNo ?? planNo,
roofSizeSet: firstRes?.roofSizeSet ?? 0,
roofAngleSet: firstRes?.roofAngleSet ?? 0,
roofsData: roofsArray,
selectedRoofMaterial: selectRoofs.find((roof) => roof.selected),
})
setBasicInfo({
planNo: '' + res[0].planNo,
roofSizeSet: '' + res[0].roofSizeSet,
roofAngleSet: '' + res[0].roofAngleSet,
planNo: '' + (firstRes?.planNo ?? planNo),
roofSizeSet: '' + (firstRes?.roofSizeSet ?? 0),
roofAngleSet: '' + (firstRes?.roofAngleSet ?? 0),
})
//데이터 동기화
setCurrentRoofList(selectRoofs)
// 데이터 동기화: 렌더링용 필드 기본값 보정
const normalizedRoofs = selectRoofs.map((roof) => ({
...roof,
width: roof.width ?? '',
length: roof.length ?? '',
hajebichi: roof.hajebichi ?? '',
pitch: roof.pitch ?? '',
angle: roof.angle ?? '',
}))
setCurrentRoofList(normalizedRoofs)
})
} catch (error) {
console.error('Data fetching error:', error)