1414 class =" button-medium-primary" >
1515 승인
1616 </button >
17- <button class =" button-medium-default" >거부</button >
17+ <button
18+ @click =" toggleModal('reject')"
19+ class =" button-medium-default" >
20+ 거부
21+ </button >
1822 </div >
1923 </div >
24+
25+ <ModalView
26+ :is-open =" isModalVisible.reject"
27+ @update:model-value =" value => (rejectReason = value)"
28+ type =" inputType"
29+ @close =" closeModal"
30+ @click =" rejectRequest" >
31+ <template #header >거부 사유를 입력해주세요</template >
32+ </ModalView >
33+ <ModalView
34+ :is-open =" isModalVisible.success"
35+ type =" successType"
36+ @close =" closeModal" >
37+ <template #header >거부가 완료되었습니다</template >
38+ </ModalView >
39+ <ModalView
40+ :is-open =" isModalVisible.fail"
41+ type =" failType"
42+ @close =" closeModal" >
43+ <template #header >{{ modalError }}</template >
44+ </ModalView >
2045</template >
2146
2247<script setup lang="ts">
@@ -25,6 +50,10 @@ import ListCardTab from '../lists/ListCardTab.vue'
2550import type { RequestedListData } from ' @/types/manager'
2651import { useRouter } from ' vue-router'
2752import { formatDate } from ' @/utils/date'
53+ import ModalView from ' ../ModalView.vue'
54+ import { ref } from ' vue'
55+ import { axiosInstance } from ' @/utils/axios'
56+ import { useQueryClient } from ' @tanstack/vue-query'
2857
2958const { info } = defineProps <{ info: RequestedListData }>()
3059const requestedTabList: ListCardProps [] = [
@@ -36,4 +65,37 @@ const requestedTabList: ListCardProps[] = [
3665]
3766
3867const router = useRouter ()
68+ const queryClient = useQueryClient ()
69+
70+ const isModalVisible = ref ({
71+ reject: false ,
72+ fail: false ,
73+ success: false
74+ })
75+ const modalError = ref (' ' )
76+ const rejectReason = ref (' ' )
77+ const toggleModal = (key : keyof typeof isModalVisible .value ) => {
78+ isModalVisible .value = Object .fromEntries (
79+ Object .keys (isModalVisible .value ).map (k => [k , k === key ])
80+ ) as typeof isModalVisible .value
81+ }
82+ const closeModal = () => {
83+ const prevSuccess = isModalVisible .value .success
84+ isModalVisible .value = { reject: false , fail: false , success: false }
85+ if (prevSuccess ) queryClient .invalidateQueries ({ queryKey: [' requested' ] })
86+ }
87+ const rejectRequest = async () => {
88+ if (rejectReason .value .length === 0 ) {
89+ toggleModal (' fail' )
90+ modalError .value = ' 거부 사유를 입력해주세요'
91+ return
92+ }
93+ try {
94+ await axiosInstance .patch (` /api/tasks/${info .taskId }/terminate ` , rejectReason )
95+ toggleModal (' success' )
96+ } catch {
97+ toggleModal (' fail' )
98+ modalError .value = ' 작업 거부에 실패했습니다'
99+ }
100+ }
39101 </script >
0 commit comments