feat: move send-test sections inline — WhatsApp right panel, Email side card with account selector

This commit is contained in:
Ghassan Yusuf 2026-05-26 15:05:24 +03:00
parent b3650489af
commit 303cdf6d6e
3 changed files with 241 additions and 153 deletions

View File

@ -5,6 +5,7 @@ namespace App\Http\Controllers;
use App\Models\MailAccount; use App\Models\MailAccount;
use Illuminate\Http\JsonResponse; use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Facades\Mail;
use PromoSeven\AzureMailer\Graph\TokenManager; use PromoSeven\AzureMailer\Graph\TokenManager;
class MailAccountController extends Controller class MailAccountController extends Controller
@ -64,6 +65,24 @@ class MailAccountController extends Controller
} }
} }
public function sendTestEmail(Request $request, MailAccount $mailAccount): JsonResponse
{
$request->validate(['to' => ['required', 'email', 'max:255']]);
try {
Mail::mailer($mailAccount->name)->raw(
'This is a test email from SteelERP. Your mail account "' . $mailAccount->label . '" is working correctly.',
function ($message) use ($request, $mailAccount) {
$message->to($request->to)
->from($mailAccount->from_address, $mailAccount->from_name ?: 'SteelERP')
->subject('Test Email from SteelERP');
}
);
return response()->json(['success' => true]);
} catch (\Exception $e) {
return response()->json(['success' => false, 'message' => $e->getMessage()]);
}
}
public function toggleEnabled(MailAccount $mailAccount): JsonResponse public function toggleEnabled(MailAccount $mailAccount): JsonResponse
{ {
$mailAccount->update(['enabled' => ! $mailAccount->enabled]); $mailAccount->update(['enabled' => ! $mailAccount->enabled]);

View File

@ -8,7 +8,7 @@
<p class="page-subtitle">Configure third-party service integrations.</p> <p class="page-subtitle">Configure third-party service integrations.</p>
</div> </div>
<div style="max-width:680px;" x-data="{ tab: 'whatsapp' }"> <div style="max-width:900px;" x-data="{ tab: 'whatsapp' }">
{{-- Pill tabs --}} {{-- Pill tabs --}}
<div style="display:flex;gap:8px;margin-bottom:20px;"> <div style="display:flex;gap:8px;margin-bottom:20px;">
@ -35,155 +35,152 @@
<h3 style="font-size:16px;font-weight:600;color:#111827;margin:0;">WhatsApp (UltraMSG)</h3> <h3 style="font-size:16px;font-weight:600;color:#111827;margin:0;">WhatsApp (UltraMSG)</h3>
</div> </div>
<div style="padding:24px;"> {{-- Two-column body --}}
<div style="display:flex;gap:0;align-items:stretch;">
{{-- Enable toggle --}} {{-- Left: Settings form --}}
<div style="display:flex;align-items:center;justify-content:space-between;margin-bottom:20px;"> <div style="flex:1;padding:24px;border-right:1px solid #e5e7eb;">
<div>
<p style="font-size:14px;font-weight:500;color:#374151;margin:0 0 2px;">Enable WhatsApp Notifications</p> {{-- Enable toggle --}}
<p style="font-size:12px;color:#6b7280;margin:0;">When disabled, no messages will be sent.</p> <div style="display:flex;align-items:center;justify-content:space-between;margin-bottom:20px;">
</div> <div>
<div style="position:relative;display:inline-flex;align-items:center;cursor:pointer;"> <p style="font-size:14px;font-weight:500;color:#374151;margin:0 0 2px;">Enable WhatsApp Notifications</p>
<input type="hidden" id="wa-enabled-hidden" value="{{ $whatsappSettings['enabled'] ? '1' : '0' }}"> <p style="font-size:12px;color:#6b7280;margin:0;">When disabled, no messages will be sent.</p>
<div id="wa-toggle-track" onclick="toggleWaSwitch()" style=" </div>
width:44px;height:24px;border-radius:12px;cursor:pointer; <div style="position:relative;display:inline-flex;align-items:center;cursor:pointer;">
background:{{ $whatsappSettings['enabled'] ? '#22c55e' : '#d1d5db' }}; <input type="hidden" id="wa-enabled-hidden" value="{{ $whatsappSettings['enabled'] ? '1' : '0' }}">
position:relative;transition:background .2s;"> <div id="wa-toggle-track" onclick="toggleWaSwitch()" style="
<div id="wa-toggle-thumb" style=" width:44px;height:24px;border-radius:12px;cursor:pointer;
position:absolute;top:2px; background:{{ $whatsappSettings['enabled'] ? '#22c55e' : '#d1d5db' }};
left:{{ $whatsappSettings['enabled'] ? '22px' : '2px' }}; position:relative;transition:background .2s;">
width:20px;height:20px;border-radius:50%;background:#fff; <div id="wa-toggle-thumb" style="
box-shadow:0 1px 3px rgba(0,0,0,.2);transition:left .2s;"></div> position:absolute;top:2px;
left:{{ $whatsappSettings['enabled'] ? '22px' : '2px' }};
width:20px;height:20px;border-radius:50%;background:#fff;
box-shadow:0 1px 3px rgba(0,0,0,.2);transition:left .2s;"></div>
</div>
</div> </div>
</div> </div>
</div>
<hr style="border:none;border-top:1px solid #e5e7eb;margin:0 0 20px;"> <hr style="border:none;border-top:1px solid #e5e7eb;margin:0 0 20px;">
{{-- Instance ID --}} {{-- Instance ID --}}
<div style="margin-bottom:16px;"> <div style="margin-bottom:16px;">
<label class="form-label">Instance ID</label> <label class="form-label">Instance ID</label>
<input type="text" id="wa-instance-id" <input type="text" id="wa-instance-id"
value="{{ $whatsappSettings['instance_id'] }}" value="{{ $whatsappSettings['instance_id'] }}"
placeholder="e.g. instance177593" placeholder="e.g. instance177593"
class="form-input"> class="form-input">
</div>
{{-- API Token --}}
<div style="margin-bottom:16px;" x-data="{ showWaToken: false }">
<label class="form-label">API Token</label>
<div style="position:relative;">
<input :type="showWaToken ? 'text' : 'password'" id="wa-token"
value="{{ $whatsappSettings['token'] }}"
placeholder="Your UltraMSG token"
class="form-input" style="padding-right:40px;">
<button type="button" @click="showWaToken = !showWaToken"
style="position:absolute;inset-y:0;right:0;padding:0 10px;background:none;border:none;cursor:pointer;color:#9ca3af;"
onmouseover="this.style.color='#4b5563'" onmouseout="this.style.color='#9ca3af'">
<svg x-show="!showWaToken" style="width:16px;height:16px;" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 12a3 3 0 11-6 0 3 3 0 016 0z"/>
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M2.458 12C3.732 7.943 7.523 5 12 5c4.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542 7-4.477 0-8.268-2.943-9.542-7z"/>
</svg>
<svg x-show="showWaToken" style="width:16px;height:16px;" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13.875 18.825A10.05 10.05 0 0112 19c-4.478 0-8.268-2.943-9.543-7a9.97 9.97 0 011.563-3.029m5.858.908a3 3 0 114.243 4.243M9.878 9.878l4.242 4.242M9.88 9.88l-3.29-3.29m7.532 7.532l3.29 3.29M3 3l3.59 3.59m0 0A9.953 9.953 0 0112 5c4.478 0 8.268 2.943 9.543 7a10.025 10.025 0 01-4.132 4.411m0 0L21 21"/>
</svg>
</button>
</div> </div>
</div>
{{-- Webhook Secret --}} {{-- API Token --}}
<div style="margin-bottom:16px;" x-data="{ showWaSecret: false }"> <div style="margin-bottom:16px;" x-data="{ showWaToken: false }">
<label class="form-label"> <label class="form-label">API Token</label>
Webhook Secret <span style="color:#9ca3af;font-weight:400;">(optional)</span> <div style="position:relative;">
</label> <input :type="showWaToken ? 'text' : 'password'" id="wa-token"
<div style="position:relative;"> value="{{ $whatsappSettings['token'] }}"
<input :type="showWaSecret ? 'text' : 'password'" id="wa-webhook-secret" placeholder="Your UltraMSG token"
value="{{ $whatsappSettings['webhook_secret'] }}" class="form-input" style="padding-right:40px;">
placeholder="Leave empty to skip HMAC verification" <button type="button" @click="showWaToken = !showWaToken"
class="form-input" style="padding-right:40px;"> style="position:absolute;inset-y:0;right:0;padding:0 10px;background:none;border:none;cursor:pointer;color:#9ca3af;"
<button type="button" @click="showWaSecret = !showWaSecret" onmouseover="this.style.color='#4b5563'" onmouseout="this.style.color='#9ca3af'">
style="position:absolute;inset-y:0;right:0;padding:0 10px;background:none;border:none;cursor:pointer;color:#9ca3af;" <svg x-show="!showWaToken" style="width:16px;height:16px;" fill="none" stroke="currentColor" viewBox="0 0 24 24">
onmouseover="this.style.color='#4b5563'" onmouseout="this.style.color='#9ca3af'"> <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 12a3 3 0 11-6 0 3 3 0 016 0z"/>
<svg x-show="!showWaSecret" style="width:16px;height:16px;" fill="none" stroke="currentColor" viewBox="0 0 24 24"> <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M2.458 12C3.732 7.943 7.523 5 12 5c4.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542 7-4.477 0-8.268-2.943-9.542-7z"/>
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 12a3 3 0 11-6 0 3 3 0 016 0z"/> </svg>
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M2.458 12C3.732 7.943 7.523 5 12 5c4.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542 7-4.477 0-8.268-2.943-9.542-7z"/> <svg x-show="showWaToken" style="width:16px;height:16px;" fill="none" stroke="currentColor" viewBox="0 0 24 24">
</svg> <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13.875 18.825A10.05 10.05 0 0112 19c-4.478 0-8.268-2.943-9.543-7a9.97 9.97 0 011.563-3.029m5.858.908a3 3 0 114.243 4.243M9.878 9.878l4.242 4.242M9.88 9.88l-3.29-3.29m7.532 7.532l3.29 3.29M3 3l3.59 3.59m0 0A9.953 9.953 0 0112 5c4.478 0 8.268 2.943 9.543 7a10.025 10.025 0 01-4.132 4.411m0 0L21 21"/>
<svg x-show="showWaSecret" style="width:16px;height:16px;" fill="none" stroke="currentColor" viewBox="0 0 24 24"> </svg>
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13.875 18.825A10.05 10.05 0 0112 19c-4.478 0-8.268-2.943-9.543-7a9.97 9.97 0 011.563-3.029m5.858.908a3 3 0 114.243 4.243M9.878 9.878l4.242 4.242M9.88 9.88l-3.29-3.29m7.532 7.532l3.29 3.29M3 3l3.59 3.59m0 0A9.953 9.953 0 0112 5c4.478 0 8.268 2.943 9.543 7a10.025 10.025 0 01-4.132 4.411m0 0L21 21"/> </button>
</svg> </div>
</button>
</div> </div>
</div>
{{-- Webhook Path --}} {{-- Webhook Secret --}}
<div style="margin-bottom:24px;"> <div style="margin-bottom:16px;" x-data="{ showWaSecret: false }">
<label class="form-label">Webhook Path</label> <label class="form-label">
<div style="display:flex;align-items:stretch;"> Webhook Secret <span style="color:#9ca3af;font-weight:400;">(optional)</span>
<span style="display:inline-flex;align-items:center;padding:0 12px;font-size:13px;color:#6b7280;background:#f9fafb;border:1px solid #d1d5db;border-right:none;border-radius:6px 0 0 6px;white-space:nowrap;">{{ url('/') }}/</span> </label>
<input type="text" id="wa-webhook-path" <div style="position:relative;">
value="{{ $whatsappSettings['webhook_path'] }}" <input :type="showWaSecret ? 'text' : 'password'" id="wa-webhook-secret"
class="form-input" style="border-radius:0 6px 6px 0;flex:1;"> value="{{ $whatsappSettings['webhook_secret'] }}"
placeholder="Leave empty to skip HMAC verification"
class="form-input" style="padding-right:40px;">
<button type="button" @click="showWaSecret = !showWaSecret"
style="position:absolute;inset-y:0;right:0;padding:0 10px;background:none;border:none;cursor:pointer;color:#9ca3af;"
onmouseover="this.style.color='#4b5563'" onmouseout="this.style.color='#9ca3af'">
<svg x-show="!showWaSecret" style="width:16px;height:16px;" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 12a3 3 0 11-6 0 3 3 0 016 0z"/>
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M2.458 12C3.732 7.943 7.523 5 12 5c4.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542 7-4.477 0-8.268-2.943-9.542-7z"/>
</svg>
<svg x-show="showWaSecret" style="width:16px;height:16px;" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13.875 18.825A10.05 10.05 0 0112 19c-4.478 0-8.268-2.943-9.543-7a9.97 9.97 0 011.563-3.029m5.858.908a3 3 0 114.243 4.243M9.878 9.878l4.242 4.242M9.88 9.88l-3.29-3.29m7.532 7.532l3.29 3.29M3 3l3.59 3.59m0 0A9.953 9.953 0 0112 5c4.478 0 8.268 2.943 9.543 7a10.025 10.025 0 01-4.132 4.411m0 0L21 21"/>
</svg>
</button>
</div>
</div> </div>
<p style="font-size:12px;color:#6b7280;margin-top:4px;">
Paste this full URL in your UltraMSG dashboard: <strong>{{ url('/') }}/{{ $whatsappSettings['webhook_path'] }}</strong>
</p>
</div>
{{-- Actions --}} {{-- Webhook Path --}}
<div style="display:flex;align-items:center;justify-content:space-between;padding-top:16px;border-top:1px solid #f3f4f6;"> <div style="margin-bottom:24px;">
<div style="display:flex;align-items:center;gap:12px;"> <label class="form-label">Webhook Path</label>
<button type="button" id="btn-wa-test" onclick="testWaConnection()" <div style="display:flex;align-items:stretch;">
style="display:inline-flex;align-items:center;gap:6px;font-size:13px;color:#2563eb;background:none;border:none;cursor:pointer;text-decoration:underline;text-underline-offset:2px;padding:0;" <span style="display:inline-flex;align-items:center;padding:0 12px;font-size:13px;color:#6b7280;background:#f9fafb;border:1px solid #d1d5db;border-right:none;border-radius:6px 0 0 6px;white-space:nowrap;">{{ url('/') }}/</span>
onmouseover="this.style.color='#1d4ed8'" onmouseout="this.style.color='#2563eb'"> <input type="text" id="wa-webhook-path"
<svg style="width:15px;height:15px;" fill="none" stroke="currentColor" viewBox="0 0 24 24"> value="{{ $whatsappSettings['webhook_path'] }}"
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"/> class="form-input" style="border-radius:0 6px 6px 0;flex:1;">
</svg> </div>
Test Connection <p style="font-size:12px;color:#6b7280;margin-top:4px;">
</button> Paste this full URL in your UltraMSG dashboard: <strong>{{ url('/') }}/{{ $whatsappSettings['webhook_path'] }}</strong>
<span id="wa-conn-status" style="font-size:13px;display:none;"></span> </p>
</div> </div>
<button type="button" id="btn-wa-save" onclick="saveWhatsapp()" class="btn-primary">Save Settings</button>
{{-- Actions --}}
<div style="display:flex;align-items:center;justify-content:space-between;padding-top:16px;border-top:1px solid #f3f4f6;">
<div style="display:flex;align-items:center;gap:12px;">
<button type="button" id="btn-wa-test" onclick="testWaConnection()"
style="display:inline-flex;align-items:center;gap:6px;font-size:13px;color:#2563eb;background:none;border:none;cursor:pointer;text-decoration:underline;text-underline-offset:2px;padding:0;"
onmouseover="this.style.color='#1d4ed8'" onmouseout="this.style.color='#2563eb'">
<svg style="width:15px;height:15px;" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"/>
</svg>
Test Connection
</button>
<span id="wa-conn-status" style="font-size:13px;display:none;"></span>
</div>
<button type="button" id="btn-wa-save" onclick="saveWhatsapp()" class="btn-primary">Save Settings</button>
</div>
</div> </div>
</div> {{-- Right: Send Test Message --}}
</div> <div style="width:300px;flex-shrink:0;padding:24px;background:#f9fafb;">
<div style="display:flex;align-items:center;gap:8px;margin-bottom:16px;">
{{-- Send Test Message accordion --}} <svg style="width:16px;height:16px;color:#22c55e;flex-shrink:0;" fill="currentColor" viewBox="0 0 24 24">
<div class="card" style="margin-top:16px;">
<button type="button" onclick="toggleWaMsg()"
style="width:100%;display:flex;align-items:center;justify-content:space-between;padding:16px 24px;background:none;border:none;cursor:pointer;text-align:left;">
<div style="display:flex;align-items:center;gap:10px;">
<svg style="width:18px;height:18px;color:#22c55e;flex-shrink:0;" fill="currentColor" viewBox="0 0 24 24">
<path d="M17.472 14.382c-.297-.149-1.758-.867-2.03-.967-.273-.099-.471-.148-.67.15-.197.297-.767.966-.94 1.164-.173.199-.347.223-.644.075-.297-.15-1.255-.463-2.39-1.475-.883-.788-1.48-1.761-1.653-2.059-.173-.297-.018-.458.13-.606.134-.133.298-.347.446-.52.149-.174.198-.298.298-.497.099-.198.05-.371-.025-.52-.075-.149-.669-1.612-.916-2.207-.242-.579-.487-.5-.669-.51-.173-.008-.371-.01-.57-.01-.198 0-.52.074-.792.372-.272.297-1.04 1.016-1.04 2.479 0 1.462 1.065 2.875 1.213 3.074.149.198 2.096 3.2 5.077 4.487.709.306 1.262.489 1.694.625.712.227 1.36.195 1.871.118.571-.085 1.758-.719 2.006-1.413.248-.694.248-1.289.173-1.413-.074-.124-.272-.198-.57-.347m-5.421 7.403h-.004a9.87 9.87 0 01-5.031-1.378l-.361-.214-3.741.982.998-3.648-.235-.374a9.86 9.86 0 01-1.51-5.26c.001-5.45 4.436-9.884 9.888-9.884 2.64 0 5.122 1.03 6.988 2.898a9.825 9.825 0 012.893 6.994c-.003 5.45-4.437 9.884-9.885 9.884m8.413-18.297A11.815 11.815 0 0012.05 0C5.495 0 .16 5.335.157 11.892c0 2.096.547 4.142 1.588 5.945L.057 24l6.305-1.654a11.882 11.882 0 005.683 1.448h.005c6.554 0 11.89-5.335 11.893-11.893a11.821 11.821 0 00-3.48-8.413z"/>
</svg>
<span style="font-size:14px;font-weight:600;color:#111827;">Send Test Message</span>
<span style="font-size:12px;color:#6b7280;"> verify the connection works end-to-end</span>
</div>
<svg id="wa-msg-chevron" style="width:16px;height:16px;color:#9ca3af;transition:transform .2s;" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 9l-7 7-7-7"/>
</svg>
</button>
<div id="wa-msg-body" style="display:none;padding:0 24px 24px;">
<hr style="border:none;border-top:1px solid #e5e7eb;margin:0 0 20px;">
<div style="margin-bottom:14px;">
<label style="display:block;font-size:12px;font-weight:600;color:#374151;margin-bottom:5px;">Phone Number</label>
<input type="text" id="wa-test-to" placeholder="+97333165444" class="form-input" style="width:100%;">
</div>
<div style="margin-bottom:16px;">
<label style="display:block;font-size:12px;font-weight:600;color:#374151;margin-bottom:5px;">Message</label>
<textarea id="wa-test-body" rows="3" class="form-input" style="width:100%;resize:vertical;">Test message from SteelERP WhatsApp integration is working!</textarea>
</div>
<div style="display:flex;align-items:center;gap:14px;">
<button type="button" id="btn-wa-send" onclick="sendWaTestMessage()"
style="display:inline-flex;align-items:center;gap:7px;padding:9px 18px;font-size:13px;font-weight:600;color:#fff;background:#22c55e;border:none;border-radius:8px;cursor:pointer;"
onmouseover="this.style.background='#16a34a'" onmouseout="this.style.background='#22c55e'">
<svg style="width:15px;height:15px;" fill="currentColor" viewBox="0 0 24 24">
<path d="M17.472 14.382c-.297-.149-1.758-.867-2.03-.967-.273-.099-.471-.148-.67.15-.197.297-.767.966-.94 1.164-.173.199-.347.223-.644.075-.297-.15-1.255-.463-2.39-1.475-.883-.788-1.48-1.761-1.653-2.059-.173-.297-.018-.458.13-.606.134-.133.298-.347.446-.52.149-.174.198-.298.298-.497.099-.198.05-.371-.025-.52-.075-.149-.669-1.612-.916-2.207-.242-.579-.487-.5-.669-.51-.173-.008-.371-.01-.57-.01-.198 0-.52.074-.792.372-.272.297-1.04 1.016-1.04 2.479 0 1.462 1.065 2.875 1.213 3.074.149.198 2.096 3.2 5.077 4.487.709.306 1.262.489 1.694.625.712.227 1.36.195 1.871.118.571-.085 1.758-.719 2.006-1.413.248-.694.248-1.289.173-1.413-.074-.124-.272-.198-.57-.347m-5.421 7.403h-.004a9.87 9.87 0 01-5.031-1.378l-.361-.214-3.741.982.998-3.648-.235-.374a9.86 9.86 0 01-1.51-5.26c.001-5.45 4.436-9.884 9.888-9.884 2.64 0 5.122 1.03 6.988 2.898a9.825 9.825 0 012.893 6.994c-.003 5.45-4.437 9.884-9.885 9.884m8.413-18.297A11.815 11.815 0 0012.05 0C5.495 0 .16 5.335.157 11.892c0 2.096.547 4.142 1.588 5.945L.057 24l6.305-1.654a11.882 11.882 0 005.683 1.448h.005c6.554 0 11.89-5.335 11.893-11.893a11.821 11.821 0 00-3.48-8.413z"/> <path d="M17.472 14.382c-.297-.149-1.758-.867-2.03-.967-.273-.099-.471-.148-.67.15-.197.297-.767.966-.94 1.164-.173.199-.347.223-.644.075-.297-.15-1.255-.463-2.39-1.475-.883-.788-1.48-1.761-1.653-2.059-.173-.297-.018-.458.13-.606.134-.133.298-.347.446-.52.149-.174.198-.298.298-.497.099-.198.05-.371-.025-.52-.075-.149-.669-1.612-.916-2.207-.242-.579-.487-.5-.669-.51-.173-.008-.371-.01-.57-.01-.198 0-.52.074-.792.372-.272.297-1.04 1.016-1.04 2.479 0 1.462 1.065 2.875 1.213 3.074.149.198 2.096 3.2 5.077 4.487.709.306 1.262.489 1.694.625.712.227 1.36.195 1.871.118.571-.085 1.758-.719 2.006-1.413.248-.694.248-1.289.173-1.413-.074-.124-.272-.198-.57-.347m-5.421 7.403h-.004a9.87 9.87 0 01-5.031-1.378l-.361-.214-3.741.982.998-3.648-.235-.374a9.86 9.86 0 01-1.51-5.26c.001-5.45 4.436-9.884 9.888-9.884 2.64 0 5.122 1.03 6.988 2.898a9.825 9.825 0 012.893 6.994c-.003 5.45-4.437 9.884-9.885 9.884m8.413-18.297A11.815 11.815 0 0012.05 0C5.495 0 .16 5.335.157 11.892c0 2.096.547 4.142 1.588 5.945L.057 24l6.305-1.654a11.882 11.882 0 005.683 1.448h.005c6.554 0 11.89-5.335 11.893-11.893a11.821 11.821 0 00-3.48-8.413z"/>
</svg> </svg>
Send Message <span style="font-size:13px;font-weight:600;color:#111827;">Send Test Message</span>
</button> </div>
<span id="wa-send-status" style="font-size:13px;display:none;"></span> <div style="font-size:12px;color:#6b7280;margin-bottom:16px;">Verify the connection works end-to-end by sending a real message.</div>
<div style="margin-bottom:12px;">
<label style="display:block;font-size:12px;font-weight:600;color:#374151;margin-bottom:5px;">Phone Number</label>
<input type="text" id="wa-test-to" placeholder="+97333165444" class="form-input">
</div>
<div style="margin-bottom:14px;">
<label style="display:block;font-size:12px;font-weight:600;color:#374151;margin-bottom:5px;">Message</label>
<textarea id="wa-test-body" rows="4" class="form-input" style="resize:vertical;">Test message from SteelERP WhatsApp integration is working!</textarea>
</div>
<div style="display:flex;align-items:center;gap:10px;">
<button type="button" id="btn-wa-send" onclick="sendWaTestMessage()"
style="display:inline-flex;align-items:center;gap:7px;padding:9px 16px;font-size:13px;font-weight:600;color:#fff;background:#22c55e;border:none;border-radius:8px;cursor:pointer;"
onmouseover="this.style.background='#16a34a'" onmouseout="this.style.background='#22c55e'">
<svg style="width:14px;height:14px;" fill="currentColor" viewBox="0 0 24 24">
<path d="M17.472 14.382c-.297-.149-1.758-.867-2.03-.967-.273-.099-.471-.148-.67.15-.197.297-.767.966-.94 1.164-.173.199-.347.223-.644.075-.297-.15-1.255-.463-2.39-1.475-.883-.788-1.48-1.761-1.653-2.059-.173-.297-.018-.458.13-.606.134-.133.298-.347.446-.52.149-.174.198-.298.298-.497.099-.198.05-.371-.025-.52-.075-.149-.669-1.612-.916-2.207-.242-.579-.487-.5-.669-.51-.173-.008-.371-.01-.57-.01-.198 0-.52.074-.792.372-.272.297-1.04 1.016-1.04 2.479 0 1.462 1.065 2.875 1.213 3.074.149.198 2.096 3.2 5.077 4.487.709.306 1.262.489 1.694.625.712.227 1.36.195 1.871.118.571-.085 1.758-.719 2.006-1.413.248-.694.248-1.289.173-1.413-.074-.124-.272-.198-.57-.347m-5.421 7.403h-.004a9.87 9.87 0 01-5.031-1.378l-.361-.214-3.741.982.998-3.648-.235-.374a9.86 9.86 0 01-1.51-5.26c.001-5.45 4.436-9.884 9.888-9.884 2.64 0 5.122 1.03 6.988 2.898a9.825 9.825 0 012.893 6.994c-.003 5.45-4.437 9.884-9.885 9.884m8.413-18.297A11.815 11.815 0 0012.05 0C5.495 0 .16 5.335.157 11.892c0 2.096.547 4.142 1.588 5.945L.057 24l6.305-1.654a11.882 11.882 0 005.683 1.448h.005c6.554 0 11.89-5.335 11.893-11.893a11.821 11.821 0 00-3.48-8.413z"/>
</svg>
Send
</button>
<span id="wa-send-status" style="font-size:12px;display:none;"></span>
</div>
</div> </div>
</div> </div>
</div> </div>
@ -192,22 +189,61 @@
{{-- ===== Email tab ===== --}} {{-- ===== Email tab ===== --}}
<div x-show="tab==='email'" style="display:none;" id="email-tab-panel"> <div x-show="tab==='email'" style="display:none;" id="email-tab-panel">
<div style="display:flex;align-items:center;justify-content:space-between;margin-bottom:14px;"> {{-- Two-column layout: account list left, send test right --}}
<div> <div style="display:flex;gap:16px;align-items:flex-start;">
<div style="font-size:15px;font-weight:600;color:#111827;">Mail Accounts</div>
<div id="ma-count" style="font-size:12px;color:#6b7280;">Loading…</div> {{-- Left: account list --}}
<div style="flex:1;min-width:0;">
<div style="display:flex;align-items:center;justify-content:space-between;margin-bottom:14px;">
<div>
<div style="font-size:15px;font-weight:600;color:#111827;">Mail Accounts</div>
<div id="ma-count" style="font-size:12px;color:#6b7280;">Loading…</div>
</div>
<button type="button" onclick="maOpen()" class="btn-primary" style="display:inline-flex;align-items:center;gap:6px;">
<span style="font-size:16px;line-height:1;">+</span> Add Account
</button>
</div>
<div id="ma-list" style="background:#fff;border:1px solid #e5e7eb;border-radius:12px;overflow:hidden;display:none;"></div>
<div id="ma-empty" style="display:none;background:#fff;border:1px solid #e5e7eb;border-radius:12px;padding:40px 24px;text-align:center;">
<div style="font-size:32px;margin-bottom:12px;">✉️</div>
<div style="font-size:14px;font-weight:600;color:#374151;margin-bottom:4px;">No mail accounts configured</div>
<div style="font-size:13px;color:#6b7280;">Click <strong>Add Account</strong> to get started.</div>
</div>
</div> </div>
<button type="button" onclick="maOpen()" class="btn-primary" style="display:inline-flex;align-items:center;gap:6px;">
<span style="font-size:16px;line-height:1;">+</span> Add Account
</button>
</div>
<div id="ma-list" style="background:#fff;border:1px solid #e5e7eb;border-radius:12px;overflow:hidden;display:none;"></div> {{-- Right: Send Test Email --}}
<div style="width:280px;flex-shrink:0;background:#fff;border:1px solid #e5e7eb;border-radius:12px;overflow:hidden;">
<div style="padding:16px 20px;border-bottom:1px solid #e5e7eb;display:flex;align-items:center;gap:8px;">
<span style="font-size:15px;">📧</span>
<span style="font-size:13px;font-weight:600;color:#111827;">Send Test Email</span>
</div>
<div style="padding:16px 20px;">
<div style="font-size:12px;color:#6b7280;margin-bottom:14px;">Send a test email via any configured account.</div>
<div style="margin-bottom:12px;">
<label style="display:block;font-size:12px;font-weight:600;color:#374151;margin-bottom:5px;">Account</label>
<select id="em-test-account" class="form-input">
<option value=""> select account </option>
</select>
</div>
<div style="margin-bottom:14px;">
<label style="display:block;font-size:12px;font-weight:600;color:#374151;margin-bottom:5px;">To</label>
<input type="text" id="em-test-to" placeholder="recipient@example.com" class="form-input">
</div>
<div style="display:flex;align-items:center;gap:10px;">
<button type="button" id="btn-em-send" onclick="sendTestEmail()"
style="display:inline-flex;align-items:center;gap:6px;padding:9px 16px;font-size:13px;font-weight:600;color:#fff;background:#2563eb;border:none;border-radius:8px;cursor:pointer;"
onmouseover="this.style.background='#1d4ed8'" onmouseout="this.style.background='#2563eb'">
✉️ Send
</button>
<span id="em-send-status" style="font-size:12px;display:none;"></span>
</div>
</div>
</div>
<div id="ma-empty" style="display:none;background:#fff;border:1px solid #e5e7eb;border-radius:12px;padding:40px 24px;text-align:center;">
<div style="font-size:32px;margin-bottom:12px;">✉️</div>
<div style="font-size:14px;font-weight:600;color:#374151;margin-bottom:4px;">No mail accounts configured</div>
<div style="font-size:13px;color:#6b7280;">Click <strong>Add Account</strong> to get started.</div>
</div> </div>
</div>{{-- end Email tab --}} </div>{{-- end Email tab --}}
@ -378,13 +414,6 @@ function toggleWaSwitch() {
thumb.style.left = on ? '2px' : '22px'; thumb.style.left = on ? '2px' : '22px';
} }
var _waMsgOpen = false;
function toggleWaMsg() {
_waMsgOpen = !_waMsgOpen;
document.getElementById('wa-msg-body').style.display = _waMsgOpen ? 'block' : 'none';
document.getElementById('wa-msg-chevron').style.transform = _waMsgOpen ? 'rotate(180deg)' : '';
}
function saveWhatsapp() { function saveWhatsapp() {
var btn = document.getElementById('btn-wa-save'); var btn = document.getElementById('btn-wa-save');
btn.disabled = true; btn.style.opacity = '.6'; btn.disabled = true; btn.style.opacity = '.6';
@ -447,9 +476,22 @@ function loadMailAccounts() {
.then(function(data) { .then(function(data) {
_maAccounts = data.accounts; _maAccounts = data.accounts;
renderMailAccounts(); renderMailAccounts();
refreshEmailAccountSelect();
}); });
} }
function refreshEmailAccountSelect() {
var sel = document.getElementById('em-test-account');
if (!sel) return;
var cur = sel.value;
sel.innerHTML = '<option value="">— select account —</option>' +
_maAccounts.map(function(a) {
return '<option value="' + a.id + '"' + (String(a.id) === cur ? ' selected' : '') + '>' +
escHtml(a.label) + ' (' + escHtml(a.name) + ')' +
'</option>';
}).join('');
}
function renderMailAccounts() { function renderMailAccounts() {
var list = document.getElementById('ma-list'); var list = document.getElementById('ma-list');
var empty = document.getElementById('ma-empty'); var empty = document.getElementById('ma-empty');
@ -640,5 +682,31 @@ function maTest() {
} }
}).catch(function() { statusEl.textContent = 'Request failed.'; statusEl.style.color = '#dc2626'; }); }).catch(function() { statusEl.textContent = 'Request failed.'; statusEl.style.color = '#dc2626'; });
} }
function sendTestEmail() {
var accountId = document.getElementById('em-test-account').value;
var to = document.getElementById('em-test-to').value.trim();
if (!accountId) { showToast('Select a mail account.', 'warn'); return; }
if (!to) { showToast('Enter a recipient email.', 'warn'); return; }
var btn = document.getElementById('btn-em-send');
var statusEl = document.getElementById('em-send-status');
btn.disabled = true; btn.style.opacity = '.6';
statusEl.textContent = 'Sending…'; statusEl.style.display = ''; statusEl.style.color = '#6b7280';
fetch(MA_BASE + '/' + accountId + '/send-test', {
method: 'POST',
headers: { 'X-CSRF-TOKEN': CSRF, 'Accept': 'application/json', 'Content-Type': 'application/json' },
body: JSON.stringify({ to: to })
}).then(function(r) { return r.json(); }).then(function(data) {
if (data.success) {
statusEl.textContent = 'Sent ✓'; statusEl.style.color = '#16a34a';
showToast('Test email sent!', 'success');
} else {
statusEl.textContent = 'Failed.'; statusEl.style.color = '#dc2626';
showToast(data.message || 'Failed to send.', 'error');
}
}).catch(function() {
statusEl.textContent = 'Request failed.'; statusEl.style.color = '#dc2626';
}).finally(function() { btn.disabled = false; btn.style.opacity = '1'; });
}
</script> </script>
@endsection @endsection

