feat: Add some new connection
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import React, { useState } from "react";
|
import React, { useState } from "react";
|
||||||
|
import { useCreateTaskMutation } from "../../../store/api/taskApi";
|
||||||
|
|
||||||
const CreateTask = ({ farmId, onTaskCreated }) => {
|
const CreateTask = ({ farmId, onTaskCreated }) => {
|
||||||
const [farm, setFarm] = useState(farmId);
|
const [farm, setFarm] = useState(farmId);
|
||||||
@@ -10,6 +11,8 @@ const CreateTask = ({ farmId, onTaskCreated }) => {
|
|||||||
const [message, setMessage] = useState("");
|
const [message, setMessage] = useState("");
|
||||||
const [modalOpen, setModalOpen] = useState(false);
|
const [modalOpen, setModalOpen] = useState(false);
|
||||||
|
|
||||||
|
const [createTask] = useCreateTaskMutation();
|
||||||
|
|
||||||
const handleSubmit = async (e) => {
|
const handleSubmit = async (e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
@@ -27,20 +30,11 @@ const CreateTask = ({ farmId, onTaskCreated }) => {
|
|||||||
status,
|
status,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
console.log("Task Data is worked : ", taskData);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch("http://localhost:8000/api/v1/task", {
|
const res = await createTask(taskData).unwrap();
|
||||||
method: "POST",
|
|
||||||
credentials: "include",
|
|
||||||
headers: {
|
|
||||||
"Content-Type": "application/json",
|
|
||||||
},
|
|
||||||
body: JSON.stringify(taskData),
|
|
||||||
});
|
|
||||||
if (!response.ok) {
|
|
||||||
throw new Error("Failed to create task");
|
|
||||||
}
|
|
||||||
const data = await response.json();
|
|
||||||
console.log("Task created:", data);
|
|
||||||
setMessage("Task created successfully!");
|
setMessage("Task created successfully!");
|
||||||
setModalOpen(false);
|
setModalOpen(false);
|
||||||
// Call the parent's callback with the newly created task
|
// Call the parent's callback with the newly created task
|
||||||
|
|||||||
@@ -1,11 +1,20 @@
|
|||||||
import React, { useState, useEffect } from "react";
|
import React, { useState, useEffect } from "react";
|
||||||
import Loader from "../../../components/Loader";
|
import Loader from "../../../components/Loader";
|
||||||
|
import { useGetTasksByFarmQuery } from "../../../store/api/taskApi";
|
||||||
|
|
||||||
const DisplayTast = ({ farmId }) => {
|
const DisplayTast = ({ farmId }) => {
|
||||||
const [tasks, setTasks] = useState([]);
|
const [tasks, setTasks] = useState([]);
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
const [error, setError] = useState(null);
|
const [error, setError] = useState(null);
|
||||||
|
|
||||||
|
const {
|
||||||
|
data: taskList,
|
||||||
|
error: taskError,
|
||||||
|
isLoading,
|
||||||
|
} = useGetTasksByFarmQuery(farmId);
|
||||||
|
|
||||||
|
console.log("Task list is : ", taskList);
|
||||||
|
|
||||||
// Function to delete a task and update the state
|
// Function to delete a task and update the state
|
||||||
const handleDeleteTask = async (taskId) => {
|
const handleDeleteTask = async (taskId) => {
|
||||||
try {
|
try {
|
||||||
@@ -31,33 +40,11 @@ const DisplayTast = ({ farmId }) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const fetchTasks = async () => {
|
if (taskList) {
|
||||||
setLoading(true);
|
setTasks(taskList);
|
||||||
setError(null);
|
|
||||||
try {
|
|
||||||
const response = await fetch(
|
|
||||||
`http://localhost:8000/api/v1/task/farm/${farmId}`,
|
|
||||||
{
|
|
||||||
credentials: "include",
|
|
||||||
headers: {
|
|
||||||
"Content-Type": "application/json",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
);
|
|
||||||
if (!response.ok) {
|
|
||||||
throw new Error("Failed to fetch tasks");
|
|
||||||
}
|
|
||||||
const data = await response.json();
|
|
||||||
setTasks(data);
|
|
||||||
} catch (err) {
|
|
||||||
setError(err.message);
|
|
||||||
} finally {
|
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
}
|
}
|
||||||
};
|
}, [farmId, taskList]);
|
||||||
|
|
||||||
fetchTasks();
|
|
||||||
}, [farmId]);
|
|
||||||
|
|
||||||
if (loading) return <div>Loading tasks...</div>;
|
if (loading) return <div>Loading tasks...</div>;
|
||||||
if (error) return <div className="text-red-600">Error: {error}</div>;
|
if (error) return <div className="text-red-600">Error: {error}</div>;
|
||||||
|
|||||||
@@ -1,11 +1,35 @@
|
|||||||
import React, { useState, useEffect } from "react";
|
import React, { useState, useEffect } from "react";
|
||||||
import Loader from "../../../components/Loader";
|
import Loader from "../../../components/Loader";
|
||||||
|
import { useGetTransactionsQuery } from "../../../store/api/financeApi";
|
||||||
|
|
||||||
|
function formatTimestamp(isoString) {
|
||||||
|
const date = new Date(isoString);
|
||||||
|
return date.toLocaleString("en-US", {
|
||||||
|
year: "numeric",
|
||||||
|
month: "long",
|
||||||
|
day: "numeric",
|
||||||
|
hour: "2-digit",
|
||||||
|
minute: "2-digit",
|
||||||
|
second: "2-digit",
|
||||||
|
hour12: true, // Ensures AM/PM format
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
const FinanceSummary = ({ farmId, financeId }) => {
|
const FinanceSummary = ({ farmId, financeId }) => {
|
||||||
const [summary, setSummary] = useState(null);
|
const [summary, setSummary] = useState(null);
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
const [error, setError] = useState("");
|
const [error, setError] = useState("");
|
||||||
|
|
||||||
|
console.log("Finance id /mljkfgj is : ", financeId);
|
||||||
|
|
||||||
|
const {
|
||||||
|
data: transaction,
|
||||||
|
error: transactionError,
|
||||||
|
isLoading,
|
||||||
|
} = useGetTransactionsQuery(financeId);
|
||||||
|
|
||||||
|
console.log("Transaction data is : ", transaction);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const fetchSummary = async () => {
|
const fetchSummary = async () => {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
@@ -52,23 +76,48 @@ const FinanceSummary = ({ farmId, financeId }) => {
|
|||||||
<thead className="text-xs text-gray-700 uppercase bg-gray-50 dark:bg-gray-700 dark:text-gray-400">
|
<thead className="text-xs text-gray-700 uppercase bg-gray-50 dark:bg-gray-700 dark:text-gray-400">
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="col" className="px-6 py-3">
|
<th scope="col" className="px-6 py-3">
|
||||||
Farm name
|
Type of Transaction
|
||||||
</th>
|
</th>
|
||||||
<th scope="col" className="px-6 py-3">
|
<th scope="col" className="px-6 py-3">
|
||||||
Location
|
Amount
|
||||||
</th>
|
</th>
|
||||||
<th scope="col" className="px-6 py-3">
|
<th scope="col" className="px-6 py-3">
|
||||||
Type
|
Description
|
||||||
</th>
|
</th>
|
||||||
<th scope="col" className="px-6 py-3">
|
<th scope="col" className="px-6 py-3">
|
||||||
Size (acres)
|
Date
|
||||||
</th>
|
</th>
|
||||||
<th scope="col" className="px-6 py-3">
|
<th scope="col" className="px-6 py-3">
|
||||||
Action
|
Action
|
||||||
</th>
|
</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody></tbody>
|
<tbody>
|
||||||
|
{transaction?.map((transaction) => (
|
||||||
|
<tr>
|
||||||
|
<td scope="col" className="px-6 py-3">
|
||||||
|
{transaction.type}
|
||||||
|
</td>
|
||||||
|
<td scope="col" className="px-6 py-3">
|
||||||
|
{transaction.amount}
|
||||||
|
</td>
|
||||||
|
<td scope="col" className="px-6 py-3">
|
||||||
|
{transaction.description}
|
||||||
|
</td>
|
||||||
|
<td scope="col" className="px-6 py-3">
|
||||||
|
{formatTimestamp(transaction.date)}
|
||||||
|
</td>
|
||||||
|
<td className="px-6 py-4">
|
||||||
|
<button
|
||||||
|
className="block text-white bg-red-600 hover:bg-red-800 focus:ring-4 focus:outline-none focus:ring-red-300 font-medium rounded-lg text-sm px-5 py-2.5"
|
||||||
|
type="button"
|
||||||
|
>
|
||||||
|
Remove
|
||||||
|
</button>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
))}
|
||||||
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user