-
Notifications
You must be signed in to change notification settings - Fork 191
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Nevo David
committed
Oct 17, 2023
1 parent
3df456d
commit 04120aa
Showing
7 changed files
with
247 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import { usePlausible } from 'next-plausible'; | ||
import PropTypes from 'prop-types'; | ||
import { useCallback, useState } from 'react'; | ||
import { toast } from 'react-toastify'; | ||
|
||
import GitHubIcon from '../../../../icons/github.inline.svg'; | ||
|
||
const ForkTheLibrary = ({ bonus, number, name, library, accepted }) => { | ||
const plausible = usePlausible(); | ||
const [starred, setStarred] = useState(accepted); | ||
const test = useCallback(async () => { | ||
const data = await ( | ||
await fetch('/api/github-fork', { | ||
headers: { | ||
Accept: 'application/json', | ||
'Content-Type': 'application/json', | ||
}, | ||
method: 'POST', | ||
body: JSON.stringify({ library }), | ||
}) | ||
).json(); | ||
|
||
if (data.finish) { | ||
plausible('star-the-library', { props: { library } }); | ||
setStarred(true); | ||
} else { | ||
toast.error('No fork found, please try to remove the fork and fork again'); | ||
} | ||
}, []); | ||
|
||
return ( | ||
<li className="grid grid-cols-[20px_485px_230px_1fr] gap-x-5 border-b border-gray-2 py-4 lg:grid-cols-[20px_390px_1fr_1fr] md:grid-cols-[20px_485px_230px_1fr] sm:grid-cols-[100px_100px_120px]"> | ||
<span className="sm:hidden">{number + 2}</span> | ||
<span> | ||
<a | ||
href={`https://github.com/${library}`} | ||
className="cursor-pointer" | ||
target="_blank" | ||
rel="external noopener" | ||
> | ||
<div className="flex"> | ||
<div> | ||
Fork <strong>{name}</strong> | ||
</div> | ||
<div> | ||
<GitHubIcon className="ml-[10px] h-[20px] leading-[0]" /> | ||
</div> | ||
</div> | ||
</a> | ||
</span> | ||
<span>{bonus || 1} points</span> | ||
<span> | ||
{starred ? ( | ||
<span>Accepted!</span> | ||
) : ( | ||
<a | ||
className="cta-btn-animation relative flex max-w-full cursor-pointer items-center justify-center leading-none" | ||
rel="noreferrer" | ||
onClick={test} | ||
> | ||
<svg | ||
className="cta-btn-animation-border xs:w-full" | ||
width="200" | ||
height="59" | ||
viewBox="0 0 268 59" | ||
fill="none" | ||
> | ||
<path d="M1 58V1H251.586L267 16.4142V58H1Z" stroke="white" strokeWidth="2" /> | ||
</svg> | ||
|
||
<div className="absolute inset-0 flex items-center justify-center space-x-2.5"> | ||
<span className="text-lg sm:text-[18px]">Check</span> | ||
</div> | ||
</a> | ||
)} | ||
</span> | ||
</li> | ||
); | ||
}; | ||
|
||
ForkTheLibrary.propTypes = { | ||
bonus: PropTypes.number, | ||
number: PropTypes.number, | ||
name: PropTypes.string, | ||
library: PropTypes.string, | ||
accepted: PropTypes.bool, | ||
}; | ||
|
||
export default ForkTheLibrary; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import findGitHubToken from '~/helpers/find.github.token'; | ||
import findUserAndTeam from '~/helpers/find.user.and.team'; | ||
import prisma from '~/prisma/client'; | ||
|
||
const list = [ | ||
'novuhq/novu', | ||
'tooljet/tooljet', | ||
'wasp-lang/wasp', | ||
'teamhanko/hanko', | ||
'CrowdDotDev/crowd.dev', | ||
'clickvote/clickvote', | ||
]; | ||
export default async function handler(req, res) { | ||
const { user } = await findUserAndTeam(req, res); | ||
if (!req?.body?.library || !list.includes(req?.body?.library) || !user) { | ||
res.json({ finish: false }); | ||
return; | ||
} | ||
|
||
const exists = await prisma.forkGiven.findFirst({ | ||
where: { | ||
userId: user.id, | ||
library: req.body.library, | ||
}, | ||
}); | ||
|
||
if (exists) { | ||
res.json({ finish: false }); | ||
return; | ||
} | ||
|
||
const accessToken = await findGitHubToken(user.id); | ||
const load = await ( | ||
await fetch(`https://api.github.com/repos/${req?.body?.library}/forks`, { | ||
method: 'GET', | ||
headers: { | ||
Authorization: `token ${accessToken}`, | ||
Accept: 'application/vnd.github.v3+json', | ||
}, | ||
}) | ||
).json(); | ||
|
||
if (!load.find((p) => p.full_name.indexOf(user.handle) > -1)) { | ||
res.json({ finish: false }); | ||
return; | ||
} | ||
|
||
await prisma.forkGiven.create({ | ||
data: { | ||
userId: user.id, | ||
library: req.body.library, | ||
}, | ||
}); | ||
|
||
res.json({ finish: true }); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
04120aa
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
hacksquad-website – ./
hacksquad-website-git-new-hacksquad-novuhq.vercel.app
hacksquad-website-novuhq.vercel.app
hacksquad-website.vercel.app
www.hacksquad.dev