From aede1f76d0b375f63ad0593a76883e7e32005614 Mon Sep 17 00:00:00 2001 From: yashkanakiya Date: Tue, 14 Mar 2023 12:59:58 +0530 Subject: [PATCH] connect mail sender with api --- app/Http/Requests/MailSenderRequest.php | 8 +- app/Http/Requests/SendEstimatesRequest.php | 2 +- app/Http/Requests/SendInvoiceRequest.php | 2 +- app/Http/Requests/SendPaymentRequest.php | 2 +- app/Mail/SendEstimateMail.php | 9 +- app/Mail/SendInvoiceMail.php | 6 +- app/Mail/SendPaymentMail.php | 8 +- app/Models/Estimate.php | 5 +- app/Models/Invoice.php | 4 +- app/Models/Payment.php | 5 +- app/Space/EnvironmentManager.php | 198 ----------- app/Traits/MailTrait.php | 62 ++++ .../admin/components/FeedbackAlert.vue | 123 +++++++ .../modal-components/MailSenderModal.vue | 5 - .../modal-components/SendEstimateModal.vue | 115 +++++-- .../modal-components/SendInvoiceModal.vue | 115 +++++-- .../modal-components/SendPaymentModal.vue | 114 +++++-- resources/scripts/admin/stores/mail-driver.js | 146 --------- resources/scripts/admin/stores/mail-sender.js | 3 + .../scripts/admin/views/customers/Create.vue | 5 +- .../views/installation/Step5EmailConfig.vue | 308 ++++++++++++++---- .../settings/mail-driver/BasicMailDriver.vue | 158 --------- .../mail-driver/MailgunMailDriver.vue | 247 -------------- .../settings/mail-driver/SesMailDriver.vue | 294 ----------------- .../settings/mail-driver/SmtpMailDriver.vue | 275 ---------------- resources/scripts/locales/en.json | 3 +- 26 files changed, 756 insertions(+), 1466 deletions(-) create mode 100644 app/Traits/MailTrait.php create mode 100644 resources/scripts/admin/components/FeedbackAlert.vue delete mode 100644 resources/scripts/admin/stores/mail-driver.js delete mode 100644 resources/scripts/admin/views/settings/mail-driver/BasicMailDriver.vue delete mode 100644 resources/scripts/admin/views/settings/mail-driver/MailgunMailDriver.vue delete mode 100644 resources/scripts/admin/views/settings/mail-driver/SesMailDriver.vue delete mode 100644 resources/scripts/admin/views/settings/mail-driver/SmtpMailDriver.vue diff --git a/app/Http/Requests/MailSenderRequest.php b/app/Http/Requests/MailSenderRequest.php index 44e64a2f..2b2936ba 100644 --- a/app/Http/Requests/MailSenderRequest.php +++ b/app/Http/Requests/MailSenderRequest.php @@ -70,7 +70,13 @@ class MailSenderRequest extends FormRequest public function getMailSenderPayload() { - return collect($this->validated()) + $data = $this->validated(); + + if ($data['settings']['encryption'] == 'none') { + $data['settings']['encryption'] = ''; + } + + return collect($data) ->merge([ 'company_id' => $this->header('company'), ]) diff --git a/app/Http/Requests/SendEstimatesRequest.php b/app/Http/Requests/SendEstimatesRequest.php index d7826486..6ece4a5f 100644 --- a/app/Http/Requests/SendEstimatesRequest.php +++ b/app/Http/Requests/SendEstimatesRequest.php @@ -30,7 +30,7 @@ class SendEstimatesRequest extends FormRequest 'body' => [ 'required', ], - 'from' => [ + 'mail_sender_id' => [ 'required', ], 'to' => [ diff --git a/app/Http/Requests/SendInvoiceRequest.php b/app/Http/Requests/SendInvoiceRequest.php index 077e8047..c1dc5dc0 100644 --- a/app/Http/Requests/SendInvoiceRequest.php +++ b/app/Http/Requests/SendInvoiceRequest.php @@ -30,7 +30,7 @@ class SendInvoiceRequest extends FormRequest 'subject' => [ 'required', ], - 'from' => [ + 'mail_sender_id' => [ 'required', ], 'to' => [ diff --git a/app/Http/Requests/SendPaymentRequest.php b/app/Http/Requests/SendPaymentRequest.php index 87745b94..70fd4600 100644 --- a/app/Http/Requests/SendPaymentRequest.php +++ b/app/Http/Requests/SendPaymentRequest.php @@ -30,7 +30,7 @@ class SendPaymentRequest extends FormRequest 'body' => [ 'required', ], - 'from' => [ + 'mail_sender_id' => [ 'required', ], 'to' => [ diff --git a/app/Mail/SendEstimateMail.php b/app/Mail/SendEstimateMail.php index 70121e00..664f09bd 100644 --- a/app/Mail/SendEstimateMail.php +++ b/app/Mail/SendEstimateMail.php @@ -34,7 +34,7 @@ class SendEstimateMail extends Mailable public function build() { $log = EmailLog::create([ - 'from' => $this->data['from'], + 'from' => $this->data['from_address'], 'to' => $this->data['to'], 'subject' => $this->data['subject'], 'body' => $this->data['body'], @@ -47,9 +47,10 @@ class SendEstimateMail extends Mailable $this->data['url'] = route('estimate', ['email_log' => $log->token]); - $mailContent = $this->from($this->data['from'], config('mail.from.name')) - ->subject($this->data['subject']) - ->markdown('emails.send.estimate', ['data', $this->data]); + $mailContent = $this->from($this->data['from_address'], $this->data['from_name']) + ->subject($this->data['subject']) + ->markdown("emails.send.estimate", ['data', $this->data]); + if ($this->data['attach']['data']) { $mailContent->attachData( diff --git a/app/Mail/SendInvoiceMail.php b/app/Mail/SendInvoiceMail.php index 81d76fa7..b48c3508 100644 --- a/app/Mail/SendInvoiceMail.php +++ b/app/Mail/SendInvoiceMail.php @@ -34,7 +34,7 @@ class SendInvoiceMail extends Mailable public function build() { $log = EmailLog::create([ - 'from' => $this->data['from'], + 'from' => $this->data['from_address'], 'to' => $this->data['to'], 'subject' => $this->data['subject'], 'body' => $this->data['body'], @@ -47,9 +47,9 @@ class SendInvoiceMail extends Mailable $this->data['url'] = route('invoice', ['email_log' => $log->token]); - $mailContent = $this->from($this->data['from'], config('mail.from.name')) + $mailContent = $this->from($this->data['from_address'], $this->data['from_name']) ->subject($this->data['subject']) - ->markdown('emails.send.invoice', ['data', $this->data]); + ->markdown("emails.send.invoice", ['data', $this->data]); if ($this->data['attach']['data']) { $mailContent->attachData( diff --git a/app/Mail/SendPaymentMail.php b/app/Mail/SendPaymentMail.php index 4d52547f..81b50413 100644 --- a/app/Mail/SendPaymentMail.php +++ b/app/Mail/SendPaymentMail.php @@ -34,7 +34,7 @@ class SendPaymentMail extends Mailable public function build() { $log = EmailLog::create([ - 'from' => $this->data['from'], + 'from' => $this->data['from_address'], 'to' => $this->data['to'], 'subject' => $this->data['subject'], 'body' => $this->data['body'], @@ -47,9 +47,9 @@ class SendPaymentMail extends Mailable $this->data['url'] = route('payment', ['email_log' => $log->token]); - $mailContent = $this->from($this->data['from'], config('mail.from.name')) - ->subject($this->data['subject']) - ->markdown('emails.send.payment', ['data', $this->data]); + $mailContent = $this->from($this->data['from_address'], $this->data['from_name']) + ->subject($this->data['subject']) + ->markdown("emails.send.payment", ['data', $this->data]); if ($this->data['attach']['data']) { $mailContent->attachData( diff --git a/app/Models/Estimate.php b/app/Models/Estimate.php index 5b7c3b8f..2e0356b4 100644 --- a/app/Models/Estimate.php +++ b/app/Models/Estimate.php @@ -5,10 +5,10 @@ namespace Crater\Models; use App; use Barryvdh\DomPDF\Facade as PDF; use Carbon\Carbon; -use Crater\Mail\SendEstimateMail; use Crater\Services\SerialNumberFormatter; use Crater\Traits\GeneratesPdfTrait; use Crater\Traits\HasCustomFieldsTrait; +use Crater\Traits\MailTrait; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Facades\Storage; @@ -20,6 +20,7 @@ use Vinkla\Hashids\Facades\Hashids; class Estimate extends Model implements HasMedia { use HasFactory; + use MailTrait; use InteractsWithMedia; use GeneratesPdfTrait; use HasCustomFieldsTrait; @@ -363,7 +364,7 @@ class Estimate extends Model implements HasMedia $this->save(); } - \Mail::to($data['to'])->send(new SendEstimateMail($data)); + $this->setMail('estimate', $data); return [ 'success' => true, diff --git a/app/Models/Invoice.php b/app/Models/Invoice.php index 39cd3165..4618bc4b 100644 --- a/app/Models/Invoice.php +++ b/app/Models/Invoice.php @@ -9,6 +9,7 @@ use Crater\Mail\SendInvoiceMail; use Crater\Services\SerialNumberFormatter; use Crater\Traits\GeneratesPdfTrait; use Crater\Traits\HasCustomFieldsTrait; +use Crater\Traits\MailTrait; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Facades\Storage; @@ -21,6 +22,7 @@ use Vinkla\Hashids\Facades\Hashids; class Invoice extends Model implements HasMedia { use HasFactory; + use MailTrait; use InteractsWithMedia; use GeneratesPdfTrait; use HasCustomFieldsTrait; @@ -464,7 +466,7 @@ class Invoice extends Model implements HasMedia { $data = $this->sendInvoiceData($data); - \Mail::to($data['to'])->send(new SendInvoiceMail($data)); + $this->setMail('invoice', $data); if ($this->status == Invoice::STATUS_DRAFT) { $this->status = Invoice::STATUS_SENT; diff --git a/app/Models/Payment.php b/app/Models/Payment.php index 83a17441..84b60c36 100644 --- a/app/Models/Payment.php +++ b/app/Models/Payment.php @@ -5,10 +5,10 @@ namespace Crater\Models; use Barryvdh\DomPDF\Facade as PDF; use Carbon\Carbon; use Crater\Jobs\GeneratePaymentPdfJob; -use Crater\Mail\SendPaymentMail; use Crater\Services\SerialNumberFormatter; use Crater\Traits\GeneratesPdfTrait; use Crater\Traits\HasCustomFieldsTrait; +use Crater\Traits\MailTrait; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Spatie\MediaLibrary\HasMedia; @@ -18,6 +18,7 @@ use Vinkla\Hashids\Facades\Hashids; class Payment extends Model implements HasMedia { use HasFactory; + use MailTrait; use InteractsWithMedia; use GeneratesPdfTrait; use HasCustomFieldsTrait; @@ -135,7 +136,7 @@ class Payment extends Model implements HasMedia { $data = $this->sendPaymentData($data); - \Mail::to($data['to'])->send(new SendPaymentMail($data)); + $this->setMail('payment', $data); return [ 'success' => true, diff --git a/app/Space/EnvironmentManager.php b/app/Space/EnvironmentManager.php index 7ba57dcb..a1600fec 100755 --- a/app/Space/EnvironmentManager.php +++ b/app/Space/EnvironmentManager.php @@ -223,204 +223,6 @@ class EnvironmentManager return false; } - /** - * Save the mail content to the .env file. - * - * @param Request $request - * @return array - */ - public function saveMailVariables(MailEnvironmentRequest $request) - { - $mailData = $this->getMailData($request); - - try { - file_put_contents($this->envPath, str_replace( - $mailData['old_mail_data'], - $mailData['new_mail_data'], - file_get_contents($this->envPath) - )); - - if ($mailData['extra_old_mail_data']) { - file_put_contents($this->envPath, str_replace( - $mailData['extra_old_mail_data'], - $mailData['extra_mail_data'], - file_get_contents($this->envPath) - )); - } else { - file_put_contents( - $this->envPath, - "\n".$mailData['extra_mail_data'], - FILE_APPEND - ); - } - } catch (Exception $e) { - return [ - 'error' => 'mail_variables_save_error', - ]; - } - - return [ - 'success' => 'mail_variables_save_successfully', - ]; - } - - private function getMailData($request) - { - $mailFromCredential = ""; - $extraMailData = ""; - $extraOldMailData = ""; - $oldMailData = ""; - $newMailData = ""; - - if (env('MAIL_FROM_ADDRESS') !== null && env('MAIL_FROM_NAME') !== null) { - $mailFromCredential = - 'MAIL_FROM_ADDRESS='.config('mail.from.address')."\n". - 'MAIL_FROM_NAME="'.config('mail.from.name')."\"\n\n"; - } - - switch ($request->mail_driver) { - case 'smtp': - - $oldMailData = - 'MAIL_DRIVER='.config('mail.driver')."\n". - 'MAIL_HOST='.config('mail.host')."\n". - 'MAIL_PORT='.config('mail.port')."\n". - 'MAIL_USERNAME='.config('mail.username')."\n". - 'MAIL_PASSWORD='.config('mail.password')."\n". - 'MAIL_ENCRYPTION='.config('mail.encryption')."\n\n". - $mailFromCredential; - - $newMailData = - 'MAIL_DRIVER='.$request->mail_driver."\n". - 'MAIL_HOST='.$request->mail_host."\n". - 'MAIL_PORT='.$request->mail_port."\n". - 'MAIL_USERNAME='.$request->mail_username."\n". - 'MAIL_PASSWORD='.$request->mail_password."\n". - 'MAIL_ENCRYPTION='.$request->mail_encryption."\n\n". - 'MAIL_FROM_ADDRESS='.$request->from_mail."\n". - 'MAIL_FROM_NAME="'.$request->from_name."\"\n\n"; - - break; - - case 'mailgun': - $oldMailData = - 'MAIL_DRIVER='.config('mail.driver')."\n". - 'MAIL_HOST='.config('mail.host')."\n". - 'MAIL_PORT='.config('mail.port')."\n". - 'MAIL_USERNAME='.config('mail.username')."\n". - 'MAIL_PASSWORD='.config('mail.password')."\n". - 'MAIL_ENCRYPTION='.config('mail.encryption')."\n\n". - $mailFromCredential; - - $newMailData = - 'MAIL_DRIVER='.$request->mail_driver."\n". - 'MAIL_HOST='.$request->mail_host."\n". - 'MAIL_PORT='.$request->mail_port."\n". - 'MAIL_USERNAME='.config('mail.username')."\n". - 'MAIL_PASSWORD='.config('mail.password')."\n". - 'MAIL_ENCRYPTION='.$request->mail_encryption."\n\n". - 'MAIL_FROM_ADDRESS='.$request->from_mail."\n". - 'MAIL_FROM_NAME="'.$request->from_name."\"\n\n"; - - $extraMailData = - 'MAILGUN_DOMAIN='.$request->mail_mailgun_domain."\n". - 'MAILGUN_SECRET='.$request->mail_mailgun_secret."\n". - 'MAILGUN_ENDPOINT='.$request->mail_mailgun_endpoint."\n"; - - if (env('MAILGUN_DOMAIN') !== null && env('MAILGUN_SECRET') !== null && env('MAILGUN_ENDPOINT') !== null) { - $extraOldMailData = - 'MAILGUN_DOMAIN='.config('services.mailgun.domain')."\n". - 'MAILGUN_SECRET='.config('services.mailgun.secret')."\n". - 'MAILGUN_ENDPOINT='.config('services.mailgun.endpoint')."\n"; - } - - break; - - case 'ses': - $oldMailData = - 'MAIL_DRIVER='.config('mail.driver')."\n". - 'MAIL_HOST='.config('mail.host')."\n". - 'MAIL_PORT='.config('mail.port')."\n". - 'MAIL_USERNAME='.config('mail.username')."\n". - 'MAIL_PASSWORD='.config('mail.password')."\n". - 'MAIL_ENCRYPTION='.config('mail.encryption')."\n\n". - $mailFromCredential; - - $newMailData = - 'MAIL_DRIVER='.$request->mail_driver."\n". - 'MAIL_HOST='.$request->mail_host."\n". - 'MAIL_PORT='.$request->mail_port."\n". - 'MAIL_USERNAME='.config('mail.username')."\n". - 'MAIL_PASSWORD='.config('mail.password')."\n". - 'MAIL_ENCRYPTION='.$request->mail_encryption."\n\n". - 'MAIL_FROM_ADDRESS='.$request->from_mail."\n". - 'MAIL_FROM_NAME="'.$request->from_name."\"\n\n"; - - $extraMailData = - 'SES_KEY='.$request->mail_ses_key."\n". - 'SES_SECRET='.$request->mail_ses_secret."\n"; - - if (env('SES_KEY') !== null && env('SES_SECRET') !== null) { - $extraOldMailData = - 'SES_KEY='.config('services.ses.key')."\n". - 'SES_SECRET='.config('services.ses.secret')."\n"; - } - - break; - - case 'mail': - $oldMailData = - 'MAIL_DRIVER='.config('mail.driver')."\n". - 'MAIL_HOST='.config('mail.host')."\n". - 'MAIL_PORT='.config('mail.port')."\n". - 'MAIL_USERNAME='.config('mail.username')."\n". - 'MAIL_PASSWORD='.config('mail.password')."\n". - 'MAIL_ENCRYPTION='.config('mail.encryption')."\n\n". - $mailFromCredential; - - $newMailData = - 'MAIL_DRIVER='.$request->mail_driver."\n". - 'MAIL_HOST='.config('mail.host')."\n". - 'MAIL_PORT='.config('mail.port')."\n". - 'MAIL_USERNAME='.config('mail.username')."\n". - 'MAIL_PASSWORD='.config('mail.password')."\n". - 'MAIL_ENCRYPTION='.config('mail.encryption')."\n\n". - 'MAIL_FROM_ADDRESS='.$request->from_mail."\n". - 'MAIL_FROM_NAME="'.$request->from_name."\"\n\n"; - - break; - - case 'sendmail': - $oldMailData = - 'MAIL_DRIVER='.config('mail.driver')."\n". - 'MAIL_HOST='.config('mail.host')."\n". - 'MAIL_PORT='.config('mail.port')."\n". - 'MAIL_USERNAME='.config('mail.username')."\n". - 'MAIL_PASSWORD='.config('mail.password')."\n". - 'MAIL_ENCRYPTION='.config('mail.encryption')."\n\n". - $mailFromCredential; - - $newMailData = - 'MAIL_DRIVER='.$request->mail_driver."\n". - 'MAIL_HOST='.config('mail.host')."\n". - 'MAIL_PORT='.config('mail.port')."\n". - 'MAIL_USERNAME='.config('mail.username')."\n". - 'MAIL_PASSWORD='.config('mail.password')."\n". - 'MAIL_ENCRYPTION='.config('mail.encryption')."\n\n". - 'MAIL_FROM_ADDRESS='.$request->from_mail."\n". - 'MAIL_FROM_NAME="'.$request->from_name."\"\n\n"; - - break; - } - - return [ - 'old_mail_data' => $oldMailData, - 'new_mail_data' => $newMailData, - 'extra_mail_data' => $extraMailData, - 'extra_old_mail_data' => $extraOldMailData, - ]; - } - /** * Save the disk content to the .env file. * diff --git a/app/Traits/MailTrait.php b/app/Traits/MailTrait.php new file mode 100644 index 00000000..54ca6062 --- /dev/null +++ b/app/Traits/MailTrait.php @@ -0,0 +1,62 @@ +from_address; + $data['from_name'] = $mailSender->from_name; + + switch ($model) { + case 'invoice': + $mail = new SendInvoiceMail($data); + + break; + + case 'estimate': + $mail = new SendEstimateMail($data); + + break; + + case 'payment': + $mail = new SendPaymentMail($data); + + break; + } + + if ($mailSender->bcc && $mailSender->cc) { + \Mail::to($data['to']) + ->bcc(explode(',', $mailSender->bcc)) + ->cc(explode(',', $mailSender->cc)) + ->send($mail); + } + + if ($mailSender->bcc && $mailSender->cc == null) { + \Mail::to($data['to']) + ->bcc(explode(',', $mailSender->bcc)) + ->send($mail); + } + + if ($mailSender->bcc == null && $mailSender->cc) { + \Mail::to($data['to']) + ->cc(explode(',', $mailSender->cc)) + ->send($mail); + } + + if ($mailSender->bcc == null && $mailSender->cc == null) { + \Mail::to($data['to']) + ->send($mail); + } + + return true; + } +} diff --git a/resources/scripts/admin/components/FeedbackAlert.vue b/resources/scripts/admin/components/FeedbackAlert.vue new file mode 100644 index 00000000..2c1b14cf --- /dev/null +++ b/resources/scripts/admin/components/FeedbackAlert.vue @@ -0,0 +1,123 @@ + + + diff --git a/resources/scripts/admin/components/modal-components/MailSenderModal.vue b/resources/scripts/admin/components/modal-components/MailSenderModal.vue index d1532644..6a942ce5 100644 --- a/resources/scripts/admin/components/modal-components/MailSenderModal.vue +++ b/resources/scripts/admin/components/modal-components/MailSenderModal.vue @@ -171,19 +171,14 @@ const loadMailDriver = computed(() => { switch (mailSenderStore.currentMailSender.driver) { case 'smtp': return SmtpDriver - break case 'mail': return false - break case 'sendmail': return false - break case 'mailgun': return MailgunDriver - break case 'ses': return SesDriver - break default: return false } diff --git a/resources/scripts/admin/components/modal-components/SendEstimateModal.vue b/resources/scripts/admin/components/modal-components/SendEstimateModal.vue index 795cdfeb..640c0c3c 100644 --- a/resources/scripts/admin/components/modal-components/SendEstimateModal.vue +++ b/resources/scripts/admin/components/modal-components/SendEstimateModal.vue @@ -16,18 +16,28 @@
-
+ +
-
+ +
+ + + +
+
@@ -75,6 +124,7 @@ { }) const rules = { - from: { + mail_sender_id: { required: helpers.withMessage(t('validation.required'), required), - email: helpers.withMessage(t('validation.email_incorrect'), email), }, to: { required: helpers.withMessage(t('validation.required'), required), @@ -207,20 +262,26 @@ function cancelPreview() { } async function setInitialData() { - let admin = await companyStore.fetchBasicMailConfig() - estimateMailForm.id = modalStore.id - - if (admin.data) { - estimateMailForm.from = admin.data.from_mail - } - if (modalData.value) { estimateMailForm.to = modalData.value.customer.email } estimateMailForm.body = companyStore.selectedCompanySettings.estimate_mail_body + + isFetchingInitialData.value = true + let mailSenderData = await mailSenderStore.fetchMailSenderList() + if (mailSenderData.data) { + mailSenders.value = mailSenderData.data.data + let defaultMailSender = mailSenderData.data.data.find( + (mailSender) => mailSender.is_default == true + ) + estimateMailForm.mail_sender_id = defaultMailSender + ? defaultMailSender.id + : null + isFetchingInitialData.value = false + } } async function submitForm() { @@ -274,4 +335,18 @@ function closeSendEstimateModal() { templateUrl.value = null }, 300) } + +function getTickImage() { + const imgUrl = new URL('/img/tick.png', import.meta.url) + return imgUrl +} + +const isMailSenderExist = computed(() => { + return mailSenders.value && mailSenders.value.length +}) + +function gotoMailSender() { + closeSendEstimateModal() + router.push('/admin/settings/mail-sender') +} diff --git a/resources/scripts/admin/components/modal-components/SendInvoiceModal.vue b/resources/scripts/admin/components/modal-components/SendInvoiceModal.vue index 63e7e6af..c685b8c6 100644 --- a/resources/scripts/admin/components/modal-components/SendInvoiceModal.vue +++ b/resources/scripts/admin/components/modal-components/SendInvoiceModal.vue @@ -15,18 +15,28 @@
-
+ +
-
+ +
+ + + +
+
@@ -77,6 +126,7 @@ {{ $t('general.cancel') }} { }) const rules = { - from: { + mail_sender_id: { required: helpers.withMessage(t('validation.required'), required), - email: helpers.withMessage(t('validation.email_incorrect'), email), }, to: { required: helpers.withMessage(t('validation.required'), required), @@ -224,19 +279,25 @@ function cancelPreview() { } async function setInitialData() { - let admin = await companyStore.fetchBasicMailConfig() - invoiceMailForm.id = modalStore.id - - if (admin.data) { - invoiceMailForm.from = admin.data.from_mail - } - if (modalData.value) { invoiceMailForm.to = modalData.value.customer.email } invoiceMailForm.body = companyStore.selectedCompanySettings.invoice_mail_body + + isFetchingInitialData.value = true + let mailSenderData = await mailSenderStore.fetchMailSenderList() + if (mailSenderData.data) { + mailSenders.value = mailSenderData.data.data + let defaultMailSender = mailSenderData.data.data.find( + (mailSender) => mailSender.is_default == true + ) + invoiceMailForm.mail_sender_id = defaultMailSender + ? defaultMailSender.id + : null + isFetchingInitialData.value = false + } } async function submitForm() { @@ -287,4 +348,18 @@ function closeSendInvoiceModal() { templateUrl.value = null }, 300) } + +function getTickImage() { + const imgUrl = new URL('/img/tick.png', import.meta.url) + return imgUrl +} + +const isMailSenderExist = computed(() => { + return mailSenders.value && mailSenders.value.length +}) + +function gotoMailSender() { + closeSendInvoiceModal() + router.push('/admin/settings/mail-sender') +} diff --git a/resources/scripts/admin/components/modal-components/SendPaymentModal.vue b/resources/scripts/admin/components/modal-components/SendPaymentModal.vue index 6c786312..b25e9b22 100644 --- a/resources/scripts/admin/components/modal-components/SendPaymentModal.vue +++ b/resources/scripts/admin/components/modal-components/SendPaymentModal.vue @@ -15,18 +15,28 @@
-
+ +
-
+ +
+ + + +
+
@@ -77,6 +126,7 @@ {{ $t('general.cancel') }} { }) const rules = { - from: { + mail_sender_id: { required: helpers.withMessage(t('validation.required'), required), - email: helpers.withMessage(t('validation.email_incorrect'), email), }, to: { required: helpers.withMessage(t('validation.required'), required), @@ -221,18 +276,25 @@ function cancelPreview() { } async function setInitialData() { - let admin = await companyStore.fetchBasicMailConfig() paymentMailForm.id = modalStore.id - - if (admin.data) { - paymentMailForm.from = admin.data.from_mail - } - if (modalData.value) { paymentMailForm.to = modalData.value.customer.email } paymentMailForm.body = companyStore.selectedCompanySettings.payment_mail_body + + isFetchingInitialData.value = true + let mailSenderData = await mailSenderStore.fetchMailSenderList() + if (mailSenderData.data) { + mailSenders.value = mailSenderData.data.data + let defaultMailSender = mailSenderData.data.data.find( + (mailSender) => mailSender.is_default == true + ) + paymentMailForm.mail_sender_id = defaultMailSender + ? defaultMailSender.id + : null + isFetchingInitialData.value = false + } } async function sendPaymentData() { @@ -280,4 +342,18 @@ function closeSendPaymentModal() { modalStore.resetModalData() }, 300) } + +function getTickImage() { + const imgUrl = new URL('/img/tick.png', import.meta.url) + return imgUrl +} + +const isMailSenderExist = computed(() => { + return mailSenders.value && mailSenders.value.length +}) + +function gotoMailSender() { + closeSendPaymentModal() + router.push('/admin/settings/mail-sender') +} diff --git a/resources/scripts/admin/stores/mail-driver.js b/resources/scripts/admin/stores/mail-driver.js deleted file mode 100644 index f6086efd..00000000 --- a/resources/scripts/admin/stores/mail-driver.js +++ /dev/null @@ -1,146 +0,0 @@ -import axios from 'axios' -import { defineStore } from 'pinia' -import { useNotificationStore } from '@/scripts/stores/notification' -import { handleError } from '@/scripts/helpers/error-handling' - -export const useMailDriverStore = (useWindow = false) => { - const defineStoreFunc = useWindow ? window.pinia.defineStore : defineStore - const { global } = window.i18n - - return defineStoreFunc({ - id: 'mail-driver', - - state: () => ({ - mailConfigData: null, - mail_driver: 'smtp', - mail_drivers: [], - - basicMailConfig: { - mail_driver: '', - mail_host: '', - from_mail: '', - from_name: '', - }, - - mailgunConfig: { - mail_driver: '', - mail_mailgun_domain: '', - mail_mailgun_secret: '', - mail_mailgun_endpoint: '', - from_mail: '', - from_name: '', - }, - - sesConfig: { - mail_driver: '', - mail_host: '', - mail_port: null, - mail_ses_key: '', - mail_ses_secret: '', - mail_encryption: 'tls', - from_mail: '', - from_name: '', - }, - - smtpConfig: { - mail_driver: '', - mail_host: '', - mail_port: null, - mail_username: '', - mail_password: '', - mail_encryption: 'tls', - from_mail: '', - from_name: '', - }, - }), - - actions: { - fetchMailDrivers() { - return new Promise((resolve, reject) => { - axios - .get('/api/v1/mail/drivers') - .then((response) => { - if (response.data) { - this.mail_drivers = response.data - } - resolve(response) - }) - .catch((err) => { - handleError(err) - reject(err) - }) - }) - }, - - fetchMailConfig() { - return new Promise((resolve, reject) => { - axios - .get('/api/v1/mail/config') - .then((response) => { - if (response.data) { - this.mailConfigData = response.data - this.mail_driver = response.data.mail_driver - } - resolve(response) - }) - .catch((err) => { - handleError(err) - reject(err) - }) - }) - }, - - updateMailConfig(data) { - return new Promise((resolve, reject) => { - axios - .post('/api/v1/mail/config', data) - .then((response) => { - const notificationStore = useNotificationStore() - if (response.data.success) { - notificationStore.showNotification({ - type: 'success', - message: global.t('wizard.success.' + response.data.success), - }) - } else { - notificationStore.showNotification({ - type: 'error', - message: global.t('wizard.errors.' + response.data.error), - }) - } - resolve(response) - }) - .catch((err) => { - handleError(err) - reject(err) - }) - }) - }, - - sendTestMail(data) { - return new Promise((resolve, reject) => { - axios - .post('/api/v1/mail/test', data) - .then((response) => { - const notificationStore = useNotificationStore() - if (response.data.success) { - notificationStore.showNotification({ - type: 'success', - message: global.t('general.send_mail_successfully'), - }) - } else { - notificationStore.showNotification({ - type: 'error', - message: global.t('validation.something_went_wrong'), - }) - } - resolve(response) - }) - .catch((err) => { - handleError(err) - reject(err) - }) - }) - }, - }, - })() -} diff --git a/resources/scripts/admin/stores/mail-sender.js b/resources/scripts/admin/stores/mail-sender.js index 588d5241..cfaed799 100644 --- a/resources/scripts/admin/stores/mail-sender.js +++ b/resources/scripts/admin/stores/mail-sender.js @@ -88,15 +88,18 @@ export const useMailSenderStore = (useWindow = false) => { this.currentMailSender = response.data.data if (response.data.data.settings) { var settings = response.data.data.settings + const encryptionNone = settings.encryption == '' || settings.encryption == undefined switch (response.data.data.driver) { case 'smtp': this.smtpConfig = settings + encryptionNone ? this.smtpConfig.encryption = 'none' : '' break case 'mailgun': this.mailgunConfig = settings break case 'ses': this.sesConfig = settings + encryptionNone ? this.sesConfig.encryption = 'none' : '' break } } diff --git a/resources/scripts/admin/views/customers/Create.vue b/resources/scripts/admin/views/customers/Create.vue index eea559ae..141ada45 100644 --- a/resources/scripts/admin/views/customers/Create.vue +++ b/resources/scripts/admin/views/customers/Create.vue @@ -708,7 +708,10 @@ const rules = computed(() => { url: helpers.withMessage(t('validation.invalid_url'), url), }, mail_sender_id: { - required: helpers.withMessage(t('validation.required'), required), + required: helpers.withMessage( + t('validation.required'), + requiredIf(customerStore.currentCustomer.enable_portal == true) + ), }, billing: { address_street_1: { diff --git a/resources/scripts/admin/views/installation/Step5EmailConfig.vue b/resources/scripts/admin/views/installation/Step5EmailConfig.vue index ad2813d4..8d6a0ca3 100644 --- a/resources/scripts/admin/views/installation/Step5EmailConfig.vue +++ b/resources/scripts/admin/views/installation/Step5EmailConfig.vue @@ -3,75 +3,259 @@ :title="$t('wizard.mail.mail_config')" :description="$t('wizard.mail.mail_config_desc')" > - - + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + {{ $t('wizard.save_cont') }} + +
- diff --git a/resources/scripts/admin/views/settings/mail-driver/BasicMailDriver.vue b/resources/scripts/admin/views/settings/mail-driver/BasicMailDriver.vue deleted file mode 100644 index 031c9412..00000000 --- a/resources/scripts/admin/views/settings/mail-driver/BasicMailDriver.vue +++ /dev/null @@ -1,158 +0,0 @@ - - - diff --git a/resources/scripts/admin/views/settings/mail-driver/MailgunMailDriver.vue b/resources/scripts/admin/views/settings/mail-driver/MailgunMailDriver.vue deleted file mode 100644 index fa2ebbcf..00000000 --- a/resources/scripts/admin/views/settings/mail-driver/MailgunMailDriver.vue +++ /dev/null @@ -1,247 +0,0 @@ - - - diff --git a/resources/scripts/admin/views/settings/mail-driver/SesMailDriver.vue b/resources/scripts/admin/views/settings/mail-driver/SesMailDriver.vue deleted file mode 100644 index 5eae5a07..00000000 --- a/resources/scripts/admin/views/settings/mail-driver/SesMailDriver.vue +++ /dev/null @@ -1,294 +0,0 @@ - - - diff --git a/resources/scripts/admin/views/settings/mail-driver/SmtpMailDriver.vue b/resources/scripts/admin/views/settings/mail-driver/SmtpMailDriver.vue deleted file mode 100644 index dbb947f2..00000000 --- a/resources/scripts/admin/views/settings/mail-driver/SmtpMailDriver.vue +++ /dev/null @@ -1,275 +0,0 @@ - - - diff --git a/resources/scripts/locales/en.json b/resources/scripts/locales/en.json index 6265fec3..7d44e0a3 100644 --- a/resources/scripts/locales/en.json +++ b/resources/scripts/locales/en.json @@ -101,6 +101,7 @@ "login_successfully": "Logged in successfully!", "logged_out_successfully": "Logged out successfully", "mark_as_default": "Mark as default", + "select_option": "Select option", "send_test_mail": "Send Test Mail" }, "dashboard": { @@ -1572,4 +1573,4 @@ "pdf_ship_to": "Ship to,", "pdf_received_from": "Received from:", "pdf_tax_label": "Tax" -} \ No newline at end of file +}