Просмотр исходного кода

feat(support): adiciona destino como select

ebagabee 4 недель назад
Родитель
Сommit
129af80642

+ 21 - 0
src/api/support_ticket.js

@@ -0,0 +1,21 @@
+import api from "src/api";
+
+export const getSupportTickets = async () => {
+  const { data } = await api.get("/support-ticket");
+  return data.payload;
+};
+
+export const createSupportTicket = async (payload) => {
+  const { data } = await api.post("/support-ticket", payload);
+  return data.payload;
+};
+
+export const updateSupportTicket = async (id, payload) => {
+  const { data } = await api.put(`/support-ticket/${id}`, payload);
+  return data.payload;
+};
+
+export const deleteSupportTicket = async (id) => {
+  const { data } = await api.delete(`/support-ticket/${id}`);
+  return data;
+};

+ 16 - 27
src/pages/support/SupportPage.vue

@@ -4,11 +4,11 @@
     <DefaultTable
       ref="tableRef"
       :columns="columns"
-      :rows="rows"
+      :api-call="getSupportTickets"
+      :delete-function="deleteSupportTicket"
       add-item
       title="Tickets"
       :female="false"
-      no-api-call
       description="tickets"
       @on-add-item="openAddEditTicketDialog()"
     >
@@ -19,24 +19,18 @@
           style="width: 36px"
           @click.prevent.stop="handleEdit(row)"
         />
-        <q-btn
-          outline
-          icon="mdi-trash-can-outline"
-          style="width: 36px"
-          color="negative"
-          @click.prevent.stop="handleDelete(row)"
-        />
       </template>
     </DefaultTable>
   </div>
 </template>
 
 <script setup>
-import { ref, defineAsyncComponent, useTemplateRef } from "vue";
+import { defineAsyncComponent, useTemplateRef } from "vue";
 import { useQuasar } from "quasar";
 
 import DefaultTable from "src/components/defaults/DefaultTable.vue";
 import DefaultHeaderPage from "src/components/layout/DefaultHeaderPage.vue";
