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 (
);
};
export default Home;