fix(name): change name from Web Control to WhatsApp Control

This commit is contained in:
zain94rif
2026-04-02 14:03:17 +07:00
parent 8becbc2a6b
commit 34beee4975
6 changed files with 83 additions and 82 deletions

View File

@@ -1,21 +1,21 @@
import React, { useState, useEffect, memo } from 'react';
import { useNavigate } from 'react-router-dom';
import { Button, Typography } from 'antd';
import { resetWA } from '../../api/web-control';
import { resetWA } from '../../api/whatsapp-control';
import { useBreadcrumb } from '../../layout/LayoutBreadcrumb';
import { ReloadOutlined } from '@ant-design/icons';
const { Text } = Typography;
const IndexWebControl = memo(function IndexWebControl() {
const IndexWhatsAppControl = memo(function IndexWhatsAppControl() {
const navigate = useNavigate();
const { setBreadcrumbItems } = useBreadcrumb();
const [isPlaying, setIsPlaying] = useState(true);
const url = "http://localhost:9531/qrview";
const url = import.meta.env.VITE_WHATSAPP_URL;
const handleReset = async() => {
const handleReset = async () => {
setIsPlaying(false);
await resetWA();
setIsPlaying(true);
@@ -29,7 +29,7 @@ const IndexWebControl = memo(function IndexWebControl() {
{
title: (
<Text strong style={{ fontSize: '14px' }}>
Web Control Panel
WhatsApp Control Panel
</Text>
),
},
@@ -41,10 +41,9 @@ const IndexWebControl = memo(function IndexWebControl() {
return (
<div style={{ padding: '20px' }}>
<div style={{ marginBottom: 20 }}>
<Button type="primary" onClick={handleReset} style={{ marginRight: 10 }}>
<ReloadOutlined/> Restart WhatsApp
<ReloadOutlined /> Restart WhatsApp
</Button>
</div>
@@ -58,7 +57,7 @@ const IndexWebControl = memo(function IndexWebControl() {
{isPlaying ? (
<iframe
src={url}
title="Web Preview"
title="WhatsApp Preview"
style={{
width: '100%',
height: '100%',
@@ -83,4 +82,4 @@ const IndexWebControl = memo(function IndexWebControl() {
);
});
export default IndexWebControl;
export default IndexWhatsAppControl;

View File

@@ -12,27 +12,27 @@ const IndexWebControl = memo(function IndexWebControl() {
const { setBreadcrumbItems } = useBreadcrumb();
const [isPlaying, setIsPlaying] = useState(true);
const [currentUrl, setCurrentUrl] = useState("http://localhost:9531");
const [currentUrl, setCurrentUrl] = useState('http://localhost:9531');
const iframeRef = useRef(null);
const handleReset = async() => {
const handleReset = async () => {
setIsPlaying(false);
await resetWA();
setIsPlaying(true);
// Kembali ke halaman login setelah reset
setCurrentUrl("https://localhost:9531");
setCurrentUrl('https://localhost:9531');
message.success('WhatsApp berhasil di-restart');
};
// Fungsi untuk redirect ke QR View
const redirectToQRView = () => {
setCurrentUrl("https://localhost:9531/qrview");
setCurrentUrl('https://localhost:9531/qrview');
message.info('Redirecting to QR View...');
};
// Fungsi untuk kembali ke login
const backToLogin = () => {
setCurrentUrl("https://localhost:9531");
setCurrentUrl('https://localhost:9531');
message.info('Back to login page');
};
@@ -59,27 +59,31 @@ const IndexWebControl = memo(function IndexWebControl() {
// Terima pesan dari domain manapun untuk testing
console.log('Message received from:', event.origin);
console.log('Message data:', event.data);
// Cek apakah ini pesan login success
if (event.data) {
// Jika pesan adalah string
if (typeof event.data === 'string') {
const lowerData = event.data.toLowerCase();
if (lowerData.includes('login') ||
lowerData.includes('success') ||
if (
lowerData.includes('login') ||
lowerData.includes('success') ||
lowerData.includes('authenticated') ||
lowerData.includes('qrview')) {
lowerData.includes('qrview')
) {
console.log('Login detected via string message');
redirectToQRView();
}
}
// Jika pesan adalah object
if (typeof event.data === 'object') {
if (event.data.type === 'LOGIN_SUCCESS' ||
if (
event.data.type === 'LOGIN_SUCCESS' ||
event.data.status === 'success' ||
event.data.logged_in === true ||
event.data.redirect === true) {
event.data.redirect === true
) {
console.log('Login detected via object message');
redirectToQRView();
}
@@ -88,7 +92,7 @@ const IndexWebControl = memo(function IndexWebControl() {
};
window.addEventListener('message', handleMessage);
return () => {
window.removeEventListener('message', handleMessage);
};
@@ -99,12 +103,12 @@ const IndexWebControl = memo(function IndexWebControl() {
// Jika tidak ada pesan dari iframe, coba redirect otomatis setelah 10 detik
// Asumsi: login biasanya selesai dalam 10 detik
const timer = setTimeout(() => {
if (currentUrl === "https://localhost:9531") {
if (currentUrl === 'https://localhost:9531') {
console.log('Auto redirect after 10 seconds (fallback)');
redirectToQRView();
}
}, 10000);
return () => clearTimeout(timer);
}, [currentUrl]);
@@ -112,7 +116,7 @@ const IndexWebControl = memo(function IndexWebControl() {
<div style={{ padding: '20px' }}>
<div style={{ marginBottom: 20, display: 'flex', gap: '10px', flexWrap: 'wrap' }}>
<Button type="primary" onClick={handleReset}>
<ReloadOutlined/> Restart WhatsApp
<ReloadOutlined /> Restart WhatsApp
</Button>
{/* <Button onClick={redirectToQRView} type="default">
Redirect ke QR View
@@ -165,4 +169,4 @@ const IndexWebControl = memo(function IndexWebControl() {
);
});
export default IndexWebControl;
export default IndexWebControl;