ifixkart-storefront/app/error.tsx

178 lines
7 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

'use client';
import React, { useEffect, useState } from 'react';
import { RefreshCw, Home, ChevronDown } from 'lucide-react';
import Link from 'next/link';
interface ErrorProps {
error: Error & { digest?: string };
reset: () => void;
}
export default function Error({ error, reset }: ErrorProps) {
const [isRetrying, setIsRetrying] = useState(false);
const [showDetails, setShowDetails] = useState(false);
useEffect(() => {
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]);
const handleRefresh = () => {
setIsRetrying(true);
if (typeof window !== 'undefined') {
window.location.reload();
} else {
reset();
}
};
return (
<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-[620px] w-full bg-white rounded-2xl overflow-hidden shadow-2xl border border-gray-100">
{/* Top Navy Banner matching Image 2 */}
<div className="bg-[#2D4364] px-6 py-8 sm:px-10 sm:py-10 flex items-center gap-6 sm:gap-8">
{/* White Circular Badge with crossed wrench & screwdriver */}
<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">
<svg
viewBox="0 0 100 100"
className="w-20 h-20 sm:w-28 sm:h-28"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
{/* Long 45-deg flat shadow */}
<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>
<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>
);
}