Skip to content

Commit 0622e4e

Browse files
Merge pull request #361 from Code102SoftwareProject/user-verificstion-markwith-skill-match
feat: Add KYC status fetching for users in ListingCard, MatchCard, an…
2 parents d1cc9c3 + 79478f5 commit 0622e4e

3 files changed

Lines changed: 92 additions & 9 deletions

File tree

src/components/Dashboard/listings/ListingCard.tsx

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33

44
import React, { useState, useEffect } from 'react';
55
import Image from 'next/image';
6+
import { useRouter } from 'next/navigation';
67
import { SkillListing } from '@/types/skillListing';
7-
import { BadgeCheck, Edit, Trash2, Eye, Users, Shield, CheckCircle, Clock, XCircle } from 'lucide-react';
8+
import { BadgeCheck, Edit, Trash2, Eye, Users, Shield, CheckCircle, Clock, XCircle, AlertCircle } from 'lucide-react';
89
import { useAuth } from '@/lib/context/AuthContext';
910
import { processAvatarUrl } from '@/utils/avatarUtils';
1011

@@ -19,15 +20,33 @@ interface ListingCardProps {
1920

2021
const ListingCard: React.FC<ListingCardProps> = ({ listing, onDelete, onEdit }) => {
2122
const { user } = useAuth();
23+
const router = useRouter();
2224
const [isOwner, setIsOwner] = useState(false);
2325
const [showDetailsModal, setShowDetailsModal] = useState(false);
26+
const [kycStatus, setKycStatus] = useState<string | null>(null);
2427

2528
useEffect(() => {
2629
// Check if the current user is the owner of this listing
2730
if (user && listing) {
2831
setIsOwner(user._id === listing.userId);
2932
}
3033
}, [user, listing]);
34+
35+
// Fetch KYC status for the listing user
36+
useEffect(() => {
37+
async function fetchKycStatus() {
38+
try {
39+
const res = await fetch(`/api/kyc/status?userId=${listing.userId}`);
40+
const data = await res.json();
41+
setKycStatus(data.success ? data.status : null);
42+
} catch (err) {
43+
setKycStatus(null);
44+
}
45+
}
46+
if (listing.userId) {
47+
fetchKycStatus();
48+
}
49+
}, [listing.userId]);
3150

3251
const formatDate = (dateString: string) => {
3352
const options: Intl.DateTimeFormatOptions = { year: 'numeric', month: 'short', day: 'numeric' };
@@ -89,7 +108,17 @@ const ListingCard: React.FC<ListingCardProps> = ({ listing, onDelete, onEdit })
89108
<div className="flex-1 min-w-0">
90109
<h3 className="font-medium text-gray-800 flex items-center truncate">
91110
<span className="truncate">{listing.userDetails.firstName} {listing.userDetails.lastName}</span>
92-
<BadgeCheck className="w-4 h-4 ml-1 text-blue-500 flex-shrink-0" />
111+
{(kycStatus === 'Accepted' || kycStatus === 'Approved') ? (
112+
<BadgeCheck className="w-4 h-4 ml-1 text-blue-500 flex-shrink-0" />
113+
) : (
114+
<button
115+
onClick={() => router.push('/dashboard?component=setting')}
116+
title="Click to verify your account"
117+
className="inline-flex"
118+
>
119+
<AlertCircle className="w-4 h-4 ml-1 text-orange-500 flex-shrink-0 hover:text-orange-600 transition-colors cursor-pointer" />
120+
</button>
121+
)}
93122
</h3>
94123
<p className="text-xs text-gray-500 truncate">
95124
{formatDate(listing.createdAt)}
@@ -226,7 +255,18 @@ const ListingCard: React.FC<ListingCardProps> = ({ listing, onDelete, onEdit })
226255
<div className="flex-1">
227256
<h3 className="font-semibold text-gray-800 flex items-center">
228257
{listing.userDetails.firstName} {listing.userDetails.lastName}
229-
<BadgeCheck className="w-5 h-5 ml-2 text-blue-500" />
258+
{(kycStatus === 'Accepted' || kycStatus === 'Approved') ? (
259+
<BadgeCheck className="w-5 h-5 ml-2 text-blue-500" />
260+
) : (
261+
<button
262+
onClick={() => router.push('/dashboard?component=setting')}
263+
className="ml-2 px-3 py-1 text-sm bg-orange-100 text-orange-600 rounded-full flex items-center hover:bg-orange-200 transition-colors"
264+
title="Click to verify your account"
265+
>
266+
<AlertCircle className="w-4 h-4 mr-1" />
267+
Verify
268+
</button>
269+
)}
230270
</h3>
231271
<p className="text-sm text-gray-500">
232272
Posted on {formatDate(listing.createdAt)}

src/components/Dashboard/matches/MatchCard.tsx

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
'use client';
22

3-
import React from 'react';
3+
import React, { useState, useEffect } from 'react';
44
import Image from 'next/image';
55
import { SkillMatch } from '@/types/skillMatch';
6-
import { BadgeCheck, ArrowRightLeft, Eye, MessageCircle, Clock, CheckCircle, XCircle, Award, Calendar } from 'lucide-react';
6+
import { BadgeCheck, ArrowRightLeft, Eye, MessageCircle, Clock, CheckCircle, XCircle, Award, Calendar, AlertCircle } from 'lucide-react';
77
import { processAvatarUrl } from '@/utils/avatarUtils';
88

99
interface MatchCardProps {
@@ -12,6 +12,24 @@ interface MatchCardProps {
1212
}
1313

1414
const MatchCard: React.FC<MatchCardProps> = ({ match, onClick }) => {
15+
const [otherUserKycStatus, setOtherUserKycStatus] = useState<string | null>(null);
16+
17+
// Fetch KYC status for the other user
18+
useEffect(() => {
19+
async function fetchKycStatus() {
20+
try {
21+
const res = await fetch(`/api/kyc/status?userId=${match.otherUser.userId}`);
22+
const data = await res.json();
23+
setOtherUserKycStatus(data.success ? data.status : null);
24+
} catch (err) {
25+
setOtherUserKycStatus(null);
26+
}
27+
}
28+
if (match.otherUser.userId) {
29+
fetchKycStatus();
30+
}
31+
}, [match.otherUser.userId]);
32+
1533
// Format date
1634
const formatDate = (dateString: string) => {
1735
const options: Intl.DateTimeFormatOptions = { year: 'numeric', month: 'short', day: 'numeric' };
@@ -222,7 +240,11 @@ const MatchCard: React.FC<MatchCardProps> = ({ match, onClick }) => {
222240
>
223241
{match.otherUser.firstName} {match.otherUser.lastName}
224242
</span>
225-
<BadgeCheck className="w-4 h-4 ml-1 text-blue-500 flex-shrink-0" />
243+
{(otherUserKycStatus === 'Accepted' || otherUserKycStatus === 'Approved') ? (
244+
<BadgeCheck className="w-4 h-4 ml-1 text-blue-500 flex-shrink-0" />
245+
) : (
246+
<AlertCircle className="w-4 h-4 ml-1 text-orange-500 flex-shrink-0" title="Not Verified" />
247+
)}
226248
</h3>
227249
</div>
228250

src/components/Dashboard/matches/MatchDetailsModal.tsx

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
'use client';
22

3-
import React, { useState } from 'react';
3+
import React, { useState, useEffect } from 'react';
44
import Image from 'next/image';
55
import { useRouter } from 'next/navigation';
66
import { SkillMatch } from '@/types/skillMatch';
77
import { useToast } from '@/lib/context/ToastContext';
88
import { updateMatchStatus, acceptMatchAndCreateChatRoom } from '@/services/matchService';
99
import { fetchUserChatRooms } from '@/services/chatApiServices';
1010
import { useAuth } from '@/lib/context/AuthContext';
11-
import { BadgeCheck, ArrowRight, MessageCircle, Calendar, XCircle, CheckCircle, Clock, Award, BarChart3, Target } from 'lucide-react';
11+
import { BadgeCheck, ArrowRight, MessageCircle, Calendar, XCircle, CheckCircle, Clock, Award, BarChart3, Target, AlertCircle } from 'lucide-react';
1212
import { processAvatarUrl } from '@/utils/avatarUtils';
1313

1414
interface MatchDetailsModalProps {
@@ -92,6 +92,23 @@ const MatchDetailsModal: React.FC<MatchDetailsModalProps> = ({ match, currentUse
9292
const [showAcceptConfirmation, setShowAcceptConfirmation] = useState(false);
9393
const [showRejectConfirmation, setShowRejectConfirmation] = useState(false);
9494
const [openingChat, setOpeningChat] = useState(false);
95+
const [otherUserKycStatus, setOtherUserKycStatus] = useState<string | null>(null);
96+
97+
// Fetch KYC status for the other user
98+
useEffect(() => {
99+
async function fetchKycStatus() {
100+
try {
101+
const res = await fetch(`/api/kyc/status?userId=${match.otherUser.userId}`);
102+
const data = await res.json();
103+
setOtherUserKycStatus(data.success ? data.status : null);
104+
} catch (err) {
105+
setOtherUserKycStatus(null);
106+
}
107+
}
108+
if (match.otherUser.userId) {
109+
fetchKycStatus();
110+
}
111+
}, [match.otherUser.userId]);
95112

96113
// Format date
97114
const formatDate = (dateString: string) => {
@@ -411,7 +428,11 @@ const MatchDetailsModal: React.FC<MatchDetailsModalProps> = ({ match, currentUse
411428
<div>
412429
<h3 className="font-semibold text-gray-800 flex items-center">
413430
{match.otherUser.firstName} {match.otherUser.lastName}
414-
<BadgeCheck className="w-4 h-4 ml-1 text-blue-500" />
431+
{(otherUserKycStatus === 'Accepted' || otherUserKycStatus === 'Approved') ? (
432+
<BadgeCheck className="w-4 h-4 ml-1 text-blue-500" />
433+
) : (
434+
<AlertCircle className="w-4 h-4 ml-1 text-orange-500" title="Not Verified" />
435+
)}
415436
</h3>
416437
<p className="text-xs text-gray-600">Partner Profile</p>
417438
</div>

0 commit comments

Comments
 (0)