View File

@ -130,6 +130,7 @@ Route::middleware(['auth', 'verified'])->group(function () {
Route::put('settings/integrations/mail-accounts/{mailAccount}', [MailAccountController::class, 'update'])->name('settings.mail-accounts.update'); Route::put('settings/integrations/mail-accounts/{mailAccount}', [MailAccountController::class, 'update'])->name('settings.mail-accounts.update');
Route::delete('settings/integrations/mail-accounts/{mailAccount}', [MailAccountController::class, 'destroy'])->name('settings.mail-accounts.destroy'); Route::delete('settings/integrations/mail-accounts/{mailAccount}', [MailAccountController::class, 'destroy'])->name('settings.mail-accounts.destroy');
Route::post('settings/integrations/mail-accounts/{mailAccount}/test', [MailAccountController::class, 'testConnection'])->name('settings.mail-accounts.test'); Route::post('settings/integrations/mail-accounts/{mailAccount}/test', [MailAccountController::class, 'testConnection'])->name('settings.mail-accounts.test');
Route::post('settings/integrations/mail-accounts/{mailAccount}/send-test', [MailAccountController::class, 'sendTestEmail'])->name('settings.mail-accounts.send-test');
Route::patch('settings/integrations/mail-accounts/{mailAccount}/toggle', [MailAccountController::class, 'toggleEnabled'])->name('settings.mail-accounts.toggle'); Route::patch('settings/integrations/mail-accounts/{mailAccount}/toggle', [MailAccountController::class, 'toggleEnabled'])->name('settings.mail-accounts.toggle');
// Projects settings // Projects settings