+import { getSupportTickets, deleteSupportTicket } from "src/api/support_ticket";
 
 const AddEditTicketDialog = defineAsyncComponent(
   () => import("src/pages/support/components/AddEditTicketDialog.vue"),
@@ -44,7 +38,6 @@ const AddEditTicketDialog = defineAsyncComponent(
 
 const $q = useQuasar();
 const tableRef = useTemplateRef("tableRef");
-const rows = ref([]);
 
 const openAddEditTicketDialog = (ticket = null) => {
   $q.dialog({
@@ -57,44 +50,44 @@ const openAddEditTicketDialog = (ticket = null) => {
 
 const columns = [
   {
-    name: "ticket",
+    name: "id",
     label: "Ticket",
-    field: "ticket",
+    field: "id",
     align: "left",
     sortable: true,
     required: true,
   },
   {
-    name: "prioridade",
+    name: "severity",
     label: "Prioridade",
-    field: "prioridade",
+    field: "severity",
     align: "left",
     sortable: true,
   },
   {
-    name: "data",
+    name: "created_at",
     label: "Data",
-    field: "data",
+    field: "created_at",
     align: "left",
     sortable: true,
   },
   {
-    name: "setor",
+    name: "sector",
     label: "Setor",
-    field: "setor",
+    field: "sector",
     align: "left",
     sortable: true,
   },
   {
-    name: "descricao",
+    name: "title",
     label: "Descrição",
-    field: "descricao",
+    field: "title",
     align: "left",
   },
   {
-    name: "status",
+    name: "support_status_id",
     label: "Status",
-    field: "status",
+    field: "support_status_id",
     align: "left",
     sortable: true,
   },
@@ -110,8 +103,4 @@ const columns = [
 const handleEdit = (row) => {
   openAddEditTicketDialog(row);
 };
-
-const handleDelete = () => {
-  // TODO: implement delete
-};
 </script>

+ 28 - 22
src/pages/support/components/AddEditTicketDialog.vue

@@ -25,16 +25,12 @@
                   class="col-12"
                 />
 
-                <DefaultInputDatePicker
-                  v-model:untreated-date="form.date"
-                  label="Data do Registro"
-                  class="col-6"
-                />
-
                 <DefaultSelect
-                  v-model="form.priority"
+                  v-model="form.severity"
                   label="Prioridade"
                   :options="priorityOptions"
+                  emit-value
+                  map-options
                   class="col-6"
                 />
 
@@ -46,7 +42,7 @@
                 />
 
                 <DefaultSelect
-                  v-model="form.unit_target"
+                  v-model="form.scope"
                   label="Destino"
                   :options="unitTargetOptions"
                   emit-value
@@ -61,8 +57,8 @@
                 />
 
                 <UnitSelect
-                  v-if="form.unit_target === 'specific'"
-                  v-model="form.unit"
+                  v-if="form.scope === 'specific'"
+                  v-model="selectedUnit"
                   class="col-6"
                 />
 
@@ -128,11 +124,11 @@ import { useDialogPluginComponent } from "quasar";
 import CustomTabComponent from "src/components/shared/CustomTabComponent.vue";
 import DefaultDialogHeader from "src/components/defaults/DefaultDialogHeader.vue";
 import DefaultInput from "src/components/defaults/DefaultInput.vue";
-import DefaultInputDatePicker from "src/components/defaults/DefaultInputDatePicker.vue";
 import DefaultSelect from "src/components/defaults/DefaultSelect.vue";
 import UnitSelect from "src/components/selects/UnitSelect.vue";
 import TicketCommentCard from "./TicketCommentCard.vue";
 import { userStore } from "src/stores/user";
+import { createSupportTicket, updateSupportTicket } from "src/api/support_ticket";
 
 defineEmits([...useDialogPluginComponent.emits]);
 
@@ -151,6 +147,7 @@ const { user } = userStore();
 const formRef = ref(null);
 const loading = ref(false);
 const currentTab = ref("ticket");
+const selectedUnit = ref(ticket?.unit_id ? { value: ticket.unit_id } : null);
 
 const tabs = computed(() => {
   const base = [{ name: "ticket", label: "Ticket" }];
@@ -197,19 +194,23 @@ const unitTargetOptions = [
   { label: "Unidade Específica", value: "specific" },
 ];
 
-const today = new Date();
-const todayUntreated = `${today.getFullYear()}-${String(today.getMonth() + 1).padStart(2, "0")}-${String(today.getDate()).padStart(2, "0")}`;
-
 const form = ref({
-  title: ticket?.title ?? null,
-  date: ticket?.date ?? todayUntreated,
-  priority: ticket?.priority ?? null,
-  unit_target: ticket?.unit_target ?? null,
-  unit: ticket?.unit ?? null,
-  sector: ticket?.sector ?? null,
+  title:       ticket?.title ?? null,
+  severity:    ticket?.severity ?? null,
+  scope:       ticket?.scope ?? null,
+  sector:      ticket?.sector ?? null,
   description: ticket?.description ?? null,
 });
 
+const buildPayload = () => ({
+  title:       form.value.title,
+  severity:    form.value.severity,
+  scope:       form.value.scope,
+  sector:      form.value.sector || null,
+  description: form.value.description || null,
+  unit_id:     form.value.scope === "specific" ? (selectedUnit.value?.value ?? null) : null,
+});
+
 const onAddComment = () => {
   // TODO: implement add comment
 };
@@ -217,8 +218,13 @@ const onAddComment = () => {
 const onOKClick = async () => {
   loading.value = true;
   try {
-    // TODO: implement save
-    onDialogOK(form.value);
+    const payload = buildPayload();
+    if (ticket?.id) {
+      await updateSupportTicket(ticket.id, payload);
+    } else {
+      await createSupportTicket(payload);
+    }
+    onDialogOK(true);
   } finally {
     loading.value = false;
   }