Assist_Design/apps/portal/src/components/guards/profile-completion-guard.tsx
T. Narantuya 0a387275ff Refactor address handling in AuthService and SignupDto, and enhance order processing with address verification
- Updated AuthService to directly access address fields and added support for address line 2.
- Introduced AddressDto in SignupDto for structured address validation.
- Modified OrdersController to utilize CreateOrderDto for improved type safety.
- Enhanced OrderBuilder to include address snapshot functionality during order creation.
- Updated UsersService to handle address updates and added new methods in WHMCS service for client updates.
- Improved address confirmation logic in AddressConfirmation component for internet orders.
2025-08-29 13:26:57 +09:00

79 lines
2.7 KiB
TypeScript

"use client";
import { useEffect } from "react";
import { useProfileCompletion } from "@/hooks/use-profile-completion";
import { MapPinIcon, ExclamationTriangleIcon } from "@heroicons/react/24/outline";
interface ProfileCompletionGuardProps {
children: React.ReactNode;
requireComplete?: boolean;
showBanner?: boolean;
}
export function ProfileCompletionGuard({
children,
requireComplete = false,
showBanner = true,
}: ProfileCompletionGuardProps) {
const { isComplete, loading, redirectToCompletion } = useProfileCompletion();
useEffect(() => {
// If profile completion is required and profile is incomplete, redirect
if (!loading && requireComplete && !isComplete) {
redirectToCompletion();
}
}, [loading, requireComplete, isComplete, redirectToCompletion]);
// Show loading state
if (loading) {
return (
<div className="flex items-center justify-center p-8">
<div className="animate-spin rounded-full h-8 w-8 border-b-2 border-blue-600"></div>
<span className="ml-3 text-gray-600">Loading...</span>
</div>
);
}
// If requiring complete profile and it's not complete, show loading (will redirect)
if (requireComplete && !isComplete) {
return (
<div className="flex items-center justify-center p-8">
<div className="animate-spin rounded-full h-8 w-8 border-b-2 border-blue-600"></div>
<span className="ml-3 text-gray-600">Redirecting to complete profile...</span>
</div>
);
}
// Show banner if profile is incomplete and banner is enabled
if (!isComplete && showBanner) {
return (
<div>
<div className="bg-gradient-to-r from-amber-50 to-orange-50 border border-amber-200 rounded-xl p-6 mb-6">
<div className="flex items-start space-x-4">
<div className="flex-shrink-0">
<ExclamationTriangleIcon className="h-6 w-6 text-amber-600" />
</div>
<div className="flex-1">
<h3 className="text-lg font-semibold text-amber-900 mb-2">Complete Your Profile</h3>
<p className="text-amber-800 mb-4">
Some features may be limited until you complete your profile information.
</p>
<button
onClick={redirectToCompletion}
className="inline-flex items-center px-4 py-2 bg-amber-600 text-white rounded-lg hover:bg-amber-700 transition-colors font-medium"
>
<MapPinIcon className="h-4 w-4 mr-2" />
Complete Profile
</button>
</div>
</div>
</div>
{children}
</div>
);
}
// Profile is complete or banner is disabled, show children
return <>{children}</>;
}