import { Link, router, usePage } from "@inertiajs/react"; import React, { useState } from "react"; import Swal from "sweetalert2"; const Home = () => { const [showPassword, setShowPassword] = useState(false); const props = usePage().props; const [dataLogin, setDataLogin] = useState({ email: "", password: "", }); const handleSubmit = async (e) => { e.preventDefault(); Swal.fire({ title: "Loading", html: '
', // add html attribute if you want or remove allowOutsideClick: false, showConfirmButton: false, }); const res = await fetch("/login", { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ ...dataLogin, _token: props.csrf_token }), }); // Tutup loading Swal.close(); if (res.ok) { const result = await res.json(); Swal.fire({ title: result.status == "berhasil" ? "Berhasil" : "Gagal", text: result.message, icon: result.status == "berhasil" ? "success" : "warning", }); if (result.status == "berhasil") { location.href = "/user"; } // router.get('/') } else { // Jika error server Swal.fire({ title: "Gagal", text: "Gagal terhubung server", icon: "error", }); } }; return (

Halaman Login

setDataLogin({ ...dataLogin, email: e.target.value, }) } id="Email" />
setDataLogin({ ...dataLogin, password: e.target.value, }) } type={showPassword ? "text" : "password"} placeholder="Password" id="password" />
setShowPassword(!showPassword)} className="cursor-pointer absolute h-full flex items-center w-6 right-5" id="btnShowHide" > {!showPassword ? ( ) : ( )}
); }; export default Home;