)}
diff --git a/src/pages/LandDetail.jsx b/src/pages/LandDetail.jsx
index 1fb587dd..e022cd6b 100644
--- a/src/pages/LandDetail.jsx
+++ b/src/pages/LandDetail.jsx
@@ -128,8 +128,15 @@ export default function LandDetail() {
console.warn("Server unreachable, searching locally...");
}
- const localData = await OfflineService.getEntities("lands", { id: id });
+ const localData = await OfflineService.getEntities("lands");
+
if (localData && localData.length > 0) {
+ localData.map((data) => {
+ const isOwned = data.id === paramsId;
+ if(isOwned){
+ return isOwned;
+ }
+ })
return { ...localData[0], isOffline: true };
}
throw new Error("Lahan tidak ditemukan");
@@ -270,7 +277,7 @@ export default function LandDetail() {
});
}
}, [land, isEditing]);
-
+ console.log(land, "Data lahan");
if (isLoading) {
return (
diff --git a/src/pages/LandRegister.jsx b/src/pages/LandRegister.jsx
index 7809b902..c95e2aa1 100644
--- a/src/pages/LandRegister.jsx
+++ b/src/pages/LandRegister.jsx
@@ -166,7 +166,6 @@ export default function LandRegister() {
// };
const handlePolygonSave = (polygonData) => {
- // Pastikan data adalah angka murni, bukan objek LatLng Leaflet
const cleanCoordinates = JSON.parse(JSON.stringify(polygonData.polygon_coordinates));
console.log(cleanCoordinates)
setFormData(prev => ({
diff --git a/src/pages/Login.jsx b/src/pages/Login.jsx
index d89193d6..fca023e9 100644
--- a/src/pages/Login.jsx
+++ b/src/pages/Login.jsx
@@ -4,47 +4,28 @@ import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
-import { TreePine, Lock, Mail, Loader2 } from "lucide-react";
+import { TreePine, Lock, Mail, Loader2, ArrowRight } from "lucide-react";
import { toast } from "sonner";
+import { useAuth } from "@/lib/AuthContext";
+import { useNavigate } from "react-router-dom";
export default function Login() {
const [email, setEmail] = useState("");
const [password, setPassword] = useState("");
const [isSubmitting, setIsSubmitting] = useState(false);
- const [user, setUser] = useState(null);
- const [isAuthenticated, setIsAuthenticated] = useState(false);
-
- const dataToken = localStorage.getItem('access_token')
-
- console.log(dataToken);
+ const { login } = useAuth();
+ const navigate = useNavigate();
const handleSubmit = async (e) => {
e.preventDefault();
setIsSubmitting(true);
- try {
- const response = await base44.post("/auth/login", {
- email,
- password,
- });
-
- const data = response.data;
- console.log(response,data)
- if (data.access_token) {
- // setUser(userData);
- setIsAuthenticated(true);
-
- localStorage.setItem('access_token', data.access_token);
- // localStorage.setItem('user_data', JSON.stringify(userData));
-
- toast.success("Login berhasil!");
- window.location.href = "/";
- } else {
- toast.error("Email atau password salah");
- }
- } catch (error) {
- toast.error(error.response?.data?.message || "Terjadi kesalahan saat login");
- } finally {
+ const result = await login(email, password);
+ if (result.success) {
+ toast.success("Login berhasil!");
+ navigate("/ProductivityMonitoring");
+ } else {
+ toast.error(result.message);
setIsSubmitting(false);
}
};
@@ -105,7 +86,10 @@ export default function Login() {
- Lupa password? Silakan hubungi admin koperasi.
+ Belum punya akun ? {" "}
+
+ Daftar di sini
+
diff --git a/src/utils/db.js b/src/utils/db.js
index 6ba7acae..fed33291 100644
--- a/src/utils/db.js
+++ b/src/utils/db.js
@@ -15,6 +15,9 @@ db.version(1).stores({
profile: 'id,user_id, kk,ktp,email, sync_status, name, nama',
harvest: 'id, plant_id, land_id,farmer_id, sync_status',
plant_inspections: 'id, plant_id, land_id, farmer_id, sync_status',
- master_villages: 'id, district_id, name',
- distributions: 'id, farmer_id,offtaker_id, sync_status'
+ distributions: 'id, farmer_id,offtaker_id, sync_status',
+ villages: 'id, name',
+ districts: 'id, name',
+ regencies: 'id, name',
+ provinces: 'id, name'
});
\ No newline at end of file