-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34 from aswanthabam/dev
feat : admin panel & launch anims
- Loading branch information
Showing
8 changed files
with
371 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { _EventCreateData } from "../utils/types"; | ||
import { | ||
ApiResponse, | ||
ResponseStatus, | ||
ResponseType, | ||
publicRouter, | ||
validateResponse, | ||
} from "./api"; | ||
|
||
export const isAdmin = async (): Promise<boolean> => { | ||
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<ApiResponse> => { | ||
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; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
.admin { | ||
background: wheat; | ||
width: 100vw; | ||
height: 100vh; | ||
padding: 10px; | ||
color: black; | ||
|
||
.content { | ||
height: 100%; | ||
overflow: scroll; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<AdminProps> = ({}) => { | ||
const [admin, setAdmin] = useState<boolean>(false); | ||
const redirect = useNavigate(); | ||
useEffect(() => { | ||
isAdmin().then((res) => { | ||
setAdmin(res); | ||
if (!res) redirect("/"); | ||
}); | ||
document.head.innerHTML += | ||
'<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" crossorigin="anonymous">'; | ||
document.head.innerHTML += | ||
'<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-C6RzsynM9kWDrMNeT87bh95OGNyZPhcTNXj1NW7RuBCsyN/o0jlpcV8Qyq46cDfL" crossorigin="anonymous"></script>'; | ||
}, []); | ||
return admin ? ( | ||
<div className={style.admin + " container-fluid row"}> | ||
<div className="col-3"> | ||
<h3 style={{ textAlign: "center" }}>Vijnana Admin</h3> | ||
<ul className="list-group"> | ||
<li className="list-group-item">About Event</li> | ||
<li className="list-group-item">Events</li> | ||
<li className="list-group-item">Add Event</li> | ||
<li className="list-group-item">Add Admin</li> | ||
<li className="list-group-item">Users</li> | ||
</ul> | ||
</div> | ||
<div className={style.content + " col-9"}> | ||
<Outlet /> | ||
</div> | ||
</div> | ||
) : ( | ||
<div>Admin permission required ..</div> | ||
); | ||
}; | ||
|
||
export default Admin; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ( | ||
<div> | ||
<h3 className="underline start" style={{ marginBottom: "30px" }}> | ||
Create New Event | ||
</h3> | ||
<form onSubmit={handleSubmit} method="post"> | ||
<div className="mb-3"> | ||
<label htmlFor="title" className="form-label"> | ||
Event Name: | ||
</label> | ||
<input | ||
type="text" | ||
id="name" | ||
className="form-control" | ||
value={formData.name} | ||
onChange={handleChange} | ||
required | ||
/> | ||
</div> | ||
<div className="mb-3"> | ||
<label htmlFor="description" className="form-label"> | ||
Description: | ||
</label> | ||
<textarea | ||
id="description" | ||
className="form-control" | ||
value={formData.description} | ||
onChange={handleChange} | ||
required | ||
/> | ||
</div> | ||
<div className="mb-3"> | ||
<label htmlFor="details" className="form-label"> | ||
details: | ||
</label> | ||
<textarea | ||
id="details" | ||
className="form-control" | ||
value={formData.details} | ||
onChange={handleChange} | ||
required | ||
/> | ||
</div> | ||
<div className="mb-3"> | ||
<label htmlFor="date" className="form-label"> | ||
Date: | ||
</label> | ||
<input | ||
type="datetime-local" | ||
id="date" | ||
className="form-control" | ||
value={formData.date} | ||
onChange={handleChange} | ||
required | ||
/> | ||
</div> | ||
<div className="mb-3"> | ||
<label htmlFor="category" className="form-label"> | ||
Event Category: | ||
</label> | ||
<select | ||
id="type" | ||
className="form-select" | ||
value={formData.type} | ||
onChange={handleChange} | ||
required | ||
> | ||
<option value="">Select a category</option> | ||
<option value="cp">Competition</option> | ||
<option value="tk">Talk</option> | ||
<option value="sr">Seminar</option> | ||
<option value="ws">Workshop</option> | ||
</select> | ||
</div> | ||
<div className="mb-3"> | ||
<label htmlFor="image" className="form-label"> | ||
Event Image URL: | ||
</label> | ||
<input | ||
type="text" | ||
id="image" | ||
className="form-control" | ||
value={formData.image || ""} | ||
onChange={handleChange} | ||
required | ||
/> | ||
</div> | ||
<div className="mb-3"> | ||
<label htmlFor="venue" className="form-label"> | ||
Event Venue: | ||
</label> | ||
<input | ||
type="text" | ||
id="venue" | ||
className="form-control" | ||
value={formData.venue} | ||
onChange={handleChange} | ||
required | ||
/> | ||
</div> | ||
<div className="mb-3 d-flex " style={{ gap: "15px" }}> | ||
<label htmlFor="gctian_only" className="form-label"> | ||
kbmgct STUDENT ONLY? | ||
</label> | ||
<div> | ||
<input | ||
type="radio" | ||
id="gctian_only" | ||
className="form-check-input" | ||
value="1" | ||
checked={formData.gctian_only == true} | ||
onChange={handleChange} | ||
required | ||
/> | ||
<label htmlFor="gctian_only" className="form-check-label"> | ||
Yes | ||
</label> | ||
</div> | ||
<div> | ||
<input | ||
type="radio" | ||
id="gctian_only" | ||
className="form-check-input" | ||
value="0" | ||
checked={formData.gctian_only == false} | ||
onChange={handleChange} | ||
required | ||
/> | ||
<label htmlFor="studentOnly" className="form-check-label"> | ||
No | ||
</label> | ||
</div> | ||
</div> | ||
<div className="mb-3 d-flex" style={{ gap: "15px" }}> | ||
<label htmlFor="is_reg" className="form-label"> | ||
Open to all? | ||
</label> | ||
<div> | ||
<input | ||
type="radio" | ||
id="is_reg" | ||
className="form-check-input" | ||
value="0" | ||
checked={formData.is_reg == false} | ||
onChange={handleChange} | ||
required | ||
/> | ||
<label htmlFor="is_reg" className="form-check-label"> | ||
Yes | ||
</label> | ||
</div> | ||
<div> | ||
<input | ||
type="radio" | ||
id="is_reg" | ||
className="form-check-input" | ||
value="1" | ||
checked={formData.is_reg == true} | ||
onChange={handleChange} | ||
required | ||
/> | ||
<label htmlFor="studentOnly" className="form-check-label"> | ||
No | ||
</label> | ||
</div> | ||
</div> | ||
|
||
<button className="btn btn-primary">Create Event</button> | ||
</form> | ||
</div> | ||
); | ||
}; | ||
|
||
export default NewEvent; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.