Skip to content

Commit

Permalink
Merge pull request #1067 from ssiyad/feat/email_cc_bcc_multiple
Browse files Browse the repository at this point in the history
feat: email: cc bcc multiple value support
  • Loading branch information
ssiyad committed Mar 18, 2023
2 parents 6d6dbd2 + 4a2b544 commit ad3d930
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 35 deletions.
2 changes: 1 addition & 1 deletion desk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"autoprefixer": "^10.4.13",
"dayjs": "^1.11.7",
"echarts": "^5.4.1",
"frappe-ui": "^0.0.103",
"frappe-ui": "^0.0.105",
"vee-validate": "^4.8.2",
"vue": "^3.2.47",
"vue-echarts": "^6.5.4",
Expand Down
116 changes: 86 additions & 30 deletions desk/src/pages/desk/Ticket.vue
Original file line number Diff line number Diff line change
Expand Up @@ -144,40 +144,69 @@
>
<div
v-if="editingType == 'reply'"
class="flex w-[85%] flex-col"
class="flex flex-col gap-2"
>
<div
v-if="ticket.raised_by"
class="flex flex-row items-center space-x-2"
class="flex flex-row items-center gap-2"
>
<div class="text-gray-700">To</div>
<div class="rounded-[6px] bg-gray-50 px-[10px] py-[4px]">
<div class="rounded-md bg-gray-100 px-2 py-1">
{{ ticket.raised_by }}
</div>
</div>
<div
v-if="showCc"
class="flex flex-row items-center space-x-2 bg-transparent"
v-show="showCc"
class="flex flex-row flex-wrap items-center gap-2"
>
<div class="text-gray-700">Cc</div>
<div
v-for="email in ccList"
class="flex items-center rounded-md bg-gray-100"
:class="{
'bg-red-100': !validateEmail(email),
}"
>
<div class="px-2 py-1">
{{ email }}
</div>
<FeatherIcon
name="x"
class="h-5 cursor-pointer py-1 pr-2"
@click="() => removeFromEmailList(ccList, email)"
/>
</div>
<Input
v-model="cc"
class="font-inter w-11/12 bg-white py-[4px] pl-[4px] text-[12px] focus:bg-white"
class="bg-white focus:bg-white"
@keyup.enter="(e) => pushToEmailList(ccList, e)"
/>
</div>
<ErrorMessage :message="ccValidationError" />
<div
v-if="showBcc"
class="flex flex-row items-center space-x-2"
v-show="showBcc"
class="flex flex-row flex-wrap items-center gap-2"
>
<div class="bg-transparent text-gray-700">Bcc</div>

