Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 37 additions & 16 deletions src/components/request-task/RequestTask.vue
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
<template>
<div class="w-full flex flex-col gap-y-6">
<RequestTaskDropdown
<CategoryDropDown
v-model="category1"
:options="DUMMY_REQUEST_TASK_CATEGORIES"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

더미 데이터는 삭제하고 있으신 걸까요?
사용되지 않을 더미 데이터는 확인 후 삭제 부탁드립니다!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아직 1,2차 카테고리를 사용하는 페이지들에 전부 반영하지 않아서 (요청 승인) 해당 파트를 진행하며 마지막으로 지우려합니다!

:options="mainCategoryArr"
:label-name="'1차 카테고리'"
:placeholderText="'1차 카테고리를 선택해주세요'" />
<RequestTaskDropdown
:placeholderText="'1차 카테고리를 선택해주세요'"
:isDisabled="false" />
<CategoryDropDown
v-model="category2"
:options="DUMMY_REQUEST_TASK_CATEGORIES"
:options="afterSubCategoryArr"
:label-name="'2차 카테고리'"
:placeholderText="'2차 카테고리를 선택해주세요'" />
:placeholderText="'2차 카테고리를 선택해주세요'"
:isDisabled="!category1" />
<RequestTaskInput
v-model="title"
:placeholderText="TITLE_PLACEHOLDER"
Expand All @@ -27,27 +29,46 @@
</template>

<script lang="ts" setup>
import { getMainCategory, getSubCategory } from '@/api/common'
import { postTaskRequest } from '@/api/user'
import { EXPLANATION_PLACEHOLDER, TITLE_PLACEHOLDER } from '@/constants/user'
import { DUMMY_REQUEST_TASK_CATEGORIES } from '@/datas/taskdetail'
import { ref } from 'vue'
import type { MainCategoryTypes, SubCategoryTypes } from '@/types/common'
import { onMounted, ref, watch } from 'vue'
import { useRouter } from 'vue-router'
import FormButtonContainer from '../common/FormButtonContainer.vue'
import RequestTaskDropdown from './RequestTaskDropdown.vue'
import CategoryDropDown from './CategoryDropDown.vue'
import RequestTaskFileInput from './RequestTaskFileInput.vue'
import RequestTaskInput from './RequestTaskInput.vue'
import RequestTaskTextArea from './RequestTaskTextArea.vue'

const category1 = ref('1차 카테고리를 선택해주세요')
const category2 = ref('2차 카테고리를 선택해주세요')
const category1 = ref<MainCategoryTypes | null>(null)
const category2 = ref<MainCategoryTypes | null>(null)

const title = ref('')
const description = ref('')
const file = ref(null as File[] | null)

const mainCategoryArr = ref<MainCategoryTypes[]>([])
const subCategoryArr = ref<SubCategoryTypes[]>([])
const afterSubCategoryArr = ref<SubCategoryTypes[]>([])

onMounted(async () => {
mainCategoryArr.value = await getMainCategory()
subCategoryArr.value = await getSubCategory()
afterSubCategoryArr.value = await getSubCategory()
})

watch(category1, async newValue => {
category2.value = null
afterSubCategoryArr.value = subCategoryArr.value.filter(
subCategory => subCategory.mainCategoryId === newValue?.id
)
})

const router = useRouter()
const handleCancel = () => {
category1.value = ''
category2.value = ''
category1.value = null
category2.value = null
title.value = ''
description.value = ''
file.value = []
Expand All @@ -57,7 +78,7 @@ const handleCancel = () => {
const handleSubmit = async () => {
const formData = new FormData()
const taskInfo = {
categoryId: 1,
categoryId: category2.value?.id,
title: title.value,
description: description.value
}
Expand All @@ -66,15 +87,15 @@ const handleSubmit = async () => {
const newBlob = new Blob([jsonTaskInfo], { type: 'application/json' })

formData.append('taskInfo', newBlob)

if (file.value && file.value.length > 0) {
file.value.forEach(f => {
formData.append('attachment', f)
})
}
console.log(Object.fromEntries(formData), '응답')
console.log(file.value, '파일 현황 응답')
try {
const res = await postTaskRequest(formData)
console.error('요청 성공:', res)
} catch (error) {
console.error('요청 실패:', error)
}
Expand Down
4 changes: 2 additions & 2 deletions src/types/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ export interface LabelDataTypes {
labelColor: string
}


export interface MainCategoryTypes {
id: number
name: string
Expand All @@ -96,6 +95,7 @@ export interface CategoryDropdownProps {
placeholderText: string
options: MainCategoryTypes[] | SubCategoryTypes[]
labelName: string
modelValue: string
modelValue: MainCategoryTypes | SubCategoryTypes | null
isLabel?: boolean
isDisabled?: boolean
}