Advertisement
SherinKR

TicketAgentFields.vue

Sep 25th, 2024 (edited)
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 5.09 KB | Source Code | 0 0
  1. <template>
  2.     <div class="flex flex-1 flex-col overflow-hidden overflow-y-auto border-b">
  3.         <div v-for="o in options" :key="o.field" class="flex items-center gap-2 px-6 pb-1 leading-5 first:mt-3">
  4.             <Tooltip :text="o.label">
  5.                 <div class="w-[106px] shrink-0 truncate text-sm text-gray-600">
  6.                     {{ o.label }}
  7.                 </div>
  8.             </Tooltip>
  9.             <div class="-m-0.5 min-h-[28px] flex-1 items-center overflow-hidden p-0.5 text-base">
  10.                 <FormControl v-if="o.type === 'textarea'" class="form-control" :type="o.type" :value="ticket[o.field]"
  11.                     variant="subtle" rows="2" @change="update(o.field, $event.target.value, $event)" />
  12.                 <FormControl v-else-if="o.type === 'select'" class="form-control" :type="o.type" :value="ticket[o.field]"
  13.                     :options="customers?.data" @change="update(o.field, $event.target.value)" />
  14.                 <Autocomplete v-else class="form-control" :options="o.store.dropdown" :placeholder="`Add ${o.label}`"
  15.                     :value="ticket[o.field]" @change="update(o.field, $event.value)" />
  16.             </div>
  17.         </div>
  18.         <UniInput2 v-for="field in ticket.template.fields" :key="field.fieldname" :field="field"
  19.             :value="ticket[field.fieldname]" @change="(data) => update(data.fieldname, data.value)" />
  20.     </div>
  21.     <div class="flex flex-1 flex-col overflow-hidden overflow-y-auto border-b">
  22.         <div class="flex items-center gap-2 px-6 pb-1 leading-5 first:mt-3">
  23.             <div class="-m-0.5 min-h-[28px] flex-1 items-center overflow-hidden p-0.5 text-base">
  24.                 <label for="pw_category"> PW Category </label>
  25.                 <Autocomplete id="pw_category" class="form-control" :options="usePwCategoryStore().dropdown"
  26.                     :value="ticket['pw_category']" @change="update('pw_category', $event.value)" />
  27.                 <label for="pw_sub_category"> PW Category </label>
  28.                 <Autocomplete id="pw_sub_category" class="form-control" :options="usePwSubCategoryStore().dropdown"
  29.                     :value="ticket['pw_sub_category']" @change="update('pw_sub_category', $event.value)" />
  30.  
  31.             </div>
  32.         </div>
  33.     </div>
  34. </template>
  35.  
  36. <script setup lang="ts">
  37. import { computed } from "vue";
  38. import { createResource, FormControl, Tooltip } from "frappe-ui";
  39. import { Autocomplete } from "@/components";
  40. import { useTeamStore } from "@/stores/team";
  41. import { useTicketPriorityStore } from "@/stores/ticketPriority";
  42. import { useTicketTypeStore } from "@/stores/ticketType";
  43. import { usePwCategoryStore, usePwSubCategoryStore } from "@/stores/pwCategory";
  44. import UniInput2 from "@/components/UniInput2.vue";
  45. import { createToast } from "@/utils";
  46. import { Field, FieldValue } from "@/types";
  47.  
  48. const emit = defineEmits(["update"]);
  49.  
  50. const field1 = "test 1"
  51.  
  52. const props = defineProps({
  53.     ticket: {
  54.         type: Object,
  55.         required: true,
  56.     },
  57. });
  58.  
  59. const customers = createResource({
  60.     url: "helpdesk.utils.get_customer",
  61.     params: {
  62.         contact: props.ticket.raised_by,
  63.     },
  64.     auto: true,
  65.     transform: (data: Array<object>) => {
  66.         return data.map((d: object) => ({
  67.             label: d,
  68.             value: d,
  69.         }));
  70.     },
  71. });
  72.  
  73. const options = computed(() => {
  74.     return [
  75.         {
  76.             field: "ticket_type",
  77.             label: "Ticket type",
  78.             store: useTicketTypeStore(),
  79.         },
  80.         {
  81.             field: "priority",
  82.             label: "Priority",
  83.             store: useTicketPriorityStore(),
  84.         },
  85.         {
  86.             field: "agent_group",
  87.             label: "Team",
  88.             store: useTeamStore(),
  89.         },
  90.         {
  91.             field: "customer",
  92.             label: "Customer",
  93.             type: "select",
  94.             placeholder: "Select Customer",
  95.         },
  96.         {
  97.             field: "subject",
  98.             label: "Subject",
  99.             type: "textarea",
  100.             placeholder: "Problem in XYZ",
  101.         },
  102.     ];
  103. });
  104.  
  105. function update(field: Field["fieldname"], value: FieldValue, event = null) {
  106.     if (field === "subject" && value === "") {
  107.         createToast({
  108.             title: "Subject is required",
  109.             icon: "x",
  110.             iconClasses: "text-red-600",
  111.         });
  112.         event.target.value = props.ticket.subject;
  113.         return;
  114.     }
  115.     if (field === 'pw_category') {
  116.         localStorage.setItem("pw_category", value.toString());
  117.     }
  118.     emit("update", { field, value });
  119. }
  120. </script>
  121. <style scoped>
  122. :deep(.form-control input:not([type="checkbox"])),
  123. :deep(.form-control select),
  124. :deep(.form-control textarea),
  125. :deep(.form-control button) {
  126.     border-color: transparent;
  127.     background: white;
  128. }
  129.  
  130. :deep(.form-control button) {
  131.     gap: 0;
  132. }
  133.  
  134. :deep(.form-control [type="checkbox"]) {
  135.     margin-left: 9px;
  136.     cursor: pointer;
  137. }
  138.  
  139. :deep(.form-control button > div) {
  140.     overflow: hidden;
  141.     text-overflow: ellipsis;
  142.     white-space: nowrap;
  143. }
  144.  
  145. :deep(.form-control button svg) {
  146.     color: white;
  147.     width: 0;
  148. }
  149. </style>
  150.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement