Skip to content

Commit

Permalink
Merge pull request #264 from moinulmoin/improve-structure
Browse files Browse the repository at this point in the history
refactor: ♻️ improve file, folder structure
  • Loading branch information
moinulmoin authored Nov 23, 2024
2 parents b80841c + dd8b62c commit 41b6cec
Show file tree
Hide file tree
Showing 42 changed files with 69 additions and 95 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
"autoprefixer": "10.4.20",
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.1",
"encoding": "^0.1.13",
"eslint": "8.56.0",
"eslint-config-next": "15.0.3",
"eslint-config-prettier": "^8.10.0",
Expand Down
18 changes: 0 additions & 18 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions src/actions/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
import { revalidatePath } from "next/cache";
import { redirect } from "next/navigation";
import { alphabet, generateRandomString } from "oslo/crypto";
import { deleteSessionTokenCookie } from "~/lib/cookies";
import prisma from "~/lib/prisma";
import { getCurrentSession, invalidateSession } from "~/lib/session";
import { deleteSessionTokenCookie } from "~/lib/server/cookies";
import prisma from "~/lib/server/prisma";
import { getCurrentSession, invalidateSession } from "~/lib/server/session";

export async function logout() {
const { session } = await getCurrentSession();

if (!session) {
return {
message: "Unauthorized",
Expand Down
2 changes: 1 addition & 1 deletion src/actions/mail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import ThanksTemp from "emails/thanks";
import VerificationTemp from "emails/verification";
import { nanoid } from "nanoid";
import { resend } from "~/lib/resend";
import { resend } from "~/lib/server/resend";
import { type SendOTPProps, type SendWelcomeEmailProps } from "~/types";

export const sendWelcomeEmail = async ({
Expand Down
2 changes: 1 addition & 1 deletion src/actions/subscription.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use server";

import { freePlan, proPlan } from "~/config/subscription";
import prisma from "~/lib/prisma";
import prisma from "~/lib/server/prisma";
import { type UserSubscriptionPlan } from "~/types";

export async function getUserSubscriptionPlan(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { redirect } from "next/navigation";
import AuthForm from "~/components/layout/auth-form";
import { Card } from "~/components/ui/card";
import { getCurrentSession } from "~/lib/session";
import { getCurrentSession } from "~/lib/server/session";

export default async function Login() {
const { session } = await getCurrentSession();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { type Metadata } from "next";
function AboutCard(about: About) {
return (
<article className="prose prose-slate mb-8 dark:prose-invert">
<h2 className="mb-0 text-3xl font-semibold tracking-tight transition-colors ">
<h2 className="mb-0 text-3xl font-semibold tracking-tight transition-colors">
{about.title}
</h2>
<div dangerouslySetInnerHTML={{ __html: about.content }} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import { type Metadata } from "next";
function ChangeCard(change: Change) {
return (
<article className="prose prose-slate mb-8 dark:prose-invert">
<h2 className=" mb-0 text-3xl font-semibold tracking-tight transition-colors">
<h2 className="mb-0 text-3xl font-semibold tracking-tight transition-colors">
{change.title}
</h2>
<time className=" text-sm text-muted-foreground" dateTime={change.date}>
<time className="text-sm text-muted-foreground" dateTime={change.date}>
{dayjs(change.date).format("MMM DD YYYY")}
</time>
<div dangerouslySetInnerHTML={{ __html: change.content }} />
Expand Down
2 changes: 1 addition & 1 deletion src/app/[locale]/@loginDialog/(.)login/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { redirect } from "next/navigation";
import LoginModal from "~/components/layout/login-modal";
import { getCurrentSession } from "~/lib/session";
import { getCurrentSession } from "~/lib/server/session";

export default async function Login() {
const { session } = await getCurrentSession();
Expand Down
4 changes: 2 additions & 2 deletions src/app/[locale]/dashboard/billing/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { AlertTriangleIcon } from "lucide-react";
import { getUserSubscriptionPlan } from "~/actions/subscription";
import { BillingForm } from "~/components/billing-form";
import { Alert, AlertDescription } from "~/components/ui/alert";
import { getCurrentSession } from "~/lib/session";
import { stripe } from "~/lib/stripe";
import { getCurrentSession } from "~/lib/server/session";
import { stripe } from "~/lib/server/stripe";

export const revalidate = 0;
export const dynamic = "force-dynamic";
Expand Down
4 changes: 2 additions & 2 deletions src/app/[locale]/dashboard/error.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ export default function Error({
}) {
useEffect(() => {
// Log the error to an error reporting service
console.error(error);
console.log(error);
}, [error]);

return (
<div className="flex h-[calc(100vh-160px)] w-full flex-col items-center justify-center gap-y-4">
<h2 className=" text-5xl font-bold text-destructive">
<h2 className="text-5xl font-bold text-destructive">
Oops, Something Went Wrong!
</h2>
<Button onClick={() => reset()}>Try Again</Button>
Expand Down
2 changes: 1 addition & 1 deletion src/app/[locale]/dashboard/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { redirect } from "next/navigation";
import SidebarNav from "~/components/layout/sidebar-nav";
import { getCurrentSession } from "~/lib/session";
import { getCurrentSession } from "~/lib/server/session";

interface DashboardLayoutProps {
children: React.ReactNode;
Expand Down
15 changes: 9 additions & 6 deletions src/app/[locale]/dashboard/projects/[projectId]/delete-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
import { Button } from "~/components/ui/button";
import { Card, CardDescription, CardTitle } from "~/components/ui/card";
import { toast } from "~/hooks/use-toast";
import { isRedirectError } from "~/lib/utils";
import { deleteProjectById } from "../action";

export default function DeleteCard({ id }: { id: string }) {
Expand All @@ -27,12 +28,14 @@ export default function DeleteCard({ id }: { id: string }) {
});
})
.catch((error) => {
console.error(error);
toast({
title: "Error deleting project.",
description: "Please try again.",
variant: "destructive",
});
console.log(error);
if (!isRedirectError(error)) {
toast({
title: "Error deleting project.",
description: "Please try again.",
variant: "destructive",
});
}
})
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,6 @@ import { toast } from "~/hooks/use-toast";
import { updateProjectById } from "../action";
import { projectSchema, type ProjectFormValues } from "../create-project-modal";

// const projectEditSchema = projectSchema.extend({
// id: z.string().readonly(),
// });

// type ProjectEditValues = z.infer<typeof projectEditSchema>;

export default function EditableDetails({
initialValues,
}: {
Expand All @@ -42,7 +36,7 @@ export default function EditableDetails({
});
form.reset();
} catch (error) {
console.error(error);
console.log(error);
toast({
title: "Error creating project.",
description: "Please try again.",
Expand Down
4 changes: 2 additions & 2 deletions src/app/[locale]/dashboard/projects/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { type Project } from "@prisma/client";
import { revalidatePath } from "next/cache";
import { redirect } from "next/navigation";
import { getUserSubscriptionPlan } from "~/actions/subscription";
import prisma from "~/lib/prisma";
import { getCurrentSession } from "~/lib/session";
import prisma from "~/lib/server/prisma";
import { getCurrentSession } from "~/lib/server/session";

interface Payload {
name: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export default function CreateProjectModal() {
form.reset();
setIsOpen(false);
} catch (error) {
console.error({ error });
console.log(error);
if (error instanceof FreePlanLimitError) {
return toast({
title: "Free plan limit reached. Please upgrade your plan.",
Expand Down
8 changes: 4 additions & 4 deletions src/app/[locale]/dashboard/settings/actions.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"use server";

import { revalidatePath, revalidateTag } from "next/cache";
import prisma from "~/lib/prisma";
import { utapi } from "~/lib/uploadthing-server";
import { revalidatePath } from "next/cache";
import prisma from "~/lib/server/prisma";
import { utapi } from "~/lib/server/uploadthing";
import { getImageKeyFromUrl, isOurCdnUrl } from "~/lib/utils";
import { type payload } from "~/types";

Expand All @@ -26,7 +26,7 @@ export async function removeUserOldImageFromCDN(
await utapi.deleteFiles(currentImageFileKey as string);
}
} catch (e) {
console.error(e);
console.log(e);
const newImageFileKey = getImageKeyFromUrl(newImageUrl);
await utapi.deleteFiles(newImageFileKey as string);
}
Expand Down
4 changes: 2 additions & 2 deletions src/app/[locale]/dashboard/settings/error.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ export default function Error({
}) {
useEffect(() => {
// Log the error to an error reporting service
console.error(error);
console.log(error);
}, [error]);

return (
<div className="flex h-full w-full flex-col items-center justify-center gap-y-4">
<h2 className=" text-4xl font-bold text-destructive">
<h2 className="text-4xl font-bold text-destructive">
Something Went Wrong!
</h2>
<Button onClick={() => reset()}>Try Again</Button>
Expand Down
2 changes: 1 addition & 1 deletion src/app/[locale]/dashboard/settings/page.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { type Metadata } from "next";
import { getCurrentSession } from "~/lib/session";
import { getCurrentSession } from "~/lib/server/session";
import SettingsForm from "./settings-form";

export const metadata: Metadata = {
Expand Down
2 changes: 1 addition & 1 deletion src/app/[locale]/dashboard/settings/settings-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export default function SettingsForm({ currentUser }: { currentUser: User }) {
try {
await removeNewImageFromCDN(getValues().picture);
} catch (error) {
console.error(error);
console.log(error);
}
}
reset();
Expand Down
4 changes: 2 additions & 2 deletions src/app/[locale]/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ const fontHeading = localFont({
variable: "--font-heading",
});

export default async function SubLayout({
export default async function RootLayout({
children,
loginDialog,
params,
Expand All @@ -122,7 +122,7 @@ export default async function SubLayout({
}) {
const { locale } = await params;
return (
<html lang={locale} suppressHydrationWarning>
<html lang={locale}>
<body
className={cn(
"font-sans antialiased",
Expand Down
8 changes: 4 additions & 4 deletions src/app/api/auth/login/github/callback/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { ArcticFetchError, OAuth2RequestError } from "arctic";
import { revalidatePath } from "next/cache";
import { cookies } from "next/headers";
import { sendWelcomeEmail } from "~/actions/mail";
import { setSessionTokenCookie } from "~/lib/cookies";
import { github } from "~/lib/github";
import prisma from "~/lib/prisma";
import { createSession, generateSessionToken } from "~/lib/session";
import { setSessionTokenCookie } from "~/lib/server/cookies";
import { github } from "~/lib/server/github";
import prisma from "~/lib/server/prisma";
import { createSession, generateSessionToken } from "~/lib/server/session";

export const GET = async (request: Request) => {
const url = new URL(request.url);
Expand Down
2 changes: 1 addition & 1 deletion src/app/api/auth/login/github/route.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { generateState } from "arctic";
import { cookies } from "next/headers";
import { github } from "~/lib/github";
import { github } from "~/lib/server/github";

export const GET = async () => {
const state = generateState();
Expand Down
2 changes: 1 addition & 1 deletion src/app/api/auth/login/send-otp/route.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { generateEmailVerificationCode } from "~/actions/auth";
import { sendOTP } from "~/actions/mail";
import prisma from "~/lib/prisma";
import prisma from "~/lib/server/prisma";

export const POST = async (req: Request) => {
const body = await req.json();
Expand Down
6 changes: 3 additions & 3 deletions src/app/api/auth/login/verify-otp/route.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { revalidatePath } from "next/cache";
import { verifyVerificationCode } from "~/actions/auth";
import { setSessionTokenCookie } from "~/lib/cookies";
import prisma from "~/lib/prisma";
import { setSessionTokenCookie } from "~/lib/server/cookies";
import prisma from "~/lib/server/prisma";
import {
createSession,
generateSessionToken,
invalidateAllSessions,
} from "~/lib/session";
} from "~/lib/server/session";

export const POST = async (req: Request, response: Response) => {
const body = await req.json();
Expand Down
4 changes: 2 additions & 2 deletions src/app/api/stripe/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { z } from "zod";
import { getUserSubscriptionPlan } from "~/actions/subscription";
import { siteConfig } from "~/config/site";
import { proPlan } from "~/config/subscription";
import { getCurrentSession } from "~/lib/session";
import { stripe } from "~/lib/stripe";
import { getCurrentSession } from "~/lib/server/session";
import { stripe } from "~/lib/server/stripe";

export async function GET(req: NextRequest) {
const locale = req.cookies.get("Next-Locale")?.value || "en";
Expand Down
2 changes: 1 addition & 1 deletion src/app/api/uploadthing/core.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createUploadthing, type FileRouter } from "uploadthing/next";
import { UploadThingError } from "uploadthing/server";
import { getCurrentSession } from "~/lib/session";
import { getCurrentSession } from "~/lib/server/session";

const f = createUploadthing();

Expand Down
4 changes: 2 additions & 2 deletions src/app/api/webhooks/stripe/route.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { type NextRequest } from "next/server";
import { buffer } from "node:stream/consumers";
import type Stripe from "stripe";
import prisma from "~/lib/prisma";
import { stripe } from "~/lib/stripe";
import prisma from "~/lib/server/prisma";
import { stripe } from "~/lib/server/stripe";

export async function POST(req: NextRequest) {
//@ts-expect-error Argument of type 'ReadableStream<any>' is not assignable to parameter of type 'ReadableStream | Readable | AsyncIterable<any>'
Expand Down
Loading

0 comments on commit 41b6cec

Please sign in to comment.