<div class="text-gray-700">Bcc</div>
<div
v-for="email in bccList"
class="flex items-center rounded-md bg-gray-100"
:class="{
'bg-red-100': !validateEmail(email),
}"
>
<div class="px-2 py-1">
{{ email }}
</div>
<FeatherIcon
name="x"
class="h-5 cursor-pointer py-1 pr-2"
@click="() => removeFromEmailList(bccList, email)"
/>
</div>
<Input
v-model="bcc"
class="font-inter w-11/12 bg-white py-[4px] pl-[2px] text-[12px] focus:bg-white"
class="bg-white focus:bg-white"
@keyup.enter="(e) => pushToEmailList(bccList, e)"
/>
</div>
<ErrorMessage :message="bccValidationError" />
</div>
<div v-else class="flex flex-row items-center space-x-2">
<span class="text-gray-700">as</span>
Expand Down Expand Up @@ -504,20 +533,13 @@ export default {
const showBcc = ref(false);
const showCcBtn = ref(true);
const showBccBtn = ref(true);
const validateEmail = toFieldValidator(zod.string().email());
const { value: cc, errorMessage: ccValidationError } = useField(
"ccField",
validateEmail
);
const { value: bcc, errorMessage: bccValidationError } = useField(
"bccField",
validateEmail
);
const ccList = ref([]);
const bccList = ref([]);
return {
cc,
bcc,
ccList,
bccList,
showTextFormattingMenu,
viewportWidth,
user,
Expand All @@ -531,8 +553,6 @@ export default {
tempContent,
editingSubject,
replied,
ccValidationError,
bccValidationError,
showCc,
showBcc,
showCcBtn,
Expand All @@ -554,7 +574,21 @@ export default {
type: "document",
doctype: "Ticket",
name: this.ticketId,
onSuccess: () => {
this.$resources.ticket.lastCommunication.fetch();
},
whitelistedMethods: {
lastCommunication: {
method: "last_communication",
onSuccess: (data) => {
this.ccList = this.ccList.length
? this.ccList
: data.cc?.split(",") || [];
this.bccList = this.bccList.length
? this.bccList
: data.bcc?.split(",") || [];
},
},
markSeen: "mark_seen",
replyViaAgent: {
method: "reply_via_agent",
Expand Down Expand Up @@ -669,8 +703,8 @@ export default {
this.$resources.ticket.replyViaAgent.submit({
attachments: this.attachments.map((x) => x.name),
bcc: this.bcc,
cc: this.cc,
bcc: this.bccList.join(","),
cc: this.ccList.join(","),
message,
});
Expand Down Expand Up @@ -723,6 +757,28 @@ export default {
this.tempContent = content;
this.content = this.tempContent;
},
validateEmail(email) {
return zod.string().email().safeParse(email).success;
},
pushToEmailList(list, e) {
if (list.indexOf(e.target.value) > 0) return;
if (!this.validateEmail(e.target.value)) {
this.$toast({
title: "Invalid email",
icon: "x",
iconClasses: "text-red-500",
});
return;
}
list.push(e.currentTarget.value);
e.currentTarget.value = "";
},
removeFromEmailList(list, email) {
list.splice(list.indexOf(email), 1);
},
},
};
</script>
8 changes: 4 additions & 4 deletions desk/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -892,10 +892,10 @@ fraction.js@^4.2.0:
resolved "https://registry.yarnpkg.com/fraction.js/-/fraction.js-4.2.0.tgz#448e5109a313a3527f5a3ab2119ec4cf0e0e2950"
integrity sha512-MhLuK+2gUcnZe8ZHlaaINnQLl0xRIGRfcGk2yl8xoQAfHrSsL3rYu6FCmBdkdbhc9EPlwyGHewaRsvwRMJtAlA==

frappe-ui@^0.0.103:
version "0.0.103"
resolved "https://registry.yarnpkg.com/frappe-ui/-/frappe-ui-0.0.103.tgz#54be8966b4602f66b0eee36df94e2f0137889e4d"
integrity sha512-TEfAUsmJLzfIT28rFbl2eCA//apgOwMA12DIPOxOpUB8+mh0s6Ze5ADK1pE+/p3hJlPG9QSS8JxRXvH9t/lOKQ==
frappe-ui@^0.0.105:
version "0.0.105"
resolved "https://registry.yarnpkg.com/frappe-ui/-/frappe-ui-0.0.105.tgz#173acd4dbf8e14f1d072c1a19a4dd597af0d7833"
integrity sha512-/CbbpAgEHgOXQ6L69hg1hW99rHsc6Q5VKccaBSCZbczU9iWNXvnm+YZ3LggnwNiFpiJBjNsy1TqMUy448ry+oQ==
dependencies:
"@headlessui/vue" "^1.5.0"
"@popperjs/core" "^2.11.2"
Expand Down
1 change: 1 addition & 0 deletions frappedesk/frappedesk/doctype/ticket/ticket.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ def instantly_send_email(self):

return bool(int(check))

@frappe.whitelist()
def last_communication(self):
filters = {"reference_doctype": "Ticket", "reference_name": ["=", self.name]}

Expand Down

0 comments on commit ad3d930

Please sign in to comment.