Skip to content

BSL-40-AdminEventUI#38

Open
sanjanamanivannan wants to merge 1 commit intomainfrom
bsl-40-admin-events-ui
Open

BSL-40-AdminEventUI#38
sanjanamanivannan wants to merge 1 commit intomainfrom
bsl-40-admin-events-ui

Conversation

@sanjanamanivannan
Copy link
Copy Markdown
Contributor

Screenshot 2026-03-06 at 3 23 18 PM

const [startAt, setStartAt] = useState("");
const [location, setLocation] = useState("");

const [message, setMessage] = useState("");
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Track success vs error...

const [message, setMessage] = useState<{ text: string; isError: boolean } | null>(null);

Now have to update every setMessage(...) call (I will create a comment on each one to help)


if (!res.ok) {
setEvents([]);
setMessage(data?.error || "Failed to load events");
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

setMessage({ text: data?.error || "Failed to load events", isError: true });

setEvents(Array.isArray(data) ? data : []);
} catch {
setEvents([]);
setMessage("Failed to load events");
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

setMessage({ text: "Failed to load events", isError: true });

return;
}

setMessage("Event created successfully");
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

setMessage({ text: "Event created successfully", isError: false });

const data = await res.json();

if (!res.ok) {
setMessage(data?.error || "Failed to create event");
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

setMessage({ text: data?.error || "Failed to create event", isError: true });


async function createEvent(e: React.FormEvent) {
e.preventDefault();
setMessage("");
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

setMessage(null);


async function loadEvents() {
setLoading(true);
setMessage("");
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

setMessage(null);

}
}

return (
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something like this for the role checking, adding to what i added above:

{canCreate && (
  <form onSubmit={createEvent} className="mt-6 space-y-4 max-w-md">
    ...
  </form>
)}
{!canCreate && (
  <p className="mt-6 text-sm text-gray-500">You do not have permission to create events.</p>
)}


import { useEffect, useState } from "react";
import AdminLayout from "@/components/admin/AdminLayout";

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to incorporate RBAC (Role-based access control). So incorporate useSession() and hasRole()

here add this:

import { useSession } from "next-auth/react";
import { hasRole } from "@/lib/rbac";

};

export default function AdminEventsPage() {
const [events, setEvents] = useState<Event[]>([]);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Continuing with the RBAC comments, add this right under AdminEventsPage() and keep the other stuff:

  const { data: session } = useSession();
  const canCreate = hasRole(session?.user?.role ?? "USER", "AMBASSADOR");

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants