Skip to content

Commit

Permalink
add2
Browse files Browse the repository at this point in the history
  • Loading branch information
sayandedotcom committed Dec 6, 2024
1 parent 238ba4c commit 3ace453
Show file tree
Hide file tree
Showing 10 changed files with 141 additions and 76 deletions.
94 changes: 63 additions & 31 deletions apps/web/app/(portals)/[profile]/posts/[postId]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import { Metadata } from "next";
"use client";

import { useRouter } from "next/navigation";

import Loading from "@/app/(portals)/loading";
import { expired, fromNow } from "@refhiredcom/utils";
import { useQuery } from "@tanstack/react-query";
import { useSession } from "next-auth/react";

import { Button } from "@referrer/ui";

import { PostCard } from "@/components/custom-components";
import {
Expand All @@ -12,7 +19,6 @@ import {
} from "@/components/custom-components/post-card/post-buttons";
import { ApplyDialog } from "@/components/ui";

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

import { TPostsData } from "@/types/types";
Expand Down Expand Up @@ -43,69 +49,95 @@ interface PostProps {
// };
// }

export const metadata: Metadata = {
title: "Posts",
description: "Get job referrals to the top best companies of the world",
};
export default function Post({ params }: PostProps) {
const { data: session } = useSession();

export default async function Post({ params }: PostProps) {
const session = await auth();
const router = useRouter();

const { data } = (await request.get<TPostsData>(`/posts/${params.postId}`)).data;
const {
data: postData,
error,
isStale,
isLoading,
isFetching,
} = useQuery<TPostsData>({
queryKey: ["posts", params.postId],
queryFn: () => {
return request.get(`/posts/${params.postId}`);
},
// refetchInterval: 5000,
// staleTime: 200000,
// gcTime: Infinity,
});
const data = postData?.data?.data;

if (isLoading) {
return <Loading />;
}

return (
<>
<PostCard key={data.id}>
<PostCard.Image
src={data.user?.image ?? "/images/avatar/avatar.png"}
name={data.user?.name}
userName={data.user?.userName}
bio={data.user?.bio}
src={data?.user?.image ?? "/images/avatar/avatar.png"}
name={data?.user?.name}
userName={data?.user?.userName}
bio={data?.user?.bio}
/>
<PostCard.Content>
<PostCard.Header
name={data.user?.name}
userName={data.user?.userName}
image={data.user?.image ?? "/images/avatar/avatar.png"}
bio={data.user?.bio}
name={data?.user?.name}
userName={data?.user?.userName}
image={data?.user?.image ?? "/images/avatar/avatar.png"}
bio={data?.user?.bio}
time={fromNow(data.createdAt)}
timeLeft={data.expiresAt ? fromNow(data.expiresAt) : "No Expiry"}
postType={data.postType}
isAuthor={session?.user?.id === data.userId}
expired={expired(data.expiresAt)}
/>
<PostCard.Description showMore={false}>{data.description}</PostCard.Description>
<PostCard.Description>{data.description}</PostCard.Description>
<PostCard.Tags
allTags={true}
allTags
skills={data.tags}
companyName={data.companyName}
locationType={data.jobLocationType}
location={data.jobLocation}
experience={data.jobExperience}
jobType={data.jobType}
role={data.jobRole}
salary={data.jobCompensation}
skills={data.tags}
postType={data.postType}
/>
<PostCard.Footer>
<MultipleButtons>
{/* <CommentButton /> */}
<ShareButton link={`${data.user.userName}/posts/${data.id}`} title={data.description} />
<BookmarkButton />
<BookmarkButton postId={data.id} />
<ApplyStatus totalApplied={data.totalApplied} acceptLimit={data.acceptLimit} />
<StarButton star={data.stars} />
{data.postType === "REFERRALPOST" && <StarButton star={data.stars} />}
</MultipleButtons>
{session?.user?.id === data.userId ? (
// <Button
// onClick={() => {

// router.push(`/dashboard/requests/${data.id}`);
// }}
// className="h-9 rounded-full text-sm md:w-36">
// Requests
// </Button>
<></>
data.totalApplied > 0 ? (
<Button
onClick={() => {
router.push(`/dashboard/requests?postId=${data.id}`);
}}
className="h-9 rounded-full text-sm md:w-36">
Explore Requests
</Button>
) : (
<Button
onClick={() => {
router.push(`/dashboard/requests?postId=${data.id}`);
}}
className="h-9 rounded-full text-sm md:w-36">
No applies yet
</Button>
)
) : (
<ApplyDialog
postType={data.postType}
myObject={data.accept}
postId={data.id}
stars={data.stars}
Expand Down
4 changes: 1 addition & 3 deletions apps/web/app/(portals)/home/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,7 @@ export default function Home() {
<ShareButton link={`${data.user.userName}/posts/${data.id}`} title={data.description} />
<BookmarkButton postId={data.id} />
<ApplyStatus totalApplied={data.totalApplied} acceptLimit={data.acceptLimit} />
{data.postType != "POST" && data.postType != "FINDREFERRER" && (
<StarButton star={data.stars} />
)}
{data.postType === "REFERRALPOST" && <StarButton star={data.stars} />}
</MultipleButtons>
{session?.user?.id === data.userId ? (
data.totalApplied > 0 ? (
Expand Down
8 changes: 6 additions & 2 deletions apps/web/app/api/v1/posts/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@ import { auth } from "@/lib/auth";
import { TPost } from "@/types/types";

export async function GET(request: NextRequest, context: any) {
const searchParams = request.nextUrl.searchParams;
const take = searchParams.get("take");
const skip = searchParams.get("skip");

// const cachedAllPosts = await redis.get("ALL_POSTS");
// if (cachedAllPosts) return JSON.parse(cachedAllPosts);

const posts = await prisma.posts.findMany({
take: 10,
skip: 0,
take: +take,
skip: +skip,
orderBy: {
createdAt: "desc",
},
Expand Down
85 changes: 58 additions & 27 deletions apps/web/components/custom-components/post-card/post-buttons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

import { useState } from "react";

import { useRouter } from "next/navigation";

import { useLoading, useWindowSize } from "@/hooks";
import { useMutation } from "@tanstack/react-query";
import axios from "axios";
import { Bookmark, MessageCircle, Share2, Star } from "lucide-react";
import { useSession } from "next-auth/react";

Expand Down Expand Up @@ -64,12 +67,15 @@ export const CommentButton = () => {
};

export const BookmarkButton = ({ postId }: { postId?: string }) => {
const [bookmark, setBookmark] = useState(false);
const { data: session } = useSession();
const router = useRouter();

const [bookmark, setBookmark] = useState(false);

const { mutate, isPending } = useMutation({
mutationKey: ["bookmarks"],
mutationFn: ({ postId }: { postId: string }) => {
return request.post("/bookmarks", {
return request.post("/bookmarks", null, {
params: {
postId: postId,
},
Expand All @@ -78,36 +84,58 @@ export const BookmarkButton = ({ postId }: { postId?: string }) => {
},
});
},
// onSuccess(data, variables) {
// setUserName(variables.userName);
// router.push("/auth/sign-up");
// },
// onError(error) {
// setError("userName", {
// ///@ts-expect-error
// message: error?.response.data.message,
// });
// },
onSuccess(data, variables) {
setBookmark(!bookmark);
sonerToast({
severity: "neutral",
title: (
<div className="my-auto mr-4 flex items-center gap-3">
<p className="text-sm">{bookmark ? "Removed from Bookmarks" : "Added to Bookmarks"}</p>
</div>
),
actions: (
<Button onClick={() => setBookmark(!bookmark)} className="h-6" variant="secondary">
Undo
</Button>
),
});
},
onError(error) {
if (axios.isAxiosError(error) && error?.response.status === 401) {
router.push("/auth/login");
sonerToast({
severity: "error",
title: "Error !",
message: error?.response.data.message,
});
}
axios.isAxiosError(error) &&
error?.response.status != 401 &&
sonerToast({
severity: "info",
title: "Error !",
message: error?.response.data.message,
});
},
});

const bookmarked = () => {
setBookmark(!bookmark);
mutate({
postId: postId,
});
sonerToast({
severity: "neutral",
title: (
<div className="my-auto mr-4 flex items-center gap-3">
<p className="text-sm">{bookmark ? "Removed from Bookmarks" : "Added to Bookmarks"}</p>
</div>
),
actions: (
<Button onClick={() => setBookmark(!bookmark)} className="h-6" variant="secondary">
Undo
</Button>
),
});
// sonerToast({
// severity: "neutral",
// title: (
// <div className="my-auto mr-4 flex items-center gap-3">
// <p className="text-sm">{bookmark ? "Removed from Bookmarks" : "Added to Bookmarks"}</p>
// </div>
// ),
// actions: (
// <Button onClick={() => setBookmark(!bookmark)} className="h-6" variant="secondary">
// Undo
// </Button>
// ),
// });
};

return (
Expand Down Expand Up @@ -216,21 +244,23 @@ export const Tags = ({
variant="secondary">
🧑‍💻 {experience} + years of experience
</Badge>

<Badge
search={jobType}
search_query={"jobType"}
className="hover:bg-foreground hover:text-background cursor-pointer border border-black dark:border-gray-200"
variant="secondary">
🧑‍💼 {jobType}
</Badge>

{allTags && (
<>
<Badge
className="hover:bg-foreground hover:text-background cursor-pointer border border-black dark:border-gray-200"
variant="secondary">
💵 {salary}
</Badge>
{skills.map(({ __typename, name }, i) => (
{skills?.map(({ __typename, name }, i) => (
<Badge
key={i}
search={name}
Expand All @@ -242,6 +272,7 @@ export const Tags = ({
))}
</>
)}

{allTags ? (
<></>
) : (
Expand Down
6 changes: 2 additions & 4 deletions apps/web/components/custom-components/post-card/post-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ function PostCardHeader({
isAuthor?: boolean;
image?: any;
bio: any;
expired: any;
expired?: any;
}) {
const type = {
REFERRALPOST: "Referral Post",
Expand Down Expand Up @@ -160,9 +160,7 @@ function PostCardTags({
postType?: any;
}) {
return (
<div
id="post-tags"
className={cn("font-heading", postType === "POST" || postType === "FINDREFERRER", "hidden")}>
<div id="post-tags" className={cn("font-heading", postType != "REFERRALPOST" && "hidden")}>
<Tags
allTags={allTags}
companyName={companyName}
Expand Down
6 changes: 3 additions & 3 deletions apps/web/components/custom-components/pricing-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { useSession } from "next-auth/react";

import { Button } from "@referrer/ui";

import { siteConfig } from "@/config";

function PricingButton({
planId,
className,
Expand All @@ -24,7 +26,7 @@ function PricingButton({
const buyPlan = async (planId: string, stars: number, quantity?: number) => {
setState(true);

await fetch("http://localhost:3000/api/stripe", {
await fetch(`${siteConfig.url}/api/stripe`, {
method: "POST",
headers: new Headers({
"Content-Type": "application/json",
Expand All @@ -51,8 +53,6 @@ function PricingButton({
console.error("Error:", error);
});

session.user.stars;

// const stripeUrl = await checkout({ planId: priceId, quantity: quantity, stars: stars });
// router.push(data);
// window.location.replace(data);
Expand Down
8 changes: 5 additions & 3 deletions apps/web/components/ui/ApplyDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { useRouter } from "next/navigation";

import { zodResolver } from "@hookform/resolvers/zod";
import { useMutation } from "@tanstack/react-query";
import clsx from "clsx";
import { useSession } from "next-auth/react";
import { useForm } from "react-hook-form";
import * as z from "zod";
Expand Down Expand Up @@ -137,10 +138,11 @@ export function ApplyDialog({
// isLoading={isPending}
// iconBefore={applied && <AiOutlineCheckCircle className="mr-2 h-4 w-4 text-green-400" />}
// onClick={apply}
className={cn(
className={clsx(
"h-9 rounded-full text-sm md:w-36",
postType === "POST" || postType === "FINDREFERRER",
"hidden"
postType != "REFERRALPOST" && "hidden"
// postType === "POST" || postType === "FINDREFERRER",
// "hidden"
)}>
{(full && "Full") || (expired && "Expired") || "Apply"}
</Button>
Expand Down
Loading

0 comments on commit 3ace453

Please sign in to comment.