diff --git a/.gitignore b/.gitignore index 634b3fe6..bbc7d1da 100644 --- a/.gitignore +++ b/.gitignore @@ -32,3 +32,6 @@ pnpm-debug.log* # OS files .DS_Store Thumbs.db +package-lock.json +.env +package-lock.json diff --git a/package.json b/package.json index 0ef6d067..15e303c5 100644 --- a/package.json +++ b/package.json @@ -57,6 +57,7 @@ "class-variance-authority": "^0.7.1", "clsx": "^2.1.1", "cmdk": "^1.0.0", + "crypto-js": "^4.2.0", "date-fns": "^3.6.0", "dexie": "^4.3.0", "dexie-react-hooks": "^4.2.0", diff --git a/pertanian-app.code-workspace b/pertanian-app.code-workspace index a6e4b4d3..68f93f75 100644 --- a/pertanian-app.code-workspace +++ b/pertanian-app.code-workspace @@ -8,6 +8,9 @@ }, { "path": "../siks" + }, + { + "path": "../pertamina-point" } ], "settings": {} diff --git a/src/App.jsx b/src/App.jsx index 9425baca..290abe69 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -66,7 +66,6 @@ const AuthenticatedApp = () => { function ProtectedLayout() { const { token } = useAuth(); - console.log("token on app", token) if (!token) { return ; } diff --git a/src/Layout.jsx b/src/Layout.jsx index 1272d000..e7ea036e 100644 --- a/src/Layout.jsx +++ b/src/Layout.jsx @@ -126,9 +126,9 @@ export default function Layout({ children, currentPageName }) { const location = useLocation(); const { user, logout } = useAuth(); - if (!user) { - return
Memuat Sesi...
; - } + // if (!user) { + // return
Memuat Sesi...
; + // } const filteredNavigation = navigation.filter((item) => { if (!user?.role) return false; @@ -142,7 +142,7 @@ export default function Layout({ children, currentPageName }) { return (
{/* Mobile Header */} -
+
)}
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