Skip to content

Commit

Permalink
Refactor: requested changes from vyshnav
Browse files Browse the repository at this point in the history
- moved constants to constant/index
- shifted layout wrappers to provider
- used constants
  • Loading branch information
joywin2003 committed Sep 26, 2024
1 parent 88fcdbc commit 8ba8eb0
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 27 deletions.
4 changes: 2 additions & 2 deletions src/app/actions/get-price.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"use server";

import prisma from "@/server/db";
import { basePrice, initialdiscount } from "@/constants";

class CouponError extends Error {
constructor(message: string) {
Expand All @@ -16,8 +17,7 @@ export const getPrice = async (
discountAmount: number;
finalPrice: number;
}> => {
const basePrice = 1000;
let discountAmount = 0;
let discountAmount = initialdiscount;
let finalPrice = basePrice;
if (couponCode) {
const coupon = await prisma.referral.findUnique({
Expand Down
21 changes: 1 addition & 20 deletions src/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
import Providers from "@/components/Layout/Provider";
import { NextSSRPlugin } from "@uploadthing/react/next-ssr-plugin";
import type { Metadata } from "next";
import { Inter } from "next/font/google";
import { Toaster } from "sonner";
import { extractRouterConfig } from "uploadthing/server";
import "./globals.css";

import { ourFileRouter } from "@/app/api/uploadthing/core";

const inter = Inter({ subsets: ["latin"] });

export const metadata: Metadata = {
Expand All @@ -23,21 +18,7 @@ export default function RootLayout({
return (
<html lang="en" className="dark">
<body className={inter.className}>
<NextSSRPlugin routerConfig={extractRouterConfig(ourFileRouter)} />
<Providers>
{children}{" "}
<Toaster
position="top-center"
toastOptions={{
classNames: {
error: "text-red-400 border-red-400",
success: "text-green-400 border-green-400",
warning: "text-yellow-400 border-yellow-400",
info: "text-blue-400 border-blue-400",
},
}}
/>
</Providers>
<Providers>{children} </Providers>
</body>
</html>
);
Expand Down
21 changes: 19 additions & 2 deletions src/components/Layout/Provider.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,31 @@
"use client";
"use client";;
import { ourFileRouter } from "@/app/api/uploadthing/core";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { NextSSRPlugin } from "@uploadthing/react/next-ssr-plugin";
import { SessionProvider } from "next-auth/react";
import { ReactNode } from "react";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { Toaster } from "sonner";
import { extractRouterConfig } from "uploadthing/server";

export default function Providers({ children }: { children: ReactNode }) {
const queryClient = new QueryClient();
return (
<>
<SessionProvider>
<QueryClientProvider client={queryClient}>
<NextSSRPlugin routerConfig={extractRouterConfig(ourFileRouter)} />
{children}
<Toaster
position="top-center"
toastOptions={{
classNames: {
error: "text-red-400 border-red-400",
success: "text-green-400 border-green-400",
warning: "text-yellow-400 border-yellow-400",
info: "text-blue-400 border-blue-400",
},
}}
/>
</QueryClientProvider>
</SessionProvider>
</>
Expand Down
7 changes: 4 additions & 3 deletions src/components/payment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ import { useState } from "react";
import { Input } from "./ui/input";
import { toast } from "sonner";
import getErrorMessage from "@/utils/getErrorMessage";
import { basePrice, initialdiscount } from "@/constants";

export function Payment() {
const [coupon, setCoupon] = useState("");
const [pricing, setPricing] = useState({
basePrice: 1200,
discountAmount: 0,
finalPrice: 1200,
basePrice: basePrice,
discountAmount: initialdiscount,
finalPrice: basePrice,
});
const verifyCoupon = async () => {
try {
Expand Down
2 changes: 2 additions & 0 deletions src/constants/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const basePrice = 1000;
export const initialdiscount = 0;

0 comments on commit 8ba8eb0

Please sign in to comment.