diff --git a/src/App.tsx b/src/App.tsx index bc03f42b..8776834e 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -24,6 +24,8 @@ import { GoogleIdentity, isLoggedIn } from "./utils/utils"; import WhatsappIcon from "./components/whatsapp/Whatsapp"; import Launch from "./pages/launch/launch"; import LaunchHome from "./pages/launch/Home"; +import Admin from "./pages/admin/Admin"; +import NewEvent from "./pages/admin/admin_pages/new_event/NewEvent"; function getTheme() { var theme = localStorage.getItem("theme"); @@ -181,6 +183,9 @@ function App() { // } > + }> + }> + }> diff --git a/src/apis/adminApi.tsx b/src/apis/adminApi.tsx new file mode 100644 index 00000000..bcfacfd4 --- /dev/null +++ b/src/apis/adminApi.tsx @@ -0,0 +1,35 @@ +import { _EventCreateData } from "../utils/types"; +import { + ApiResponse, + ResponseStatus, + ResponseType, + publicRouter, + validateResponse, +} from "./api"; + +export const isAdmin = async (): Promise => { + var res = publicRouter.post("/api/v2/admin/is_admin"); + var val = await validateResponse(res); + if ( + val.status == ResponseStatus.SUCCESS && + val.contentType == ResponseType.DATA + ) { + return (val.data.data as any)["is_admin"] as boolean; + } + return false; +}; + +export const createEvent = async ( + event: _EventCreateData, + setToast: ( + status: boolean, + message: string | null, + hideAfter: number | null + ) => void +): Promise => { + var res = publicRouter.post("/api/v2/events/create", event); + var val = await validateResponse(res); + console.log(val); + setToast(true, val.data.message, 3000); + return val; +}; diff --git a/src/pages/admin/Admin.module.css b/src/pages/admin/Admin.module.css new file mode 100644 index 00000000..eee382c9 --- /dev/null +++ b/src/pages/admin/Admin.module.css @@ -0,0 +1,12 @@ +.admin { + background: wheat; + width: 100vw; + height: 100vh; + padding: 10px; + color: black; + + .content { + height: 100%; + overflow: scroll; + } +} diff --git a/src/pages/admin/Admin.tsx b/src/pages/admin/Admin.tsx new file mode 100644 index 00000000..9f3f7c2e --- /dev/null +++ b/src/pages/admin/Admin.tsx @@ -0,0 +1,42 @@ +import { useEffect, useState } from "react"; +import style from "./Admin.module.css"; +import { Outlet, useNavigate } from "react-router-dom"; +import { isAdmin } from "../../apis/adminApi"; + +interface AdminProps {} + +const Admin: React.FC = ({}) => { + const [admin, setAdmin] = useState(false); + const redirect = useNavigate(); + useEffect(() => { + isAdmin().then((res) => { + setAdmin(res); + if (!res) redirect("/"); + }); + document.head.innerHTML += + ''; + document.head.innerHTML += + ''; + }, []); + return admin ? ( +
+
+

Vijnana Admin

+
    +
  • About Event
  • +
  • Events
  • +
  • Add Event
  • +
  • Add Admin
  • +
  • Users
  • +
+
+
+ +
+
+ ) : ( +
Admin permission required ..
+ ); +}; + +export default Admin; diff --git a/src/pages/admin/admin_pages/new_event/NewEvent.tsx b/src/pages/admin/admin_pages/new_event/NewEvent.tsx new file mode 100644 index 00000000..7d820ba7 --- /dev/null +++ b/src/pages/admin/admin_pages/new_event/NewEvent.tsx @@ -0,0 +1,213 @@ +import React, { useState } from "react"; +import { _Event, _EventCreateData } from "../../../../utils/types"; +import { createEvent } from "../../../../apis/adminApi"; +import { useToast } from "../../../../components/toast/useToast"; + +const NewEvent: React.FC = () => { + const [formData, setFormData] = useState<_EventCreateData>({ + name: "", + description: "", + details: "", + date: "", + type: "", + image: null, + reg_link: null, + venue: "", + gctian_only: false, + is_reg: true, + closed: false, + }); + const { setToastStatus } = useToast(); + const handleChange = ( + e: React.ChangeEvent< + HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement + > + ) => { + console.log(e.target.id, e.target.value); + setFormData({ + ...formData, + [e.target.id]: e.target.value, + }); + }; + + const handleSubmit = async (event: React.FormEvent) => { + event.preventDefault(); + console.log("Form submitted!"); + console.log(formData); + await createEvent(formData, setToastStatus); + }; + + return ( +
+

+ Create New Event +

+
+
+ + +
+
+ +