diff --git a/app/layout.tsx b/app/layout.tsx
index 493e8fb..e47a10a 100644
--- a/app/layout.tsx
+++ b/app/layout.tsx
@@ -13,6 +13,7 @@ import { Toaster } from '@/components/ui/sonner';
import AntdConfigProvider from '@/providers/AntdConfigProvider';
import ProgressBarProviders from '@/providers/ProgressBarProvider';
import { TooltipProvider } from '@/components/ui/tooltip';
+import ServiceWorkerRegister from '@/components/pwa/ServiceWorkerRegister';
const jakarta = Plus_Jakarta_Sans({ subsets: ['latin'] })
@@ -25,13 +26,40 @@ export const metadata: Metadata = {
keywords: ["react", "server components", 'rsc', 'nextjs', 'tailwind', 'typescript', 'shadcn', 'presence', 'absence', 'task', 'admin', 'cms', 'dashboard'],
authors: [{ name: 'ichsankurnia', url: 'https://ichsankurnia-portfolio.vercel.app' }],
creator: 'ichsankurnia',
+ manifest: '/manifest.webmanifest',
+ appleWebApp: {
+ capable: true,
+ statusBarStyle: 'default',
+ title: 'H.A.T.s',
+ },
+ icons: {
+ icon: [
+ { url: '/assets/logo192.png', sizes: '192x192', type: 'image/png' },
+ { url: '/assets/logo512.png', sizes: '512x512', type: 'image/png' },
+ ],
+ apple: [
+ { url: '/assets/apple-touch-icon.png', sizes: '180x180', type: 'image/png' },
+ ],
+ },
+ formatDetection: {
+ telephone: false,
+ },
openGraph: {
title: "HIS Attendance Task System (H.A.T.s)",
description: "H.A.T.s HIS Attendance Task System (smart absence, task management, work permit and leave mangement, etc).",
+ images: [
+ {
+ url: '/assets/logo512.png',
+ width: 512,
+ height: 512,
+ alt: 'HIS Attendance Task System (H.A.T.s)',
+ },
+ ],
},
twitter: {
title: "HIS Attendance Task System (H.A.T.s)",
description: "H.A.T.s HIS Attendance Task System (smart absence, task management, work permit and leave mangement, etc).",
+ images: ['/assets/logo512.png'],
},
pinterest: {
richPin: true
@@ -57,6 +85,8 @@ export const viewport: Viewport = {
{ media: '(prefers-color-scheme: light)', color: '#EA512C' },
{ media: '(prefers-color-scheme: dark)', color: '#EA512C' },
],
+ width: 'device-width',
+ initialScale: 1,
}
export default async function RootLayout({
@@ -74,9 +104,11 @@ export default async function RootLayout({
return (
+
+
diff --git a/app/manifest.ts b/app/manifest.ts
new file mode 100644
index 0000000..d608f27
--- /dev/null
+++ b/app/manifest.ts
@@ -0,0 +1,48 @@
+import type { MetadataRoute } from 'next';
+
+export default function manifest(): MetadataRoute.Manifest {
+ return {
+ name: 'HIS Attendance Task System (H.A.T.s)',
+ short_name: 'H.A.T.s',
+ description: 'H.A.T.s HIS Attendance Task System (smart absence, task management, work permit and leave mangement, etc).',
+ start_url: '/',
+ id: '/',
+ scope: '/',
+ display: 'standalone',
+ background_color: '#ffffff',
+ theme_color: '#EA512C',
+ orientation: 'portrait',
+ icons: [
+ {
+ src: '/assets/logo192.png',
+ sizes: '192x192',
+ type: 'image/png',
+ purpose: 'any',
+ },
+ {
+ src: '/assets/hats-256x256.png',
+ sizes: '256x256',
+ type: 'image/png',
+ purpose: 'any',
+ },
+ {
+ src: '/assets/logo512.png',
+ sizes: '512x512',
+ type: 'image/png',
+ purpose: 'any',
+ },
+ {
+ src: '/assets/logo512.png',
+ sizes: '512x512',
+ type: 'image/png',
+ purpose: 'maskable',
+ },
+ {
+ src: '/assets/apple-touch-icon.png',
+ sizes: '180x180',
+ type: 'image/png',
+ purpose: 'any',
+ },
+ ],
+ };
+}
diff --git a/app/offline/page.tsx b/app/offline/page.tsx
new file mode 100644
index 0000000..fd94213
--- /dev/null
+++ b/app/offline/page.tsx
@@ -0,0 +1,43 @@
+'use client';
+
+import { WifiOff, RefreshCw } from 'lucide-react';
+import Image from 'next/image';
+import { Button } from '@/components/ui/button';
+
+export default function OfflinePage() {
+ return (
+
+
+
+
+
+
+ You are currently offline
+
+
+ It looks like your internet connection was lost. Please check your network and try again.
+
+
+
+
+
+
+ );
+}
diff --git a/components/pwa/ServiceWorkerRegister.tsx b/components/pwa/ServiceWorkerRegister.tsx
new file mode 100644
index 0000000..4da5853
--- /dev/null
+++ b/components/pwa/ServiceWorkerRegister.tsx
@@ -0,0 +1,40 @@
+'use client';
+
+import { useEffect } from 'react';
+
+export default function ServiceWorkerRegister() {
+ useEffect(() => {
+ if (typeof window !== 'undefined' && 'serviceWorker' in navigator) {
+ const registerSW = async () => {
+ try {
+ const registration = await navigator.serviceWorker.register('/sw.js', {
+ scope: '/',
+ });
+
+ // Listen for updates
+ registration.addEventListener('updatefound', () => {
+ const newWorker = registration.installing;
+ if (newWorker) {
+ newWorker.addEventListener('statechange', () => {
+ if (newWorker.state === 'installed' && navigator.serviceWorker.controller) {
+ console.log('[PWA] New content is available; please refresh.');
+ }
+ });
+ }
+ });
+ } catch (error) {
+ console.error('[PWA] Service Worker registration failed:', error);
+ }
+ };
+
+ if (document.readyState === 'complete') {
+ registerSW();
+ } else {
+ window.addEventListener('load', registerSW);
+ return () => window.removeEventListener('load', registerSW);
+ }
+ }
+ }, []);
+
+ return null;
+}
diff --git a/proxy.ts b/proxy.ts
index 22a149e..af4da0a 100644
--- a/proxy.ts
+++ b/proxy.ts
@@ -13,7 +13,7 @@ export const config = {
* 6. /favicon.ico, /sitemap.xml (static files)
* 7. /auth page
*/
- "/((?!api/|_next/|_proxy/|_static|_vercel|auth|terms|privacy-policy|not-found|avatars/|assets/|files/|admin/sourceMap/chrome/css/|admin/administration/sourceMap/chrome/css/|firebase-messaging-sw.js|favicon.ico|sitemap.xml).*)",
+ "/((?!api/|_next/|_proxy/|_static|_vercel|auth|terms|privacy-policy|not-found|avatars/|assets/|files/|admin/sourceMap/chrome/css/|admin/administration/sourceMap/chrome/css/|firebase-messaging-sw.js|sw.js|manifest.json|manifest.webmanifest|offline|favicon.ico|sitemap.xml).*)",
],
// matcher: [
// "/",
diff --git a/public/assets/apple-touch-icon.png b/public/assets/apple-touch-icon.png
new file mode 100644
index 0000000..d89e4ae
Binary files /dev/null and b/public/assets/apple-touch-icon.png differ
diff --git a/public/assets/logo192.png b/public/assets/logo192.png
new file mode 100644
index 0000000..da2bc4b
Binary files /dev/null and b/public/assets/logo192.png differ
diff --git a/public/assets/logo512.png b/public/assets/logo512.png
new file mode 100644
index 0000000..546fccb
Binary files /dev/null and b/public/assets/logo512.png differ
diff --git a/public/manifest.json b/public/manifest.json
new file mode 100644
index 0000000..5372d51
--- /dev/null
+++ b/public/manifest.json
@@ -0,0 +1,44 @@
+{
+ "name": "HIS Attendance Task System (H.A.T.s)",
+ "short_name": "H.A.T.s",
+ "description": "H.A.T.s HIS Attendance Task System (smart absence, task management, work permit and leave mangement, etc).",
+ "start_url": "/",
+ "id": "/",
+ "scope": "/",
+ "display": "standalone",
+ "background_color": "#ffffff",
+ "theme_color": "#EA512C",
+ "orientation": "portrait",
+ "icons": [
+ {
+ "src": "/assets/logo192.png",
+ "sizes": "192x192",
+ "type": "image/png",
+ "purpose": "any"
+ },
+ {
+ "src": "/assets/hats-256x256.png",
+ "sizes": "256x256",
+ "type": "image/png",
+ "purpose": "any"
+ },
+ {
+ "src": "/assets/logo512.png",
+ "sizes": "512x512",
+ "type": "image/png",
+ "purpose": "any"
+ },
+ {
+ "src": "/assets/logo512.png",
+ "sizes": "512x512",
+ "type": "image/png",
+ "purpose": "maskable"
+ },
+ {
+ "src": "/assets/apple-touch-icon.png",
+ "sizes": "180x180",
+ "type": "image/png",
+ "purpose": "any"
+ }
+ ]
+}
diff --git a/public/sw.js b/public/sw.js
new file mode 100644
index 0000000..777c91f
--- /dev/null
+++ b/public/sw.js
@@ -0,0 +1,138 @@
+const CACHE_NAME = 'hats-pwa-v1';
+
+const PRECACHE_ASSETS = [
+ '/',
+ '/offline',
+ '/assets/logo192.png',
+ '/assets/logo512.png',
+ '/assets/apple-touch-icon.png',
+ '/assets/hats-256x256.png',
+ '/assets/illustrations/maintenance.svg',
+];
+
+self.addEventListener('install', (event) => {
+ event.waitUntil(
+ caches.open(CACHE_NAME).then(async (cache) => {
+ // Attempt to precache essential assets, ignoring individual failures
+ for (const asset of PRECACHE_ASSETS) {
+ try {
+ await cache.add(asset);
+ } catch (err) {
+ console.warn(`[PWA SW] Precache failed for ${asset}:`, err);
+ }
+ }
+ })
+ );
+ self.skipWaiting();
+});
+
+self.addEventListener('activate', (event) => {
+ event.waitUntil(
+ caches.keys().then((keys) => {
+ return Promise.all(
+ keys.map((key) => {
+ if (key !== CACHE_NAME) {
+ return caches.delete(key);
+ }
+ })
+ );
+ })
+ );
+ self.clients.claim();
+});
+
+self.addEventListener('fetch', (event) => {
+ const { request } = event;
+ const url = new URL(request.url);
+
+ // Only handle GET requests
+ if (request.method !== 'GET') return;
+
+ // Do not intercept browser extensions, HMR, or internal telemetry
+ if (url.protocol !== 'http:' && url.protocol !== 'https:') return;
+ if (url.pathname.includes('webpack-hmr')) return;
+
+ // Do not cache API requests or authentication endpoints
+ if (
+ url.pathname.startsWith('/api/') ||
+ url.hostname.includes('api') ||
+ url.pathname.startsWith('/auth')
+ ) {
+ return;
+ }
+
+ // Navigation requests (HTML pages)
+ if (request.mode === 'navigate') {
+ event.respondWith(
+ fetch(request)
+ .then((response) => {
+ // Only cache successful standard responses
+ if (response && response.status === 200 && response.type === 'basic') {
+ const responseToCache = response.clone();
+ caches.open(CACHE_NAME).then((cache) => {
+ cache.put(request, responseToCache);
+ });
+ }
+ return response;
+ })
+ .catch(async () => {
+ const cachedResponse = await caches.match(request);
+ if (cachedResponse) {
+ return cachedResponse;
+ }
+ const offlineFallback = await caches.match('/offline');
+ if (offlineFallback) {
+ return offlineFallback;
+ }
+ return new Response(
+ `
+
+
+
+
+ Offline - H.A.T.s
+
+
+
+
+

+
You are currently offline
+
Please check your internet connection to continue using H.A.T.s.
+
+
+
+ `,
+ { headers: { 'Content-Type': 'text/html; charset=utf-8' } }
+ );
+ })
+ );
+ return;
+ }
+
+ // Static assets (images, icons, fonts) - Cache First, Fallback to Network
+ if (
+ url.pathname.startsWith('/assets/') ||
+ url.pathname.match(/\.(png|jpg|jpeg|svg|webp|gif|ico|woff|woff2|ttf|css)$/)
+ ) {
+ event.respondWith(
+ caches.match(request).then((cached) => {
+ if (cached) return cached;
+ return fetch(request).then((response) => {
+ if (response && response.status === 200) {
+ const clone = response.clone();
+ caches.open(CACHE_NAME).then((cache) => {
+ cache.put(request, clone);
+ });
+ }
+ return response;
+ });
+ })
+ );
+ }
+});