-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
9a69b63
commit 97e81f8
Showing
21 changed files
with
985 additions
and
184 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
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,81 @@ | ||
import { type NextRequest, NextResponse } from "next/server"; | ||
|
||
import prisma from "@referrer/prisma"; | ||
|
||
import { auth } from "@/lib/auth"; | ||
|
||
import { TPostReferralPost } from "@/types/types"; | ||
|
||
export async function POST(request: NextRequest) { | ||
const token = request.headers.get("authorization")?.replace(/^Bearer\s+/, ""); | ||
|
||
if (!token) { | ||
return NextResponse.json( | ||
{ message: "You are not authenticated" }, | ||
{ | ||
status: 401, | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
} | ||
); | ||
} | ||
const response: TPostReferralPost = await request.json(); | ||
const session = await auth(); | ||
// const key = `RATE_LIMIT:POST:${response.userId}`; | ||
// const currentCount = await redis.incr(key); | ||
|
||
// if (currentCount === 1) { | ||
// // If the key was just created, set its expiration time | ||
// await redis.expire(key, rateLimitTimeInSeconds); | ||
// } | ||
|
||
// if (currentCount > rateLimitMaxActionsAllowed) { | ||
// // If the user has exceeded the maximum allowed posts, return false | ||
// throw new RateLimitError("Please Wait"); | ||
// } | ||
|
||
// const rateLimitFlag = await redis.get(`RATE_LIMIT:POST:${response.userId}`); | ||
// if (rateLimitFlag) throw new RateLimitError("Please Wait"); | ||
|
||
const data = await prisma.posts.create({ | ||
data: { | ||
userId: session.user.id, | ||
description: response.description, | ||
accept: response.accept, | ||
acceptLimit: response.acceptLimit, | ||
companyName: response.companyName, | ||
expiresAt: response.expiresAt, | ||
jobCode: response.jobCode, | ||
jobCompensation: response.jobCompensation, | ||
jobExperience: response.jobExperience, | ||
jobLocation: response.jobLocation, | ||
jobRole: response.jobRole, | ||
jobType: response.jobType, | ||
postType: "REFERRALPOST", | ||
stars: response.stars, | ||
tags: { | ||
connectOrCreate: response?.tags?.map((tag) => ({ | ||
where: { | ||
name: tag, | ||
}, | ||
create: { | ||
name: tag, | ||
}, | ||
})), | ||
}, | ||
}, | ||
}); | ||
// await redis.set(`RATE_LIMIT:POST:${response.userId}`, 1, "EX", rateLimitTimeInSeconds); | ||
// await redis.del("ALL_POSTS"); | ||
|
||
return NextResponse.json( | ||
{ data: data, message: "Sucessfully created the Referral Post" }, | ||
{ | ||
status: 200, | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
} | ||
); | ||
} |
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
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,99 @@ | ||
"use client"; | ||
|
||
import CharacterCount from "@tiptap/extension-character-count"; | ||
import Link from "@tiptap/extension-link"; | ||
import { EditorContent, useEditor } from "@tiptap/react"; | ||
import StarterKit from "@tiptap/starter-kit"; | ||
|
||
import { cn } from "@/utils"; | ||
|
||
const RichTextEditor = ({ | ||
value, | ||
onChange, | ||
className, | ||
placeholder, | ||
charactersLimit, | ||
}: { | ||
value: string; | ||
onChange: (value: string) => void; | ||
className?: string; | ||
placeholder?: string; | ||
charactersLimit?: number; | ||
}) => { | ||
const limit = charactersLimit; | ||
const editor = useEditor({ | ||
autofocus: "end", | ||
editorProps: { | ||
attributes: { | ||
class: cn( | ||
"border-input placeholder:text-muted-foreground focus-visible:ring-ring min-h-[60px] w-full rounded-md border bg-transparent px-3 py-2 text-sm shadow-sm focus-visible:outline-none focus-visible:ring-1 disabled:cursor-not-allowed disabled:opacity-50", | ||
className | ||
), | ||
}, | ||
}, | ||
extensions: [ | ||
StarterKit.configure({ | ||
orderedList: { | ||
HTMLAttributes: { | ||
class: "list-decimal pl-4", | ||
}, | ||
}, | ||
bulletList: { | ||
HTMLAttributes: { | ||
class: "list-disc pl-4", | ||
}, | ||
}, | ||
}), | ||
CharacterCount.configure({ | ||
limit, | ||
}), | ||
Link.configure({ | ||
openOnClick: true, | ||
autolink: true, | ||
defaultProtocol: "https", | ||
HTMLAttributes: { | ||
class: "text-blue-400 cursor-pointer font-bold", | ||
// Change rel to different value | ||
// Allow search engines to follow links(remove nofollow) | ||
rel: "noopener noreferrer", | ||
// Remove target entirely so links open in current tab | ||
target: null, | ||
}, | ||
}), | ||
], | ||
content: value, // Set the initial content with the provided value | ||
onUpdate: ({ editor }) => { | ||
onChange(editor.getHTML()); // Call the onChange callback with the updated HTML content | ||
}, | ||
}); | ||
const percentage = editor ? Math.round((100 / limit) * editor.storage.characterCount.characters()) : 0; | ||
return ( | ||
<> | ||
<EditorContent placeholder={placeholder} editor={editor} /> | ||
{editor && ( | ||
<div | ||
className={`ml-3 flex items-center gap-3 text-xs ${ | ||
editor.storage.characterCount.characters() === limit ? "text-red-600" : "" | ||
}`}> | ||
<svg height="14" width="14" viewBox="0 0 20 20"> | ||
<circle r="10" cx="10" cy="10" fill="#000" /> | ||
<circle | ||
r="5" | ||
cx="10" | ||
cy="10" | ||
fill="transparent" | ||
stroke={editor.storage.characterCount.characters() === limit ? "#cb2424" : "#05FB31"} | ||
strokeWidth="10" | ||
strokeDasharray={`calc(${percentage} * 31.4 / 100) 31.4`} | ||
transform="rotate(-90) translate(-20)" | ||
/> | ||
<circle r="6" cx="10" cy="10" fill="black" /> | ||
</svg> | ||
{editor.storage.characterCount.characters()} / {limit} characters | ||
</div> | ||
)} | ||
</> | ||
); | ||
}; | ||
|
||
export default RichTextEditor; |
Oops, something went wrong.