import React, { useState } from "react"; import AdminLayout from "./Layout/AdminLayout"; import MDEditor from "@uiw/react-md-editor"; import { Link } from "@inertiajs/react"; import Swal from "sweetalert2"; import HitApi from "../../Utils/HitApi"; const InputMateri = (props) => { const { data } = props; const [form, setForm] = useState({ materi: data.materi ?? "", video: data.video ?? "", fileVideo: undefined, }); const handleSubmit = (e) => { e.preventDefault(); Swal.fire({ title: "Konfirmasi", text: "Apakah anda yakin ingin menyimpan data?", icon: "warning", showCancelButton: true, confirmButtonColor: "#3085d6", cancelButtonColor: "#d33", confirmButtonText: "Ya", }).then((result) => { if (result.isConfirmed) { Swal.fire({ title: "Loading", html: '
', // add html attribute if you want or remove allowOutsideClick: false, showConfirmButton: false, }); if (form.fileVideo) { const formData = new FormData(); formData.append("file", form.fileVideo); formData.append("id", data.id); formData.append("video", form.video); formData.append("materi", form.materi); HitApi({ url: "/api/v1/materi/input", method: "POST", body: formData, onSuccess: (res) => { Swal.fire( "Berhasil", "Data berhasil disimpan", "success" ); }, onError: () => { // Swal.fire("Gagal", "Data gagal ditambahkan", "error"); }, isFormData: true, }); } else { HitApi({ url: "/api/v1/materi/input", method: "POST", body: { ...form, id: data.id }, onSuccess: () => { Swal.fire( "Berhasil", "Data berhasil disimpan", "success" ); }, onError: () => { // Swal.fire("Gagal", "Data gagal ditambahkan", "error"); }, }); } } }); }; return (
{/*
  • SD
  • Matematika
  • Input Materi
*/}

Judul: {data.name}

setForm({ ...form, materi: e })} />
); }; export default InputMateri;