1414 <template #header >{{ route.params.id ? '수정을' : '추가를' }} 취소 하시겠습니까?</template >
1515 <template #body >작성하신 내용은 사라집니다</template >
1616 </ModalView >
17- <ModalView
18- :is-open =" isModalVisible.fail"
19- type =" failType"
20- @close =" handleFailModal" >
21- <template #header >{{ errorMessage }}</template >
22- </ModalView >
2317 <RequestTaskDropdown
2418 v-model =" mainCategory"
2519 :options =" categoryOptions.map(el => el.name)"
2620 label-name =" 1차 카테고리"
2721 placeholder-text =" 1차 카테고리를 선택해주세요"
2822 v-if =" categoryStep == '2'"
29- :disabled =" route.params.id !== undefined" />
23+ :disabled =" route.params.id !== undefined"
24+ :is-invalidate =" hasMainCategory" />
3025 <RequestTaskInput
3126 v-model =" categoryForm.name"
3227 placeholder-text =" 카테고리명을 입력해주세요"
33- :label-name =" `${categoryStep}차 카테고리명`" />
28+ :label-name =" `${categoryStep}차 카테고리명`"
29+ :is-invalidate =" errorMessage.categoryName" />
3430 <RequestTaskInput
3531 v-model =" categoryForm.code"
3632 placeholder-text =" 카테고리의 작업코드를 입력해주세요"
3733 label-name =" 작업코드 (대문자 영어 2글자까지)"
38- :is-invalidate =" isCodeInvalidate" />
34+ :is-invalidate =" errorMessage.categoryCode === 'noCode' ? 'noCode' : isCodeInvalidate" />
3935
4036 <div
4137 v-if =" categoryStep === '2'"
@@ -68,7 +64,6 @@ import { axiosInstance } from '@/utils/axios'
6864import { getMainCategory } from ' @/api/common'
6965import type { Category , CategoryForm } from ' @/types/common'
7066import ModalView from ' ../common/ModalView.vue'
71- import axios from ' axios'
7267
7368const router = useRouter ()
7469const route = useRoute ()
@@ -78,7 +73,8 @@ const { categoryStep } = defineProps<{
7873}>()
7974
8075const isModalVisible = ref ({ add: false , cancel: false , fail: false })
81- const errorMessage = ref (' ' )
76+ const errorMessage = ref ({ categoryName: ' ' , categoryCode: ' ' })
77+ const hasMainCategory = ref (true )
8278
8379const categoryForm = ref <CategoryForm >(CATEGORY_FORM )
8480
@@ -89,10 +85,6 @@ const handleAddModal = () => {
8985const handleCancelModal = () => {
9086 isModalVisible .value .cancel = ! isModalVisible .value .cancel
9187}
92- const handleFailModal = (message : string = ' 카테고리 정보를 확인해주세요' ) => {
93- errorMessage .value = message
94- isModalVisible .value .fail = ! isModalVisible .value .fail
95- }
9688
9789const handleCancel = () => {
9890 handleCancelModal ()
@@ -103,36 +95,32 @@ const handleGoBack = () => {
10395}
10496
10597const handleSubmit = async () => {
106- if (
107- isCodeInvalidate .value ||
108- categoryForm .value .name .length === 0 ||
109- categoryForm .value .code .length === 0 ||
110- (categoryStep === ' 2' && categoryForm .value .mainCategoryId === undefined )
111- ) {
112- handleFailModal ()
98+ hasMainCategory .value = true
99+ errorMessage .value = { categoryCode: ' ' , categoryName: ' ' }
100+ if (! categoryForm .value .mainCategoryId ) {
101+ hasMainCategory .value = false
102+ return
103+ } else if (isCodeInvalidate .value ) {
104+ errorMessage .value .categoryCode = ' code'
105+ return
106+ } else if (categoryForm .value .name .length === 0 ) {
107+ errorMessage .value .categoryName = ' categoryName'
108+ return
109+ } else if (categoryForm .value .code .length === 0 ) {
110+ errorMessage .value .categoryCode = ' noCode'
113111 return
114112 }
115113
116- try {
117- const categoryId = route .params .id
118- if (categoryId ) {
119- const patchUrl = ` /api/managements/categories/${categoryId } `
120- await axiosInstance .patch (patchUrl , categoryForm .value )
121- } else {
122- const postUrl =
123- categoryStep === ' 1' ? ' /api/managements/main-category' : ' /api/managements/sub-category'
124- await axiosInstance .post (postUrl , categoryForm .value )
125- }
126- isModalVisible .value .add = true
127- } catch (error ) {
128- if (axios .isAxiosError (error )) {
129- if (error .response ?.data === ' TASK_013' ) {
130- handleFailModal (' 중복된 카테고리명\n 혹은 고유코드입니다' )
131- } else {
132- handleFailModal ()
133- }
134- }
114+ const categoryId = route .params .id
115+ if (categoryId ) {
116+ const patchUrl = ` /api/managements/categories/${categoryId } `
117+ await axiosInstance .patch (patchUrl , categoryForm .value )
118+ } else {
119+ const postUrl =
120+ categoryStep === ' 1' ? ' /api/managements/main-category' : ' /api/managements/sub-category'
121+ await axiosInstance .post (postUrl , categoryForm .value )
135122 }
123+ isModalVisible .value .add = true
136124}
137125
138126const isCodeInvalidate = computed (() => {
@@ -163,7 +151,8 @@ onMounted(async () => {
163151 const mainCategoryId = ref (Number (route .query .mainCategoryId ))
164152 categoryForm .value .mainCategoryId = mainCategoryId .value
165153 mainCategory .value =
166- categoryOptions .value .find (el => el .mainCategoryId === mainCategoryId .value )?.name || ' '
154+ categoryOptions .value .find (el => el .mainCategoryId === mainCategoryId .value )?.name ||
155+ ' 1차 카테고리를 선택해주세요'
167156 }
168157 if (id ) {
169158 const { data : initialValue } = await axiosInstance .get (` /api/sub-categories/${id } ` )
0 commit comments