From edfbf4a51c4ca9ce2be81aaed96ff41984f9f6bb Mon Sep 17 00:00:00 2001 From: pradeepkumar Date: Mon, 2 Feb 2026 00:34:31 +0530 Subject: [PATCH] feat: Implement agent availability status with a toggle for agents and display on user profiles. --- src/app/(agent)/agent/dashboard/page.tsx | 33 ++++++++- src/app/(user)/user/profile/[id]/page.tsx | 4 +- src/components/profile/StatusButtons.tsx | 81 +++++++++++++++++++---- src/services/agents.service.ts | 2 + 4 files changed, 102 insertions(+), 18 deletions(-) diff --git a/src/app/(agent)/agent/dashboard/page.tsx b/src/app/(agent)/agent/dashboard/page.tsx index b6d1046..e385528 100644 --- a/src/app/(agent)/agent/dashboard/page.tsx +++ b/src/app/(agent)/agent/dashboard/page.tsx @@ -109,6 +109,8 @@ export default function AgentDashboard() { const [isPhotoModalOpen, setIsPhotoModalOpen] = useState(false); const [imageError, setImageError] = useState(false); const [avatarUrl, setAvatarUrl] = useState(null); + const [isAvailable, setIsAvailable] = useState(true); + const [isTogglingAvailability, setIsTogglingAvailability] = useState(false); const defaultImage = '/assets/demo_images/8f017153a7b4a239a4f0691234ef97dd55092282.jpg'; @@ -134,6 +136,7 @@ export default function AgentDashboard() { setAgentProfile(profile); setFieldValues(fieldValuesResponse.fieldValues); + setIsAvailable(profile.isAvailable ?? true); // Map field values to experience data structure const mappedExperience = mapFieldValuesToExperience(fieldValuesResponse.fieldValues); @@ -175,6 +178,28 @@ export default function AgentDashboard() { fetchData(); }, []); + // Handle availability toggle + const handleToggleAvailability = async () => { + if (isTogglingAvailability) return; + + try { + setIsTogglingAvailability(true); + const newAvailability = !isAvailable; + + // Update on server + const updatedProfile = await agentsService.updateProfile({ isAvailable: newAvailability }); + + // Update local state + setIsAvailable(newAvailability); + setAgentProfile(updatedProfile); + } catch (err) { + console.error('Failed to update availability:', err); + // Revert on error - state stays the same + } finally { + setIsTogglingAvailability(false); + } + }; + const handlePhotoUpload = async (file: File) => { // Upload avatar to S3 (uses agent ID as filename for auto-replacement) const uploadedFile = await uploadService.uploadAvatar(file); @@ -300,8 +325,12 @@ export default function AgentDashboard() { - {/* Status Buttons */} - + {/* Status Buttons - Toggle for agent to set availability */} + {/* Contact Info */} - {/* Status Buttons */} - + {/* Status Buttons - Public view shows availability status */} + {/* Contact Info */} void; + showToggle?: boolean; // If true, show as toggle (for agent's own dashboard) } -export function StatusButtons({ isAvailable = true }: StatusButtonsProps) { +export function StatusButtons({ + isAvailable = true, + onToggleAvailability, + showToggle = false +}: StatusButtonsProps) { const { data: session } = useSession(); const router = useRouter(); const pathname = usePathname(); // Handle connect click - require login if not authenticated const handleConnectClick = () => { + if (!isAvailable) return; // Don't do anything if unavailable + if (!session) { // Store the current page to redirect back after login const returnUrl = encodeURIComponent(pathname); @@ -23,28 +31,73 @@ export function StatusButtons({ isAvailable = true }: StatusButtonsProps) { // TODO: Handle connect action when logged in }; - return ( -
-
-
- - Available. -
+ // If showToggle is true, render both options as a toggle selector (for agent dashboard) + if (showToggle) { + return ( +
+ {/* Available Option */} + + {/* Unavailable Option */} +
+ ); + } + + // Public view - show single status with Connect button + return ( +
- - Unavailable. + + + {isAvailable ? 'Available.' : 'Unavailable.'} +
diff --git a/src/services/agents.service.ts b/src/services/agents.service.ts index 4d614b7..0e25f17 100644 --- a/src/services/agents.service.ts +++ b/src/services/agents.service.ts @@ -28,6 +28,7 @@ export interface AgentProfile { isVerified: boolean; isFeatured: boolean; isActive: boolean; + isAvailable: boolean; agentTypeId: string | null; agentType: AgentType | null; user?: { @@ -121,6 +122,7 @@ export interface PublicAgentProfile { reviewCount: number; isVerified: boolean; isFeatured: boolean; + isAvailable: boolean; agentTypeId: string | null; agentType: AgentType | null; createdAt?: string;