Skip to content

Commit 94e346a

Browse files
committed
Enhance the certificate Varification Logic
1 parent 910f6fd commit 94e346a

File tree

1 file changed

+42
-2
lines changed

1 file changed

+42
-2
lines changed

src/User/pages/Certification/Certification.jsx

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,23 @@ function Certification() {
223223

224224
if (contributor) {
225225
// Show success message with contributor info
226+
// Fetch user's contributions to VigyBag
227+
const contributionsResponse = await axios.get(
228+
`https://api.github.com/repos/codervivek5/VigyBag/commits?author=${contributor.login}`
229+
);
230+
231+
const contributions = contributionsResponse.data || [];
232+
const contributionCount = contributions.length;
233+
const lastContribution = contributions[0] ? new Date(contributions[0].commit.author.date).toLocaleDateString() : 'N/A';
234+
235+
// Prepare commits list HTML
236+
const commitsList = contributions.slice(0, 5).map(commit => `
237+
<div class="text-left py-2 border-b border-gray-100 last:border-0">
238+
<p class="text-sm font-medium text-gray-800 truncate">${commit.commit.message.split('\n')[0]}</p>
239+
<p class="text-xs text-gray-500">${new Date(commit.commit.author.date).toLocaleString()}</p>
240+
</div>
241+
`).join('');
242+
226243
Swal.fire({
227244
title: '✅ Certificate Verified!',
228245
html: `
@@ -233,21 +250,44 @@ function Certification() {
233250
class="w-20 h-20 rounded-full mx-auto mb-4"
234251
/>
235252
<p class="text-lg font-semibold text-gray-800">${contributor.login}</p>
236-
<p class="text-sm text-gray-600">Contributions: ${contributor.contributions}</p>
253+
<p class="text-sm text-gray-600">Total Contributions: ${contributor.contributions}</p>
254+
255+
<div class="mt-4 p-4 bg-gray-50 rounded-lg text-left">
256+
<h4 class="font-medium text-gray-800 mb-2">VigyBag Contributions:</h4>
257+
<p class="text-sm text-gray-700">
258+
<span class="font-medium">${contributionCount}</span> commits
259+
${lastContribution !== 'N/A' ? `<span class="text-gray-500 text-xs block mt-1">Last contribution: ${lastContribution}</span>` : ''}
260+
</p>
261+
262+
${contributionCount > 0 ? `
263+
<div class="mt-3 max-h-40 overflow-y-auto border rounded p-2 bg-white">
264+
<p class="text-xs font-medium text-gray-500 mb-2">Recent Commits:</p>
265+
${commitsList}
266+
${contributionCount > 5 ? `<p class="text-xs text-gray-500 mt-2">+ ${contributionCount - 5} more commits</p>` : ''}
267+
</div>
268+
` : '<p class="text-sm text-gray-500 mt-2">No commits found in the main repository.</p>'}
269+
</div>
270+
237271
<div class="mt-4 p-3 bg-green-50 rounded-lg">
238272
<p class="text-sm text-green-700">This certificate is valid and verified.</p>
239273
<p class="text-xs text-green-600 mt-1">User ID: ${contributor.id}</p>
240274
</div>
241275
</div>
242276
`,
243-
confirmButtonText: 'View Profile',
277+
confirmButtonText: 'View GitHub Profile',
244278
confirmButtonColor: '#10b981',
245279
showCancelButton: true,
246280
cancelButtonText: 'Close',
247281
cancelButtonColor: '#6b7280',
282+
showDenyButton: contributionCount > 0,
283+
denyButtonText: 'View All Commits',
284+
denyButtonColor: '#3b82f6',
285+
width: '500px'
248286
}).then((result) => {
249287
if (result.isConfirmed) {
250288
window.open(contributor.html_url, '_blank');
289+
} else if (result.isDenied) {
290+
window.open(`https://github.com/codervivek5/VigyBag/commits?author=${contributor.login}`, '_blank');
251291
}
252292
});
253293
} else {

0 commit comments

Comments
 (0)