Skip to content

Commit 26614d1

Browse files
committed
fix: ticket composable
1 parent 79d7528 commit 26614d1

File tree

3 files changed

+45
-82
lines changed

3 files changed

+45
-82
lines changed

desk/src/pages/ticket/TicketCustomer.vue

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -67,49 +67,46 @@
6767
<script setup lang="ts">
6868
import { computed, onMounted, onUnmounted, provide, ref } from "vue";
6969
import { createResource, Button, Breadcrumbs, confirmDialog } from "frappe-ui";
70+
import { useConfigStore } from "@/stores/config";
7071
import { Icon } from "@iconify/vue";
7172
import { useError } from "@/composables/error";
72-
import TicketConversation from "./TicketConversation.vue";
73-
import TicketCustomerTemplateFields from "./TicketCustomerTemplateFields.vue";
74-
import TicketFeedback from "./TicketFeedback.vue";
75-
import TicketTextEditor from "./TicketTextEditor.vue";
7673
import { ITicket } from "./symbols";
7774
import { useRouter } from "vue-router";
7875
import { createToast, isContentEmpty, setupCustomActions } from "@/utils";
7976
import { socket } from "@/socket";
8077
import { LayoutHeader } from "@/components";
81-
import TicketCustomerSidebar from "@/components/ticket/TicketCustomerSidebar.vue";
8278
import { useScreenSize } from "@/composables/screen";
83-
import { useConfigStore } from "@/stores/config";
79+
import TicketConversation from "./TicketConversation.vue";
80+
import TicketCustomerTemplateFields from "./TicketCustomerTemplateFields.vue";
81+
import TicketTextEditor from "./TicketTextEditor.vue";
82+
import TicketFeedback from "./TicketFeedback.vue";
83+
import TicketCustomerSidebar from "@/components/ticket/TicketCustomerSidebar.vue";
84+
import { useTicket } from "./data";
8485
interface P {
8586
ticketId: string;
8687
}
8788
const router = useRouter();
8889
8990
const props = defineProps<P>();
90-
const ticket = createResource({
91-
url: "helpdesk.helpdesk.doctype.hd_ticket.api.get_one",
92-
cache: ["Ticket", props.ticketId],
93-
auto: true,
94-
params: {
95-
name: props.ticketId,
96-
is_customer_portal: true,
91+
const ticket = useTicket(
92+
props.ticketId,
93+
true,
94+
null,
95+
(data) => {
96+
setupCustomActions(data, {
97+
doc: data,
98+
updateField,
99+
});
97100
},
98-
onError: () => {
101+
() => {
99102
createToast({
100103
title: "Ticket not found",
101104
icon: "x",
102105
iconClasses: "text-red-600",
103106
});
104107
router.replace("/my-tickets");
105-
},
106-
onSuccess: (data) => {
107-
setupCustomActions(data, {
108-
doc: data,
109-
updateField,
110-
});
111-
},
112-
});
108+
}
109+
);
113110
provide(ITicket, ticket);
114111
const editor = ref(null);
115112
const placeholder = "Type a message";

desk/src/pages/ticket/data.ts

Lines changed: 25 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,30 @@
1-
import { Ref, reactive, ref } from "vue";
2-
import { defineStore } from "pinia";
31
import { createResource } from "frappe-ui";
4-
import { emitter } from "@/emitter";
52
import { Resource, Ticket } from "@/types";
63

7-
const ticket: Ref<Resource<Ticket>> = ref(null);
8-
export function useTicket(id?: number | string) {
9-
if (!ticket.value && id) {
10-
const t = createResource({
11-
url: "helpdesk.helpdesk.doctype.hd_ticket.api.get_one",
12-
params: {
13-
name: id,
14-
},
15-
auto: true,
16-
});
17-
ticket.value = t;
18-
}
19-
return ticket;
20-
}
21-
22-
export const useTicketStore = defineStore("ticket", () => {
23-
const sidebar = reactive({
24-
isExpanded: true,
25-
});
26-
const editor = reactive({
27-
type: "Comment",
28-
isExpanded: false,
29-
content: "",
30-
attachments: [],
31-
cc: [],
32-
bcc: [],
33-
isCcVisible: false,
34-
isBccVisible: false,
35-
tiptap: null,
36-
clean: () => {
37-
editor.type = "Comment";
38-
editor.isExpanded = false;
39-
editor.content = "";
40-
editor.attachments = [];
41-
editor.cc = [];
42-
editor.bcc = [];
43-
editor.isCcVisible = false;
44-
editor.isBccVisible = false;
45-
sidebar.isExpanded = true;
4+
export function useTicket(
5+
id?: number | string,
6+
isCustomerPortal: boolean = false,
7+
transformCB?: (data: any) => any,
8+
successCB?: (data: any) => any,
9+
errorCB?: (err: any) => any
10+
): Resource<Ticket> {
11+
const t = createResource({
12+
url: "helpdesk.helpdesk.doctype.hd_ticket.api.get_one",
13+
cache: ["Ticket", id],
14+
params: {
15+
name: id,
16+
is_customer_portal: isCustomerPortal,
17+
},
18+
auto: true,
19+
transform: (data) => {
20+
transformCB && transformCB(data);
21+
},
22+
onSuccess: (data) => {
23+
successCB && successCB(data);
24+
},
25+
onError: (err) => {
26+
errorCB && errorCB(err);
4627
},
4728
});
48-
49-
function scrollTo(id: string) {
50-
const e = document.getElementById(id);
51-
e.scrollIntoView({ behavior: "smooth" });
52-
}
53-
54-
function $reset() {
55-
editor.clean();
56-
}
57-
58-
emitter.on("ticket:focus", (id: string) => scrollTo(id));
59-
60-
return {
61-
$reset,
62-
editor,
63-
sidebar,
64-
};
65-
});
29+
return t;
30+
}

desk/src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ export interface Ticket {
100100
history: Activity[];
101101
template: Template;
102102
views: ViewLog[];
103+
_customActions: Function[];
103104
}
104105

105106
export interface DocField {

0 commit comments

Comments
 (0)