|
13 | 13 | import InputText from 'primevue/inputtext'; |
14 | 14 | import { GoalTopic, StudyRole, StudyStatus } from '@gs'; |
15 | 15 | import MoreTable from '@/components/shared/MoreTable.vue'; |
| 16 | + import { useToastService } from '@/composable/toastService'; |
16 | 17 | import { |
17 | 18 | MoreTableAction, |
18 | 19 | MoreTableColumn, |
|
26 | 27 | interface Props { |
27 | 28 | studyId: number; |
28 | 29 | studyStatus: StudyStatus; |
| 30 | + actionsDisabled?: boolean; |
29 | 31 | } |
30 | 32 |
|
31 | | - const props = defineProps<Props>(); |
| 33 | + const props = withDefaults(defineProps<Props>(), { |
| 34 | + actionsDisabled: false, |
| 35 | + }); |
| 36 | + const { showErrorToast } = useToastService(); |
32 | 37 |
|
33 | | - const { data: goalConfig } = useGoalConfig(props.studyId) as { data: { value: StudyGoalConfigData | undefined } }; |
| 38 | + const { data: goalConfig } = useGoalConfig(props.studyId) as { |
| 39 | + data: { value: StudyGoalConfigData | undefined }; |
| 40 | + }; |
34 | 41 | const { mutateAsync: createGoalTopicMutation } = useCreateGoalTopic(); |
35 | 42 | const { mutateAsync: updateGoalTopicMutation } = useUpdateGoalTopic(); |
36 | 43 | const { mutateAsync: deleteGoalTopicMutation } = useDeleteGoalTopic(); |
|
56 | 63 | description: newTopicDescription.value, |
57 | 64 | } as any; |
58 | 65 |
|
59 | | - await createGoalTopicMutation({ studyId: props.studyId, topic: topic as GoalTopic }) |
60 | | - .then(() => { |
61 | | - isOpen.value = false; |
62 | | - overlayPanel.value?.hide(); |
63 | | - }); |
| 66 | + await createGoalTopicMutation({ |
| 67 | + studyId: props.studyId, |
| 68 | + topic: topic as GoalTopic, |
| 69 | + }).then(() => { |
| 70 | + isOpen.value = false; |
| 71 | + overlayPanel.value?.hide(); |
| 72 | + }); |
64 | 73 | newTopicName.value = ''; |
65 | 74 | newTopicDescription.value = ''; |
66 | 75 | }; |
67 | 76 |
|
68 | 77 | async function deleteTopic(topic: GoalTopic): Promise<void> { |
69 | 78 | if (!topic.key) return; |
70 | | - await deleteGoalTopicMutation({ studyId: props.studyId, key: topic.key }); |
| 79 | + try { |
| 80 | + await deleteGoalTopicMutation({ studyId: props.studyId, key: topic.key }); |
| 81 | + } catch (error: any) { |
| 82 | + if (error.response?.status === 409) { |
| 83 | + error.errorMessage = t( |
| 84 | + 'goaltemplate.goalTemplateList.error.conflictUsedCategory', |
| 85 | + ); |
| 86 | + } else { |
| 87 | + error.errorMessage = t('global.error.generic'); |
| 88 | + } |
| 89 | + throw error; |
| 90 | + } |
71 | 91 | } |
72 | 92 |
|
73 | 93 | const goalCategoryColumns: MoreTableColumn[] = [ |
|
108 | 128 |
|
109 | 129 | function changeValueInPlace(topic: GoalTopic): void { |
110 | 130 | if (topic && !!topic?.key) { |
111 | | - updateGoalTopicMutation({ studyId: props.studyId, key: topic.key, topic: topic }); |
| 131 | + updateGoalTopicMutation({ |
| 132 | + studyId: props.studyId, |
| 133 | + key: topic.key, |
| 134 | + topic: topic, |
| 135 | + }).catch((error) => { |
| 136 | + if (error.response?.status === 409) { |
| 137 | + showErrorToast( |
| 138 | + t('goaltemplate.goalTemplateList.error.conflictUsedElement'), |
| 139 | + ); |
| 140 | + } |
| 141 | + }); |
112 | 142 | } |
113 | 143 | } |
114 | 144 |
|
|
138 | 168 | elTitle: row.title, |
139 | 169 | elInfoTitle: t('global.labels.description'), |
140 | 170 | elInfoDesc: row.description, |
| 171 | + onDelete: deleteTopic, |
141 | 172 | }, |
142 | 173 | props: { |
143 | 174 | header: t('goaltemplate.dialog.header.delete'), |
|
152 | 183 | draggable: false, |
153 | 184 | }, |
154 | 185 | onClose: (options) => { |
155 | | - if (options?.data) { |
156 | | - executeAction({ |
157 | | - id: 'delete', |
158 | | - row: options.data, |
159 | | - } as MoreTableRowActionResult); |
| 186 | + if (options?.data && !options?.data?.key) { |
| 187 | + console.info('category section was closed successfully') |
160 | 188 | } |
161 | 189 | }, |
162 | 190 | }), |
|
174 | 202 | <Button |
175 | 203 | type="button" |
176 | 204 | class="flex shrink-0 items-center justify-between text-nowrap" |
| 205 | + :disabled="actionsDisabled" |
177 | 206 | @click="toggleOverlay($event)" |
178 | 207 | > |
179 | 208 | <span>{{ t('goaltemplate.goalTemplateList.categories.add') }}</span> |
|
0 commit comments