Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added setting page for admin #317

Merged
merged 1 commit into from
Mar 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/commons/Sidebar/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ const SidebarItems = ({ backupName, backupData }) => {
<Dropdown.Item as="a">
<DropItem to="/leaderboard" title="Event Standings" />
</Dropdown.Item>

<Dropdown.Item as="a">
<DropItem to="/settings" title="Settings" />
</Dropdown.Item>
</Dropdown>
}

Expand Down
21 changes: 16 additions & 5 deletions src/components/CollegeTeams/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { getUser } from "../../services/userServices";
import LoadContent from "../../commons/LoadContent";
import { isTeamChangeFreezed } from "../../utils/common";
import { FiEdit } from "react-icons/fi";
import { getSetting } from "../../services/settingsServices";

const styles = {
memberCard: {
Expand All @@ -26,11 +27,11 @@ const styles = {
},
};

const MemberCard = ({ member, team }) => (
<Link to={!isTeamChangeFreezed() && "/teams/members/" + member.id + "/edit"} css={{
const MemberCard = ({ member, team, teamEditEnabled }) => (
<Link to={teamEditEnabled && "/teams/members/" + member.id + "/edit"} css={{
...styles.memberCard,
}}>
{!isTeamChangeFreezed() &&<div className="w-100 flex justify-end opacity-60"><FiEdit/></div> }
{teamEditEnabled &&<div className="w-100 flex justify-end opacity-60"><FiEdit/></div> }
<div css={{
fontSize: "1.3em",
}}>
Expand All @@ -55,7 +56,8 @@ export default class Teams extends React.Component {
collegeLoading: true,
events: [],
teams: {},
teamsLoading: true
teamsLoading: true,
teamEditEnabled: false,
};

componentWillMount() {
Expand Down Expand Up @@ -85,6 +87,15 @@ export default class Teams extends React.Component {
});
});
});

getSetting("editTeamEnabled").then((data)=>{
if(data)
{
this.setState({teamEditEnabled: data})
}else{
this.setState({teamEditEnabled: false})
}
});
}

render = () => {
Expand All @@ -110,7 +121,7 @@ export default class Teams extends React.Component {
{
this.state.teams[event].map((team) =>
team.members.map((member, i) => (
<MemberCard key={i} member={member} team={team} />
<MemberCard key={i} member={member} team={team} teamEditEnabled={this.state.teamEditEnabled} />
))
)
}
Expand Down
18 changes: 13 additions & 5 deletions src/components/Index/index.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from "react";
import React, { useEffect, useState } from "react";
import utsavLogo from "../../images/loader.gif"
import Countdown from 'react-countdown';
import { getSetting } from "../../services/settingsServices";

const cookingEventsOpenDate = new Date("February 27, 2023, 23:59:59");
const cookingEventsCloseDate = new Date("March 6, 2023, 17:00:00");
Expand Down Expand Up @@ -40,12 +41,19 @@ const RegistrationTimer = () => {

}

export default () =>
<div css={{ textAlign: "center" }}>
export default () =>{
const [title, setTitle] = useState("UTSAV 2024!")
useEffect(() => {
getSetting("title").then(data=>setTitle(data || "UTSAV 2024!"));
}, [])

return (
<div css={{ textAlign: "center" }}>
<h2 className="mucapp">MAHE Utsav Coordinators App</h2>
<h1 className="mucapp"> UTSAV 2024!</h1>
<h1 className="mucapp">{title}</h1>
{/* <RegistrationTimer /> */}
{/* <div className="festival-live-message">The festival is on!</div> */}
<img className="mucapp" css={{ width: "60%" }} alt="Logo" src={utsavLogo} />
</div >
;
)
};
78 changes: 78 additions & 0 deletions src/components/Settings/Index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import React from "react";

import {getSettings, updateSettings} from "../../services/settingsServices";
import Loader from "../../commons/Loader";
import { toast } from "../../actions/toastActions";

const styles = {
teamCard: {
display: "inline-block",
marginRight: 20,
marginBottom: 20,
padding: 20,
width: "100%",
borderRadius: 3,
border: "2px solid rgba(0, 0, 0, .1)",
color: "inherit",
boxShadow: "0px 5px 20px -4px rgba(0, 0, 0, .1)",
transition: "box-shadow .2s ease",
":hover": {
color: "inherit",
boxShadow: "0px 5px 50px -4px rgba(0, 0, 0, .1)",
}
},
};


export default class Settings extends React.Component {
state = {
title: "",
enableTeamEdit: false,
};



handleSave(){
const data = {title: this.state.title, editTeamEnabled: this.state.enableTeamEdit};
console.log(data)
updateSettings(data).then(data=>{
toast("Updated ✔")
});
}

componentWillMount() {
getSettings().then(settings=>{
console.log(settings);
if(settings){
this.setState({
title: settings.title || "",
enableTeamEdit: settings.editTeamEnabled || false,
})
}
}).catch((err)=>{
console.error(err)
})
}



render = () => (
<div className=" w-[400px] bg-zinc-50 border p-4 rounded-md ">
<h2 className="mucapp">Settings</h2>

<div className="flex flex-col gap-4 p-6">
<div className="input-group gap-1 flex flex-col">
<label htmlFor="title" className=" text-md">Title</label>
<input className=" border rounded-sm h-10 py-2 px-1 text-base" type="text" id="title" value={this.state.title} onChange={(e)=>this.setState({title: e.target.value})}/>
</div>

<div className="input-group gap-2 flex">
<label htmlFor="enable_team_edit" className=" text-md">Enable Team Edit</label>
<input className=" border rounded-sm w-[20px]" type="checkbox" id="enable_team_edit" value={this.state.enableTeamEdit} onChange={(e)=>this.setState({enableTeamEdit: e.target.checked})} checked={this.state.enableTeamEdit}/>
</div>

<button className="mucapp mt-4 w-[200px]" onClick={this.handleSave.bind(this)}>Save</button>
</div>
</div>
);
};
4 changes: 4 additions & 0 deletions src/pages/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ import PracticeSlots from "../components/PracticeSlots";
import PublicPracticeSlots from "../components/PublicPracticeSlots";
import Notifications from "../components/Notifications";
import PublicEvents from "../components/PublicEvents";
import Settings from "../components/Settings/Index";


if (typeof (document) != 'undefined')
Expand Down Expand Up @@ -155,6 +156,9 @@ export default () =>
<PrivateRoute path="/practice-slots/public" component={PublicPracticeSlots} type={8} />
<PrivateRoute path="/notifications" component={Notifications} type={8} />

<PrivateRoute path="/settings" component={Settings} type={1} />



{/* <PrivateRoute path="/volunteers/event" component={EventVolunteer} type={1 << 3} /> */}
{/* <PrivateRoute path="/viewCoreVolunteer" component={ViewCoreVolunteer} type={4} />
Expand Down
39 changes: 39 additions & 0 deletions src/services/settingsServices.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { toast } from "../actions/toastActions";
import request from "../utils/request";


/**
* @typedef {"title" | "editTeamEnabled"} SettingValues
*/


/**
*
* @param {SettingValues} setting
*/
export const getSetting = async (setting) =>{
let response = await request(`/settings/${setting}`);
if(response.status == 200){
return response.data;
}else{
console.error("Error in getSetting", response);
return null
}
}

export const getSettings = async () => {
let response = await request(`/settings`);
return response.data;
}

export const updateSettings = async ({title, editTeamEnabled}) => {
const data = {title, editTeamEnabled};
let response = await request(`/settings`, 'POST', data);

if(response?.status == 200){
return response.data
}else{
console.error(response);
toast("Failed to update!");
}
}
Loading