Skip to content

Commit

Permalink
Update page.tsx
Browse files Browse the repository at this point in the history
  • Loading branch information
ArhanAnsari authored Sep 20, 2024
1 parent 1506373 commit 5edcb56
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions app/dashboard/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import { useRouter } from "next/navigation";
import { ToastContainer, toast } from "react-toastify";
import "react-toastify/dist/ReactToastify.css";
import PlansPage from "../plans/page";
import MarkdownRenderer from "@/components/MarkdownRenderer";
import { checkUserPlanLimit, incrementRequestCount } from "@/firebaseFunctions";
import { checkUserPlanLimit, incrementRequestCount } from "@/firebaseFunctions"; // Import Firebase functions
import MarkdownRenderer from "@/components/MarkdownRenderer"; // Import the custom MarkdownRenderer

export default function Dashboard() {
const { data: session, status } = useSession();
const [input, setInput] = useState("");
Expand All @@ -27,6 +28,9 @@ export default function Dashboard() {
return;
}

// Avoid making Firebase API calls on the server side
if (typeof window === "undefined") return;

// Check user's plan limits before making the API call
const canGenerate = await checkUserPlanLimit(session?.user?.email ?? "");

Expand All @@ -49,12 +53,12 @@ export default function Dashboard() {
if (response.ok) {
setOutput(data.generatedContent);
toast.success("AI content generated successfully!");

// Increment the user's request count in Firebase
await incrementRequestCount(session?.user?.email ?? "");
} else {
toast.error("Failed to generate AI content.");
}

// Increment the user's request count in Firebase
await incrementRequestCount(session?.user?.email ?? "");
} catch (error) {
toast.error("An error occurred while generating AI content.");
}
Expand Down

0 comments on commit 5edcb56

Please sign in to comment.