Skip to content

Commit

Permalink
add
Browse files Browse the repository at this point in the history
  • Loading branch information
sayandedotcom committed Oct 19, 2024
1 parent 9a69b63 commit 97e81f8
Show file tree
Hide file tree
Showing 21 changed files with 985 additions and 184 deletions.
27 changes: 16 additions & 11 deletions apps/web/app/(portals)/[profile]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ import { MultipleButtons } from "@/components/custom-components/post-card/post-b
import Navigate from "@/components/navigate";
import { ApplyDialog } from "@/components/ui";

import { auth } from "@/lib/auth";
import { request } from "@/lib/axios";

import { cn } from "@/utils";

export const metadata: Metadata = {
title: "Profile",
description: "Get job referrals to the top best companies of the world",
Expand All @@ -32,6 +35,8 @@ async function getProfile(profile) {
const Profile = async ({ params }: paramsProps) => {
const { profile } = params;

const session = await auth();

if (profile === "profile")
return (
<>
Expand All @@ -43,7 +48,7 @@ const Profile = async ({ params }: paramsProps) => {
height={120}
className="rounded-full"
/>
<h6 className="font-sans">Profile donot exists</h6>
<h6 className="font-sans">Get your profile !</h6>
<Link href={"/auth/login"}>
<Button>
Login <ArrowRight className="ml-2 h-4 w-4" />
Expand Down Expand Up @@ -77,7 +82,7 @@ const Profile = async ({ params }: paramsProps) => {

return (
<>
<div className="flex w-11/12 flex-col items-center gap-2 p-2">
<div className="flex flex-col items-center gap-2 p-2">
<Image
alt="img"
src={data.image ?? "/images/avatar/avatar.png"}
Expand All @@ -91,16 +96,16 @@ const Profile = async ({ params }: paramsProps) => {
<Mail />
<span>{data.email}</span><MapPin />
<span>Kolkata</span><p>{fromNow(data.createdAt)}</p>
{session?.user.userName === data?.userName && (
<Link
href="/settings/profile"
className={cn(
"focus-visible:ring-ring ring-offset-background bg-primary text-primary-foreground hover:bg-primary/90 inline-flex h-10 items-center justify-center rounded-lg px-4 py-2 text-sm font-semibold transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50"
)}>
Edit Profile
</Link>
)}
</div>
{/* {session?.user.id === data?.id && (
<Link
href="/settings/profile"
className={cn(
"focus-visible:ring-ring ring-offset-background bg-primary text-primary-foreground hover:bg-primary/90 inline-flex h-10 items-center justify-center rounded-lg px-4 py-2 text-sm font-semibold transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50"
)}>
Edit Profile
</Link>
)} */}
</div>
<Separator />
{data?.posts.map((postData) => (
Expand Down
4 changes: 2 additions & 2 deletions apps/web/app/(portals)/home/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ export default function Home() {
name={data.user?.name}
userName={data.user?.userName}
time={fromNow(data.createdAt)}
timeLeft={fromNow(data.expiresAt)}
timeLeft={data.expiresAt && fromNow(data.expiresAt)}
/>
<Navigate userName={data.user.userName} postId={data.id}>
<PostCard.Description>{data.description}</PostCard.Description>
<PostCard.Description>{data.description.substring(0, 300)}</PostCard.Description>
</Navigate>
<PostCard.Tags
allTags={false}
Expand Down
6 changes: 2 additions & 4 deletions apps/web/app/api/stripe/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import { auth } from "@/lib/auth";
import { stripe } from "@/lib/stripe";

export async function POST(req: NextRequest) {
const locale = req.cookies.get("NEXT_LOCALE")?.value || "en";

// const billingUrl = siteConfig(locale).url + "/dashboard/billing/";
const { planId = process.env.STRIPE_CUST0M_PRICE_ID, quantity = 1, stars } = await req.json();

Expand All @@ -30,8 +28,8 @@ export async function POST(req: NextRequest) {
userId: user.id,
stars,
},
success_url: `http://localhost:3000/${locale}`,
cancel_url: `http://localhost:3000/${locale}/pricing`,
success_url: "http://localhost:3000/",
cancel_url: "http://localhost:3000/purchase",
});

return new NextResponse(JSON.stringify({ url: checkoutSession.url }));
Expand Down
81 changes: 81 additions & 0 deletions apps/web/app/api/v1/posts/referral/route.ts
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",
},
}
);
}
12 changes: 9 additions & 3 deletions apps/web/app/api/v1/username/[username]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,17 @@ import { type NextRequest, NextResponse } from "next/server";

import prisma from "@referrer/prisma";

export async function GET(request: NextRequest, context: any) {
const { username } = context;
export async function GET(request: NextRequest, { params }: { params: { username: string } }) {
const { username } = params;

// const cachedUserById = await redis.get(`USER:ID:${id}`);
// if (cachedUserById) return JSON.parse(cachedUserById);
const user = await prisma.user.findFirst({ where: { userName: username } });
const user = await prisma.user.findFirst({
where: { userName: username },
include: {
posts: true,
},
});
// await redis.set(`USER:ID:${id}`, JSON.stringify(user), "EX", cacheTime);

return NextResponse.json(
Expand Down
19 changes: 6 additions & 13 deletions apps/web/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,15 @@ import {
Username,
} from "@/components/custom-components";

import { auth } from "@/lib/auth";

import Loading from "./loading";

export default async function Page() {
// const session = await getServerSession();
const session = await auth();

// if (session?.user) {
// redirect("/home");
// }
const t = await getTranslations("Index");

const user = null;

return (
<div className="relative">
<Starfield starCount={5000} />
Expand Down Expand Up @@ -68,9 +65,7 @@ export default async function Page() {
job through referrals which has the highest convertion rates among other methods . It simplifies the
tasks for both job seekers and employees who gives referrals
</p> */}
<Suspense fallback={<Loading />}>
<JoinWaitlist />
</Suspense>
<Suspense fallback={<Loading />}>{!session?.user && <JoinWaitlist />}</Suspense>
<Suspense fallback={<Loading />}>
<ShimmerButtonComponent href={"/home"}>Explore the MVP !</ShimmerButtonComponent>
</Suspense>
Expand All @@ -81,9 +76,7 @@ export default async function Page() {
<Companies />
</Suspense>

<Suspense fallback={<Loading />}>
<Username session={user} />
</Suspense>
<Suspense fallback={<Loading />}>{!session?.user && <Username />}</Suspense>

<Suspense fallback={<Loading />}>
{/* <Section /> */}
Expand Down Expand Up @@ -129,7 +122,7 @@ export default async function Page() {
<ScrollBasedVelocityCOmponent />
</Suspense>

<Suspense fallback={<Loading />}>{user && user ? <></> : <Joinnow />}</Suspense>
<Suspense fallback={<Loading />}>{!session?.user && <Joinnow />}</Suspense>

<Suspense fallback={<Loading />}>
<Opensource />
Expand Down
6 changes: 2 additions & 4 deletions apps/web/app/server/page.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { auth, signIn } from "@/lib/auth";
import { auth } from "@/lib/auth";
import { request } from "@/lib/axios";

async function getTest(refreshToken: string) {
Expand All @@ -13,9 +13,7 @@ async function getTest(refreshToken: string) {

export default async function Server() {
const session = await auth();
if (session?.error === "RefreshTokenError") {
await signIn("google"); // Force sign in to obtain a new set of access and refresh tokens
}

const response = await getTest(session.user.refresh_token);

console.log("😊😊😊😊😊😊😊😊😊😊😊😊😊😊😊😊😊😊😊datadatadatadatadata", response);
Expand Down
99 changes: 99 additions & 0 deletions apps/web/components/Tiptap.tsx
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;
Loading

0 comments on commit 97e81f8

Please sign in to comment.