feat: Enable direct navigation to specific message conversations via URL parameters and initiate new conversations from the network page.
This commit is contained in:
@@ -1,11 +1,15 @@
|
||||
'use client';
|
||||
|
||||
import { useSearchParams } from 'next/navigation';
|
||||
import { MessagingPage } from '@/components/message';
|
||||
|
||||
export default function AgentMessagePage() {
|
||||
const searchParams = useSearchParams();
|
||||
const conversationId = searchParams.get('conversationId');
|
||||
|
||||
return (
|
||||
<div className="max-w-7xl mx-auto px-4 lg:px-8 py-6">
|
||||
<MessagingPage />
|
||||
<MessagingPage initialConversationId={conversationId} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import { NetworkSidebar } from './component/NetworkSidebar';
|
||||
import { InvitationCard } from './component/InvitationCard';
|
||||
import { ConnectionCard } from './component/ConnectionCard';
|
||||
import { connectionRequestsService, ConnectionRequest, ConnectionRequestCounts } from '@/services/connection-requests.service';
|
||||
import { messagesService } from '@/services/messages.service';
|
||||
|
||||
export default function NetworkPage() {
|
||||
const router = useRouter();
|
||||
@@ -100,8 +101,20 @@ export default function NetworkPage() {
|
||||
}
|
||||
};
|
||||
|
||||
const handleMessage = (userId: string) => {
|
||||
router.push('/agent/message');
|
||||
const [messagingUserId, setMessagingUserId] = useState<string | null>(null);
|
||||
|
||||
const handleMessage = async (userId: string) => {
|
||||
if (messagingUserId) return;
|
||||
setMessagingUserId(userId);
|
||||
try {
|
||||
const conversation = await messagesService.startConversation({ userId });
|
||||
router.push(`/agent/message?conversationId=${conversation.id}`);
|
||||
} catch (err) {
|
||||
console.error('Failed to start conversation:', err);
|
||||
router.push('/agent/message');
|
||||
} finally {
|
||||
setMessagingUserId(null);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
|
||||
@@ -1,11 +1,15 @@
|
||||
'use client';
|
||||
|
||||
import { useSearchParams } from 'next/navigation';
|
||||
import { MessagingPage } from '@/components/message';
|
||||
|
||||
export default function UserMessagePage() {
|
||||
const searchParams = useSearchParams();
|
||||
const conversationId = searchParams.get('conversationId');
|
||||
|
||||
return (
|
||||
<div className="max-w-7xl mx-auto px-4 lg:px-8 py-6">
|
||||
<MessagingPage />
|
||||
<MessagingPage initialConversationId={conversationId} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -126,7 +126,7 @@ interface ConnectedAgent {
|
||||
state: string | null;
|
||||
}
|
||||
|
||||
export function MessagingPage() {
|
||||
export function MessagingPage({ initialConversationId }: { initialConversationId?: string | null }) {
|
||||
const { data: session } = useSession();
|
||||
const {
|
||||
conversations,
|
||||
@@ -298,6 +298,20 @@ export function MessagingPage() {
|
||||
}
|
||||
}, [conversations]);
|
||||
|
||||
// Auto-select conversation when navigated with initialConversationId
|
||||
const initialConvHandledRef = useRef(false);
|
||||
useEffect(() => {
|
||||
if (
|
||||
initialConversationId &&
|
||||
!initialConvHandledRef.current &&
|
||||
conversations.length > 0 &&
|
||||
!isLoading
|
||||
) {
|
||||
initialConvHandledRef.current = true;
|
||||
selectConversation(initialConversationId);
|
||||
}
|
||||
}, [initialConversationId, conversations, isLoading, selectConversation]);
|
||||
|
||||
// Convert current conversation avatar when selected
|
||||
useEffect(() => {
|
||||
const convertCurrentAvatar = async () => {
|
||||
|
||||
Reference in New Issue
Block a user