Skip to content

Commit

Permalink
refactor: use updateDraftMail for Send
Browse files Browse the repository at this point in the history
  • Loading branch information
krantheman committed Nov 22, 2024
1 parent eaf8946 commit 6f754e6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 17 deletions.
28 changes: 11 additions & 17 deletions frontend/src/components/Modals/SendMail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ const bccInput = ref(null)
const cc = ref(false)
const bcc = ref(false)
const emoji = ref()
const isSendMail = ref(false)
const editor = computed(() => {
return textEditor.value.editor
Expand Down Expand Up @@ -264,9 +265,15 @@ const updateDraftMail = createResource({
return {
mail_id: mailID.value,
from_: `${user.data?.full_name} <${mail.from}>`,
do_submit: isSendMail.value,
...mail,
}
},
onSuccess() {
if (!isSendMail.value) return
isSendMail.value = false
show.value = false
},
})
const deleteDraftMail = createResource({
Expand All @@ -277,27 +284,14 @@ const deleteDraftMail = createResource({
mail_id: mailID.value,
}
},
})
const sendMail = createResource({
url: 'mail_client.api.outbound.send',
method: 'POST',
makeParams(values) {
return {
mail_id: mailID.value,
}
onSuccess() {
mailID.value = null
},
})
const send = () => {
sendMail.submit(
{},
{
onSuccess() {
show.value = false
},
}
)
isSendMail.value = true
updateDraftMail.submit()
}
const toggleCC = () => {
Expand Down
4 changes: 4 additions & 0 deletions mail_client/api/mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@ def update_draft_mail(
bcc: str | list[str] | None = None,
html: str | None = None,
attachments: list[dict] | None = None,
do_submit: bool = False,
):
"""Update draft mail."""

Expand All @@ -401,6 +402,9 @@ def update_draft_mail(
doc.save()
doc._add_attachment(attachments)

if do_submit:
doc.submit()


@frappe.whitelist()
def delete_mail(mail_type: str, mail_id: str):
Expand Down

0 comments on commit 6f754e6

Please sign in to comment.