refactor: 플랜 추가 로직 수정
기존 add-plan, canvas-statuses 두 개 api를 사용하던 내용을 api 변경에 따라 add-plan api 한 개만 사용하도록 변경
This commit is contained in:
parent
0299977c94
commit
7b5c0b615c
@ -150,48 +150,56 @@ export function usePlan(params = {}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 물건번호(object) plan 추가 (canvas 생성 전 planNo 할당)
|
* 신규 plan 추가
|
||||||
|
*
|
||||||
|
* case 1) 초기 플랜 생성 : isInitPlan = true, isCopy = false
|
||||||
|
* case 2) 빈 플랜 생성 : isInitPlan = false, isCopy = false
|
||||||
|
* case 3) 복제 플랜 생성 : isInitPlan = false, isCopy = true
|
||||||
*/
|
*/
|
||||||
const postObjectPlan = async (userId, objectNo) => {
|
const postObjectPlanTemp = async (userId, objectNo, isCopy = false, isInitPlan = false) => {
|
||||||
return await promisePost({ url: '/api/object/add-plan', data: { userId: userId, objectNo: objectNo } })
|
const planData = isCopy
|
||||||
|
? {
|
||||||
|
userId: userId,
|
||||||
|
objectNo: objectNo,
|
||||||
|
copyFlg: '1',
|
||||||
|
planNo: currentCanvasPlan?.planNo,
|
||||||
|
}
|
||||||
|
: {
|
||||||
|
userId: userId,
|
||||||
|
objectNo: objectNo,
|
||||||
|
copyFlg: '0',
|
||||||
|
}
|
||||||
|
await promisePost({ url: '/api/object/add-plan', data: planData })
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
return res.data.planNo
|
let newPlan = {
|
||||||
})
|
id: res.data.canvasId,
|
||||||
.catch((error) => {
|
objectNo: objectNo,
|
||||||
swalFire({ text: error.response.data.message, icon: 'error' })
|
planNo: res.data.planNo,
|
||||||
return null
|
userId: userId,
|
||||||
})
|
canvasStatus: '',
|
||||||
}
|
isCurrent: true,
|
||||||
|
bgImageName: null,
|
||||||
|
mapPositionAddress: null,
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 신규 canvas 데이터를 저장
|
|
||||||
*/
|
|
||||||
const postCanvasStatus = async (userId, objectNo, canvasStatus, isInitPlan = false) => {
|
|
||||||
const planNo = await postObjectPlan(userId, objectNo)
|
|
||||||
if (!planNo) return
|
|
||||||
|
|
||||||
const planData = {
|
|
||||||
userId: userId,
|
|
||||||
objectNo: objectNo,
|
|
||||||
planNo: planNo,
|
|
||||||
bgImageName: currentCanvasPlan?.bgImageName ?? null,
|
|
||||||
mapPositionAddress: currentCanvasPlan?.mapPositionAddress ?? null,
|
|
||||||
canvasStatus: canvasToDbFormat(canvasStatus),
|
|
||||||
}
|
|
||||||
await promisePost({ url: '/api/canvas-management/canvas-statuses', data: planData })
|
|
||||||
.then((res) => {
|
|
||||||
const newPlan = { id: res.data, objectNo: objectNo, planNo: planNo, userId: userId, canvasStatus: canvasStatus, isCurrent: true }
|
|
||||||
setCurrentCanvasPlan(newPlan)
|
|
||||||
if (isInitPlan) {
|
if (isInitPlan) {
|
||||||
// 초기 플랜 생성인 경우 플랜 목록 초기화
|
// 초기 플랜 생성인 경우 플랜 목록 초기화
|
||||||
|
setCurrentCanvasPlan(newPlan)
|
||||||
setPlans([newPlan])
|
setPlans([newPlan])
|
||||||
} else {
|
} else {
|
||||||
|
if (isCopy) {
|
||||||
|
// 복제 플랜 생성인 경우 현재 캔버스 데이터를 복제
|
||||||
|
newPlan.canvasStatus = currentCanvasData()
|
||||||
|
newPlan.bgImageName = currentCanvasPlan?.bgImageName ?? null
|
||||||
|
newPlan.mapPositionAddress = currentCanvasPlan?.mapPositionAddress ?? null
|
||||||
|
}
|
||||||
|
setCurrentCanvasPlan(newPlan)
|
||||||
setPlans((plans) => [...plans.map((plan) => ({ ...plan, isCurrent: false })), newPlan])
|
setPlans((plans) => [...plans.map((plan) => ({ ...plan, isCurrent: false })), newPlan])
|
||||||
swalFire({ text: getMessage('plan.message.save') })
|
swalFire({ text: getMessage('plan.message.save') })
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
swalFire({ text: error.message, icon: 'error' })
|
swalFire({ text: error.response.data.message, icon: 'error' })
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -337,13 +345,13 @@ export function usePlan(params = {}) {
|
|||||||
text: `Plan ${currentCanvasPlan.planNo} ` + getMessage('plan.message.confirm.copy'),
|
text: `Plan ${currentCanvasPlan.planNo} ` + getMessage('plan.message.confirm.copy'),
|
||||||
type: 'confirm',
|
type: 'confirm',
|
||||||
confirmFn: async () => {
|
confirmFn: async () => {
|
||||||
await postCanvasStatus(userId, objectNo, currentCanvasData(), false)
|
await postObjectPlanTemp(userId, objectNo, true, false)
|
||||||
},
|
},
|
||||||
denyFn: async () => {
|
denyFn: async () => {
|
||||||
await postCanvasStatus(userId, objectNo, '', false)
|
await postObjectPlanTemp(userId, objectNo, false, false)
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
: await postCanvasStatus(userId, objectNo, '', false)
|
: await postObjectPlanTemp(userId, objectNo, false, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -394,12 +402,12 @@ export function usePlan(params = {}) {
|
|||||||
*/
|
*/
|
||||||
const loadCanvasPlanData = async (userId, objectNo, planNo) => {
|
const loadCanvasPlanData = async (userId, objectNo, planNo) => {
|
||||||
console.log('🚀 ~ loadCanvasPlanData ~ userId, objectNo, planNo:', userId, objectNo, planNo)
|
console.log('🚀 ~ loadCanvasPlanData ~ userId, objectNo, planNo:', userId, objectNo, planNo)
|
||||||
await getCanvasByObjectNo(userId, objectNo, planNo).then((res) => {
|
await getCanvasByObjectNo(userId, objectNo, planNo).then(async (res) => {
|
||||||
if (res.length > 0) {
|
if (res.length > 0) {
|
||||||
setCurrentCanvasPlan(res.find((plan) => plan.planNo === planNo))
|
setCurrentCanvasPlan(res.find((plan) => plan.planNo === planNo))
|
||||||
setPlans(res)
|
setPlans(res)
|
||||||
} else {
|
} else {
|
||||||
postCanvasStatus(userId, objectNo, '', true)
|
await postObjectPlanTemp(userId, objectNo, false, true)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user