feat:Add env variables file
This commit is contained in:
@@ -27,6 +27,7 @@ import AddFarm from "./pages/UserPanel/Farm/AddFarm.jsx";
|
||||
import UpdateFarm from "./pages/UserPanel/Farm/UpdateForm.jsx";
|
||||
import FarmPage from "./pages/UserPanel/Farm/FarmPage.jsx";
|
||||
import Ai from "./pages/UserPanel/Ai.jsx";
|
||||
import CropPage from "./pages/UserPanel/Farm/CropPage.jsx";
|
||||
createRoot(document.getElementById("root")).render(
|
||||
<StrictMode>
|
||||
<Provider store={MentifyStore}>
|
||||
@@ -61,6 +62,7 @@ createRoot(document.getElementById("root")).render(
|
||||
<Route path="addfarm" element={<AddFarm />} />
|
||||
<Route path="updatefarm" element={<UpdateFarm />} />
|
||||
<Route path="farmpage/:farmId" element={<FarmPage />} />
|
||||
<Route path="croppage/:cropId" element={<CropPage />} />
|
||||
</Route>
|
||||
</Route>
|
||||
</Routes>
|
||||
|
||||
@@ -0,0 +1,105 @@
|
||||
import React, { useEffect, useState } from "react";
|
||||
import { useParams, useNavigate } from "react-router-dom";
|
||||
import Farm from "./Farm";
|
||||
import CropTable from "./CropTable";
|
||||
import Transactions from "./Transactions";
|
||||
import CreateTransactions from "./CreateTransactions";
|
||||
import Loader from "../../../components/Loader";
|
||||
import AddTransaction from "./AddTransactions";
|
||||
import FinanceSummary from "./FinanceSummary";
|
||||
import CreateTask from "./CreateTask";
|
||||
import DisplayTast from "./DisplayTask";
|
||||
import { useGetFarmByIdQuery } from "../../../store/api/farmApi";
|
||||
import { useGetCropByIdQuery } from "../../../store/api/cropApi";
|
||||
|
||||
export default function CropPage() {
|
||||
const { cropId } = useParams();
|
||||
const navigate = useNavigate();
|
||||
const [farmData, setFarmData] = useState("");
|
||||
const [loading, setLoading] = useState(true);
|
||||
|
||||
const farmId = cropId;
|
||||
|
||||
console.log("Farm id is : ", farmId);
|
||||
|
||||
const { data: farm, error, isLoading } = useGetFarmByIdQuery(farmId);
|
||||
const {
|
||||
data: crop,
|
||||
error: cropError,
|
||||
isLoading: cropLoading,
|
||||
} = useGetCropByIdQuery(cropId);
|
||||
|
||||
useEffect(() => {
|
||||
if (!isLoading && !error && farm) {
|
||||
setFarmData(farm);
|
||||
setLoading(false);
|
||||
}
|
||||
}, [farm]);
|
||||
|
||||
console.log("djoejwrru9", crop);
|
||||
|
||||
return (
|
||||
<div className="w-full bg-white rounded-lg shadow p-4 space-y-8">
|
||||
{/* Header Section */}
|
||||
<header className="mb-4">
|
||||
<div className="flex justify-between items-center">
|
||||
<h2 className="text-2xl font-bold">{crop?.name}</h2>
|
||||
<div className="flex items-center space-x-4">
|
||||
<button
|
||||
type="button"
|
||||
className="bg-green-500 hover:bg-green-600 text-white font-semibold py-2 px-4 rounded"
|
||||
onClick={() => navigate(`/user/dashboard`)}
|
||||
>
|
||||
Back
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
{/* Crop Table Section */}
|
||||
<section>
|
||||
<CropTable farmId={farmId} />
|
||||
</section>
|
||||
|
||||
{/* Create Transactions Section */}
|
||||
<section>
|
||||
<div className="flex justify-end">
|
||||
<CreateTransactions farmId={farmId} />
|
||||
</div>
|
||||
</section>
|
||||
|
||||
{/* Transactions Table Section */}
|
||||
<section>
|
||||
<Transactions farmId={farmId} />
|
||||
</section>
|
||||
|
||||
{/* Add Transaction Modal Section */}
|
||||
<section>
|
||||
<div className="flex justify-end">
|
||||
<AddTransaction farmId={farmId} financeId={farmData?.finances?._id} />
|
||||
</div>
|
||||
</section>
|
||||
|
||||
{/* Finance Summary Section */}
|
||||
<section>
|
||||
<div className="flex justify-end">
|
||||
<FinanceSummary farmId={farmId} financeId={farmData?.finances?._id} />
|
||||
</div>
|
||||
</section>
|
||||
|
||||
{/* Create Task Section */}
|
||||
<section>
|
||||
<div className="flex justify-end">
|
||||
<CreateTask farmId={farmId} />
|
||||
</div>
|
||||
</section>
|
||||
|
||||
{/* Display Task Section */}
|
||||
<section>
|
||||
<div className="flex justify-end">
|
||||
<DisplayTast farmId={farmId} />
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -67,6 +67,8 @@ export default function FarmPage() {
|
||||
// );
|
||||
// }
|
||||
|
||||
console.log("Backend URI ", import.meta.env.VITE_API_URL);
|
||||
|
||||
return (
|
||||
<div className="w-full bg-white rounded-lg shadow p-4 space-y-8">
|
||||
{/* Header Section */}
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import { createApi, fetchBaseQuery } from "@reduxjs/toolkit/query/react";
|
||||
|
||||
const API_URI = import.meta.env.VITE_API_URL;
|
||||
|
||||
export const cropApi = createApi({
|
||||
reducerPath: "cropApi",
|
||||
baseQuery: fetchBaseQuery({
|
||||
baseUrl: "http://localhost:8000/api/v1/crop",
|
||||
baseUrl: `${API_URI}/api/v1/crop`,
|
||||
credentials: "include", // Ensures credentials (cookies, tokens) are included
|
||||
}),
|
||||
tagTypes: ["Crops"],
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import { createApi, fetchBaseQuery } from "@reduxjs/toolkit/query/react";
|
||||
|
||||
const API_URI = import.meta.env.VITE_API_URL;
|
||||
|
||||
export const farmApi = createApi({
|
||||
reducerPath: "farmApi",
|
||||
baseQuery: fetchBaseQuery({
|
||||
baseUrl: "http://localhost:8000/api/v1/farm",
|
||||
baseUrl: `${API_URI}/api/v1/farm`,
|
||||
credentials: "include",
|
||||
}),
|
||||
tagTypes: ["Farms"],
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import { createApi, fetchBaseQuery } from "@reduxjs/toolkit/query/react";
|
||||
|
||||
const API_URI = import.meta.env.VITE_API_URL;
|
||||
|
||||
export const financeApi = createApi({
|
||||
reducerPath: "financeApi",
|
||||
baseQuery: fetchBaseQuery({
|
||||
baseUrl: "http://localhost:8000/api/v1/finance",
|
||||
baseUrl: `${API_URI}/api/v1/finance`,
|
||||
credentials: "include",
|
||||
}),
|
||||
tagTypes: ["Finance", "Transactions"],
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import { createApi, fetchBaseQuery } from "@reduxjs/toolkit/query/react";
|
||||
const API_URI = import.meta.env.VITE_API_URL;
|
||||
|
||||
export const taskApi = createApi({
|
||||
reducerPath: "taskApi",
|
||||
baseQuery: fetchBaseQuery({
|
||||
baseUrl: "http://localhost:8000/api/v1/task",
|
||||
baseUrl: `${API_URI}/api/v1/task`,
|
||||
credentials: "include",
|
||||
}),
|
||||
tagTypes: ["Tasks"],
|
||||
|
||||
Reference in New Issue
Block a user