main
vue 72 lines 1.67 KB
Raw
1 <template>
2 <n-spin class="soc-notes-form" :show="loading">
3 <div class="flex flex-col gap-2">
4 <n-input v-model:value="title" placeholder="Title..." clearable />
5 <n-input
6 v-model:value="content"
7 type="textarea"
8 clearable
9 placeholder="Content..."
10 :autosize="{
11 minRows: 3,
12 maxRows: 10
13 }"
14 />
15 <div class="flex justify-end gap-2">
16 <n-button :disabled="loading" secondary class="w-32!" @click="clear(true)">Close</n-button>
17 <n-button :disabled="loading || !title" secondary type="primary" class="w-32!" @click="addNote()">
18 Submit
19 </n-button>
20 </div>
21 </div>
22 </n-spin>
23 </template>
24
25 <script setup lang="ts">
26 import type { SocNewNote } from "@/types/soc/note.d"
27 import { NButton, NInput, NSpin, useMessage } from "naive-ui"
28 import { ref } from "vue"
29 import Api from "@/api"
30
31 const { caseId } = defineProps<{ caseId: string | number }>()
32
33 const emit = defineEmits<{
34 (e: "close"): void
35 (e: "added", value: SocNewNote): void
36 }>()
37
38 const loading = ref(false)
39 const message = useMessage()
40 const title = ref("")
41 const content = ref("")
42
43 function clear(close?: boolean) {
44 title.value = ""
45 content.value = ""
46
47 if (close) {
48 emit("close")
49 }
50 }
51
52 function addNote() {
53 loading.value = true
54
55 Api.soc
56 .createCaseNote(caseId.toString(), { title: title.value, content: content.value })
57 .then(res => {
58 if (res.data.success) {
59 emit("added", res.data.note)
60 clear()
61 } else {
62 message.warning(res.data?.message || "An error occurred. Please try again later.")
63 }
64 })
65 .catch(err => {
66 message.error(err.response?.data?.message || "An error occurred. Please try again later.")
67 })
68 .finally(() => {
69 loading.value = false
70 })
71 }
72 </script>