ok
This commit is contained in:
@@ -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,
|
||||
@@ -80,12 +86,6 @@ const ChatBot = ({ existingConversation, readOnly, hh }) => {
|
||||
{ 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) {
|
||||
console.log(tryCount)
|
||||
@@ -194,7 +194,7 @@ function formatBoldText(text) {
|
||||
Kirim
|
||||
</button>
|
||||
</div>
|
||||
{isPoppedUp &&
|
||||
{isPoppedUp != '' &&
|
||||
<div className={styles.PopUp}>
|
||||
<div className={`${styles.message} ${styles['bot']}`}>
|
||||
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)
|
||||
}
|
||||
}}
|
||||
>
|
||||
|
||||
@@ -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');
|
||||
}
|
||||
};
|
||||
|
||||
@@ -69,7 +69,7 @@ const Login = () => {
|
||||
</button>
|
||||
</form>
|
||||
<div className={styles.footer}>
|
||||
© 2025 Kloowear AI - Admin Panel
|
||||
© 2025 Kediri Technopark
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -28,17 +28,11 @@ const ProfileTab = () => {
|
||||
localStorage.removeItem('token');
|
||||
localStorage.removeItem('user');
|
||||
|
||||
navigator.serviceWorker.ready.then((registration) => {
|
||||
registration.pushManager.getSubscription().then((subscription) => {
|
||||
navigator.serviceWorker.ready.then(function (registration) {
|
||||
registration.pushManager.getSubscription().then(function (subscription) {
|
||||
console.log(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 }),
|
||||
});
|
||||
});
|
||||
subscription.unsubscribe();
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -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');
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user