ok
This commit is contained in:
@@ -62,7 +62,7 @@ const ChatBot = ({ existingConversation, readOnly, hh }) => {
|
||||
setIsLoading(true);
|
||||
try {
|
||||
// Send to backend
|
||||
const response = await fetch('https://bot.kediritechnopark.com/webhook/master-agent/ask/dev', {
|
||||
const response = await fetch('https://bot.kediritechnopark.com/webhook/master-agent/ask', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ pertanyaan: message, sessionId: JSON.parse(localStorage.getItem('session')).sessionId, lastSeen: new Date().toISOString(), name: JSON.parse(localStorage.getItem('session')).name, phoneNumber: JSON.parse(localStorage.getItem('session')).phoneNumber }),
|
||||
@@ -72,7 +72,7 @@ const ChatBot = ({ existingConversation, readOnly, hh }) => {
|
||||
console.log(data)
|
||||
// Assuming your backend sends back something like: { answer: "text" }
|
||||
// Adjust this according to your actual response shape
|
||||
const botAnswer = data.jawaban || 'Maaf, saya tidak mengerti.';
|
||||
const botAnswer = data.jawaban || 'Maaf saya sedang tidak tersedia sekarang, coba lagi nanti';
|
||||
|
||||
// Add bot's reply
|
||||
setMessages(prev => [
|
||||
@@ -106,15 +106,29 @@ const ChatBot = ({ existingConversation, readOnly, hh }) => {
|
||||
function formatBoldText(text) {
|
||||
const parts = text.split(/(\*\*[^\*]+\*\*)/g);
|
||||
|
||||
return parts.map((part, index) => {
|
||||
return parts.flatMap((part, index) => {
|
||||
const elements = [];
|
||||
|
||||
if (part.startsWith('**') && part.endsWith('**')) {
|
||||
return <strong key={index}>{part.slice(2, -2)}</strong>;
|
||||
// Bold text
|
||||
part = part.slice(2, -2);
|
||||
part.split('\n').forEach((line, i) => {
|
||||
if (i > 0) elements.push(<br key={`br-bold-${index}-${i}`} />);
|
||||
elements.push(<strong key={`bold-${index}-${i}`}>{line}</strong>);
|
||||
});
|
||||
} else {
|
||||
return <span key={index}>{part}</span>;
|
||||
}
|
||||
// Normal text
|
||||
part.split('\n').forEach((line, i) => {
|
||||
if (i > 0) elements.push(<br key={`br-${index}-${i}`} />);
|
||||
elements.push(<span key={`text-${index}-${i}`}>{line}</span>);
|
||||
});
|
||||
}
|
||||
|
||||
return elements;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
return (
|
||||
<div className={styles.chatContainer} >
|
||||
<div className={styles.chatHeader}>
|
||||
|
||||
@@ -22,7 +22,6 @@ const Dashboard = () => {
|
||||
const [modalContent, setModalContent] = useState(null);
|
||||
const [rawData, setRawData] = useState([]);
|
||||
const [loading, setLoading] = useState(true); // ⬅️ Tambahkan state loading
|
||||
const [checkOnce, setCheckOnce] = useState(false); // ⬅️ Tambahkan state loading
|
||||
|
||||
const [stats, setStats] = useState({
|
||||
totalChats: 0,
|
||||
@@ -139,33 +138,38 @@ const Dashboard = () => {
|
||||
}
|
||||
};
|
||||
|
||||
if (!checkOnce && 'serviceWorker' in navigator) {
|
||||
navigator.serviceWorker.ready.then(function (registration) {
|
||||
registration.pushManager.getSubscription().then(function (subscription) {
|
||||
setCheckOnce(true);
|
||||
if (subscription === null) {
|
||||
// Not subscribed yet — show modal asking user to subscribe
|
||||
setModalContent(<NotificationPrompt onAllow={subscribeUser} onDismiss={() => setModalContent('')} />);
|
||||
} else {
|
||||
// Already subscribed
|
||||
setModalContent('')
|
||||
console.log('User is already subscribed.');
|
||||
subscribeUser();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
fetchData(); // Jalankan langsung saat komponen di-mount
|
||||
const interval = setInterval(fetchData, 60000); // Jalankan setiap 30 detik
|
||||
return () => clearInterval(interval); // Bersihkan interval saat komponen unmount
|
||||
|
||||
}, [navigate]);
|
||||
|
||||
const subscribeUser = async () => {
|
||||
const registration = await navigator.serviceWorker.register('/sw.js', {
|
||||
scope: '/',
|
||||
useEffect(() => {
|
||||
if ('serviceWorker' in navigator) {
|
||||
navigator.serviceWorker.ready.then(async (registration) => {
|
||||
const subscription = await registration.pushManager.getSubscription();
|
||||
if (!subscription) {
|
||||
// Belum subscribe → tampilkan prompt
|
||||
setModalContent(
|
||||
<NotificationPrompt
|
||||
onAllow={subscribeUser}
|
||||
onDismiss={() => setModalContent('')}
|
||||
/>
|
||||
);
|
||||
} else {
|
||||
// Sudah subscribe → tidak perlu panggil subscribeUser lagi
|
||||
console.log('User is already subscribed.');
|
||||
setModalContent('');
|
||||
subscribeUser();
|
||||
}
|
||||
});
|
||||
}
|
||||
}, []);
|
||||
|
||||
|
||||
const subscribeUser = async () => {
|
||||
setModalContent('');
|
||||
const registration = await navigator.serviceWorker.ready;
|
||||
|
||||
const subscription = await registration.pushManager.subscribe({
|
||||
userVisibleOnly: true,
|
||||
@@ -176,18 +180,17 @@ const Dashboard = () => {
|
||||
|
||||
await fetch('https://bot.kediritechnopark.com/webhook/subscribe', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({
|
||||
subscription, // ← push subscription object
|
||||
}),
|
||||
body: JSON.stringify({ subscription }),
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': `Bearer ${token}`,
|
||||
},
|
||||
});
|
||||
|
||||
setModalContent('')
|
||||
setModalContent('');
|
||||
};
|
||||
|
||||
|
||||
function urlBase64ToUint8Array(base64String) {
|
||||
const padding = '='.repeat((4 - base64String.length % 4) % 4);
|
||||
const base64 = (base64String + padding).replace(/\-/g, '+').replace(/_/g, '/');
|
||||
|
||||
@@ -89,19 +89,15 @@ const ProfileTab = () => {
|
||||
try {
|
||||
const token = localStorage.getItem('token');
|
||||
|
||||
if (profile.newPassword && profile.newPassword !== profile.confirmPassword) {
|
||||
alert('Password dan konfirmasi tidak sama.');
|
||||
if (profile.newPassword == '' || profile.oldPassword == '') {
|
||||
alert('Password dan konfirmasi tidak boleh kosong.');
|
||||
return;
|
||||
}
|
||||
|
||||
const payload = { ...profile };
|
||||
if (!payload.newPassword) {
|
||||
delete payload.newPassword;
|
||||
delete payload.confirmPassword;
|
||||
} else {
|
||||
payload.password = payload.newPassword;
|
||||
delete payload.newPassword;
|
||||
delete payload.confirmPassword;
|
||||
delete payload.oldPassword;
|
||||
}
|
||||
|
||||
const response = await fetch('https://bot.kediritechnopark.com/webhook/profile', {
|
||||
@@ -175,7 +171,7 @@ const ProfileTab = () => {
|
||||
<label><strong>Old Password:</strong></label>
|
||||
<input
|
||||
type="password"
|
||||
name="newPassword"
|
||||
name="oldPassword"
|
||||
onChange={handleChange}
|
||||
className={styles.editableInput}
|
||||
/>
|
||||
@@ -184,7 +180,7 @@ const ProfileTab = () => {
|
||||
<label><strong>New Password:</strong></label>
|
||||
<input
|
||||
type="password"
|
||||
name="confirmPassword"
|
||||
name="newPassword"
|
||||
onChange={handleChange}
|
||||
className={styles.editableInput}
|
||||
/>
|
||||
|
||||
14
src/index.js
14
src/index.js
@@ -5,12 +5,26 @@ import App from './App';
|
||||
import reportWebVitals from './reportWebVitals';
|
||||
|
||||
const root = ReactDOM.createRoot(document.getElementById('root'));
|
||||
|
||||
if ('serviceWorker' in navigator) {
|
||||
window.addEventListener('load', () => {
|
||||
navigator.serviceWorker.register('/sw.js', { scope: '/' })
|
||||
.then((registration) => {
|
||||
console.log('✅ Service Worker registered successfully:', registration);
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error('❌ Service Worker registration failed:', error);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
root.render(
|
||||
<React.StrictMode>
|
||||
<App />
|
||||
</React.StrictMode>
|
||||
);
|
||||
|
||||
|
||||
// If you want to start measuring performance in your app, pass a function
|
||||
// to log results (for example: reportWebVitals(console.log))
|
||||
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
|
||||
|
||||
Reference in New Issue
Block a user