From 17b06531847d4c19b66646d79b759f6a936fc4d9 Mon Sep 17 00:00:00 2001 From: everythingonblack Date: Tue, 24 Jun 2025 01:07:57 +0700 Subject: [PATCH] ok --- src/ChatBot.js | 29 +++++++++++++++-------------- src/Dashboard.js | 22 +++++++++++----------- src/Login.js | 2 +- src/ProfileTab.js | 31 +++++++++++++++++-------------- 4 files changed, 44 insertions(+), 40 deletions(-) diff --git a/src/ChatBot.js b/src/ChatBot.js index 7af0140..890007e 100644 --- a/src/ChatBot.js +++ b/src/ChatBot.js @@ -8,10 +8,8 @@ const ChatBot = ({ existingConversation, readOnly, hh }) => { text: 'Hai Dermalovers! 👋 Saya siap membantu anda tampil lebih percaya diri. Ada pertanyaan seputar perawatan kulit atau kecantikan hari ini?', time: getTime(), quickReplies: [ - 'Info layanan Dermalounge', - 'Apa perawatan wajah recommended', - 'Saya ingin konsultasi masalah kulit', - 'Info lokasi & cara booking', + 'Konsultasi estetik', + 'Konsultasi kulit dan kelamin' ], }, ]); @@ -20,7 +18,7 @@ const ChatBot = ({ existingConversation, readOnly, hh }) => { const [isLoading, setIsLoading] = useState(false); - const [isPoppedUp, setIsPoppedUp] = useState(false); + const [isPoppedUp, setIsPoppedUp] = useState(''); const [name, setName] = useState(''); const [phoneNumber, setPhoneNumber] = useState(''); useEffect(() => { @@ -50,6 +48,14 @@ const ChatBot = ({ existingConversation, readOnly, hh }) => { const message = textOverride || input.trim(); if (message === '') return; + const session = JSON.parse(localStorage.getItem('session')); + + if ((!session || !session.name || !session.phoneNumber) && messages.length > 2) { + setIsPoppedUp(message); // munculkan form input + setInput(''); + return; + } + // Show user's message immediately const newMessages = [ ...messages, @@ -58,7 +64,7 @@ const ChatBot = ({ existingConversation, readOnly, hh }) => { setMessages(newMessages); setInput(''); - + setIsLoading(true); try { // Send to backend @@ -79,12 +85,6 @@ const ChatBot = ({ existingConversation, readOnly, hh }) => { ...prev, { sender: 'bot', text: botAnswer, time: getTime() }, ]); - - const session = JSON.parse(localStorage.getItem('session')); - - if ((!session || !session.name || !session.phoneNumber) && messages.length > 2) { - setIsPoppedUp(true); // munculkan form input - } setIsLoading(false); } catch (error) { @@ -194,7 +194,7 @@ function formatBoldText(text) { Kirim - {isPoppedUp && + {isPoppedUp != '' &&
Untuk bisa membantu Anda lebih jauh, boleh saya tahu nama dan nomor telepon Anda? @@ -241,7 +241,8 @@ function formatBoldText(text) { sessionData.phoneNumber = phoneNumber; localStorage.setItem('session', JSON.stringify(sessionData)); - setIsPoppedUp(false) + setIsPoppedUp('') + sendMessage(isPoppedUp) } }} > diff --git a/src/Dashboard.js b/src/Dashboard.js index 1266d82..1d94517 100644 --- a/src/Dashboard.js +++ b/src/Dashboard.js @@ -46,18 +46,9 @@ const Dashboard = () => { navigator.serviceWorker.ready.then(function (registration) { registration.pushManager.getSubscription().then(function (subscription) { + console.log(subscription) if (subscription) { - subscription.unsubscribe().then(function (successful) { - console.log('Push subscription unsubscribed on logout:', successful); - // Optional: also notify backend to clear the token - fetch('/api/clear-subscription', { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - body: JSON.stringify({ endpoint: subscription.endpoint }), - }); - }); + subscription.unsubscribe(); } }); }); @@ -134,6 +125,15 @@ const Dashboard = () => { setLoading(false); // ⬅️ Setelah berhasil, hilangkan loading } catch (error) { console.error('Error:', error); + + navigator.serviceWorker.ready.then(function (registration) { + registration.pushManager.getSubscription().then(function (subscription) { + console.log(subscription) + if (subscription) { + subscription.unsubscribe(); + } + }); + }); navigate('/login'); } }; diff --git a/src/Login.js b/src/Login.js index d366719..c5c8db9 100644 --- a/src/Login.js +++ b/src/Login.js @@ -69,7 +69,7 @@ const Login = () => {
- © 2025 Kloowear AI - Admin Panel + © 2025 Kediri Technopark
diff --git a/src/ProfileTab.js b/src/ProfileTab.js index 928154b..c5f5786 100644 --- a/src/ProfileTab.js +++ b/src/ProfileTab.js @@ -28,20 +28,14 @@ const ProfileTab = () => { localStorage.removeItem('token'); localStorage.removeItem('user'); - navigator.serviceWorker.ready.then((registration) => { - registration.pushManager.getSubscription().then((subscription) => { - if (subscription) { - subscription.unsubscribe().then((successful) => { - console.log('Unsubscribed from push notifications:', successful); - fetch('/api/clear-subscription', { - method: 'POST', - headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify({ endpoint: subscription.endpoint }), - }); - }); - } - }); - }); + navigator.serviceWorker.ready.then(function (registration) { + registration.pushManager.getSubscription().then(function (subscription) { + console.log(subscription) + if (subscription) { + subscription.unsubscribe(); + } + }); + }); window.location.reload(); }; @@ -73,6 +67,15 @@ const ProfileTab = () => { setProfileTemp(data.profile_data); } catch (error) { console.error('Fetch error:', error); + + navigator.serviceWorker.ready.then(function (registration) { + registration.pushManager.getSubscription().then(function (subscription) { + console.log(subscription) + if (subscription) { + subscription.unsubscribe(); + } + }); + }); navigate('/login'); } };