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

@@ -5,7 +5,7 @@
"version": "1.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"dev": "vite --host 0.0.0.0 --port 8592",
"build": "vite build",
"lint": "eslint . --ext js,jsx --report-unused-disable-directives --max-warnings 0",
"preview": "vite preview"

View File

@@ -36,7 +36,7 @@ import IndexNotification from './pages/notification/IndexNotification';
import IndexRole from './pages/role/IndexRole';
import IndexUser from './pages/user/IndexUser';
import IndexContact from './pages/contact/IndexContact';
import IndexWebControl from './pages/webControl/IndexWebControl';
import IndexWhatsAppControl from './pages/whatsAppControl/IndexWhatsAppControl';
import DetailNotificationTab from './pages/notificationDetail/IndexNotificationDetail';
import IndexVerificationSparepart from './pages/verificationSparepart/IndexVerificationSparepart';
@@ -145,8 +145,8 @@ const App = () => {
<Route index element={<IndexUser />} />
</Route>
<Route path="/web-control" element={<ProtectedRoute />}>
<Route index element={<IndexWebControl />} />
<Route path="/whatsapp-control" element={<ProtectedRoute />}>
<Route index element={<IndexWhatsAppControl />} />
</Route>
<Route path="/contact" element={<ProtectedRoute />}>

View File

@@ -9,6 +9,4 @@ const resetWA = async () => {
return response.data;
};
export {
resetWA,
};
export { resetWA };

View File

@@ -227,11 +227,11 @@ const allItems = [
),
},
{
key: 'web-control',
key: 'whatsapp-control',
icon: <GlobalOutlined style={{ fontSize: '19px' }} />,
label: (
<Link to="/web-control" className="fontMenus">
Web Control
<Link to="/whatsapp-control" className="fontMenus">
WhatsApp Control
</Link>
),
},
@@ -260,7 +260,7 @@ const LayoutMenu = () => {
if (pathname === '/dashboard/home') return 'home';
if (pathname === '/user') return 'user';
if (pathname === '/role') return 'role';
if (pathname === '/web-control') return 'web-control';
if (pathname === '/whatsapp-control') return 'whatsapp-control';
if (pathname === '/notification') return 'notification';
if (pathname === '/jadwal-shift') return 'jadwal-shift';
if (pathname === '/contact') return 'contact';

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');
};
@@ -65,10 +65,12 @@ const IndexWebControl = memo(function IndexWebControl() {
// Jika pesan adalah string
if (typeof event.data === 'string') {
const lowerData = event.data.toLowerCase();
if (lowerData.includes('login') ||
if (
lowerData.includes('login') ||
lowerData.includes('success') ||
lowerData.includes('authenticated') ||
lowerData.includes('qrview')) {
lowerData.includes('qrview')
) {
console.log('Login detected via string message');
redirectToQRView();
}
@@ -76,10 +78,12 @@ const IndexWebControl = memo(function IndexWebControl() {
// 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();
}
@@ -99,7 +103,7 @@ 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();
}
@@ -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