123 lines
4.1 KiB
PHP
123 lines
4.1 KiB
PHP
<div class="d-flex align-items-center justify-content-between p-3 border-bottom bg-light position-relative">
|
|
<div class="d-flex align-items-center">
|
|
<img src="https://ui-avatars.com/api/?name=<?= $_SESSION['name']; ?>&background=random" width="50" height="50" class="rounded-circle me-3" alt="Profile CS">
|
|
<div>
|
|
<strong><?= $_SESSION['name']; ?></strong><br>
|
|
<small class="text-muted">Online</small>
|
|
</div>
|
|
</div>
|
|
<div class="dropdown">
|
|
<button class="btn btn-sm btn-light" id="dropdownMenuButton" data-bs-toggle="dropdown" aria-expanded="false">
|
|
<i class="fa-solid fa-ellipsis-vertical"></i>
|
|
</button>
|
|
<ul class="dropdown-menu dropdown-menu-end" aria-labelledby="dropdownMenuButton">
|
|
<li><a class="dropdown-item" href="#">Profil</a></li>
|
|
<li><a class="dropdown-item" href="#">Pengaturan</a></li>
|
|
<li><hr class="dropdown-divider"></li>
|
|
<li><a class="dropdown-item text-danger" href="<?= base_url('auth/logout'); ?>">Logout</a></li>
|
|
</ul>
|
|
</div>
|
|
<?php
|
|
// print_r($_SESSION); ?>
|
|
</div>
|
|
|
|
<!-- PENCARIAN CHAT -->
|
|
<div class="p-3 border-bottom bg-white">
|
|
<div class="position-relative mb-2">
|
|
<!-- <input type="text" id="searchChat" class="form-control pe-5" placeholder="Cari nomor terdaftar..."> -->
|
|
<input type="text" id="searchChat" class="form-control mb-2" placeholder="Cari atau mulai chat baru...">
|
|
|
|
<!-- Tombol tambah diletakkan absolut agar tidak ikut event flex -->
|
|
<div class="position-absolute top-0 end-0 me-1 mt-1">
|
|
<button class="btn btn-outline-primary btn-sm" type="button" id="btnTambahSession" style="display: none;">
|
|
<i class="fas fa-user-plus"></i>
|
|
</button>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Tombol Filter Stylish -->
|
|
<div class="d-flex justify-content-between px-1">
|
|
<button class="btn btn-sm btn-outline-primary filter-btn active" data-filter="all">Semua</button>
|
|
<button class="btn btn-sm btn-outline-primary filter-btn" data-filter="unread">Belum Dibaca</button>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="chat-list overflow-auto">
|
|
<?php $this->load->view('chat/components/chat_list'); ?>
|
|
</div>
|
|
|
|
|
|
<script>
|
|
document.getElementById('btnTambahSession').addEventListener('click', function () {
|
|
const input = document.getElementById('searchChat');
|
|
let raw = input.value.replace(/\D/g, ''); // hanya angka
|
|
|
|
// Ubah awalan 0 jadi 62
|
|
if (raw.startsWith('0')) {
|
|
raw = '62' + raw.substring(1);
|
|
}
|
|
|
|
if (!raw || raw.length < 9) {
|
|
Swal.fire({
|
|
toast: true,
|
|
position: 'top-end',
|
|
icon: 'warning',
|
|
title: 'Nomor tidak valid!',
|
|
text: 'Masukkan nomor WhatsApp dengan benar.',
|
|
showConfirmButton: false,
|
|
timer: 2000,
|
|
timerProgressBar: true,
|
|
});
|
|
return;
|
|
}
|
|
|
|
// 🔹 Kirim POST ke controller
|
|
fetch("<?= base_url('chat/getContact') ?>", {
|
|
method: "POST",
|
|
headers: {
|
|
"Content-Type": "application/x-www-form-urlencoded"
|
|
},
|
|
body: "number=" + encodeURIComponent(raw)
|
|
})
|
|
.then(res => res.json())
|
|
.then(data => {
|
|
console.log("Response:", data);
|
|
|
|
const iconType = data.status === 'success' ? 'success' : 'error';
|
|
const titleText = data.status === 'success' ? 'Berhasil!' : 'Gagal!';
|
|
const messageText = data.message || (data.status === 'success'
|
|
? 'Chat baru berhasil ditambahkan!'
|
|
: 'Terjadi kesalahan saat menambah chat.');
|
|
|
|
Swal.fire({
|
|
toast: true,
|
|
position: 'top-end',
|
|
icon: iconType,
|
|
title: titleText,
|
|
text: messageText,
|
|
showConfirmButton: false,
|
|
timer: 2000,
|
|
timerProgressBar: true,
|
|
});
|
|
|
|
if (data.status === 'success') {
|
|
input.value = ''; // reset input
|
|
}
|
|
})
|
|
.catch(err => {
|
|
console.error("Error:", err);
|
|
Swal.fire({
|
|
toast: true,
|
|
position: 'top-end',
|
|
icon: 'error',
|
|
title: 'Kesalahan!',
|
|
text: 'Tidak dapat menghubungi server.',
|
|
showConfirmButton: false,
|
|
timer: 2000,
|
|
timerProgressBar: true,
|
|
});
|
|
});
|
|
});
|
|
</script>
|
|
|