Skip to content

Commit 3cfbb50

Browse files
authored
Merge pull request #90 from TaskFlow-CLAP/CLAP-242
CLAP-242 카테고리 수정 API 연결
2 parents 1a7cda9 + 851ba8e commit 3cfbb50

File tree

11 files changed

+80
-35
lines changed

11 files changed

+80
-35
lines changed

src/api/admin.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
import type { LabelDataTypes, NewLabelTypes } from '@/types/admin'
22
import { axiosInstance } from '@/utils/axios'
33

4-
export const getLabelsAdmin = async () => {
5-
const response = await axiosInstance.get('/api/managements/labels')
6-
return response.data
7-
}
8-
94
export const deleteLabelAdmin = async (id: number) => {
105
const response = await axiosInstance.delete(`/api/management/labels/${id}`)
116
return response.data

src/api/common.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,8 @@ export const getAllCategory = async () => {
1414
const response = await axiosInstance.get('/api/category')
1515
return response.data
1616
}
17+
18+
export const getLabels = async () => {
19+
const response = await axiosInstance.get('/api/labels')
20+
return response.data
21+
}

src/components/request-task/RequestTaskDropdown.vue

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@
1010
</div>
1111
<div class="relative flex text-base">
1212
<div
13-
class="flex w-full h-11 items-center rounded p-4 bg-white border border-border-1 cursor-pointer text-black"
14-
@click="toggleDropdown">
13+
class="flex w-full h-11 items-center rounded p-4 border border-border-1"
14+
:class="disabled ? 'bg-background-1 text-disabled' : 'bg-white text-black cursor-pointer'"
15+
@click="!disabled && toggleDropdown()">
1516
<p :class="{ 'text-disabled': modelValue === placeholderText }">
1617
{{ modelValue || placeholderText }}
1718
</p>
@@ -40,7 +41,7 @@ import type { RequestTaskDropdownProps } from '@/types/user'
4041
import { ref } from 'vue'
4142
import CommonIcons from '../common/CommonIcons.vue'
4243
43-
const { placeholderText, options, labelName, modelValue, isLabel } =
44+
const { placeholderText, options, labelName, modelValue, isLabel, disabled } =
4445
defineProps<RequestTaskDropdownProps>()
4546
const emit = defineEmits(['update:modelValue'])
4647
const dropdownOpen = ref(false)

src/components/task-management/CategoryAdd.vue

Lines changed: 47 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
:is-open="isModalVisible.add"
55
type="successType"
66
@close="handleAddModal">
7-
<template #header>카테고리가 등록되었습니다</template>
7+
<template #header>카테고리가 {{ route.params.id ? '수정' : '등록' }}되었습니다</template>
88
</ModalView>
99
<ModalView
1010
:is-open="isModalVisible.cancel"
1111
type="warningType"
1212
@close="handleCancelModal"
1313
@click="handleGoBack">
14-
<template #header>생성을 취소 하시겠습니까?</template>
14+
<template #header>{{ route.params.id ? '수정' : '생성' }}을 취소 하시겠습니까?</template>
1515
<template #body>작성하신 내용은 사라집니다</template>
1616
</ModalView>
1717
<ModalView
@@ -26,7 +26,8 @@
2626
:options="categoryOptions.map(el => el.name)"
2727
label-name="1차 카테고리"
2828
placeholder-text="1차 카테고리를 선택해주세요"
29-
v-if="categoryStep == '2'" />
29+
v-if="categoryStep == '2'"
30+
:disabled="route.params.id !== undefined" />
3031
<RequestTaskInput
3132
v-model="categoryForm.name"
3233
placeholder-text="카테고리명을 입력해주세요"
@@ -41,23 +42,24 @@
4142
:handle-cancel="handleCancel"
4243
:handle-submit="handleSubmit"
4344
cancel-text="취소"
44-
submit-text="생성" />
45+
:submit-text="route.params.id ? '수정' : '등록'" />
4546
</div>
4647
</template>
4748

4849
<script lang="ts" setup>
4950
import { CATEGORY_FORM } from '@/constants/admin'
5051
import { computed, onMounted, ref, watch } from 'vue'
51-
import { useRouter } from 'vue-router'
52+
import { useRoute, useRouter } from 'vue-router'
5253
import FormButtonContainer from '../common/FormButtonContainer.vue'
5354
import ModalView from '../ModalView.vue'
5455
import RequestTaskDropdown from '../request-task/RequestTaskDropdown.vue'
5556
import RequestTaskInput from '../request-task/RequestTaskInput.vue'
5657
import { axiosInstance } from '@/utils/axios'
57-
import { getMainCategory } from '@/api/common'
58-
import type { Category, CategoryForm } from '@/types/common'
58+
import { getMainCategory, getSubCategory } from '@/api/common'
59+
import type { Category, CategoryForm, SubCategory } from '@/types/common'
5960
6061
const router = useRouter()
62+
const route = useRoute()
6163
6264
const { categoryStep } = defineProps<{
6365
categoryStep: string
@@ -98,11 +100,18 @@ const handleSubmit = async () => {
98100
}
99101
100102
try {
101-
const requestUrl =
102-
categoryStep === '1' ? '/api/managements/main-category' : '/api/managements/sub-category'
103-
await axiosInstance.post(requestUrl, categoryForm.value, {
104-
headers: { Authorization: `Bearer ${import.meta.env.VITE_ACCESS_TOKEN}` }
105-
})
103+
const categoryId = route.params.id
104+
if (categoryId) {
105+
const patchUrl = `/api/managements/categories/${categoryId}`
106+
await axiosInstance.patch(patchUrl, {
107+
name: categoryForm.value.name,
108+
code: categoryForm.value.code
109+
})
110+
} else {
111+
const postUrl =
112+
categoryStep === '1' ? '/api/managements/main-category' : '/api/managements/sub-category'
113+
await axiosInstance.post(postUrl, categoryForm.value)
114+
}
106115
isModalVisible.value.add = true
107116
} catch {
108117
handleFailModal()
@@ -120,9 +129,32 @@ const isCodeInvalidate = computed(() => {
120129
const mainCategory = ref('')
121130
const categoryOptions = ref<Category[]>([])
122131
onMounted(async () => {
123-
categoryOptions.value = await getMainCategory()
124-
if (categoryStep === '2')
125-
categoryForm.value = { ...categoryForm.value, mainCategoryId: undefined }
132+
const id = Number(route.params.id)
133+
categoryForm.value = { ...CATEGORY_FORM }
134+
if (categoryStep === '1') {
135+
if (id) {
136+
const mainCategories: Category[] = await getMainCategory()
137+
const initailValue = mainCategories.find(el => el.id === id)
138+
if (initailValue) {
139+
categoryForm.value = { name: initailValue.name, code: initailValue.code }
140+
}
141+
}
142+
} else if (categoryStep === '2') {
143+
categoryOptions.value = await getMainCategory()
144+
if (id) {
145+
const subCategory: SubCategory[] = await getSubCategory()
146+
const initailValue = subCategory.find(el => el.id === id)
147+
if (initailValue) {
148+
categoryForm.value = {
149+
name: initailValue.name,
150+
code: initailValue.code,
151+
mainCategoryId: initailValue.mainCategoryId
152+
}
153+
mainCategory.value =
154+
categoryOptions.value.find(el => el.id === initailValue.mainCategoryId)?.name || ''
155+
}
156+
}
157+
}
126158
})
127159
watch(mainCategory, () => {
128160
categoryForm.value.mainCategoryId = categoryOptions.value.find(

src/components/task-management/CategoryLine.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
</div>
1818
<div class="flex gap-2 text-xs font-bold">
1919
<button
20-
@click="router.push('수정경로')"
20+
@click="router.push(`/category-first/${main.id}`)"
2121
class="text-primary1">
2222
수정
2323
</button>

src/components/task-management/CategoryLineSub.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
</div>
1616
<div class="flex gap-2 text-xs font-bold">
1717
<button
18-
@click="router.push('수정경로')"
18+
@click="router.push(`/category-second/${sub.id}`)"
1919
class="text-primary1">
2020
수정
2121
</button>

src/components/task-management/LabelManagement.vue

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
</template>
5959

6060
<script setup lang="ts">
61-
import { getLabelsAdmin, postAddLabelAdmin } from '@/api/admin'
61+
import { postAddLabelAdmin } from '@/api/admin'
6262
import { plusIcon } from '@/constants/iconPath'
6363
import type { LabelDataTypes, NewLabelTypes } from '@/types/admin'
6464
import type { LabelColorTypes } from '@/types/common'
@@ -67,6 +67,7 @@ import { onMounted, ref } from 'vue'
6767
import CommonIcons from '../common/CommonIcons.vue'
6868
import ColorSelectModal from './ColorSelectModal.vue'
6969
import LabelManagementLine from './LabelManagementLine.vue'
70+
import { getLabels } from '@/api/common'
7071
7172
const labelData = ref<LabelDataTypes[]>([])
7273
const newLabel = ref<NewLabelTypes>({
@@ -77,7 +78,7 @@ const isColorVisible = ref(false)
7778
const isAdd = ref(false)
7879
7980
const fetchLabels = async () => {
80-
labelData.value = await getLabelsAdmin()
81+
labelData.value = await getLabels()
8182
}
8283
8384
onMounted(async () => {

src/router/index.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,26 @@ const router = createRouter({
5959
{
6060
path: '/category-first',
6161
name: 'CategoryFirst',
62-
component: () => import('../views/CategoryFirstAdd.vue')
62+
component: () => import('../views/CategoryFirstAdd.vue'),
63+
children: [
64+
{
65+
path: ':id',
66+
name: 'EditSubCategory',
67+
component: () => import('../views/CategoryFirstAdd.vue')
68+
}
69+
]
6370
},
6471
{
6572
path: '/category-second',
6673
name: 'CategorySecond',
67-
component: () => import('../views/CategorySecondAdd.vue')
74+
component: () => import('../views/CategorySecondAdd.vue'),
75+
children: [
76+
{
77+
path: ':id',
78+
name: 'EditMainCategory',
79+
component: () => import('../views/CategorySecondAdd.vue')
80+
}
81+
]
6882
},
6983
{
7084
path: '/login-logs',

src/types/user.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export interface RequestTaskDropdownProps {
1919
labelName: string
2020
modelValue: string
2121
isLabel?: boolean
22+
disabled?: boolean
2223
}
2324

2425
export interface RequestTaskInputProps {

src/views/CategoryFirstAdd.vue

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<template>
22
<div class="form-view-container">
3-
<TitleBar title="1차 카테고리 생성" />
3+
<TitleBar :title="`1차 카테고리 ${$route.params.id ? '수정' : '등록'}`" />
44
<CategoryAdd categoryStep="1" />
55
</div>
66
</template>
@@ -9,5 +9,3 @@
99
import TitleBar from '@/components/TitleBar.vue'
1010
import CategoryAdd from '../components/task-management/CategoryAdd.vue'
1111
</script>
12-
13-
<style scoped></style>

0 commit comments

Comments
 (0)