📌feat: Add popup status save hooks
This commit is contained in:
parent
370617ff63
commit
d53191b793
@ -3,11 +3,12 @@
|
||||
import { createContext, useEffect, useState } from 'react'
|
||||
import { useLocalStorage } from 'usehooks-ts'
|
||||
|
||||
export const GlobalDataContext = createContext({
|
||||
managementState: {},
|
||||
setManagementState: () => {},
|
||||
managementStateLoaded: null,
|
||||
})
|
||||
// export const GlobalDataContext = createContext({
|
||||
// managementState: {},
|
||||
// setManagementState: () => {},
|
||||
// managementStateLoaded: null,
|
||||
// })
|
||||
export const GlobalDataContext = createContext(null)
|
||||
|
||||
const GlobalDataProvider = ({ children }) => {
|
||||
const [managementState, setManagementState] = useState(null)
|
||||
|
||||
@ -27,6 +27,7 @@ import useSWR from 'swr'
|
||||
import useSWRMutation from 'swr/mutation'
|
||||
import { useCanvasPopupStatusController } from '@/hooks/common/useCanvasPopupStatusController'
|
||||
import { canvasPopupStatusStore } from '@/store/canvasPopupStatusAtom'
|
||||
import { moduleSelectionDataPlanListState } from '@/store/selectedModuleOptions'
|
||||
|
||||
export default function Playground() {
|
||||
const [useCadFile, setUseCadFile] = useRecoilState(useCadFileState)
|
||||
@ -256,25 +257,25 @@ export default function Playground() {
|
||||
})
|
||||
}
|
||||
|
||||
const [callFlag, setCallFlag] = useState(false)
|
||||
// const [callFlag, setCallFlag] = useState(false)
|
||||
// const { data: tutoData, error, isLoading } = useSWR('http://localhost:8080/api/tutorial', getFetcher)
|
||||
const { data: tutoData, error, isLoading } = useSWR(callFlag ? 'http://localhost:8080/api/tutorial' : null, getFetcher)
|
||||
const { trigger, isMutating } = useSWRMutation('http://localhost:8080/api/tutorial', postFetcher)
|
||||
// const { data: tutoData, error, isLoading } = useSWR(callFlag ? 'http://localhost:8080/api/tutorial' : null, getFetcher)
|
||||
// const { trigger, isMutating } = useSWRMutation('http://localhost:8080/api/tutorial', postFetcher)
|
||||
|
||||
if (isLoading) {
|
||||
return <div>Loading...</div>
|
||||
}
|
||||
// if (isLoading) {
|
||||
// return <div>Loading...</div>
|
||||
// }
|
||||
|
||||
if (error) {
|
||||
return <div>Error...</div>
|
||||
}
|
||||
// if (error) {
|
||||
// return <div>Error...</div>
|
||||
// }
|
||||
|
||||
useCanvasPopupStatusController(1)
|
||||
// const [moduleSelectionDataPlanListStore, setModuleSelectionDataPlanListStore] = useRecoilState(moduleSelectionDataPlanListState)
|
||||
// useEffect(() => {
|
||||
// console.log('🚀 ~ Playground ~ moduleSelectionDataPlanListStore:', moduleSelectionDataPlanListStore)
|
||||
// }, [moduleSelectionDataPlanListStore])
|
||||
// const { trigger: canvasPopupStatusTrigger } = useCanvasPopupStatusController({ objectNo: 'R201T01241120001', planNo: 2, popupType: 2 })
|
||||
|
||||
const [canvasPopupStatusState, setCanvasPopupStatusState] = useRecoilState(canvasPopupStatusStore)
|
||||
useEffect(() => {
|
||||
console.log('🚀 ~ Playground ~ canvasPopupStatusState:', canvasPopupStatusState)
|
||||
}, [canvasPopupStatusState])
|
||||
return (
|
||||
<>
|
||||
<div className="container mx-auto p-4 m-4 border">
|
||||
@ -579,7 +580,7 @@ export default function Playground() {
|
||||
Sweetalert - alert
|
||||
</Button>
|
||||
</div>
|
||||
<div className="my-2">
|
||||
{/* <div className="my-2">
|
||||
{tutoData &&
|
||||
tutoData.map((item) => (
|
||||
<div key={item.id}>
|
||||
@ -594,6 +595,301 @@ export default function Playground() {
|
||||
<Button disabled={isMutating} onClick={() => trigger({ id: 3, name: 'seulda kim', email: 'seulda.kim@interplug.co.kr' })}>
|
||||
insert data
|
||||
</Button>
|
||||
</div> */}
|
||||
<div className="my-2">
|
||||
<Button
|
||||
onClick={() => {
|
||||
canvasPopupStatusTrigger({
|
||||
common: {
|
||||
illuminationTp: '3',
|
||||
instHt: '10',
|
||||
stdWindSpeed: 'WL_32',
|
||||
stdSnowLd: '5',
|
||||
moduleTpCd: 'A1',
|
||||
moduleItemId: '106796',
|
||||
},
|
||||
roofConstructions: [
|
||||
{
|
||||
roofIndex: 0,
|
||||
addRoof: {
|
||||
roofMatlCd: 'ROOF_ID_WA_53A',
|
||||
roofMatlNm: '일본기와 A',
|
||||
roofMatlNmJp: '和瓦A',
|
||||
widAuth: 'R',
|
||||
widBase: '265.000',
|
||||
lenAuth: 'R',
|
||||
lenBase: '235.000',
|
||||
roofPchAuth: null,
|
||||
roofPchBase: null,
|
||||
raftAuth: 'C',
|
||||
raftBaseCd: 'HEI_455',
|
||||
id: 'ROOF_ID_WA_53A',
|
||||
name: '일본기와 A',
|
||||
selected: true,
|
||||
index: 0,
|
||||
nameJp: '和瓦A',
|
||||
length: 235,
|
||||
width: 265,
|
||||
raft: 'HEI_455',
|
||||
layout: 'P',
|
||||
hajebichi: 0,
|
||||
pitch: 7,
|
||||
angle: 21.8,
|
||||
roofSizeSet: '1',
|
||||
roofAngleSet: 'slope',
|
||||
},
|
||||
trestle: {
|
||||
moduleTpCd: 'A1',
|
||||
moduleTpCdNm: 'A1type',
|
||||
moduleTpCdJp: 'A1type',
|
||||
roofMatlCd: 'ROOF_ID_WA_53A',
|
||||
roofMatlCdNm: '일본기와 A',
|
||||
roofMatlCdJp: '和瓦A',
|
||||
trestleMkrCd: 'ROOF_TECHRI',
|
||||
trestleMkrCdNm: '지붕 기술 연구소',
|
||||
trestleMkrCdJp: '屋根技術研究所',
|
||||
constMthdCd: 'CST026',
|
||||
constMthdCdNm: 'YG 앵커 랙 있음',
|
||||
constMthdCdJp: 'YGアンカー ラック有り',
|
||||
roofBaseCd: 'RFB001',
|
||||
roofBaseCdNm: '구조용 합판 9mm 이상',
|
||||
roofBaseCdJp: '構造用合板9mm以上',
|
||||
rackYn: null,
|
||||
priority: 1,
|
||||
},
|
||||
construction: {
|
||||
constTp: 'WORK_LV_ID_1',
|
||||
constTpNm: '표준 시공',
|
||||
constTpJp: '標準施工',
|
||||
constPossYn: 'Y',
|
||||
plvrYn: 'Y',
|
||||
cvrYn: 'Y',
|
||||
cvrLmtRow: 9999,
|
||||
snowGdPossYn: 'Y',
|
||||
roofIndex: 0,
|
||||
setupCover: true,
|
||||
setupSnowCover: true,
|
||||
selectedIndex: 1,
|
||||
},
|
||||
},
|
||||
{
|
||||
roofIndex: 1,
|
||||
addRoof: {
|
||||
roofMatlCd: 'ROOF_ID_WA_53B',
|
||||
roofMatlNm: '일본기와 B',
|
||||
roofMatlNmJp: '和瓦B',
|
||||
widAuth: 'R',
|
||||
widBase: '275.000',
|
||||
lenAuth: 'R',
|
||||
lenBase: '225.000',
|
||||
roofPchAuth: null,
|
||||
roofPchBase: null,
|
||||
raftAuth: 'C',
|
||||
raftBaseCd: 'HEI_455',
|
||||
id: 'ROOF_ID_WA_53B',
|
||||
name: '일본기와 B',
|
||||
selected: true,
|
||||
index: 1,
|
||||
nameJp: '和瓦B',
|
||||
length: 225,
|
||||
width: 275,
|
||||
raft: 'HEI_455',
|
||||
layout: 'P',
|
||||
hajebichi: 0,
|
||||
pitch: 5,
|
||||
angle: 21.8,
|
||||
roofSizeSet: '1',
|
||||
roofAngleSet: 'slope',
|
||||
},
|
||||
trestle: {
|
||||
moduleTpCd: 'A1',
|
||||
moduleTpCdNm: 'A1type',
|
||||
moduleTpCdJp: 'A1type',
|
||||
roofMatlCd: 'ROOF_ID_WA_53B',
|
||||
roofMatlCdNm: '일본기와 B',
|
||||
roofMatlCdJp: '和瓦B',
|
||||
trestleMkrCd: 'DAIDO HUNT',
|
||||
trestleMkrCdNm: '다이도 헌트',
|
||||
trestleMkrCdJp: 'ダイドーハント',
|
||||
constMthdCd: 'CST016',
|
||||
constMthdCdNm: '지지 기와Ⅱ-B 랙 있음',
|
||||
constMthdCdJp: '支持瓦Ⅱ-B ラック有り',
|
||||
roofBaseCd: 'RFB002',
|
||||
roofBaseCdNm: 'OSB12mm 이상',
|
||||
roofBaseCdJp: 'OSB12mm以上',
|
||||
rackYn: null,
|
||||
priority: 95,
|
||||
},
|
||||
construction: {
|
||||
constTp: 'WORK_LV_ID_1',
|
||||
constTpNm: '표준 시공',
|
||||
constTpJp: '標準施工',
|
||||
constPossYn: 'Y',
|
||||
plvrYn: 'Y',
|
||||
cvrYn: 'Y',
|
||||
cvrLmtRow: 9999,
|
||||
snowGdPossYn: 'Y',
|
||||
roofIndex: 1,
|
||||
setupCover: false,
|
||||
setupSnowCover: true,
|
||||
selectedIndex: 1,
|
||||
},
|
||||
},
|
||||
{
|
||||
roofIndex: 2,
|
||||
addRoof: {
|
||||
roofMatlCd: 'ROOF_ID_HIRA_C',
|
||||
roofMatlNm: '평판기와 C',
|
||||
roofMatlNmJp: '平板瓦C',
|
||||
widAuth: 'R',
|
||||
widBase: '305.000',
|
||||
lenAuth: 'R',
|
||||
lenBase: '280.000',
|
||||
roofPchAuth: null,
|
||||
roofPchBase: null,
|
||||
raftAuth: 'C',
|
||||
raftBaseCd: 'HEI_455',
|
||||
id: 'ROOF_ID_HIRA_C',
|
||||
name: '평판기와 C',
|
||||
selected: true,
|
||||
index: 2,
|
||||
nameJp: '平板瓦C',
|
||||
length: 280,
|
||||
width: 305,
|
||||
raft: 'HEI_455',
|
||||
layout: 'P',
|
||||
hajebichi: 0,
|
||||
pitch: 4,
|
||||
angle: 21.8,
|
||||
roofSizeSet: '1',
|
||||
roofAngleSet: 'slope',
|
||||
},
|
||||
trestle: {
|
||||
moduleTpCd: 'A1',
|
||||
moduleTpCdNm: 'A1type',
|
||||
moduleTpCdJp: 'A1type',
|
||||
roofMatlCd: 'ROOF_ID_HIRA_C',
|
||||
roofMatlCdNm: '평판기와 C',
|
||||
roofMatlCdJp: '平板瓦C',
|
||||
trestleMkrCd: 'ROOF_TECHRI',
|
||||
trestleMkrCdNm: '지붕 기술 연구소',
|
||||
trestleMkrCdJp: '屋根技術研究所',
|
||||
constMthdCd: 'CST034',
|
||||
constMthdCdNm: '지지 기와 C 랙 있음',
|
||||
constMthdCdJp: '支持瓦C ラック有り',
|
||||
roofBaseCd: 'RFB001',
|
||||
roofBaseCdNm: '구조용 합판 9mm 이상',
|
||||
roofBaseCdJp: '構造用合板9mm以上',
|
||||
rackYn: null,
|
||||
priority: 122,
|
||||
},
|
||||
construction: {
|
||||
constTp: 'WORK_LV_ID_1',
|
||||
constTpNm: '표준 시공',
|
||||
constTpJp: '標準施工',
|
||||
constPossYn: 'Y',
|
||||
plvrYn: 'Y',
|
||||
cvrYn: 'Y',
|
||||
cvrLmtRow: 9999,
|
||||
snowGdPossYn: 'Y',
|
||||
roofIndex: 2,
|
||||
setupCover: false,
|
||||
setupSnowCover: false,
|
||||
selectedIndex: 1,
|
||||
},
|
||||
},
|
||||
{
|
||||
roofIndex: 3,
|
||||
addRoof: {
|
||||
roofMatlCd: 'ROOF_ID_HIRA_D',
|
||||
roofMatlNm: '평판기와 D',
|
||||
roofMatlNmJp: '平板瓦D',
|
||||
widAuth: 'R',
|
||||
widBase: '305.000',
|
||||
lenAuth: 'R',
|
||||
lenBase: '280.000',
|
||||
roofPchAuth: null,
|
||||
roofPchBase: null,
|
||||
raftAuth: 'C',
|
||||
raftBaseCd: 'HEI_455',
|
||||
id: 'ROOF_ID_HIRA_D',
|
||||
name: '평판기와 D',
|
||||
selected: true,
|
||||
index: 3,
|
||||
nameJp: '平板瓦D',
|
||||
length: 280,
|
||||
width: 305,
|
||||
raft: 'HEI_455',
|
||||
layout: 'P',
|
||||
hajebichi: 0,
|
||||
pitch: 8,
|
||||
angle: 21.8,
|
||||
roofSizeSet: '1',
|
||||
roofAngleSet: 'slope',
|
||||
},
|
||||
trestle: {
|
||||
moduleTpCd: 'A1',
|
||||
moduleTpCdNm: 'A1type',
|
||||
moduleTpCdJp: 'A1type',
|
||||
roofMatlCd: 'ROOF_ID_HIRA_D',
|
||||
roofMatlCdNm: '평판기와 D',
|
||||
roofMatlCdJp: '平板瓦D',
|
||||
trestleMkrCd: 'DAIDO HUNT',
|
||||
trestleMkrCdNm: '다이도 헌트',
|
||||
trestleMkrCdJp: 'ダイドーハント',
|
||||
constMthdCd: 'CST018',
|
||||
constMthdCdNm: '지지 기와Ⅱ-D 랙 있음',
|
||||
constMthdCdJp: '支持瓦Ⅱ-D ラック有り',
|
||||
roofBaseCd: 'RFB002',
|
||||
roofBaseCdNm: 'OSB12mm 이상',
|
||||
roofBaseCdJp: 'OSB12mm以上',
|
||||
rackYn: null,
|
||||
priority: 203,
|
||||
},
|
||||
construction: {
|
||||
constTp: 'WORK_LV_ID_3',
|
||||
constTpNm: '강화 시공',
|
||||
constTpJp: '強化施工',
|
||||
constPossYn: 'Y',
|
||||
plvrYn: 'Y',
|
||||
cvrYn: 'Y',
|
||||
cvrLmtRow: 9999,
|
||||
snowGdPossYn: 'Y',
|
||||
roofIndex: 3,
|
||||
setupCover: false,
|
||||
setupSnowCover: false,
|
||||
selectedIndex: 2,
|
||||
},
|
||||
},
|
||||
],
|
||||
module: {
|
||||
itemId: '106796',
|
||||
itemNm: 'Q.TRON M-G2.4+ 430',
|
||||
goodsNo: 'Q.TRON M-G2.4+ 430',
|
||||
itemTp: 'A1',
|
||||
mixMatlNo: null,
|
||||
mixItemTpYn: 'N',
|
||||
itemList: [
|
||||
{
|
||||
itemId: '106796',
|
||||
itemNm: 'Q.TRON M-G2.4+ 430',
|
||||
goodsNo: 'Q.TRON M-G2.4+ 430',
|
||||
itemTp: 'A1',
|
||||
color: '#BEF781',
|
||||
longAxis: '1722.000',
|
||||
shortAxis: '1134.000',
|
||||
thickness: '30.000',
|
||||
wpOut: '430',
|
||||
mixMatlNo: null,
|
||||
},
|
||||
],
|
||||
name: 'Q.TRON M-G2.4+ 430',
|
||||
},
|
||||
})
|
||||
}}
|
||||
>
|
||||
Test Data insert
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
|
||||
@ -1,8 +1,9 @@
|
||||
import { forwardRef, useImperativeHandle, useState } from 'react'
|
||||
import { forwardRef, useContext, useImperativeHandle, useState } from 'react'
|
||||
import { useMessage } from '@/hooks/useMessage'
|
||||
import { useOrientation } from '@/hooks/module/useOrientation'
|
||||
import { getDegreeInOrientation } from '@/util/canvas-util'
|
||||
import { numberCheck } from '@/util/common-utils'
|
||||
import { useCanvasPopupStatusController } from '@/hooks/common/useCanvasPopupStatusController'
|
||||
|
||||
export const Orientation = forwardRef(({ tabNum }, ref) => {
|
||||
const { getMessage } = useMessage()
|
||||
@ -17,6 +18,7 @@ export const Orientation = forwardRef(({ tabNum }, ref) => {
|
||||
|
||||
const handleNextStep = () => {
|
||||
nextStep()
|
||||
canvasPopupStatusTrigger(compasDeg)
|
||||
}
|
||||
|
||||
const checkDegree = (e) => {
|
||||
@ -27,6 +29,8 @@ export const Orientation = forwardRef(({ tabNum }, ref) => {
|
||||
}
|
||||
}
|
||||
|
||||
const { trigger: canvasPopupStatusTrigger } = useCanvasPopupStatusController(1)
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="properties-setting-wrap">
|
||||
|
||||
@ -1,28 +1,77 @@
|
||||
'use client'
|
||||
|
||||
import { useEffect } from 'react'
|
||||
import { useRecoilState, useRecoilValue } from 'recoil'
|
||||
import useSWR from 'swr'
|
||||
import useSWRMutation from 'swr/mutation'
|
||||
import { useAxios } from '../useAxios'
|
||||
import { useRecoilState } from 'recoil'
|
||||
import { canvasPopupStatusStore } from '@/store/canvasPopupStatusAtom'
|
||||
import { unescapeString } from '@/util/common-utils'
|
||||
import { moduleSelectionDataState } from '@/store/selectedModuleOptions'
|
||||
import { compasDegAtom } from '@/store/orientationAtom'
|
||||
import { currentCanvasPlanState } from '@/store/canvasAtom'
|
||||
|
||||
export function useCanvasPopupStatusController(popupType) {
|
||||
const [canvasPopupStatusState, setCanvasPopupStatusState] = useRecoilState(canvasPopupStatusStore)
|
||||
export function useCanvasPopupStatusController(param = 1) {
|
||||
const popupType = param
|
||||
|
||||
const [compasDeg, setCompasDeg] = useRecoilState(compasDegAtom)
|
||||
const [moduleSelectionDataStore, setModuleSelectionDataStore] = useRecoilState(moduleSelectionDataState)
|
||||
const { getFetcher, postFetcher } = useAxios()
|
||||
|
||||
const currentCanvasPlan = useRecoilValue(currentCanvasPlanState)
|
||||
console.log('🚀 ~ Orientation ~ currentCanvasPlan:', currentCanvasPlan)
|
||||
|
||||
const {
|
||||
data: popupStatus,
|
||||
error,
|
||||
isLoading,
|
||||
} = useSWR(popupType ? 'canvas-popup-status--data' : null, () => getFetcher(`http://localhost:8080/api/tutorial?popupType=${popupType}`))
|
||||
} = useSWR(
|
||||
popupType ? `/api/v1/canvas-popup-status?objectNo=${currentCanvasPlan.objectNo}&planNo=${currentCanvasPlan.planNo}&popupType=${popupType}` : null,
|
||||
getFetcher,
|
||||
)
|
||||
|
||||
useEffect(() => {
|
||||
console.log('🚀 ~ useEffect ~ popupStatus:', popupStatus)
|
||||
if (popupStatus) {
|
||||
setCanvasPopupStatusState({ ...canvasPopupStatusState, [popupType]: popupStatus })
|
||||
switch (parseInt(popupStatus?.popupType)) {
|
||||
case 1:
|
||||
setCompasDeg(popupStatus.popupStatus)
|
||||
break
|
||||
case 2:
|
||||
setModuleSelectionDataStore(JSON.parse(unescapeString(popupStatus.popupStatus)))
|
||||
break
|
||||
case 3:
|
||||
break
|
||||
case 4:
|
||||
break
|
||||
default:
|
||||
}
|
||||
} else {
|
||||
switch (popupType) {
|
||||
case 1:
|
||||
setCompasDeg(0)
|
||||
break
|
||||
case 2:
|
||||
setModuleSelectionDataStore({
|
||||
common: {},
|
||||
roofConstructions: [],
|
||||
})
|
||||
break
|
||||
}
|
||||
}
|
||||
}, [popupStatus])
|
||||
|
||||
const { trigger, isMutating } = useSWRMutation('canvas-popup-status-update', postFetcher)
|
||||
const { trigger, isMutating } = useSWRMutation(
|
||||
`/api/v1/canvas-popup-status?objectNo=${currentCanvasPlan.objectNo}&planNo=${currentCanvasPlan.planNo}&popupType=${popupType}`,
|
||||
(url, { arg }) => {
|
||||
const params = {
|
||||
objectNo: currentCanvasPlan.objectNo,
|
||||
planNo: parseInt(currentCanvasPlan.planNo),
|
||||
popupType: popupType.toString(),
|
||||
popupStatus: JSON.stringify(arg).replace(/"/g, '\"'),
|
||||
}
|
||||
postFetcher(`/api/v1/canvas-popup-status`, params)
|
||||
},
|
||||
)
|
||||
|
||||
return { trigger }
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user