mirror of
https://github.com/crater-invoice/crater.git
synced 2025-10-27 11:41:09 -04:00
connect mail sender with api
This commit is contained in:
@ -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'),
|
||||
])
|
||||
|
||||
@ -30,7 +30,7 @@ class SendEstimatesRequest extends FormRequest
|
||||
'body' => [
|
||||
'required',
|
||||
],
|
||||
'from' => [
|
||||
'mail_sender_id' => [
|
||||
'required',
|
||||
],
|
||||
'to' => [
|
||||
|
||||
@ -30,7 +30,7 @@ class SendInvoiceRequest extends FormRequest
|
||||
'subject' => [
|
||||
'required',
|
||||
],
|
||||
'from' => [
|
||||
'mail_sender_id' => [
|
||||
'required',
|
||||
],
|
||||
'to' => [
|
||||
|
||||
@ -30,7 +30,7 @@ class SendPaymentRequest extends FormRequest
|
||||
'body' => [
|
||||
'required',
|
||||
],
|
||||
'from' => [
|
||||
'mail_sender_id' => [
|
||||
'required',
|
||||
],
|
||||
'to' => [
|
||||
|
||||
@ -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(
|
||||
|
||||
@ -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(
|
||||
|
||||
@ -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(
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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.
|
||||
*
|
||||
|
||||
62
app/Traits/MailTrait.php
Normal file
62
app/Traits/MailTrait.php
Normal file
@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace Crater\Traits;
|
||||
|
||||
use Crater\Mail\SendEstimateMail;
|
||||
use Crater\Mail\SendInvoiceMail;
|
||||
use Crater\Mail\SendPaymentMail;
|
||||
use Crater\Models\MailSender;
|
||||
|
||||
trait MailTrait
|
||||
{
|
||||
public function setMail($model, $data)
|
||||
{
|
||||
$mailSender = MailSender::setMailConfiguration($data['mail_sender_id'], true);
|
||||
|
||||
$data['from_address'] = $mailSender->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;
|
||||
}
|
||||
}
|
||||
123
resources/scripts/admin/components/FeedbackAlert.vue
Normal file
123
resources/scripts/admin/components/FeedbackAlert.vue
Normal file
@ -0,0 +1,123 @@
|
||||
<template>
|
||||
<!-- warning alert -->
|
||||
<div
|
||||
v-if="type == 'warning'"
|
||||
class="rounded-md p-4 m-5"
|
||||
:class="{
|
||||
'bg-yellow-50': type == 'warning',
|
||||
'bg-blue-50': type == 'info',
|
||||
'bg-red-50': type == 'error',
|
||||
'bg-green-50': type == 'success',
|
||||
}"
|
||||
>
|
||||
<div class="flex">
|
||||
<div class="flex-shrink-0">
|
||||
<!-- Heroicon name: solid/exclamation -->
|
||||
<svg
|
||||
v-if="type == 'warning'"
|
||||
class="h-5 w-5 text-yellow-400"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
viewBox="0 0 20 20"
|
||||
fill="currentColor"
|
||||
aria-hidden="true"
|
||||
>
|
||||
<path
|
||||
fill-rule="evenodd"
|
||||
d="M8.257 3.099c.765-1.36 2.722-1.36 3.486 0l5.58 9.92c.75 1.334-.213 2.98-1.742 2.98H4.42c-1.53 0-2.493-1.646-1.743-2.98l5.58-9.92zM11 13a1 1 0 11-2 0 1 1 0 012 0zm-1-8a1 1 0 00-1 1v3a1 1 0 002 0V6a1 1 0 00-1-1z"
|
||||
clip-rule="evenodd"
|
||||
/>
|
||||
</svg>
|
||||
<!-- Heroicon name: solid/information-circle -->
|
||||
<svg
|
||||
v-else-if="type == 'info'"
|
||||
class="h-5 w-5 text-blue-400"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
viewBox="0 0 20 20"
|
||||
fill="currentColor"
|
||||
aria-hidden="true"
|
||||
>
|
||||
<path
|
||||
fill-rule="evenodd"
|
||||
d="M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7-4a1 1 0 11-2 0 1 1 0 012 0zM9 9a1 1 0 000 2v3a1 1 0 001 1h1a1 1 0 100-2v-3a1 1 0 00-1-1H9z"
|
||||
clip-rule="evenodd"
|
||||
/>
|
||||
</svg>
|
||||
<!-- Heroicon name: solid/x-circle -->
|
||||
<svg
|
||||
v-else-if="type == 'error'"
|
||||
class="h-5 w-5 text-red-400"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
viewBox="0 0 20 20"
|
||||
fill="currentColor"
|
||||
aria-hidden="true"
|
||||
>
|
||||
<path
|
||||
fill-rule="evenodd"
|
||||
d="M10 18a8 8 0 100-16 8 8 0 000 16zM8.707 7.293a1 1 0 00-1.414 1.414L8.586 10l-1.293 1.293a1 1 0 101.414 1.414L10 11.414l1.293 1.293a1 1 0 001.414-1.414L11.414 10l1.293-1.293a1 1 0 00-1.414-1.414L10 8.586 8.707 7.293z"
|
||||
clip-rule="evenodd"
|
||||
/>
|
||||
</svg>
|
||||
<!-- Heroicon name: solid/check-circle -->
|
||||
<svg
|
||||
v-else
|
||||
class="h-5 w-5 text-green-400"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
viewBox="0 0 20 20"
|
||||
fill="currentColor"
|
||||
aria-hidden="true"
|
||||
>
|
||||
<path
|
||||
fill-rule="evenodd"
|
||||
d="M10 18a8 8 0 100-16 8 8 0 000 16zm3.707-9.293a1 1 0 00-1.414-1.414L9 10.586 7.707 9.293a1 1 0 00-1.414 1.414l2 2a1 1 0 001.414 0l4-4z"
|
||||
clip-rule="evenodd"
|
||||
/>
|
||||
</svg>
|
||||
</div>
|
||||
<div class="ml-3">
|
||||
<h3
|
||||
class="text-sm font-medium"
|
||||
:class="{
|
||||
'text-yellow-800': type == 'warning',
|
||||
'text-blue-800': type == 'info',
|
||||
'text-red-800': type == 'error',
|
||||
'text-green-800': type == 'success',
|
||||
}"
|
||||
>
|
||||
{{ title }}
|
||||
</h3>
|
||||
<div
|
||||
class="text-sm"
|
||||
:class="{
|
||||
'text-yellow-700': type == 'warning',
|
||||
'text-blue-700': type == 'info',
|
||||
'text-red-700': type == 'error',
|
||||
'text-green-700': type == 'success',
|
||||
}"
|
||||
>
|
||||
<p>{{ description }}</p>
|
||||
</div>
|
||||
<slot name="action"></slot>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
const props = defineProps({
|
||||
title: {
|
||||
type: String,
|
||||
default: null,
|
||||
required: false,
|
||||
},
|
||||
description: {
|
||||
type: String,
|
||||
default: null,
|
||||
required: false,
|
||||
},
|
||||
type: {
|
||||
type: String,
|
||||
default: 'success',
|
||||
required: true,
|
||||
},
|
||||
})
|
||||
</script>
|
||||
@ -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
|
||||
}
|
||||
|
||||
@ -16,18 +16,28 @@
|
||||
</template>
|
||||
|
||||
<form v-if="!isPreview" action="">
|
||||
<div class="px-8 py-8 sm:p-6">
|
||||
<!-- v-if -->
|
||||
<div v-if="isMailSenderExist" class="px-8 py-8 sm:p-6">
|
||||
<BaseInputGrid layout="one-column">
|
||||
<BaseInputGroup
|
||||
:label="$t('general.from')"
|
||||
:label="$tc('settings.mail_sender.title', 1)"
|
||||
required
|
||||
:error="v$.from.$error && v$.from.$errors[0].$message"
|
||||
:error="
|
||||
v$.mail_sender_id.$error && v$.mail_sender_id.$errors[0].$message
|
||||
"
|
||||
>
|
||||
<BaseInput
|
||||
v-model="estimateMailForm.from"
|
||||
type="text"
|
||||
:invalid="v$.from.$error"
|
||||
@input="v$.from.$touch()"
|
||||
<BaseMultiselect
|
||||
v-model="estimateMailForm.mail_sender_id"
|
||||
:invalid="v$.mail_sender_id.$error"
|
||||
label="name"
|
||||
:options="mailSenders"
|
||||
value-prop="id"
|
||||
:can-deselect="false"
|
||||
:can-clear="false"
|
||||
:placeholder="$t(`settings.mail_sender.select_mail_sender`)"
|
||||
searchable
|
||||
track-by="name"
|
||||
:content-loading="isFetchingInitialData"
|
||||
/>
|
||||
</BaseInputGroup>
|
||||
<BaseInputGroup
|
||||
@ -62,6 +72,45 @@
|
||||
</BaseInputGroup>
|
||||
</BaseInputGrid>
|
||||
</div>
|
||||
<!-- v-else -->
|
||||
<div v-else>
|
||||
<FeedbackAlert
|
||||
:title="$t('settings.mail_sender.no_mail_sender_found')"
|
||||
:description="
|
||||
$t('settings.mail_sender.no_mail_sender_found_description')
|
||||
"
|
||||
type="warning"
|
||||
>
|
||||
<template #action>
|
||||
<div class="mt-4">
|
||||
<div class="-mx-2 -my-1.5 flex">
|
||||
<button
|
||||
type="button"
|
||||
class="
|
||||
bg-yellow-50
|
||||
px-2
|
||||
py-1.5
|
||||
rounded-md
|
||||
text-sm
|
||||
font-medium
|
||||
text-yellow-800
|
||||
hover:bg-yellow-100
|
||||
focus:outline-none
|
||||
focus:ring-2
|
||||
focus:ring-offset-2
|
||||
focus:ring-offset-yellow-50
|
||||
focus:ring-yellow-600
|
||||
"
|
||||
@click="gotoMailSender"
|
||||
>
|
||||
{{ $t('settings.mail_sender.manage_mail_sender') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</FeedbackAlert>
|
||||
</div>
|
||||
<!-- end v-if-else -->
|
||||
<div
|
||||
class="z-0 flex justify-end p-4 border-t border-gray-200 border-solid"
|
||||
>
|
||||
@ -75,6 +124,7 @@
|
||||
</BaseButton>
|
||||
|
||||
<BaseButton
|
||||
v-if="isMailSenderExist"
|
||||
:loading="isLoading"
|
||||
:disabled="isLoading"
|
||||
variant="primary"
|
||||
@ -141,18 +191,24 @@ import { useModalStore } from '@/scripts/stores/modal'
|
||||
import { useEstimateStore } from '@/scripts/admin/stores/estimate'
|
||||
import { useNotificationStore } from '@/scripts/stores/notification'
|
||||
import { useCompanyStore } from '@/scripts/admin/stores/company'
|
||||
import { useMailDriverStore } from '@/scripts/admin/stores/mail-driver'
|
||||
import { useMailSenderStore } from '@/scripts/admin/stores/mail-sender'
|
||||
import FeedbackAlert from '@/scripts/admin/components/FeedbackAlert.vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
|
||||
const modalStore = useModalStore()
|
||||
const estimateStore = useEstimateStore()
|
||||
const notificationStore = useNotificationStore()
|
||||
const companyStore = useCompanyStore()
|
||||
const mailDriverStore = useMailDriverStore()
|
||||
const mailSenderStore = useMailSenderStore()
|
||||
const router = useRouter()
|
||||
|
||||
const { t } = useI18n()
|
||||
const isLoading = ref(false)
|
||||
const templateUrl = ref('')
|
||||
const isPreview = ref(false)
|
||||
const mailSenders = ref(null)
|
||||
const isFetchingInitialData = ref(false)
|
||||
const emailTemplates = ref(null)
|
||||
|
||||
const estimateMailFields = ref([
|
||||
'customer',
|
||||
@ -164,7 +220,7 @@ const estimateMailFields = ref([
|
||||
|
||||
let estimateMailForm = reactive({
|
||||
id: null,
|
||||
from: null,
|
||||
mail_sender_id: null,
|
||||
to: null,
|
||||
subject: 'New Estimate',
|
||||
body: null,
|
||||
@ -181,9 +237,8 @@ const modalData = computed(() => {
|
||||
})
|
||||
|
||||
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')
|
||||
}
|
||||
</script>
|
||||
|
||||
@ -15,18 +15,28 @@
|
||||
</div>
|
||||
</template>
|
||||
<form v-if="!isPreview" action="">
|
||||
<div class="px-8 py-8 sm:p-6">
|
||||
<!-- v-if -->
|
||||
<div v-if="isMailSenderExist" class="px-8 py-8 sm:p-6">
|
||||
<BaseInputGrid layout="one-column" class="col-span-7">
|
||||
<BaseInputGroup
|
||||
:label="$t('general.from')"
|
||||
:label="$tc('settings.mail_sender.title', 1)"
|
||||
required
|
||||
:error="v$.from.$error && v$.from.$errors[0].$message"
|
||||
:error="
|
||||
v$.mail_sender_id.$error && v$.mail_sender_id.$errors[0].$message
|
||||
"
|
||||
>
|
||||
<BaseInput
|
||||
v-model="invoiceMailForm.from"
|
||||
type="text"
|
||||
:invalid="v$.from.$error"
|
||||
@input="v$.from.$touch()"
|
||||
<BaseMultiselect
|
||||
v-model="invoiceMailForm.mail_sender_id"
|
||||
:invalid="v$.mail_sender_id.$error"
|
||||
label="name"
|
||||
:options="mailSenders"
|
||||
value-prop="id"
|
||||
:can-deselect="false"
|
||||
:can-clear="false"
|
||||
:placeholder="$t(`settings.mail_sender.select_mail_sender`)"
|
||||
searchable
|
||||
track-by="name"
|
||||
:content-loading="isFetchingInitialData"
|
||||
/>
|
||||
</BaseInputGroup>
|
||||
<BaseInputGroup
|
||||
@ -65,6 +75,45 @@
|
||||
</BaseInputGroup>
|
||||
</BaseInputGrid>
|
||||
</div>
|
||||
<!-- v-else -->
|
||||
<div v-else>
|
||||
<FeedbackAlert
|
||||
:title="$t('settings.mail_sender.no_mail_sender_found')"
|
||||
:description="
|
||||
$t('settings.mail_sender.no_mail_sender_found_description')
|
||||
"
|
||||
type="warning"
|
||||
>
|
||||
<template #action>
|
||||
<div class="mt-4">
|
||||
<div class="-mx-2 -my-1.5 flex">
|
||||
<button
|
||||
type="button"
|
||||
class="
|
||||
bg-yellow-50
|
||||
px-2
|
||||
py-1.5
|
||||
rounded-md
|
||||
text-sm
|
||||
font-medium
|
||||
text-yellow-800
|
||||
hover:bg-yellow-100
|
||||
focus:outline-none
|
||||
focus:ring-2
|
||||
focus:ring-offset-2
|
||||
focus:ring-offset-yellow-50
|
||||
focus:ring-yellow-600
|
||||
"
|
||||
@click="gotoMailSender"
|
||||
>
|
||||
{{ $t('settings.mail_sender.manage_mail_sender') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</FeedbackAlert>
|
||||
</div>
|
||||
<!-- end v-if-else -->
|
||||
<div
|
||||
class="z-0 flex justify-end p-4 border-t border-gray-200 border-solid"
|
||||
>
|
||||
@ -77,6 +126,7 @@
|
||||
{{ $t('general.cancel') }}
|
||||
</BaseButton>
|
||||
<BaseButton
|
||||
v-if="isMailSenderExist"
|
||||
:loading="isLoading"
|
||||
:disabled="isLoading"
|
||||
variant="primary"
|
||||
@ -154,18 +204,24 @@ import { useI18n } from 'vue-i18n'
|
||||
import { useInvoiceStore } from '@/scripts/admin/stores/invoice'
|
||||
import { useVuelidate } from '@vuelidate/core'
|
||||
import { required, email, helpers } from '@vuelidate/validators'
|
||||
import { useMailDriverStore } from '@/scripts/admin/stores/mail-driver'
|
||||
import { useMailSenderStore } from '@/scripts/admin/stores/mail-sender'
|
||||
import FeedbackAlert from '@/scripts/admin/components/FeedbackAlert.vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
|
||||
const modalStore = useModalStore()
|
||||
const companyStore = useCompanyStore()
|
||||
const notificationStore = useNotificationStore()
|
||||
const invoiceStore = useInvoiceStore()
|
||||
const mailDriverStore = useMailDriverStore()
|
||||
const mailSenderStore = useMailSenderStore()
|
||||
const router = useRouter()
|
||||
|
||||
const { t } = useI18n()
|
||||
let isLoading = ref(false)
|
||||
const templateUrl = ref('')
|
||||
const isPreview = ref(false)
|
||||
const mailSenders = ref(null)
|
||||
const isFetchingInitialData = ref(false)
|
||||
const emailTemplates = ref(null)
|
||||
|
||||
const emit = defineEmits(['update'])
|
||||
|
||||
@ -179,7 +235,7 @@ const invoiceMailFields = ref([
|
||||
|
||||
const invoiceMailForm = reactive({
|
||||
id: null,
|
||||
from: null,
|
||||
mail_sender_id: null,
|
||||
to: null,
|
||||
subject: 'New Invoice',
|
||||
body: null,
|
||||
@ -198,9 +254,8 @@ const modalData = computed(() => {
|
||||
})
|
||||
|
||||
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')
|
||||
}
|
||||
</script>
|
||||
|
||||
@ -15,18 +15,28 @@
|
||||
</div>
|
||||
</template>
|
||||
<form v-if="!isPreview" action="">
|
||||
<div class="px-8 py-8 sm:p-6">
|
||||
<!-- v-if -->
|
||||
<div v-if="isMailSenderExist" class="px-8 py-8 sm:p-6">
|
||||
<BaseInputGrid layout="one-column" class="col-span-7">
|
||||
<BaseInputGroup
|
||||
:label="$t('general.from')"
|
||||
:label="$tc('settings.mail_sender.title', 1)"
|
||||
required
|
||||
:error="v$.from.$error && v$.from.$errors[0].$message"
|
||||
:error="
|
||||
v$.mail_sender_id.$error && v$.mail_sender_id.$errors[0].$message
|
||||
"
|
||||
>
|
||||
<BaseInput
|
||||
v-model="paymentMailForm.from"
|
||||
type="text"
|
||||
:invalid="v$.from.$error"
|
||||
@input="v$.from.$touch()"
|
||||
<BaseMultiselect
|
||||
v-model="paymentMailForm.mail_sender_id"
|
||||
:invalid="v$.mail_sender_id.$error"
|
||||
label="name"
|
||||
:options="mailSenders"
|
||||
value-prop="id"
|
||||
:can-deselect="false"
|
||||
:can-clear="false"
|
||||
:placeholder="$t(`settings.mail_sender.select_mail_sender`)"
|
||||
searchable
|
||||
track-by="name"
|
||||
:content-loading="isFetchingInitialData"
|
||||
/>
|
||||
</BaseInputGroup>
|
||||
<BaseInputGroup
|
||||
@ -65,6 +75,45 @@
|
||||
</BaseInputGroup>
|
||||
</BaseInputGrid>
|
||||
</div>
|
||||
<!-- v-else -->
|
||||
<div v-else>
|
||||
<FeedbackAlert
|
||||
:title="$t('settings.mail_sender.no_mail_sender_found')"
|
||||
:description="
|
||||
$t('settings.mail_sender.no_mail_sender_found_description')
|
||||
"
|
||||
type="warning"
|
||||
>
|
||||
<template #action>
|
||||
<div class="mt-4">
|
||||
<div class="-mx-2 -my-1.5 flex">
|
||||
<button
|
||||
type="button"
|
||||
class="
|
||||
bg-yellow-50
|
||||
px-2
|
||||
py-1.5
|
||||
rounded-md
|
||||
text-sm
|
||||
font-medium
|
||||
text-yellow-800
|
||||
hover:bg-yellow-100
|
||||
focus:outline-none
|
||||
focus:ring-2
|
||||
focus:ring-offset-2
|
||||
focus:ring-offset-yellow-50
|
||||
focus:ring-yellow-600
|
||||
"
|
||||
@click="gotoMailSender"
|
||||
>
|
||||
{{ $t('settings.mail_sender.manage_mail_sender') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</FeedbackAlert>
|
||||
</div>
|
||||
<!-- end v-if-else -->
|
||||
<div
|
||||
class="z-0 flex justify-end p-4 border-t border-gray-200 border-solid"
|
||||
>
|
||||
@ -77,6 +126,7 @@
|
||||
{{ $t('general.cancel') }}
|
||||
</BaseButton>
|
||||
<BaseButton
|
||||
v-if="isMailSenderExist"
|
||||
:loading="isLoading"
|
||||
:disabled="isLoading"
|
||||
variant="primary"
|
||||
@ -154,20 +204,26 @@ import { usePaymentStore } from '@/scripts/admin/stores/payment'
|
||||
import { useCompanyStore } from '@/scripts/admin/stores/company'
|
||||
import { useNotificationStore } from '@/scripts/stores/notification'
|
||||
import { useModalStore } from '@/scripts/stores/modal'
|
||||
import { useMailDriverStore } from '@/scripts/admin/stores/mail-driver'
|
||||
import { useDialogStore } from '@/scripts/stores/dialog'
|
||||
import { useMailSenderStore } from '@/scripts/admin/stores/mail-sender'
|
||||
import FeedbackAlert from '@/scripts/admin/components/FeedbackAlert.vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
|
||||
const paymentStore = usePaymentStore()
|
||||
const companyStore = useCompanyStore()
|
||||
const modalStore = useModalStore()
|
||||
const notificationStore = useNotificationStore()
|
||||
const mailDriversStore = useMailDriverStore()
|
||||
const dialogStore = useDialogStore()
|
||||
const mailSenderStore = useMailSenderStore()
|
||||
const router = useRouter()
|
||||
|
||||
const { t } = useI18n()
|
||||
let isLoading = ref(false)
|
||||
const templateUrl = ref('')
|
||||
const isPreview = ref(false)
|
||||
const mailSenders = ref(null)
|
||||
const isFetchingInitialData = ref(false)
|
||||
const emailTemplates = ref(null)
|
||||
|
||||
const paymentMailFields = ref([
|
||||
'customer',
|
||||
@ -179,7 +235,7 @@ const paymentMailFields = ref([
|
||||
|
||||
const paymentMailForm = reactive({
|
||||
id: null,
|
||||
from: null,
|
||||
mail_sender_id: null,
|
||||
to: null,
|
||||
subject: 'New Payment',
|
||||
body: null,
|
||||
@ -198,9 +254,8 @@ const modalData = computed(() => {
|
||||
})
|
||||
|
||||
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')
|
||||
}
|
||||
</script>
|
||||
|
||||
@ -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)
|
||||
})
|
||||
})
|
||||
},
|
||||
},
|
||||
})()
|
||||
}
|
||||
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@ -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: {
|
||||
|
||||
@ -3,75 +3,259 @@
|
||||
:title="$t('wizard.mail.mail_config')"
|
||||
:description="$t('wizard.mail.mail_config_desc')"
|
||||
>
|
||||
<form action="" @submit.prevent="next">
|
||||
<component
|
||||
:is="mailDriverStore.mail_driver"
|
||||
:config-data="mailDriverStore.mailConfigData"
|
||||
:is-saving="isSaving"
|
||||
:is-fetching-initial-data="isFetchingInitialData"
|
||||
@on-change-driver="(val) => changeDriver(val)"
|
||||
@submit-data="next"
|
||||
/>
|
||||
<form action="" @submit.prevent="submitMailSenderData">
|
||||
<div class="p-4 sm:p-6 my-2">
|
||||
<!-- Name -->
|
||||
<BaseInputGrid>
|
||||
<BaseInputGroup
|
||||
:label="$t(`${pre_t}.name`)"
|
||||
:error="v$.name.$error && v$.name.$errors[0].$message"
|
||||
:help-text="$t(`${pre_t}.name_help`)"
|
||||
required
|
||||
>
|
||||
<BaseInput
|
||||
v-model.trim="mailSenderStore.currentMailSender.name"
|
||||
:invalid="v$.name.$error"
|
||||
type="text"
|
||||
@input="v$.name.$touch()"
|
||||
/>
|
||||
</BaseInputGroup>
|
||||
|
||||
<!-- From Name -->
|
||||
<BaseInputGroup
|
||||
:label="$t(`${pre_t}.from_name`)"
|
||||
:error="v$.from_name.$error && v$.from_name.$errors[0].$message"
|
||||
required
|
||||
>
|
||||
<BaseInput
|
||||
v-model="mailSenderStore.currentMailSender.from_name"
|
||||
:invalid="v$.from_name.$error"
|
||||
type="text"
|
||||
@input="v$.from_name.$touch()"
|
||||
/>
|
||||
</BaseInputGroup>
|
||||
|
||||
<!-- From Address -->
|
||||
<BaseInputGroup
|
||||
:label="$t(`${pre_t}.from_address`)"
|
||||
:error="
|
||||
v$.from_address.$error && v$.from_address.$errors[0].$message
|
||||
"
|
||||
required
|
||||
>
|
||||
<BaseInput
|
||||
v-model="mailSenderStore.currentMailSender.from_address"
|
||||
:invalid="v$.from_address.$error"
|
||||
type="text"
|
||||
@input="v$.from_address.$touch()"
|
||||
/>
|
||||
</BaseInputGroup>
|
||||
|
||||
<!-- CC -->
|
||||
<BaseInputGroup
|
||||
:label="$t(`${pre_t}.cc`)"
|
||||
:error="v$.cc.$error && v$.cc.$errors[0].$message"
|
||||
:help-text="$t(`${pre_t}.email_list`)"
|
||||
>
|
||||
<BaseInput
|
||||
v-model="mailSenderStore.currentMailSender.cc"
|
||||
:invalid="v$.cc.$error"
|
||||
type="text"
|
||||
@input="v$.cc.$touch()"
|
||||
/>
|
||||
</BaseInputGroup>
|
||||
|
||||
<!-- BCC -->
|
||||
<BaseInputGroup
|
||||
:label="$t(`${pre_t}.bcc`)"
|
||||
:error="v$.bcc.$error && v$.bcc.$errors[0].$message"
|
||||
:help-text="$t(`${pre_t}.email_list`)"
|
||||
>
|
||||
<BaseInput
|
||||
v-model="mailSenderStore.currentMailSender.bcc"
|
||||
:invalid="v$.bcc.$error"
|
||||
type="text"
|
||||
@input="v$.bcc.$touch()"
|
||||
/>
|
||||
</BaseInputGroup>
|
||||
|
||||
<!-- Mail Driver -->
|
||||
<BaseInputGroup
|
||||
:label="$t(`${pre_t}.driver`)"
|
||||
:error="v$.driver.$error && v$.driver.$errors[0].$message"
|
||||
required
|
||||
>
|
||||
<BaseMultiselect
|
||||
v-model="mailSenderStore.currentMailSender.driver"
|
||||
:options="mailSenderStore.mail_drivers"
|
||||
:can-deselect="false"
|
||||
:invalid="v$.driver.$error"
|
||||
/>
|
||||
</BaseInputGroup>
|
||||
|
||||
<component
|
||||
:is="loadMailDriver"
|
||||
:mail-sender-store="mailSenderStore"
|
||||
/>
|
||||
</BaseInputGrid>
|
||||
|
||||
<!-- Is Default? -->
|
||||
<BaseSwitchSection
|
||||
v-model="mailSenderStore.currentMailSender.is_default"
|
||||
:title="$t(`${pre_t}.is_default`)"
|
||||
:description="$t(`${pre_t}.is_default_description`)"
|
||||
/>
|
||||
<BaseDivider class="my-4" />
|
||||
|
||||
<BaseButton
|
||||
:loading="isSaving"
|
||||
:disabled="isSaving"
|
||||
variant="primary"
|
||||
type="submit"
|
||||
>
|
||||
<template #left="slotProps">
|
||||
<BaseIcon
|
||||
v-if="!isSaving"
|
||||
name="SaveIcon"
|
||||
:class="slotProps.class"
|
||||
/>
|
||||
</template>
|
||||
{{ $t('wizard.save_cont') }}
|
||||
</BaseButton>
|
||||
</div>
|
||||
</form>
|
||||
</BaseWizardStep>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import Smtp from './mail-driver/SmtpMailDriver.vue'
|
||||
import Mailgun from './mail-driver/MailgunMailDriver.vue'
|
||||
import Ses from './mail-driver/SesMailDriver.vue'
|
||||
import Basic from './mail-driver/BasicMailDriver.vue'
|
||||
import { useMailDriverStore } from '@/scripts/admin/stores/mail-driver'
|
||||
import { ref } from 'vue'
|
||||
<script setup>
|
||||
import { computed, ref, inject, onMounted } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { useMailSenderStore } from '@/scripts/admin/stores/mail-sender'
|
||||
import { useVuelidate } from '@vuelidate/core'
|
||||
import { required, email, minLength, helpers } from '@vuelidate/validators'
|
||||
import MailSenderDropdown from '@/scripts/admin/components/dropdowns/MailSenderIndexDropdown.vue'
|
||||
import MailSenderTestModal from '@/scripts/admin/components/modal-components/MailSenderTestModal.vue'
|
||||
import SmtpDriver from '@/scripts/admin/views/settings/mail-sender/SmtpDriver.vue'
|
||||
import MailgunDriver from '@/scripts/admin/views/settings/mail-sender/MailgunDriver.vue'
|
||||
import SesDriver from '@/scripts/admin/views/settings/mail-sender/SesDriver.vue'
|
||||
|
||||
export default {
|
||||
components: {
|
||||
Smtp,
|
||||
Mailgun,
|
||||
Ses,
|
||||
sendmail: Basic,
|
||||
Mail: Basic,
|
||||
},
|
||||
const pre_t = 'settings.mail_sender'
|
||||
const mailSenderStore = useMailSenderStore()
|
||||
const { t } = useI18n()
|
||||
const table = ref(null)
|
||||
const utils = inject('utils')
|
||||
let isSaving = ref(false)
|
||||
const emit = defineEmits(['next'])
|
||||
|
||||
emits: ['next'],
|
||||
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
|
||||
}
|
||||
})
|
||||
|
||||
setup(props, { emit }) {
|
||||
const isSaving = ref(false)
|
||||
const isFetchingInitialData = ref(false)
|
||||
// This is multiple email custom validation
|
||||
const multiEmail = (value) => {
|
||||
if (value == '' || value === null) return true
|
||||
const emailRegex =
|
||||
/^(?:[A-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[A-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9]{2,}(?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])$/i
|
||||
|
||||
const mailDriverStore = useMailDriverStore()
|
||||
|
||||
mailDriverStore.mail_driver = 'mail'
|
||||
|
||||
loadData()
|
||||
|
||||
function changeDriver(value) {
|
||||
mailDriverStore.mail_driver = value
|
||||
}
|
||||
|
||||
async function loadData() {
|
||||
isFetchingInitialData.value = true
|
||||
await mailDriverStore.fetchMailDrivers()
|
||||
isFetchingInitialData.value = false
|
||||
}
|
||||
|
||||
async function next(mailConfigData) {
|
||||
isSaving.value = true
|
||||
let res = await mailDriverStore.updateMailConfig(mailConfigData)
|
||||
isSaving.value = false
|
||||
|
||||
if (res.data.success) {
|
||||
await emit('next', 5)
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
mailDriverStore,
|
||||
isSaving,
|
||||
isFetchingInitialData,
|
||||
changeDriver,
|
||||
next,
|
||||
}
|
||||
},
|
||||
const emailArr = value.split(',')
|
||||
let isValid = emailArr.every((v) => {
|
||||
return emailRegex.test(v)
|
||||
})
|
||||
return isValid
|
||||
}
|
||||
|
||||
const rules = computed(() => {
|
||||
return {
|
||||
name: {
|
||||
required: helpers.withMessage(t('validation.required'), required),
|
||||
minLength: helpers.withMessage(
|
||||
t('validation.name_min_length', { count: 3 }),
|
||||
minLength(3)
|
||||
),
|
||||
},
|
||||
from_name: {
|
||||
required: helpers.withMessage(t('validation.required'), required),
|
||||
},
|
||||
from_address: {
|
||||
required: helpers.withMessage(t('validation.required'), required),
|
||||
email: helpers.withMessage(t('validation.email_incorrect'), email),
|
||||
},
|
||||
cc: {
|
||||
multiEmail: helpers.withMessage(
|
||||
t('validation.email_incorrect'),
|
||||
multiEmail
|
||||
),
|
||||
},
|
||||
bcc: {
|
||||
multiEmail: helpers.withMessage(
|
||||
t('validation.email_incorrect'),
|
||||
multiEmail
|
||||
),
|
||||
},
|
||||
driver: {
|
||||
required: helpers.withMessage(t('validation.required'), required),
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
const v$ = useVuelidate(
|
||||
rules,
|
||||
computed(() => mailSenderStore.currentMailSender)
|
||||
)
|
||||
|
||||
async function submitMailSenderData() {
|
||||
v$.value.$touch()
|
||||
if (v$.value.$invalid) {
|
||||
return true
|
||||
}
|
||||
try {
|
||||
const action = mailSenderStore.isEdit
|
||||
? mailSenderStore.updateMailSender
|
||||
: mailSenderStore.addMailSender
|
||||
isSaving.value = true
|
||||
|
||||
var mailDriverConfig = null
|
||||
switch (mailSenderStore.currentMailSender.driver) {
|
||||
case 'smtp':
|
||||
mailDriverConfig = mailSenderStore.smtpConfig
|
||||
break
|
||||
case 'mailgun':
|
||||
mailDriverConfig = mailSenderStore.mailgunConfig
|
||||
break
|
||||
case 'ses':
|
||||
mailDriverConfig = mailSenderStore.sesConfig
|
||||
break
|
||||
}
|
||||
mailSenderStore.currentMailSender.settings = mailDriverConfig
|
||||
|
||||
let res = await action(mailSenderStore.currentMailSender)
|
||||
emit('next')
|
||||
isSaving.value = false
|
||||
} catch (err) {
|
||||
isSaving.value = false
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
await mailSenderStore.fetchMailDrivers()
|
||||
})
|
||||
</script>
|
||||
|
||||
@ -1,158 +0,0 @@
|
||||
<template>
|
||||
<form @submit.prevent="saveEmailConfig">
|
||||
<BaseInputGrid>
|
||||
<BaseInputGroup
|
||||
:label="$t('settings.mail.driver')"
|
||||
:content-loading="isFetchingInitialData"
|
||||
:error="
|
||||
v$.basicMailConfig.mail_driver.$error &&
|
||||
v$.basicMailConfig.mail_driver.$errors[0].$message
|
||||
"
|
||||
required
|
||||
>
|
||||
<BaseMultiselect
|
||||
v-model="mailDriverStore.basicMailConfig.mail_driver"
|
||||
:content-loading="isFetchingInitialData"
|
||||
:options="mailDrivers"
|
||||
:can-deselect="false"
|
||||
:invalid="v$.basicMailConfig.mail_driver.$error"
|
||||
@update:modelValue="onChangeDriver"
|
||||
/>
|
||||
</BaseInputGroup>
|
||||
|
||||
<BaseInputGroup
|
||||
:label="$t('settings.mail.from_mail')"
|
||||
:content-loading="isFetchingInitialData"
|
||||
:error="
|
||||
v$.basicMailConfig.from_mail.$error &&
|
||||
v$.basicMailConfig.from_mail.$errors[0].$message
|
||||
"
|
||||
required
|
||||
>
|
||||
<BaseInput
|
||||
v-model.trim="mailDriverStore.basicMailConfig.from_mail"
|
||||
:content-loading="isFetchingInitialData"
|
||||
type="text"
|
||||
name="from_mail"
|
||||
:invalid="v$.basicMailConfig.from_mail.$error"
|
||||
@input="v$.basicMailConfig.from_mail.$touch()"
|
||||
/>
|
||||
</BaseInputGroup>
|
||||
|
||||
<BaseInputGroup
|
||||
:label="$t('settings.mail.from_name')"
|
||||
:content-loading="isFetchingInitialData"
|
||||
:error="
|
||||
v$.basicMailConfig.from_name.$error &&
|
||||
v$.basicMailConfig.from_name.$errors[0].$message
|
||||
"
|
||||
required
|
||||
>
|
||||
<BaseInput
|
||||
v-model.trim="mailDriverStore.basicMailConfig.from_name"
|
||||
:content-loading="isFetchingInitialData"
|
||||
type="text"
|
||||
name="name"
|
||||
:invalid="v$.basicMailConfig.from_name.$error"
|
||||
@input="v$.basicMailConfig.from_name.$touch()"
|
||||
/>
|
||||
</BaseInputGroup>
|
||||
</BaseInputGrid>
|
||||
<div class="flex mt-8">
|
||||
<BaseButton
|
||||
:content-loading="isFetchingInitialData"
|
||||
:disabled="isSaving"
|
||||
:loading="isSaving"
|
||||
variant="primary"
|
||||
type="submit"
|
||||
>
|
||||
<template #left="slotProps">
|
||||
<BaseIcon v-if="!isSaving" :class="slotProps.class" name="SaveIcon" />
|
||||
</template>
|
||||
{{ $t('general.save') }}
|
||||
</BaseButton>
|
||||
<slot />
|
||||
</div>
|
||||
</form>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { onMounted, computed } from 'vue'
|
||||
import { required, email, helpers } from '@vuelidate/validators'
|
||||
import useVuelidate from '@vuelidate/core'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { useMailDriverStore } from '@/scripts/admin/stores/mail-driver'
|
||||
|
||||
const props = defineProps({
|
||||
configData: {
|
||||
type: Object,
|
||||
require: true,
|
||||
default: Object,
|
||||
},
|
||||
isSaving: {
|
||||
type: Boolean,
|
||||
require: true,
|
||||
default: false,
|
||||
},
|
||||
isFetchingInitialData: {
|
||||
type: Boolean,
|
||||
require: true,
|
||||
default: false,
|
||||
},
|
||||
mailDrivers: {
|
||||
type: Array,
|
||||
require: true,
|
||||
default: Array,
|
||||
},
|
||||
})
|
||||
|
||||
const emit = defineEmits(['submit-data', 'on-change-driver'])
|
||||
|
||||
const mailDriverStore = useMailDriverStore()
|
||||
const { t } = useI18n()
|
||||
|
||||
const rules = computed(() => {
|
||||
return {
|
||||
basicMailConfig: {
|
||||
mail_driver: {
|
||||
required: helpers.withMessage(t('validation.required'), required),
|
||||
},
|
||||
from_mail: {
|
||||
required: helpers.withMessage(t('validation.required'), required),
|
||||
email: helpers.withMessage(t('validation.email_incorrect'), email),
|
||||
},
|
||||
from_name: {
|
||||
required: helpers.withMessage(t('validation.required'), required),
|
||||
},
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
const v$ = useVuelidate(
|
||||
rules,
|
||||
computed(() => mailDriverStore)
|
||||
)
|
||||
|
||||
onMounted(() => {
|
||||
for (const key in mailDriverStore.basicMailConfig) {
|
||||
if (props.configData.hasOwnProperty(key)) {
|
||||
mailDriverStore.$patch((state) => {
|
||||
state.basicMailConfig[key] = props.configData[key]
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
async function saveEmailConfig() {
|
||||
v$.value.basicMailConfig.$touch()
|
||||
if (!v$.value.basicMailConfig.$invalid) {
|
||||
emit('submit-data', mailDriverStore.basicMailConfig)
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
function onChangeDriver() {
|
||||
v$.value.basicMailConfig.mail_driver.$touch()
|
||||
emit('on-change-driver', mailDriverStore.basicMailConfig.mail_driver)
|
||||
}
|
||||
</script>
|
||||
@ -1,247 +0,0 @@
|
||||
<template>
|
||||
<form @submit.prevent="saveEmailConfig">
|
||||
<BaseInputGrid>
|
||||
<BaseInputGroup
|
||||
:label="$t('settings.mail.driver')"
|
||||
:content-loading="isFetchingInitialData"
|
||||
:error="
|
||||
v$.mailgunConfig.mail_driver.$error &&
|
||||
v$.mailgunConfig.mail_driver.$errors[0].$message
|
||||
"
|
||||
required
|
||||
>
|
||||
<BaseMultiselect
|
||||
v-model="mailDriverStore.mailgunConfig.mail_driver"
|
||||
:content-loading="isFetchingInitialData"
|
||||
:options="mailDrivers"
|
||||
:can-deselect="false"
|
||||
:invalid="v$.mailgunConfig.mail_driver.$error"
|
||||
@update:modelValue="onChangeDriver"
|
||||
/>
|
||||
</BaseInputGroup>
|
||||
|
||||
<BaseInputGroup
|
||||
:label="$t('settings.mail.mailgun_domain')"
|
||||
:content-loading="isFetchingInitialData"
|
||||
:error="
|
||||
v$.mailgunConfig.mail_mailgun_domain.$error &&
|
||||
v$.mailgunConfig.mail_mailgun_domain.$errors[0].$message
|
||||
"
|
||||
required
|
||||
>
|
||||
<BaseInput
|
||||
v-model.trim="mailDriverStore.mailgunConfig.mail_mailgun_domain"
|
||||
:content-loading="isFetchingInitialData"
|
||||
type="text"
|
||||
name="mailgun_domain"
|
||||
:invalid="v$.mailgunConfig.mail_mailgun_domain.$error"
|
||||
@input="v$.mailgunConfig.mail_mailgun_domain.$touch()"
|
||||
/>
|
||||
</BaseInputGroup>
|
||||
|
||||
<BaseInputGroup
|
||||
:label="$t('settings.mail.mailgun_secret')"
|
||||
:content-loading="isFetchingInitialData"
|
||||
:error="
|
||||
v$.mailgunConfig.mail_mailgun_secret.$error &&
|
||||
v$.mailgunConfig.mail_mailgun_secret.$errors[0].$message
|
||||
"
|
||||
required
|
||||
>
|
||||
<BaseInput
|
||||
v-model.trim="mailDriverStore.mailgunConfig.mail_mailgun_secret"
|
||||
:content-loading="isFetchingInitialData"
|
||||
:type="getInputType"
|
||||
name="mailgun_secret"
|
||||
autocomplete="off"
|
||||
:invalid="v$.mailgunConfig.mail_mailgun_secret.$error"
|
||||
@input="v$.mailgunConfig.mail_mailgun_secret.$touch()"
|
||||
>
|
||||
<template #right>
|
||||
<BaseIcon
|
||||
v-if="isShowPassword"
|
||||
class="mr-1 text-gray-500 cursor-pointer"
|
||||
name="EyeOffIcon"
|
||||
@click="isShowPassword = !isShowPassword"
|
||||
/>
|
||||
<BaseIcon
|
||||
v-else
|
||||
class="mr-1 text-gray-500 cursor-pointer"
|
||||
name="EyeIcon"
|
||||
@click="isShowPassword = !isShowPassword"
|
||||
/>
|
||||
</template>
|
||||
</BaseInput>
|
||||
</BaseInputGroup>
|
||||
|
||||
<BaseInputGroup
|
||||
:label="$t('settings.mail.mailgun_endpoint')"
|
||||
:content-loading="isFetchingInitialData"
|
||||
:error="
|
||||
v$.mailgunConfig.mail_mailgun_endpoint.$error &&
|
||||
v$.mailgunConfig.mail_mailgun_endpoint.$errors[0].$message
|
||||
"
|
||||
required
|
||||
>
|
||||
<BaseInput
|
||||
v-model.trim="mailDriverStore.mailgunConfig.mail_mailgun_endpoint"
|
||||
:content-loading="isFetchingInitialData"
|
||||
type="text"
|
||||
name="mailgun_endpoint"
|
||||
:invalid="v$.mailgunConfig.mail_mailgun_endpoint.$error"
|
||||
@input="v$.mailgunConfig.mail_mailgun_endpoint.$touch()"
|
||||
/>
|
||||
</BaseInputGroup>
|
||||
|
||||
<BaseInputGroup
|
||||
:label="$t('settings.mail.from_mail')"
|
||||
:content-loading="isFetchingInitialData"
|
||||
:error="
|
||||
v$.mailgunConfig.from_mail.$error &&
|
||||
v$.mailgunConfig.from_mail.$errors[0].$message
|
||||
"
|
||||
required
|
||||
>
|
||||
<BaseInput
|
||||
v-model.trim="mailDriverStore.mailgunConfig.from_mail"
|
||||
:content-loading="isFetchingInitialData"
|
||||
type="text"
|
||||
name="from_mail"
|
||||
:invalid="v$.mailgunConfig.from_mail.$error"
|
||||
@input="v$.mailgunConfig.from_mail.$touch()"
|
||||
/>
|
||||
</BaseInputGroup>
|
||||
|
||||
<BaseInputGroup
|
||||
:label="$t('settings.mail.from_name')"
|
||||
:content-loading="isFetchingInitialData"
|
||||
:error="
|
||||
v$.mailgunConfig.from_name.$error &&
|
||||
v$.mailgunConfig.from_name.$errors[0].$message
|
||||
"
|
||||
required
|
||||
>
|
||||
<BaseInput
|
||||
v-model.trim="mailDriverStore.mailgunConfig.from_name"
|
||||
:content-loading="isFetchingInitialData"
|
||||
type="text"
|
||||
name="from_name"
|
||||
:invalid="v$.mailgunConfig.from_name.$error"
|
||||
@input="v$.mailgunConfig.from_name.$touch()"
|
||||
/>
|
||||
</BaseInputGroup>
|
||||
</BaseInputGrid>
|
||||
<div class="flex my-10">
|
||||
<BaseButton
|
||||
:disabled="isSaving"
|
||||
:content-loading="isFetchingInitialData"
|
||||
:loading="isSaving"
|
||||
variant="primary"
|
||||
type="submit"
|
||||
>
|
||||
<template #left="slotProps">
|
||||
<BaseIcon v-if="!isSaving" name="SaveIcon" :class="slotProps.class" />
|
||||
</template>
|
||||
{{ $t('general.save') }}
|
||||
</BaseButton>
|
||||
<slot />
|
||||
</div>
|
||||
</form>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { onMounted, ref, computed } from 'vue'
|
||||
import { required, email, helpers } from '@vuelidate/validators'
|
||||
import useVuelidate from '@vuelidate/core'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { useMailDriverStore } from '@/scripts/admin/stores/mail-driver'
|
||||
|
||||
const props = defineProps({
|
||||
configData: {
|
||||
type: Object,
|
||||
require: true,
|
||||
default: Object,
|
||||
},
|
||||
isSaving: {
|
||||
type: Boolean,
|
||||
require: true,
|
||||
default: false,
|
||||
},
|
||||
isFetchingInitialData: {
|
||||
type: Boolean,
|
||||
require: true,
|
||||
default: false,
|
||||
},
|
||||
mailDrivers: {
|
||||
type: Array,
|
||||
require: true,
|
||||
default: Array,
|
||||
},
|
||||
})
|
||||
|
||||
const emit = defineEmits(['submit-data', 'on-change-driver'])
|
||||
|
||||
const mailDriverStore = useMailDriverStore()
|
||||
const { t } = useI18n()
|
||||
|
||||
let isShowPassword = ref(false)
|
||||
|
||||
const getInputType = computed(() => {
|
||||
if (isShowPassword.value) {
|
||||
return 'text'
|
||||
}
|
||||
return 'password'
|
||||
})
|
||||
|
||||
const rules = computed(() => {
|
||||
return {
|
||||
mailgunConfig: {
|
||||
mail_driver: {
|
||||
required: helpers.withMessage(t('validation.required'), required),
|
||||
},
|
||||
mail_mailgun_domain: {
|
||||
required: helpers.withMessage(t('validation.required'), required),
|
||||
},
|
||||
mail_mailgun_endpoint: {
|
||||
required: helpers.withMessage(t('validation.required'), required),
|
||||
},
|
||||
mail_mailgun_secret: {
|
||||
required: helpers.withMessage(t('validation.required'), required),
|
||||
},
|
||||
from_mail: {
|
||||
required: helpers.withMessage(t('validation.required'), required),
|
||||
email,
|
||||
},
|
||||
from_name: {
|
||||
required: helpers.withMessage(t('validation.required'), required),
|
||||
},
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
const v$ = useVuelidate(
|
||||
rules,
|
||||
computed(() => mailDriverStore)
|
||||
)
|
||||
|
||||
onMounted(() => {
|
||||
for (const key in mailDriverStore.mailgunConfig) {
|
||||
if (props.configData.hasOwnProperty(key)) {
|
||||
mailDriverStore.mailgunConfig[key] = props.configData[key]
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
async function saveEmailConfig() {
|
||||
v$.value.mailgunConfig.$touch()
|
||||
if (!v$.value.mailgunConfig.$invalid) {
|
||||
emit('submit-data', mailDriverStore.mailgunConfig)
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
function onChangeDriver() {
|
||||
v$.value.mailgunConfig.mail_driver.$touch()
|
||||
emit('on-change-driver', mailDriverStore.mailgunConfig.mail_driver)
|
||||
}
|
||||
</script>
|
||||
@ -1,294 +0,0 @@
|
||||
<template>
|
||||
<form @submit.prevent="saveEmailConfig">
|
||||
<BaseInputGrid>
|
||||
<BaseInputGroup
|
||||
:label="$t('settings.mail.driver')"
|
||||
:content-loading="isFetchingInitialData"
|
||||
:error="
|
||||
v$.sesConfig.mail_driver.$error &&
|
||||
v$.sesConfig.mail_driver.$errors[0].$message
|
||||
"
|
||||
required
|
||||
>
|
||||
<BaseMultiselect
|
||||
v-model="mailDriverStore.sesConfig.mail_driver"
|
||||
:content-loading="isFetchingInitialData"
|
||||
:options="mailDrivers"
|
||||
:can-deselect="false"
|
||||
:invalid="v$.sesConfig.mail_driver.$error"
|
||||
@update:modelValue="onChangeDriver"
|
||||
/>
|
||||
</BaseInputGroup>
|
||||
|
||||
<BaseInputGroup
|
||||
:label="$t('settings.mail.host')"
|
||||
:content-loading="isFetchingInitialData"
|
||||
:error="
|
||||
v$.sesConfig.mail_host.$error &&
|
||||
v$.sesConfig.mail_host.$errors[0].$message
|
||||
"
|
||||
required
|
||||
>
|
||||
<BaseInput
|
||||
v-model.trim="mailDriverStore.sesConfig.mail_host"
|
||||
:content-loading="isFetchingInitialData"
|
||||
type="text"
|
||||
name="mail_host"
|
||||
:invalid="v$.sesConfig.mail_host.$error"
|
||||
@input="v$.sesConfig.mail_host.$touch()"
|
||||
/>
|
||||
</BaseInputGroup>
|
||||
|
||||
<BaseInputGroup
|
||||
:label="$t('settings.mail.port')"
|
||||
:content-loading="isFetchingInitialData"
|
||||
:error="
|
||||
v$.sesConfig.mail_port.$error &&
|
||||
v$.sesConfig.mail_port.$errors[0].$message
|
||||
"
|
||||
required
|
||||
>
|
||||
<BaseInput
|
||||
v-model.trim="mailDriverStore.sesConfig.mail_port"
|
||||
:content-loading="isFetchingInitialData"
|
||||
type="text"
|
||||
name="mail_port"
|
||||
:invalid="v$.sesConfig.mail_port.$error"
|
||||
@input="v$.sesConfig.mail_port.$touch()"
|
||||
/>
|
||||
</BaseInputGroup>
|
||||
|
||||
<BaseInputGroup
|
||||
:label="$t('settings.mail.encryption')"
|
||||
:content-loading="isFetchingInitialData"
|
||||
:error="
|
||||
v$.sesConfig.mail_encryption.$error &&
|
||||
v$.sesConfig.mail_encryption.$errors[0].$message
|
||||
"
|
||||
required
|
||||
>
|
||||
<BaseMultiselect
|
||||
v-model.trim="mailDriverStore.sesConfig.mail_encryption"
|
||||
:content-loading="isFetchingInitialData"
|
||||
:options="encryptions"
|
||||
:invalid="v$.sesConfig.mail_encryption.$error"
|
||||
placeholder="Select option"
|
||||
@input="v$.sesConfig.mail_encryption.$touch()"
|
||||
/>
|
||||
</BaseInputGroup>
|
||||
|
||||
<BaseInputGroup
|
||||
:label="$t('settings.mail.from_mail')"
|
||||
:content-loading="isFetchingInitialData"
|
||||
:error="
|
||||
v$.sesConfig.from_mail.$error &&
|
||||
v$.sesConfig.from_mail.$errors[0].$message
|
||||
"
|
||||
required
|
||||
>
|
||||
<BaseInput
|
||||
v-model.trim="mailDriverStore.sesConfig.from_mail"
|
||||
:content-loading="isFetchingInitialData"
|
||||
type="text"
|
||||
name="from_mail"
|
||||
:invalid="v$.sesConfig.from_mail.$error"
|
||||
@input="v$.sesConfig.from_mail.$touch()"
|
||||
/>
|
||||
</BaseInputGroup>
|
||||
|
||||
<BaseInputGroup
|
||||
:label="$t('settings.mail.from_name')"
|
||||
:content-loading="isFetchingInitialData"
|
||||
:error="
|
||||
v$.sesConfig.from_name.$error &&
|
||||
v$.sesConfig.from_name.$errors[0].$message
|
||||
"
|
||||
required
|
||||
>
|
||||
<BaseInput
|
||||
v-model.trim="mailDriverStore.sesConfig.from_name"
|
||||
:content-loading="isFetchingInitialData"
|
||||
type="text"
|
||||
name="name"
|
||||
:invalid="v$.sesConfig.from_name.$error"
|
||||
@input="v$.sesConfig.from_name.$touch()"
|
||||
/>
|
||||
</BaseInputGroup>
|
||||
|
||||
<BaseInputGroup
|
||||
:label="$t('settings.mail.ses_key')"
|
||||
:content-loading="isFetchingInitialData"
|
||||
:error="
|
||||
v$.sesConfig.mail_ses_key.$error &&
|
||||
v$.sesConfig.mail_ses_key.$errors[0].$message
|
||||
"
|
||||
required
|
||||
>
|
||||
<BaseInput
|
||||
v-model.trim="mailDriverStore.sesConfig.mail_ses_key"
|
||||
:content-loading="isFetchingInitialData"
|
||||
type="text"
|
||||
name="mail_ses_key"
|
||||
:invalid="v$.sesConfig.mail_ses_key.$error"
|
||||
@input="v$.sesConfig.mail_ses_key.$touch()"
|
||||
/>
|
||||
</BaseInputGroup>
|
||||
|
||||
<BaseInputGroup
|
||||
:label="$t('settings.mail.ses_secret')"
|
||||
:content-loading="isFetchingInitialData"
|
||||
:error="
|
||||
v$.sesConfig.mail_ses_secret.$error &&
|
||||
v$.mail_ses_secret.$errors[0].$message
|
||||
"
|
||||
required
|
||||
>
|
||||
<BaseInput
|
||||
v-model.trim="mailDriverStore.sesConfig.mail_ses_secret"
|
||||
:content-loading="isFetchingInitialData"
|
||||
:type="getInputType"
|
||||
name="mail_ses_secret"
|
||||
autocomplete="off"
|
||||
:invalid="v$.sesConfig.mail_ses_secret.$error"
|
||||
@input="v$.sesConfig.mail_ses_secret.$touch()"
|
||||
>
|
||||
<template #right>
|
||||
<BaseIcon
|
||||
v-if="isShowPassword"
|
||||
class="mr-1 text-gray-500 cursor-pointer"
|
||||
name="EyeOffIcon"
|
||||
@click="isShowPassword = !isShowPassword"
|
||||
/>
|
||||
<BaseIcon
|
||||
v-else
|
||||
class="mr-1 text-gray-500 cursor-pointer"
|
||||
name="EyeIcon"
|
||||
@click="isShowPassword = !isShowPassword"
|
||||
/>
|
||||
</template>
|
||||
</BaseInput>
|
||||
</BaseInputGroup>
|
||||
</BaseInputGrid>
|
||||
|
||||
<div class="flex my-10">
|
||||
<BaseButton
|
||||
:disabled="isSaving"
|
||||
:content-loading="isFetchingInitialData"
|
||||
:loading="isSaving"
|
||||
variant="primary"
|
||||
type="submit"
|
||||
>
|
||||
<template #left="slotProps">
|
||||
<BaseIcon v-if="!isSaving" name="SaveIcon" :class="slotProps.class" />
|
||||
</template>
|
||||
{{ $t('general.save') }}
|
||||
</BaseButton>
|
||||
<slot />
|
||||
</div>
|
||||
</form>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { computed, onMounted, reactive, ref } from 'vue'
|
||||
import { required, email, numeric, helpers } from '@vuelidate/validators'
|
||||
import useVuelidate from '@vuelidate/core'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { useMailDriverStore } from '@/scripts/admin/stores/mail-driver'
|
||||
|
||||
const props = defineProps({
|
||||
configData: {
|
||||
type: Object,
|
||||
require: true,
|
||||
default: Object,
|
||||
},
|
||||
isSaving: {
|
||||
type: Boolean,
|
||||
require: true,
|
||||
default: false,
|
||||
},
|
||||
isFetchingInitialData: {
|
||||
type: Boolean,
|
||||
require: true,
|
||||
default: false,
|
||||
},
|
||||
mailDrivers: {
|
||||
type: Array,
|
||||
require: true,
|
||||
default: Array,
|
||||
},
|
||||
})
|
||||
|
||||
const emit = defineEmits(['submit-data', 'on-change-driver'])
|
||||
|
||||
const mailDriverStore = useMailDriverStore()
|
||||
const { t } = useI18n()
|
||||
|
||||
let isShowPassword = ref(false)
|
||||
const encryptions = reactive(['tls', 'ssl', 'starttls'])
|
||||
|
||||
const rules = computed(() => {
|
||||
return {
|
||||
sesConfig: {
|
||||
mail_driver: {
|
||||
required: helpers.withMessage(t('validation.required'), required),
|
||||
},
|
||||
mail_host: {
|
||||
required: helpers.withMessage(t('validation.required'), required),
|
||||
},
|
||||
mail_port: {
|
||||
required: helpers.withMessage(t('validation.required'), required),
|
||||
numeric,
|
||||
},
|
||||
mail_ses_key: {
|
||||
required: helpers.withMessage(t('validation.required'), required),
|
||||
},
|
||||
mail_ses_secret: {
|
||||
required: helpers.withMessage(t('validation.required'), required),
|
||||
},
|
||||
mail_encryption: {
|
||||
required: helpers.withMessage(t('validation.required'), required),
|
||||
},
|
||||
from_mail: {
|
||||
required: helpers.withMessage(t('validation.required'), required),
|
||||
email: helpers.withMessage(t('validation.email_incorrect'), email),
|
||||
},
|
||||
from_name: {
|
||||
required: helpers.withMessage(t('validation.required'), required),
|
||||
},
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
const v$ = useVuelidate(
|
||||
rules,
|
||||
computed(() => mailDriverStore)
|
||||
)
|
||||
|
||||
const getInputType = computed(() => {
|
||||
if (isShowPassword.value) {
|
||||
return 'text'
|
||||
}
|
||||
return 'password'
|
||||
})
|
||||
|
||||
onMounted(() => {
|
||||
for (const key in mailDriverStore.sesConfig) {
|
||||
if (props.configData.hasOwnProperty(key)) {
|
||||
mailDriverStore.sesConfig[key] = props.configData[key]
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
async function saveEmailConfig() {
|
||||
v$.value.sesConfig.$touch()
|
||||
if (!v$.value.sesConfig.$invalid) {
|
||||
emit('submit-data', mailDriverStore.sesConfig)
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
function onChangeDriver() {
|
||||
v$.value.sesConfig.mail_driver.$touch()
|
||||
emit('on-change-driver', mailDriverStore.sesConfig.mail_driver)
|
||||
}
|
||||
</script>
|
||||
@ -1,275 +0,0 @@
|
||||
<template>
|
||||
<form @submit.prevent="saveEmailConfig">
|
||||
<BaseInputGrid>
|
||||
<BaseInputGroup
|
||||
:label="$t('settings.mail.driver')"
|
||||
:content-loading="isFetchingInitialData"
|
||||
:error="
|
||||
v$.smtpConfig.mail_driver.$error &&
|
||||
v$.smtpConfig.mail_driver.$errors[0].$message
|
||||
"
|
||||
required
|
||||
>
|
||||
<BaseMultiselect
|
||||
v-model="mailDriverStore.smtpConfig.mail_driver"
|
||||
:content-loading="isFetchingInitialData"
|
||||
:options="mailDrivers"
|
||||
:can-deselect="false"
|
||||
:invalid="v$.smtpConfig.mail_driver.$error"
|
||||
@update:modelValue="onChangeDriver"
|
||||
/>
|
||||
</BaseInputGroup>
|
||||
|
||||
<BaseInputGroup
|
||||
:label="$t('settings.mail.host')"
|
||||
:content-loading="isFetchingInitialData"
|
||||
:error="
|
||||
v$.smtpConfig.mail_host.$error &&
|
||||
v$.smtpConfig.mail_host.$errors[0].$message
|
||||
"
|
||||
required
|
||||
>
|
||||
<BaseInput
|
||||
v-model.trim="mailDriverStore.smtpConfig.mail_host"
|
||||
:content-loading="isFetchingInitialData"
|
||||
type="text"
|
||||
name="mail_host"
|
||||
:invalid="v$.smtpConfig.mail_host.$error"
|
||||
@input="v$.smtpConfig.mail_host.$touch()"
|
||||
/>
|
||||
</BaseInputGroup>
|
||||
|
||||
<BaseInputGroup
|
||||
:content-loading="isFetchingInitialData"
|
||||
:label="$t('settings.mail.username')"
|
||||
>
|
||||
<BaseInput
|
||||
v-model.trim="mailDriverStore.smtpConfig.mail_username"
|
||||
:content-loading="isFetchingInitialData"
|
||||
type="text"
|
||||
name="db_name"
|
||||
/>
|
||||
</BaseInputGroup>
|
||||
|
||||
<BaseInputGroup
|
||||
:content-loading="isFetchingInitialData"
|
||||
:label="$t('settings.mail.password')"
|
||||
>
|
||||
<BaseInput
|
||||
v-model.trim="mailDriverStore.smtpConfig.mail_password"
|
||||
:content-loading="isFetchingInitialData"
|
||||
:type="getInputType"
|
||||
name="password"
|
||||
>
|
||||
<template #right>
|
||||
<BaseIcon
|
||||
v-if="isShowPassword"
|
||||
class="mr-1 text-gray-500 cursor-pointer"
|
||||
name="EyeOffIcon"
|
||||
@click="isShowPassword = !isShowPassword"
|
||||
/>
|
||||
<BaseIcon
|
||||
v-else
|
||||
class="mr-1 text-gray-500 cursor-pointer"
|
||||
name="EyeIcon"
|
||||
@click="isShowPassword = !isShowPassword"
|
||||
/>
|
||||
</template>
|
||||
</BaseInput>
|
||||
</BaseInputGroup>
|
||||
|
||||
<BaseInputGroup
|
||||
:label="$t('settings.mail.port')"
|
||||
:content-loading="isFetchingInitialData"
|
||||
:error="
|
||||
v$.smtpConfig.mail_port.$error &&
|
||||
v$.smtpConfig.mail_port.$errors[0].$message
|
||||
"
|
||||
required
|
||||
>
|
||||
<BaseInput
|
||||
v-model.trim="mailDriverStore.smtpConfig.mail_port"
|
||||
:content-loading="isFetchingInitialData"
|
||||
type="text"
|
||||
name="mail_port"
|
||||
:invalid="v$.smtpConfig.mail_port.$error"
|
||||
@input="v$.smtpConfig.mail_port.$touch()"
|
||||
/>
|
||||
</BaseInputGroup>
|
||||
|
||||
<BaseInputGroup
|
||||
:label="$t('settings.mail.encryption')"
|
||||
:content-loading="isFetchingInitialData"
|
||||
:error="
|
||||
v$.smtpConfig.mail_encryption.$error &&
|
||||
v$.smtpConfig.mail_encryption.$errors[0].$message
|
||||
"
|
||||
required
|
||||
>
|
||||
<BaseMultiselect
|
||||
v-model.trim="mailDriverStore.smtpConfig.mail_encryption"
|
||||
:content-loading="isFetchingInitialData"
|
||||
:options="encryptions"
|
||||
:searchable="true"
|
||||
:show-labels="false"
|
||||
placeholder="Select option"
|
||||
:invalid="v$.smtpConfig.mail_encryption.$error"
|
||||
@input="v$.smtpConfig.mail_encryption.$touch()"
|
||||
/>
|
||||
</BaseInputGroup>
|
||||
|
||||
<BaseInputGroup
|
||||
:label="$t('settings.mail.from_mail')"
|
||||
:content-loading="isFetchingInitialData"
|
||||
:error="
|
||||
v$.smtpConfig.from_mail.$error &&
|
||||
v$.smtpConfig.from_mail.$errors[0].$message
|
||||
"
|
||||
required
|
||||
>
|
||||
<BaseInput
|
||||
v-model.trim="mailDriverStore.smtpConfig.from_mail"
|
||||
:content-loading="isFetchingInitialData"
|
||||
type="text"
|
||||
name="from_mail"
|
||||
:invalid="v$.smtpConfig.from_mail.$error"
|
||||
@input="v$.smtpConfig.from_mail.$touch()"
|
||||
/>
|
||||
</BaseInputGroup>
|
||||
|
||||
<BaseInputGroup
|
||||
:label="$t('settings.mail.from_name')"
|
||||
:content-loading="isFetchingInitialData"
|
||||
:error="
|
||||
v$.smtpConfig.from_name.$error &&
|
||||
v$.smtpConfig.from_name.$errors[0].$message
|
||||
"
|
||||
required
|
||||
>
|
||||
<BaseInput
|
||||
v-model.trim="mailDriverStore.smtpConfig.from_name"
|
||||
:content-loading="isFetchingInitialData"
|
||||
type="text"
|
||||
name="from_name"
|
||||
:invalid="v$.smtpConfig.from_name.$error"
|
||||
@input="v$.smtpConfig.from_name.$touch()"
|
||||
/>
|
||||
</BaseInputGroup>
|
||||
</BaseInputGrid>
|
||||
|
||||
<div class="flex my-10">
|
||||
<BaseButton
|
||||
:disabled="isSaving"
|
||||
:content-loading="isFetchingInitialData"
|
||||
:loading="isSaving"
|
||||
type="submit"
|
||||
variant="primary"
|
||||
>
|
||||
<template #left="slotProps">
|
||||
<BaseIcon v-if="!isSaving" name="SaveIcon" :class="slotProps.class" />
|
||||
</template>
|
||||
{{ $t('general.save') }}
|
||||
</BaseButton>
|
||||
<slot />
|
||||
</div>
|
||||
</form>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { reactive, onMounted, ref, computed } from 'vue'
|
||||
import { required, email, numeric, helpers } from '@vuelidate/validators'
|
||||
import useVuelidate from '@vuelidate/core'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { useMailDriverStore } from '@/scripts/admin/stores/mail-driver'
|
||||
|
||||
const props = defineProps({
|
||||
configData: {
|
||||
type: Object,
|
||||
require: true,
|
||||
default: Object,
|
||||
},
|
||||
isSaving: {
|
||||
type: Boolean,
|
||||
require: true,
|
||||
default: false,
|
||||
},
|
||||
isFetchingInitialData: {
|
||||
type: Boolean,
|
||||
require: true,
|
||||
default: false,
|
||||
},
|
||||
mailDrivers: {
|
||||
type: Array,
|
||||
require: true,
|
||||
default: Array,
|
||||
},
|
||||
})
|
||||
|
||||
const emit = defineEmits(['submit-data', 'on-change-driver'])
|
||||
|
||||
const mailDriverStore = useMailDriverStore()
|
||||
const { t } = useI18n()
|
||||
|
||||
let isShowPassword = ref(false)
|
||||
const encryptions = reactive(['tls', 'ssl', 'starttls'])
|
||||
|
||||
const getInputType = computed(() => {
|
||||
if (isShowPassword.value) {
|
||||
return 'text'
|
||||
}
|
||||
return 'password'
|
||||
})
|
||||
|
||||
const rules = computed(() => {
|
||||
return {
|
||||
smtpConfig: {
|
||||
mail_driver: {
|
||||
required: helpers.withMessage(t('validation.required'), required),
|
||||
},
|
||||
mail_host: {
|
||||
required: helpers.withMessage(t('validation.required'), required),
|
||||
},
|
||||
mail_port: {
|
||||
required: helpers.withMessage(t('validation.required'), required),
|
||||
numeric: helpers.withMessage(t('validation.numbers_only'), numeric),
|
||||
},
|
||||
mail_encryption: {
|
||||
required: helpers.withMessage(t('validation.required'), required),
|
||||
},
|
||||
from_mail: {
|
||||
required: helpers.withMessage(t('validation.required'), required),
|
||||
email: helpers.withMessage(t('validation.email_incorrect'), email),
|
||||
},
|
||||
from_name: {
|
||||
required: helpers.withMessage(t('validation.required'), required),
|
||||
},
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
const v$ = useVuelidate(
|
||||
rules,
|
||||
computed(() => mailDriverStore)
|
||||
)
|
||||
|
||||
onMounted(() => {
|
||||
for (const key in mailDriverStore.smtpConfig) {
|
||||
if (props.configData.hasOwnProperty(key)) {
|
||||
mailDriverStore.smtpConfig[key] = props.configData[key]
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
async function saveEmailConfig() {
|
||||
v$.value.smtpConfig.$touch()
|
||||
if (!v$.value.smtpConfig.$invalid) {
|
||||
emit('submit-data', mailDriverStore.smtpConfig)
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
function onChangeDriver() {
|
||||
v$.value.smtpConfig.mail_driver.$touch()
|
||||
emit('on-change-driver', mailDriverStore.smtpConfig.mail_driver)
|
||||
}
|
||||
</script>
|
||||
@ -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"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user