diff --git a/src/index.tsx b/src/index.tsx index da2cf5a..396e239 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -11,7 +11,8 @@ import { cors } from "@elysiajs/cors"; import packageJson from "./../package.json"; import Configs from "./server/routes/configs_route"; import { prisma } from "./server/lib/prisma"; -import JadwalSholat from "./server/routes/jadwal_sholat"; +import JadwalShalat from "./server/routes/jadwal_shalat"; +import { JadwalShalatAdmin } from "./server/routes/jadwal_shalat_admin"; const PORT = process.env.PORT || 3000; const Docs = new Elysia().use( @@ -71,11 +72,12 @@ const ApiUser = new Elysia({ const Api = new Elysia({ prefix: "/api", }) + .use(JadwalShalat) .use(Configs) .use(apiAuth) .use(ApiKeyRoute) .use(ApiUser) - .use(JadwalSholat); + .use(JadwalShalatAdmin); const app = new Elysia() .use(cors()) @@ -129,7 +131,7 @@ const app = new Elysia() }, }, ) - .get("/*", html) + .get("*", html) .listen(PORT, () => { console.log(`Server running at http://localhost:${PORT}`); }); diff --git a/src/pages/Home.tsx b/src/pages/Home.tsx index 611301c..5becbb5 100644 --- a/src/pages/Home.tsx +++ b/src/pages/Home.tsx @@ -1,7 +1,13 @@ import clientRoutes from "@/clientRoutes"; import { Button, Card, Container, Group, Stack, Title } from "@mantine/core"; +import { useShallowEffect } from "@mantine/hooks"; +import { useNavigate } from "react-router-dom"; export default function Home() { + + useShallowEffect(() => { + window.location.reload() + },[]) return ( diff --git a/src/pages/dashboard/shalat/dashboard-shalat_page.tsx b/src/pages/dashboard/shalat/dashboard-shalat_page.tsx index d5b059d..75941eb 100644 --- a/src/pages/dashboard/shalat/dashboard-shalat_page.tsx +++ b/src/pages/dashboard/shalat/dashboard-shalat_page.tsx @@ -1,12 +1,13 @@ +import clientRoutes from "@/clientRoutes"; import apiFetch from "@/lib/apiFetch"; import { + ActionIcon, Button, Card, Container, Flex, Group, Loader, - Radio, Stack, Switch, Text, @@ -15,8 +16,10 @@ import { } from "@mantine/core"; import { useShallowEffect } from "@mantine/hooks"; import { notifications } from "@mantine/notifications"; +import { IconEye } from "@tabler/icons-react"; import type { Configs, User } from "generated/prisma"; import { useState } from "react"; +import { useNavigate } from "react-router"; import useSwr from "swr"; export default function JadwalShalat() { @@ -37,6 +40,7 @@ function ListUser() { apiFetch.api["jadwal-sholat"]["user-list"].get, ); const [listUser, setListUser] = useState([]); + const navigate = useNavigate(); useShallowEffect(() => { setListUser(data?.data?.data ?? []); }, [data]); @@ -44,27 +48,38 @@ function ListUser() { if (error) return {error.message}; return ( - - - List User - {listUser.map((user) => ( - - - {user.name} - { - const { data } = await apiFetch.api["jadwal-sholat"][ - "user-active" - ].put({ id: user.id, active: e.target.checked }); - mutate(); - }} - /> - - - ))} - - + + + navigate(clientRoutes["/shalat/shalat"])} + > + + + + + + List User + {listUser.map((user) => ( + + + {user.name} + { + const { data } = await apiFetch.api["jadwal-sholat-admin"][ + "user-active" + ].put({ id: user.id, active: e.target.checked }); + mutate(); + }} + /> + + + ))} + + + ); } @@ -110,31 +125,33 @@ function ConfigUpdate() { }, [data]); async function handleUpdate() { - if (!config?.ikomahKey || !config?.imamKey) return notifications.show({ - title: "Error", - message: "Config updated failed", - color: "red", - }); - const { data , status} = await apiFetch.api["jadwal-sholat"]["config"].put({ + if (!config?.ikomahKey || !config?.imamKey) + return notifications.show({ + title: "Error", + message: "Config updated failed", + color: "red", + }); + const { data, status } = await apiFetch.api["jadwal-sholat-admin"][ + "config" + ].put({ id: "1", ikomahKey: config.ikomahKey, imamKey: config.imamKey, }); - - if(status === 200 ) { + + if (status === 200) { notifications.show({ title: "Success", message: "Config updated successfully", color: "green", }); - }else{ + } else { notifications.show({ title: "Error", message: "Config updated failed", color: "red", }); } - } if (isLoading) return ; @@ -146,11 +163,19 @@ function ConfigUpdate() { Config Imam Key - setConfig({ ...config, imamKey: e.target.value })} /> + setConfig({ ...config, imamKey: e.target.value })} + /> Ikomah Key - setConfig({ ...config, ikomahKey: e.target.value })} /> + + setConfig({ ...config, ikomahKey: e.target.value }) + } + /> diff --git a/src/pages/shalat/shalat_page.tsx b/src/pages/shalat/shalat_page.tsx index b5cc6db..def50a3 100644 --- a/src/pages/shalat/shalat_page.tsx +++ b/src/pages/shalat/shalat_page.tsx @@ -13,14 +13,13 @@ import { Stack, Text, Title, - UnstyledButton + UnstyledButton, } from "@mantine/core"; -import { DatePicker, DatePickerInput } from "@mantine/dates"; +import { DatePicker } from "@mantine/dates"; import dayjs from "dayjs"; import "dayjs/locale/id"; import duration from "dayjs/plugin/duration"; import { useEffect, useMemo, useState } from "react"; -import { DateScrollPicker } from 'react-date-wheel-picker' import { IconCalendar, @@ -39,7 +38,8 @@ import { import DateHolidays, { type HolidaysTypes } from "date-holidays"; import useSwr from "swr"; - +import { useNavigate } from "react-router"; +import clientRoutes from "@/clientRoutes"; dayjs.locale("id"); dayjs.extend(duration); @@ -62,6 +62,7 @@ export default function AdhanPage() { const [daily, setDaily] = useState(null); const [adhan, setAdhan] = useState(null); const [loading, setLoading] = useState(true); + const navigate = useNavigate(); // tahun & bulan yang dipakai const year = dayjs(date).year(); @@ -217,7 +218,12 @@ export default function AdhanPage() { - + navigate("/")} + /> Jadwal Sholat & Imam @@ -245,17 +251,22 @@ export default function AdhanPage() { locale="id" value={date} date={date || undefined} - renderDay={(d) => {dayjs(d).format("DD")}} + renderDay={(d) => ( + + {dayjs(d).format("DD")} + + )} defaultDate={date || undefined} onChange={setDate as any} /> - {/* */} @@ -531,65 +542,6 @@ function RingkasanBulalan( ); })} - {/* - - - - Tanggal - Imam - Ikomah - - - - {Object.keys(monthly.data.imam).map((d) => { - const tglNum = Number(d); - const iso = dayjs( - `${year}-${String(month).padStart(2, "0")}-${String(tglNum).padStart(2, "0")}`, - ).format("YYYY-MM-DD"); - const holiday = isHoliday(iso); - const isToday = dayjs(iso).isSame(dayjs(), "day"); - return ( - - - - {dayjs(iso).format("ddd, DD MMM")} - - - - {monthly.data.imam[d] ? ( - } - variant="light" - color="blue" - > - {monthly.data.imam[d]} - - ) : ( - - - )} - - - {monthly.data.ikomah[d] ? ( - } - variant="light" - color="grape" - > - {monthly.data.ikomah[d]} - - ) : ( - - - )} - - - ); - })} - -
-
*/} ); @@ -625,47 +577,6 @@ function FullYearHoliday(year: number, holidays: HolidaysTypes.Holiday[]) { )} - {/* - - - - Tanggal - Nama Libur - - - - - {holidays.map((h, idx) => { - const tgl = dayjs(h.date).format("dddd, DD MMMM YYYY"); - return ( - - - - - {tgl} - - - - {h.name} - - - ); - })} - -
-
*/} ); @@ -708,9 +619,6 @@ function JadwalHariIni( {p.name} - {/* - {p.isPast ? "Sudah lewat" : (formatCountdown(p.dt) ?? "-")} - */} diff --git a/src/server/routes/jadwal_sholat.ts b/src/server/routes/jadwal_shalat.ts similarity index 83% rename from src/server/routes/jadwal_sholat.ts rename to src/server/routes/jadwal_shalat.ts index 52d1c39..b19a747 100644 --- a/src/server/routes/jadwal_sholat.ts +++ b/src/server/routes/jadwal_shalat.ts @@ -9,6 +9,7 @@ import dayjs from "dayjs"; import utc from "dayjs/plugin/utc"; import tz from "dayjs/plugin/timezone"; import "dayjs/locale/id"; +import type { User } from "generated/prisma"; dayjs.extend(utc); dayjs.extend(tz); @@ -29,7 +30,7 @@ function normalize(dateStr: string) { /* ------------------------------------------------------------------ MAIN ROUTER ------------------------------------------------------------------- */ -const JadwalSholat = new Elysia({ +const JadwalShalat = new Elysia({ prefix: "/jadwal-sholat", tags: ["jadwal_sholat"], }) @@ -137,10 +138,12 @@ const JadwalSholat = new Elysia({ }, } ) - .get("/user-list", async () => { - const user = await prisma.user.findMany(); + .get("/user-list", async (ctx) => { + const { user }: { user: User } = ctx as any; + + const getUsers = await prisma.user.findMany(); return { - data: user, + data: getUsers, }; }, { detail: { @@ -148,32 +151,12 @@ const JadwalSholat = new Elysia({ description: "mendapatkan list user", }, }) - .put("/user-active", async ({ body }) => { - const { id } = body; - const user = await prisma.user.update({ - where: { id }, - data: { active: body.active }, - }); - return { - success: true, - data: user, - }; - }, { - body: t.Object({ - id: t.String(), - active: t.Boolean(), - }), - detail: { - summary: "Active user", - description: "mengaktifkan user", - }, - }) .get("/config", async () => { const config = await prisma.configs.findUnique({ where: { id: "1" }, }); console.log(config); - + return { data: config, }; @@ -182,34 +165,9 @@ const JadwalSholat = new Elysia({ summary: "Get config", description: "mendapatkan config", }, - }) - .put("/config", async ({ body }) => { - const { imamKey, ikomahKey } = body; - const config = await prisma.configs.update({ - where: { id: "1" }, - data: { imamKey, ikomahKey }, - }); - console.log({ - success: true, - config, - }); - return { - success: true, - data: config, - }; - }, { - body: t.Object({ - id: t.String(), - imamKey: t.String(), - ikomahKey: t.String(), - }), - detail: { - summary: "Update config", - description: "mengupdate config", - }, }); -export default JadwalSholat; +export default JadwalShalat; /* ------------------------------------------------------------------ FUNCTIONS diff --git a/src/server/routes/jadwal_shalat_admin.ts b/src/server/routes/jadwal_shalat_admin.ts new file mode 100644 index 0000000..a583f96 --- /dev/null +++ b/src/server/routes/jadwal_shalat_admin.ts @@ -0,0 +1,53 @@ +import Elysia, { t } from "elysia"; +import { prisma } from "../lib/prisma"; + +export const JadwalShalatAdmin = new Elysia({ + prefix: "/jadwal-sholat-admin", + tags: ["jadwal_sholat_admin"], +}) + .put("/user-active", async ({ body }) => { + + const { id } = body; + const user = await prisma.user.update({ + where: { id }, + data: { active: body.active }, + }); + return { + success: true, + data: user, + }; + }, { + body: t.Object({ + id: t.String(), + active: t.Boolean(), + }), + detail: { + summary: "Active user", + description: "mengaktifkan user", + }, + }) + .put("/config", async ({ body }) => { + const { imamKey, ikomahKey } = body; + const config = await prisma.configs.update({ + where: { id: "1" }, + data: { imamKey, ikomahKey }, + }); + console.log({ + success: true, + config, + }); + return { + success: true, + data: config, + }; + }, { + body: t.Object({ + id: t.String(), + imamKey: t.String(), + ikomahKey: t.String(), + }), + detail: { + summary: "Update config", + description: "mengupdate config", + }, + });