refactor: modify canvas status api handling
- get 함수명 수정 - post/put 응답 toast 메세지 수정
This commit is contained in:
parent
48f5d8194d
commit
4d4af3c1b5
@ -15,7 +15,7 @@ export default function CanvasLayout() {
|
||||
const [initCanvasPlans, setInitCanvasPlans] = useRecoilState(initCanvasPlansState)
|
||||
const globalLocaleState = useRecoilValue(globalLocaleStore)
|
||||
|
||||
const { getObjectCanvasList } = usePlan()
|
||||
const { getCanvasByObjectNo } = usePlan()
|
||||
|
||||
const handleCurrentPlan = (newCurrentId) => {
|
||||
if (!currentCanvasPlan?.id || currentCanvasPlan.id !== newCurrentId) {
|
||||
@ -63,7 +63,7 @@ export default function CanvasLayout() {
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
getObjectCanvasList(objectNo).then((res) => {
|
||||
getCanvasByObjectNo(objectNo).then((res) => {
|
||||
console.log('canvas 목록 ', res)
|
||||
if (res.length > 0) {
|
||||
setInitCanvasPlans(res)
|
||||
|
||||
@ -40,10 +40,10 @@ export default function CanvasMenu(props) {
|
||||
const setCurrentMenu = useSetRecoilState(currentMenuState)
|
||||
const setPoints = useSetRecoilState(outerLinePointsState)
|
||||
const [canvasZoom, setCanvasZoom] = useRecoilState(canvasZoomState)
|
||||
const [sessionState, setSessionState] = useRecoilState(sessionStore)
|
||||
|
||||
const globalLocale = useRecoilValue(globalLocaleStore)
|
||||
const canvas = useRecoilValue(canvasState)
|
||||
const sessionState = useRecoilValue(sessionStore)
|
||||
|
||||
const { getMessage } = useMessage()
|
||||
const { saveCanvas } = usePlan()
|
||||
|
||||
@ -99,20 +99,20 @@ export function usePlan() {
|
||||
|
||||
await promisePut({ url: '/api/canvas-management/canvas-statuses', data: planData })
|
||||
.then((res) => {
|
||||
toastUp({ message: getMessage('res.message'), type: 'success' }) // 성공 시 메세지 없음
|
||||
toastUp({ message: getMessage('common.message.save'), type: 'success' }) // 성공 시 메세지 없음
|
||||
console.log('[PUT] canvas-statuses res :::::::: %o', res)
|
||||
setInitCanvasPlans((initCanvasPlans) =>
|
||||
initCanvasPlans.map((plan) => (plan.id === currentCanvasPlan.id ? { ...plan, canvasStatus: canvasStatus } : plan)),
|
||||
)
|
||||
})
|
||||
.catch((error) => {
|
||||
toastUp({ message: getMessage(error.message), type: 'error' })
|
||||
toastUp({ message: error.message, type: 'error' })
|
||||
console.error('[PUT] canvas-statuses error :::::::: %o', error)
|
||||
})
|
||||
} else {
|
||||
// canvas 신규 등록
|
||||
const planData = {
|
||||
userId: 'NEW016610', // userId,
|
||||
userId: userId,
|
||||
imageName: 'image_name', // api 필수항목이여서 임시로 넣음, 이후 삭제 필요
|
||||
objectNo: currentCanvasPlan.objectNo,
|
||||
canvasStatus: canvasToDbFormat(canvasStatus),
|
||||
@ -120,11 +120,11 @@ export function usePlan() {
|
||||
|
||||
await promisePost({ url: '/api/canvas-management/canvas-statuses', data: planData })
|
||||
.then((res) => {
|
||||
toastUp({ message: getMessage('res.message'), type: 'success' }) // 성공 시 메세지 없음
|
||||
toastUp({ message: getMessage('common.message.save'), type: 'success' }) // 성공 시 메세지 없음
|
||||
console.log('[POST] canvas-statuses response :::::::: %o', res)
|
||||
})
|
||||
.catch((error) => {
|
||||
toastUp({ message: getMessage(error.message), type: 'error' })
|
||||
toastUp({ message: error.message, type: 'error' })
|
||||
console.error('[POST] canvas-statuses res error :::::::: %o', error)
|
||||
})
|
||||
}
|
||||
@ -133,7 +133,7 @@ export function usePlan() {
|
||||
/**
|
||||
* objectNo에 해당하는 canvas 목록을 조회하는 함수
|
||||
*/
|
||||
const getObjectCanvasList = (objectNo) => {
|
||||
const getCanvasByObjectNo = async (objectNo) => {
|
||||
return get({ url: `/api/canvas-management/canvas-statuses/by-object/${objectNo}` }).then((res) =>
|
||||
res.map((item) => ({
|
||||
id: item.id,
|
||||
@ -150,6 +150,6 @@ export function usePlan() {
|
||||
removeMouseLines,
|
||||
saveCanvas,
|
||||
addCanvas,
|
||||
getObjectCanvasList,
|
||||
getCanvasByObjectNo,
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user