diff --git a/website/src/App.tsx b/website/src/App.tsx index 2f36286..cde8b9f 100644 --- a/website/src/App.tsx +++ b/website/src/App.tsx @@ -1,13 +1,13 @@ import { A, useLocation } from "@solidjs/router"; -import { For, JSX } from "solid-js"; +import { createSignal, For, JSX, Match, onMount, Switch } from "solid-js"; import SettingIcon from "./icons/SettingIcon"; import HomeIcon from "./icons/HomeIcon"; import ArchiveIcon from "./icons/ArchiveIcon"; import ClockIcon from "./icons/ClockIcon"; +import supabase from "./utils/supabase"; +import { Histori } from "./types/Histori"; export default function (props: JSX.HTMLAttributes) { - const location = useLocation(); - const menus = [ { path: "/", @@ -31,6 +31,56 @@ export default function (props: JSX.HTMLAttributes) { }, ]; + const [lastHistori, setLastHistori] = createSignal(null); + + const location = useLocation(); + + const getLastHistori = async () => { + const { data } = await supabase + .from("histori_fermentasi") + .select("*") + .limit(1) + .eq("selesai", false) + .order("created_at", { ascending: false }); + + if (!!data) { + setLastHistori(data[0]); + } + }; + + const deleteAllData = async () => { + await supabase.from("kondisi_tapai").delete().neq("id", "0"); + + setLastHistori(null); + + window.alert("Aksi berhasil dilakukan"); + window.location.reload(); + }; + + const saveHistori = async () => { + await supabase + .from("histori_fermentasi") + .update({ + selesai: true, + }) + .eq("id", lastHistori()?.id); + + await deleteAllData(); + }; + + const noSaveHistori = async () => { + await supabase + .from("histori_fermentasi") + .delete() + .eq("id", lastHistori()?.id); + + await deleteAllData(); + }; + + onMount(async () => { + await getLastHistori(); + }); + return (
{props.children}
+ + + +
+
+
Pemberitahuan
+ Fermentasi tapai telah dilakukan dengan hasil{" "} + + {lastHistori()?.berhasil ? "sukses" : "gagal"} + + . Sistem akan melakukan beberapa aksi yaitu: +
    +
  • + menghapus data-data terkait dengan proses fermentasi yang + telah dilakukan. +
  • +
  • + data-data yang dihapus termasuk suhu, kelembaban, dan kadar + gas selama fermentasi. +
  • +
+ Simpan hasil fermentasi ke histori? +
+ + +
+
+
+
+
); }