1<template>
2 <Notification
3 ref="compRef"
4 name="share_feedback"
5 :title="props.notification.label"
6 :description="props.notification.description"
7 v-model:content="content"
8 :defaultContent="defaultContent"
9 v-model:enabled="enabled"
10 documentationLink="https://github.com/ikhsanddy/opendesk"
11 :onBack="props.onBack"
12 :onSubmit="onSubmit"
13 :onGetDataSuccess="onGetDataSuccess"
14 :submitting="updateSettings.loading"
15 >
16 <template #formFields>
17 <FormControl
18 type="combobox"
19 size="sm"
20 :label="__('On ticket status')"
21 :options="statusOptions"
22 :required="true"
23 :model-value="ticketStatus?.value ?? null"
24 @update:model-value="
25 (value) => {
26 ticketStatus =
27 statusOptions.find((option) => option.value === value) ?? null;
28 compRef.markUnsavedChanges();
29 }
30 "
31 />
32 </template>
33 </Notification>
34</template>
35
36<script setup lang="ts">
37import { computed, ref } from "vue";
38import Notification from "./Notification.vue";
39import { createResource, toast } from "frappe-ui";
40import type { BaseSettings, Notification as NotificationType } from "./types";
41import { useTicketStatusStore } from "@/stores/ticketStatus";
42import { __ } from "@/translation";
43
44const props = defineProps<{
45 onBack: () => void;
46 notification: NotificationType;
47}>();
48
49const content = ref("");
50const defaultContent = ref("");
51const enabled = ref(false);
52const compRef = ref<InstanceType<typeof Notification>>();
53const { statuses } = useTicketStatusStore();
54const statusOptions = computed<Record<"label" | "value", string>[]>(() =>
55 statuses.data
56 .filter((s) => s.category === "Resolved")
57 .map((s) => ({
58 label: __(s.label_agent),
59 value: s.label_agent,
60 }))
61);
62const ticketStatus = ref<Record<"label" | "value", string> | null>(null);
63
64type Data = {
65 ticket_status: Record<"label" | "value", string>;
66} & BaseSettings;
67
68const updateSettings = createResource({
69 url: "opendesk.api.settings.email_notifications.update_share_feedback",
70 method: "PUT",
71 auto: false,
72 onSuccess(_data: Data) {
73 compRef.value.resetUnsavedChanges();
74 },
75});
76
77function onSubmit() {
78 toast.success(__("Settings updated successfully."));
79 return updateSettings.submit({
80 ticket_status: ticketStatus.value,
81 enabled: enabled.value,
82 content: content.value,
83 });
84}
85
86function onGetDataSuccess(data: Data & { default_content: string }) {
87 ticketStatus.value = {
88 label: __(data.ticket_status.label),
89 value: data.ticket_status.value,
90 };
91 enabled.value = data.enabled;
92 content.value = data.content;
93 defaultContent.value = data.default_content;
94}
95</script>
96