Skip to content

Commit

Permalink
feat: email editor fields
Browse files Browse the repository at this point in the history
  • Loading branch information
sumitbhanushali committed Apr 22, 2024
1 parent cee7a11 commit 2374b4e
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 59 deletions.
2 changes: 0 additions & 2 deletions desk/src/components/AssignmentModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@
</template>
<template #suffix>
<FeatherIcon
v-if="currentAssignee.name !== owner"
class="h-3.5"
name="x"
@click.stop="removeCurrentAssignee(currentAssignee.name)"
Expand All @@ -87,7 +86,6 @@
</template>
<template #suffix>
<FeatherIcon
v-if="newAssignee.name !== owner"
class="h-3.5"
name="x"
@click.stop="removeAssignee(newAssignee.name)"
Expand Down
37 changes: 25 additions & 12 deletions desk/src/components/CommunicationArea.vue
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,11 @@
>
<EmailEditor
ref="newEmailEditor"
v-model:content="newEmail"
v-model:content="content"
v-model:attachments="attachments"
v-model="doc"
:to-emails="toEmails"
:cc-emails="ccEmails"
:bcc-emails="bccEmails"
:submit-button-props="{
variant: 'solid',
onClick: submitEmail,
Expand All @@ -77,12 +79,10 @@
:discard-button-props="{
onClick: () => {
showEmailBox = false;
newEmailEditor.toEmails = doc.email ? [doc.email] : [];
newEmailEditor.ccEmails = [];
newEmailEditor.bccEmails = [];
newEmailEditor.cc = false;
newEmailEditor.bcc = false;
newEmail = '';
},
}"
/>
Expand All @@ -95,19 +95,17 @@ import EmailIcon from "@/components/icons/EmailIcon.vue";
import CommentIcon from "@/components/icons/CommentIcon.vue";
import { useAuthStore } from "@/stores/auth";
import { EmailEditor, CommentTextEditor } from "@/components";
import { computed, ref, defineModel, nextTick, watch } from "vue";
import { computed, ref, defineModel, nextTick } from "vue";
import { useStorage } from "@vueuse/core";
const authStore = useAuthStore();
const content = defineModel("content");
const showEmailBox = ref(false);
const showCommentBox = ref(false);
const doc = defineModel();
const attachments = ref([]);
const newEmailEditor = ref(null);
const newEmail = useStorage("emailBoxContent", "");
const newComment = useStorage("commentBoxContent", "");
function toggleEmailBox() {
if (showCommentBox.value) {
showCommentBox.value = false;
Expand Down Expand Up @@ -138,6 +136,9 @@ function toggleBCC() {
});
}
const newEmail = useStorage("emailBoxContent", "");
const newComment = useStorage("commentBoxContent", "");
const commentEmpty = computed(() => {
return !newComment.value || newComment.value === "<p></p>";
});
Expand All @@ -146,13 +147,27 @@ const emailEmpty = computed(() => {
return !newEmail.value || newEmail.value === "<p></p>";
});
const reload = defineModel("reload");
const props = defineProps({
doctype: {
type: String,
default: "HD Ticket",
},
toEmails: {
type: Array,
default: () => [],
},
ccEmails: {
type: Array,
default: () => [],
},
bccEmails: {
type: Array,
default: () => [],
},
content: {
type: String,
default: "",
},
});
const emit = defineEmits(["scroll"]);
Expand Down Expand Up @@ -181,7 +196,6 @@ async function submitEmail() {
showEmailBox.value = false;
sendMail.submit();
newEmail.value = "";
reload.value = true;
emit("scroll");
}
Expand All @@ -206,7 +220,6 @@ async function submitComment() {
showCommentBox.value = false;
await sendComment();
newComment.value = "";
reload.value = true;
emit("scroll");
}
</script>
37 changes: 20 additions & 17 deletions desk/src/components/EmailEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
>
<span class="text-xs text-gray-500">TO:</span>
<MultiSelectInput
v-model="toEmails"
v-model="toEmailsClone"
class="flex-1"
:validate="validateEmail"
:error-message="(value) => `${value} is an invalid email address`"
Expand All @@ -32,7 +32,7 @@
<span class="text-xs text-gray-500">CC:</span>
<MultiSelectInput
ref="ccInput"
v-model="ccEmails"
v-model="ccEmailsClone"
class="flex-1"
:validate="validateEmail"
:error-message="(value) => `${value} is an invalid email address`"
Expand All @@ -42,7 +42,7 @@
<span class="text-xs text-gray-500">BCC:</span>
<MultiSelectInput
ref="bccInput"
v-model="bccEmails"
v-model="bccEmailsClone"
class="flex-1"
:validate="validateEmail"
:error-message="(value) => `${value} is an invalid email address`"
Expand Down Expand Up @@ -115,10 +115,6 @@ const props = defineProps({
type: String,
default: "HD Ticket",
},
subject: {
type: String,
default: "Email from Issuer",
},
editorProps: {
type: Object,
default: () => ({}),
Expand All @@ -131,17 +127,28 @@ const props = defineProps({
type: Object,
default: () => ({}),
},
toEmails: {
type: Array,
default: () => [],
},
ccEmails: {
type: Array,
default: () => [],
},
bccEmails: {
type: Array,
default: () => [],
},
});
const modelValue = defineModel();
const content = defineModel("content");
const attachments = defineModel("attachments");
const subject = ref(props.subject);
const cc = ref(false);
const bcc = ref(false);
const ccEmails = ref([]);
const bccEmails = ref([]);
const toEmails = ref(modelValue.value?.email ? [modelValue.value.email] : []);
const cc = ref(props.ccEmails.length ? true : false);
const bcc = ref(props.bccEmails.length ? true : false);
const toEmailsClone = ref([...props.toEmails]);
const ccEmailsClone = ref([...props.ccEmails]);
const bccEmailsClone = ref([...props.bccEmails]);
const ccInput = ref(null);
const bccInput = ref(null);
Expand Down Expand Up @@ -184,12 +191,8 @@ const textEditorMenuButtons = [
];
defineExpose({
subject,
cc,
bcc,
toEmails,
ccEmails,
bccEmails,
ccInput,
bccInput,
});
Expand Down
41 changes: 19 additions & 22 deletions desk/src/components/MultiSelectInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,9 @@ import {
ComboboxOptions,
ComboboxOption,
} from "@headlessui/vue";
import UserAvatar from "@/components/UserAvatar.vue";
// import { contactsStore } from "@/stores/contacts";
import { UserAvatar } from "@/components/";
import { Popover, createResource } from "frappe-ui";
import { ref, computed, nextTick, defineModel } from "vue";
import { ref, computed, nextTick } from "vue";
import { watchDebounced } from "@vueuse/core";
const props = defineProps({
Expand All @@ -111,8 +110,6 @@ const props = defineProps({
const values = defineModel();
// const { getContactByName } = contactsStore();
const emails = ref([]);
const search = ref(null);
const error = ref(null);
Expand Down Expand Up @@ -150,20 +147,20 @@ const filterOptions = createResource({
txt: text.value,
doctype: "Contact",
},
// transform: (data) => {
// let allData = data
// .filter((c) => {
// return getContactByName(c.value).email_id;
// })
// .map((option) => {
// let c = getContactByName(option.value);
// return {
// label: c.full_name || c.email_id,
// value: c.email_id,
// };
// });
// return allData;
// },
transform: (data) => {
let allData = data
.filter((c) => {
return c.description.split(", ")[1];
})
.map((option) => {
let email = option.description.split(", ")[1];
return {
label: option.label || email,
value: email,
};
});
return allData;
},
});
const options = computed(() => {
Expand Down Expand Up @@ -222,19 +219,19 @@ const removeValue = (value) => {
const removeLastValue = () => {
if (query.value) return;
let emailRef = emails.value[emails.value.length - 1].$el;
let emailRef = emails.value[emails.value.length - 1]?.$el;
if (document.activeElement === emailRef) {
values.value.pop();
nextTick(() => {
if (values.value.length) {
emailRef = emails.value[emails.value.length - 1].$el;
emailRef.focus();
emailRef?.focus();
} else {
setFocus();
}
});
} else {
emailRef.focus();
emailRef?.focus();
}
};
Expand Down
2 changes: 1 addition & 1 deletion desk/src/components/ticket/TicketAgentActivities.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<div class="overflow-y-auto">
<div class="h-screen overflow-y-auto">
<div v-for="(activity, i) in activities" :key="activity.key">
<div class="flex gap-4 px-10">
<div
Expand Down
23 changes: 18 additions & 5 deletions desk/src/pages/TicketAgent2.vue
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,10 @@
</div>
<TicketAgentActivities :activities="ticketAgentStore.activities" />
<CommunicationArea
v-model="ticket.data"
v-model:reload="reload_email"
v-model:content="ticketAgentStore.emailContent"
:to-emails="[ticket.data.raised_by]"
:cc-emails="[]"
:bcc-emails="[]"
/>
</div>
<TicketAgentSidebar :ticket="ticket.data" />
Expand All @@ -78,6 +80,7 @@

<script setup lang="ts">
import { computed, ref, h } from "vue";
import { useStorage } from "@vueuse/core";
import { Breadcrumbs, Dropdown, Switch } from "frappe-ui";
import {
Expand All @@ -102,14 +105,24 @@ const props = defineProps({
},
});
const reload_email = ref(false);
const newEmail = useStorage("emailBoxContent", "");
const newComment = useStorage("commentBoxContent", "");
const commentEmpty = computed(() => {
return !newComment.value || newComment.value === "<p></p>";
});
const emailEmpty = computed(() => {
return !newEmail.value || newEmail.value === "<p></p>";
});
const showAssignmentModal = ref(false);
const ticket = ticketAgentStore.getTicket(props.ticketId);
const ticket = computed(() => ticketAgentStore.getTicket(props.ticketId));
const breadcrumbs = computed(() => {
let items = [{ label: "Tickets", route: { name: "TicketsAgent" } }];
items.push({
label: ticket?.data?.subject,
label: ticket.value?.data?.subject,
route: { name: "TicketAgent" },
});
Expand Down
4 changes: 4 additions & 0 deletions desk/src/stores/ticketAgent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,16 @@ export const useTicketAgentStore = defineStore("ticketAgent", () => {
return data;
});

// Communication
const emailContent = ref("");

return {
updateAssignees,
assignees,
getTicket,
updateTicket,
activities,
showFullActivity,
emailContent,
};
});

0 comments on commit 2374b4e

Please sign in to comment.