feat(ui): implement modern website maintenance error boundary matching brand design

This commit is contained in:
iFixKart Dev 2026-11-17 18:50:02 +05:30
parent 6b4a1c56ec
commit 7c7311544d
2 changed files with 277 additions and 17 deletions

View file

@ -1,7 +1,8 @@
'use client'; 'use client';
import React, { useEffect } from 'react'; import React, { useEffect, useState } from 'react';
import { AlertTriangle, RefreshCw } from 'lucide-react'; import { RefreshCw, Home, ChevronDown } from 'lucide-react';
import Link from 'next/link';
interface ErrorProps { interface ErrorProps {
error: Error & { digest?: string }; error: Error & { digest?: string };
@ -9,27 +10,168 @@ interface ErrorProps {
} }
export default function Error({ error, reset }: ErrorProps) { export default function Error({ error, reset }: ErrorProps) {
const [isRetrying, setIsRetrying] = useState(false);
const [showDetails, setShowDetails] = useState(false);
useEffect(() => { useEffect(() => {
console.error('Storefront error boundary caught:', error); console.error('Storefront error boundary caught:', error);
// Auto-recover from chunk load errors caused by production redeployments
const msg = (error?.message || '').toLowerCase();
const isChunkError =
error?.name === 'ChunkLoadError' ||
msg.includes('loading chunk') ||
msg.includes('failed to fetch dynamically imported module');
if (isChunkError && typeof window !== 'undefined') {
const retryKey = `chunk_reload_${window.location.pathname}`;
const hasRetried = sessionStorage.getItem(retryKey);
if (!hasRetried) {
sessionStorage.setItem(retryKey, '1');
window.location.reload();
}
}
}, [error]); }, [error]);
const handleRefresh = () => {
setIsRetrying(true);
if (typeof window !== 'undefined') {
window.location.reload();
} else {
reset();
}
};
return ( return (
<div className="w-full min-h-screen bg-[#F8F9FB] flex flex-col items-center justify-center p-6 font-sans"> <div className="w-full min-h-screen bg-[#EEF2F6] flex flex-col items-center justify-center p-4 sm:p-6 font-sans">
<div className="max-w-md w-full bg-white border border-gray-250 rounded-2xl p-8 text-center shadow-soft"> <div className="max-w-[620px] w-full bg-white rounded-2xl overflow-hidden shadow-2xl border border-gray-100">
<div className="w-12 h-12 bg-red-50 text-red-500 rounded-full flex items-center justify-center mx-auto mb-4"> {/* Top Navy Banner matching Image 2 */}
<AlertTriangle size={24} className="stroke-[2.5]" /> <div className="bg-[#2D4364] px-6 py-8 sm:px-10 sm:py-10 flex items-center gap-6 sm:gap-8">
</div> {/* White Circular Badge with crossed wrench & screwdriver */}
<h2 className="text-lg font-extrabold text-gray-900 mb-2 font-outfit">Something Went Wrong</h2> <div className="w-24 h-24 sm:w-32 sm:h-32 rounded-full bg-white flex items-center justify-center shadow-lg flex-shrink-0 overflow-hidden relative">
<p className="text-xs text-gray-500 font-medium mb-6"> <svg
{error.message || 'We ran into an unexpected error loading this page. Please try refreshing.'} viewBox="0 0 100 100"
</p> className="w-20 h-20 sm:w-28 sm:h-28"
<button fill="none"
onClick={() => reset()} xmlns="http://www.w3.org/2000/svg"
className="inline-flex items-center justify-center gap-2 bg-[#0073EC] hover:bg-[#1565C0] text-white font-bold text-xs uppercase tracking-wider py-3.5 px-6 rounded-xl transition-all shadow-md active:scale-[0.99] cursor-pointer"
> >
<RefreshCw size={14} className="animate-spin-slow" /> {/* Long 45-deg flat shadow */}
<span>Try Again</span> <polygon
points="38,38 98,98 100,80 100,50 62,12 50,24"
fill="#E2E8F0"
opacity="0.8"
/>
{/* Screwdriver (top-left to bottom-right) */}
<g transform="rotate(-45 50 50)">
<rect x="48" y="14" width="4" height="36" fill="#2D4364" />
<polygon points="46,14 54,14 52,9 48,9" fill="#2D4364" />
<rect x="43" y="50" width="14" height="34" rx="3" fill="#2D4364" />
<line
x1="47"
y1="55"
x2="47"
y2="79"
stroke="#FFFFFF"
strokeWidth="1.5"
strokeLinecap="round"
opacity="0.3"
/>
<line
x1="53"
y1="55"
x2="53"
y2="79"
stroke="#FFFFFF"
strokeWidth="1.5"
strokeLinecap="round"
opacity="0.3"
/>
</g>
{/* Wrench (bottom-left to top-right) */}
<g transform="rotate(45 50 50)">
<rect x="45.5" y="28" width="9" height="40" rx="2" fill="#2D4364" />
<path
d="M36 26 C36 14 42 9 50 9 C58 9 64 14 64 26 C64 29 62 31 57 31 L55 21 L45 21 L43 31 C38 31 36 29 36 26 Z"
fill="#2D4364"
/>
<circle cx="50" cy="74" r="9" fill="#2D4364" />
<circle cx="50" cy="74" r="4.5" fill="white" />
</g>
</svg>
</div>
{/* Heading Text */}
<div className="text-white font-black tracking-tight uppercase leading-[1.05] text-2xl sm:text-4xl select-none font-outfit">
WEBSITE<br />
UNDER<br />
MAINTENANCE
</div>
</div>
{/* Bottom Content Body */}
<div className="p-6 sm:p-10">
<h1 className="text-xl sm:text-2xl font-extrabold text-[#1E293B] mb-3 font-outfit">
We’ll be back soon!
</h1>
<p className="text-sm sm:text-[15px] leading-relaxed text-[#475569] mb-5">
Sorry for the inconvenience but we&apos;re performing some maintenance at the moment. If you need to you can always{' '}
<Link
href="/contact"
className="text-[#D97706] hover:text-[#B45309] font-semibold underline underline-offset-2 transition-colors"
>
contact us
</Link>
, otherwise we&apos;ll be back online shortly!
</p>
<p className="text-sm sm:text-[15px] font-semibold text-[#64748B] mb-7">
— The iFixKart Team
</p>
{/* Action Buttons */}
<div className="flex flex-wrap items-center gap-3">
<button
type="button"
onClick={handleRefresh}
disabled={isRetrying}
className="inline-flex items-center justify-center gap-2 bg-[#2D4364] hover:bg-[#1E293B] text-white font-bold text-sm px-6 py-3 rounded-lg shadow-sm transition-all cursor-pointer disabled:opacity-70 active:scale-[0.99]"
>
<RefreshCw size={16} className={isRetrying ? 'animate-spin' : ''} />
<span>{isRetrying ? 'Refreshing...' : 'Refresh Page'}</span>
</button> </button>
<a
href="/"
className="inline-flex items-center justify-center gap-2 bg-[#F1F5F9] hover:bg-[#E2E8F0] text-[#334155] border border-[#CBD5E1] font-bold text-sm px-6 py-3 rounded-lg transition-all cursor-pointer active:scale-[0.99]"
>
<Home size={16} />
<span>Return Home</span>
</a>
</div>
{/* Technical Diagnostics (Collapsible for dev & debugging) */}
{error?.message && (
<div className="mt-8 pt-5 border-t border-gray-100">
<button
type="button"
onClick={() => setShowDetails(!showDetails)}
className="text-xs font-medium text-gray-400 hover:text-gray-600 flex items-center gap-1 cursor-pointer"
>
<span>Diagnostics</span>
<ChevronDown
size={13}
className={`transition-transform duration-200 ${showDetails ? 'rotate-180' : ''}`}
/>
</button>
{showDetails && (
<div className="mt-2 p-3 bg-gray-50 rounded-lg text-left text-xs font-mono text-gray-500 overflow-x-auto border border-gray-200">
<p className="font-semibold text-gray-700">{error.name || 'Error'}: {error.message}</p>
{error.digest && <p className="text-[11px] text-gray-400 mt-1">Digest: {error.digest}</p>}
</div>
)}
</div>
)}
</div>
</div> </div>
</div> </div>
); );

118
app/global-error.tsx Normal file
View file

@ -0,0 +1,118 @@
'use client';
import React, { useEffect, useState } from 'react';
import { RefreshCw, Home } from 'lucide-react';
interface GlobalErrorProps {
error: Error & { digest?: string };
reset: () => void;
}
export default function GlobalError({ error, reset }: GlobalErrorProps) {
const [isRetrying, setIsRetrying] = useState(false);
useEffect(() => {
console.error('Global error boundary caught:', error);
const msg = (error?.message || '').toLowerCase();
const isChunkError =
error?.name === 'ChunkLoadError' ||
msg.includes('loading chunk') ||
msg.includes('failed to fetch dynamically imported module');
if (isChunkError && typeof window !== 'undefined') {
const retryKey = `chunk_reload_global_${window.location.pathname}`;
if (!sessionStorage.getItem(retryKey)) {
sessionStorage.setItem(retryKey, '1');
window.location.reload();
}
}
}, [error]);
const handleRefresh = () => {
setIsRetrying(true);
if (typeof window !== 'undefined') {
window.location.reload();
} else {
reset();
}
};
return (
<html lang="en">
<head>
<meta charSet="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Website Under Maintenance | iFixKart</title>
<style>{`
* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; background: #EEF2F6; min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.card { max-width: 620px; width: 100%; background: #ffffff; border-radius: 16px; overflow: hidden; box-shadow: 0 20px 40px rgba(0,0,0,0.12); }
.banner { background: #2D4364; padding: 36px 32px; display: flex; align-items: center; gap: 24px; }
.circle { width: 110px; height: 110px; border-radius: 50%; background: #ffffff; display: flex; align-items: center; justify-content: center; flex-shrink: 0; box-shadow: 0 8px 24px rgba(0,0,0,0.18); overflow: hidden; }
.banner-title { color: #ffffff; font-weight: 900; text-transform: uppercase; line-height: 1.05; font-size: 32px; letter-spacing: 0.5px; }
.content { padding: 36px 32px; }
.headline { font-size: 24px; font-weight: 800; color: #1E293B; margin-bottom: 14px; }
.paragraph { font-size: 15px; line-height: 1.6; color: #475569; margin-bottom: 20px; }
.contact-link { color: #D97706; text-decoration: underline; font-weight: 600; }
.sign { font-size: 15px; font-weight: 600; color: #64748B; margin-bottom: 28px; }
.actions { display: flex; flex-wrap: wrap; gap: 12px; }
.btn-primary { background: #2D4364; color: #ffffff; border: none; padding: 12px 24px; border-radius: 8px; font-weight: 700; font-size: 14px; cursor: pointer; display: inline-flex; align-items: center; gap: 8px; text-decoration: none; }
.btn-primary:hover { background: #1E293B; }
.btn-secondary { background: #F1F5F9; color: #334155; border: 1px solid #CBD5E1; padding: 12px 24px; border-radius: 8px; font-weight: 700; font-size: 14px; cursor: pointer; display: inline-flex; align-items: center; gap: 8px; text-decoration: none; }
.btn-secondary:hover { background: #E2E8F0; }
`}</style>
</head>
<body>
<div className="card">
<div className="banner">
<div className="circle">
<svg viewBox="0 0 100 100" width="85" height="85" fill="none">
<polygon points="38,38 98,98 100,80 100,50 62,12 50,24" fill="#E2E8F0" opacity="0.8" />
<g transform="rotate(-45 50 50)">
<rect x="48" y="14" width="4" height="36" fill="#2D4364" />
<polygon points="46,14 54,14 52,9 48,9" fill="#2D4364" />
<rect x="43" y="50" width="14" height="34" rx="3" fill="#2D4364" />
<line x1="47" y1="55" x2="47" y2="79" stroke="#FFFFFF" strokeWidth="1.5" strokeLinecap="round" opacity="0.3" />
<line x1="53" y1="55" x2="53" y2="79" stroke="#FFFFFF" strokeWidth="1.5" strokeLinecap="round" opacity="0.3" />
</g>
<g transform="rotate(45 50 50)">
<rect x="45.5" y="28" width="9" height="40" rx="2" fill="#2D4364" />
<path d="M36 26 C36 14 42 9 50 9 C58 9 64 14 64 26 C64 29 62 31 57 31 L55 21 L45 21 L43 31 C38 31 36 29 36 26 Z" fill="#2D4364" />
<circle cx="50" cy="74" r="9" fill="#2D4364" />
<circle cx="50" cy="74" r="4.5" fill="white" />
</g>
</svg>
</div>
<div className="banner-title">
WEBSITE<br />
UNDER<br />
MAINTENANCE
</div>
</div>
<div className="content">
<div className="headline">We’ll be back soon!</div>
<p className="paragraph">
Sorry for the inconvenience but we&apos;re performing some maintenance at the moment. If you need to you can always{' '}
<a href="/contact" className="contact-link">
contact us
</a>
, otherwise we&apos;ll be back online shortly!
</p>
<div className="sign">— The iFixKart Team</div>
<div className="actions">
<button type="button" onClick={handleRefresh} disabled={isRetrying} className="btn-primary">
<RefreshCw size={16} className={isRetrying ? 'animate-spin' : ''} />
<span>{isRetrying ? 'Refreshing...' : 'Refresh Page'}</span>
</button>
<a href="/" className="btn-secondary">
<Home size={16} />
<span>Return Home</span>
</a>
</div>
</div>
</div>
</body>
</html>
);
}