dstpabuaran.com/resources/js/components/pwa-update-toast.tsx
Yoga Pangestu 23cc327190 Refactor code for improved readability and consistency across multiple files
- Adjusted indentation and formatting in login, permissions, profile, and security pages for better readability.
- Enhanced the clarity of conditional statements and function calls in permissions and profile components.
- Updated type definitions in vite-env.d.ts for better code structure.
- Cleaned up array mapping syntax in ProductTest.php for consistency.
2026-08-01 10:14:47 +07:00

41 lines
1.2 KiB
TypeScript

import { useEffect } from 'react';
import { toast } from 'sonner';
export function PWAUpdateToast() {
useEffect(() => {
const handleOfflineReady = () => {
toast.success('Aplikasi siap offline!', {
description: 'Aplikasi dapat digunakan tanpa koneksi internet.',
duration: 5000,
});
};
const handleUpdateAvailable = () => {
toast.info('Update tersedia!', {
description:
'Versi baru aplikasi telah tersedia. Klik untuk memperbarui.',
duration: Infinity,
action: {
label: 'Update',
onClick: () => {
window.location.reload();
},
},
});
};
window.addEventListener('sw-offline-ready', handleOfflineReady);
window.addEventListener('sw-update-available', handleUpdateAvailable);
return () => {
window.removeEventListener('sw-offline-ready', handleOfflineReady);
window.removeEventListener(
'sw-update-available',
handleUpdateAvailable,
);
};
}, []);
return null;
}