Skip to content

Commit

Permalink
feat: product hunt
Browse files Browse the repository at this point in the history
  • Loading branch information
nevo-david committed Oct 20, 2023
1 parent 3c3a8db commit d9c2054
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 49 deletions.
4 changes: 2 additions & 2 deletions src/app/(website)/layout.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import NextAuthSessionProvider from 'context/session-provider';
import 'styles/main.css';
import { auth } from 'lib/auth';

import Banner from '../../components/shared/banner';
// import Banner from '../../components/shared/banner';

const inter = Inter({
weight: ['300', '400', '500', '600', '700'],
Expand All @@ -27,7 +27,7 @@ export default async function RootLayout({ children }) {
<NextAuthSessionProvider>
<PlausibleProvider domain="hacksquad.dev">
<div className="relative flex min-h-screen flex-col">
<Banner />
{/* <Banner /> */}
<Header
isAuthorized={!!session}
subscriberId={session?.user?.githubHandle || undefined}
Expand Down
39 changes: 10 additions & 29 deletions src/components/shared/product-hunt/product-hunt.button.jsx
Original file line number Diff line number Diff line change
@@ -1,35 +1,16 @@
import axios from 'axios';
import PropTypes from 'prop-types';
import React, { useCallback, useState } from 'react';
import React, { useState } from 'react';

const ProductHuntButton = ({ productHunt }) => {
const [status, setStatus] = useState(!!productHunt);
const [text, setText] = useState('');
const check = useCallback(async () => {
const { data } = await axios.post('/api/product-hunt', { answer: text });
if (data.finish) {
setStatus(true);
}
}, [text]);
return (
<div className="flex">
{status === true ? (
<>Accepted!</>
) : (
<>
<input
value={text}
placeholder="Your answer"
className="h-11 w-[150px] px-1"
onChange={(e) => setText(e.target.value.toUpperCase())}
/>
<button className="h-11 bg-white px-2 text-black" onClick={check}>
Submit
</button>
</>
)}
</div>
);
const [status] = useState(!!productHunt);
// const [text, setText] = useState('');
// const check = useCallback(async () => {
// const { data } = await axios.post('/api/product-hunt', { answer: text });
// if (data.finish) {
// setStatus(true);
// }
// }, [text]);
return <div className="flex">{status === true ? <>Accepted!</> : <>Sorry! You missed it</>}</div>;
};
ProductHuntButton.propTypes = {
productHunt: PropTypes.object,
Expand Down
36 changes: 18 additions & 18 deletions src/pages/api/product-hunt.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import findUserAndTeam from '~/helpers/find.user.and.team';
import prisma from '~/prisma/client';
// import findUserAndTeam from '~/helpers/find.user.and.team';
// import prisma from '~/prisma/client';

export default async function handler(req, res) {
const { user } = await findUserAndTeam(req, res);
if (
!user ||
process.env.RIDDLE_ANSWER.split(',')
.map((p) => p.toLowerCase())
.includes(req.body.answer.toLowerCase()) === false
) {
res.json({ finish: false });
return;
}

await prisma.productHunt.create({
data: {
userId: user.id,
},
});
// const { user } = await findUserAndTeam(req, res);
// if (
// !user ||
// process.env.RIDDLE_ANSWER.split(',')
// .map((p) => p.toLowerCase())
// .includes(req.body.answer.toLowerCase()) === false
// ) {
// res.json({ finish: false });
// return;
// }
//
// await prisma.productHunt.create({
// data: {
// userId: user.id,
// },
// });

res.json({ finish: true });
}

1 comment on commit d9c2054

@vercel
Copy link

@vercel vercel bot commented on d9c2054 Oct 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.