Skip to content
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
2 changes: 1 addition & 1 deletion src/app/dashboard/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default async function Page() {
return (
<div className="container mx-auto p-6 py-25">
<div className="mb-8">
<h1 className="text-3xl font-bold text-blue-800">Admin Dashboard</h1>
<h1 className="text-3xl font-bold text-[#1f639e]">Admin Dashboard</h1>
<p className="text-muted-foreground">
Welcome, administrator! You have special access privileges.
</p>
Expand Down
14 changes: 1 addition & 13 deletions src/app/events/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,7 @@ export default async function EventPage({ params }: EventPageProps) {
notFound();
}

// Map database fields to frontend expected fields
const eventData = result.data;
const event = {
id: eventData.id,
title: eventData.eventTitle,
content: eventData.eventDesc,
event_date: eventData.eventDate,
image_url: eventData.imageUrl,
created_at: eventData.createdAt,
updated_at: eventData.updatedAt,
user_id: eventData.createdBy,
};
return <EventDetail event={event} />;
return <EventDetail event={result.data} />;
} catch (error: unknown) {
// Log the error for debugging purposes
if (error instanceof Error) {
Expand Down
36 changes: 18 additions & 18 deletions src/components/events/event-detail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ import MarkdownRenderer from "./markdown-renderer";

interface Event {
id: string;
title: string;
content: string;
event_date: string;
image_url: string | null;
created_at: string;
updated_at: string;
user_id: string;
eventTitle: string;
eventDesc: string;
eventDate: string;
imageUrl: string | null;
createdAt: string;
updatedAt: string;
createdBy: string;
}

interface EventDetailProps {
Expand All @@ -41,8 +41,8 @@ export default function EventDetail({ event }: EventDetailProps) {
});
};

const isUpcoming = new Date(event.event_date) > new Date();
const isPast = new Date(event.event_date) < new Date();
const isUpcoming = new Date(event.eventDate) > new Date();
const isPast = new Date(event.eventDate) < new Date();

return (
<div className="container mx-auto p-6 max-w-4xl pt-30">
Expand All @@ -60,7 +60,7 @@ export default function EventDetail({ event }: EventDetailProps) {
<div className="mb-8">
<div className="flex items-start justify-between mb-4">
<h1 className="text-4xl font-bold leading-tight text-[#1f639e]">
{event.title}
{event.eventTitle}
</h1>
<div className="flex gap-2">
{isUpcoming && (
Expand All @@ -83,23 +83,23 @@ export default function EventDetail({ event }: EventDetailProps) {
<div className="flex flex-wrap gap-6 text-lg text-muted-foreground mb-6">
<div className="flex items-center gap-2">
<Calendar className="w-5 h-5" />
<span>{formatDate(event.event_date)}</span>
<span>{formatDate(event.eventDate)}</span>
</div>
<div className="flex items-center gap-2">
<Clock className="w-5 h-5" />
<span>{formatTime(event.event_date)}</span>
<span>{formatTime(event.eventDate)}</span>
</div>
</div>
</div>

{/* Event Image */}
{event.image_url && (
{event.imageUrl && (
<div className="mb-8">
<div className="w-full overflow-hidden rounded-lg shadow-lg">
{/* eslint-disable-next-line @next/next/no-img-element */}
<img
src={event.image_url || "/placeholder.svg"}
alt={event.title}
src={event.imageUrl || "/placeholder.svg"}
alt={event.eventTitle}
className="w-full h-auto object-contain max-h-[600px]"
/>
</div>
Expand All @@ -113,7 +113,7 @@ export default function EventDetail({ event }: EventDetailProps) {
About This Event
</h2>
<div className="prose prose-lg max-w-none text-muted-foreground">
<MarkdownRenderer content={event.content} />
<MarkdownRenderer content={event.eventDesc} />
</div>
</CardContent>
</Card>
Expand All @@ -124,15 +124,15 @@ export default function EventDetail({ event }: EventDetailProps) {
<div className="grid grid-cols-1 md:grid-cols-2 gap-4 text-sm text-muted-foreground">
<div>
<span className="font-medium">Created:</span>{" "}
{new Date(event.created_at).toLocaleDateString("en-US", {
{new Date(event.createdAt).toLocaleDateString("en-US", {
year: "numeric",
month: "long",
day: "numeric",
})}
</div>
<div>
<span className="font-medium">Last Updated:</span>{" "}
{new Date(event.updated_at).toLocaleDateString("en-US", {
{new Date(event.updatedAt).toLocaleDateString("en-US", {
year: "numeric",
month: "long",
day: "numeric",
Expand Down
32 changes: 22 additions & 10 deletions src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type { NextRequest } from "next/server";
import { Ratelimit } from "@upstash/ratelimit";
import { Redis } from "@upstash/redis";
import { StandardResponse } from "./lib/types";
import { headers } from "next/headers";

const redis = new Redis({
url: process.env.KV_REST_API_URL,
Expand All @@ -22,19 +23,24 @@ const resetPasswordRatelimiter = new Ratelimit({
analytics: true,
});

const ALLOWED_ORIGIN =
process.env.NODE_ENV === "development"
? "http://localhost:3000"
: "https://re-envision.org";
const getHostName = async () => {
const headersList = await headers();
return headersList.get("host");
};

export async function middleware(request: NextRequest) {
const { pathname } = request.nextUrl;

const allowedOrigin =
process.env.NODE_ENV === "development"
? "http://localhost:3000"
: (await getHostName()) || "";

if (request.method === "OPTIONS" && pathname.startsWith("/api")) {
return new NextResponse(null, {
status: 204,
headers: {
"Access-Control-Allow-Origin": ALLOWED_ORIGIN,
"Access-Control-Allow-Origin": allowedOrigin,
"Access-Control-Allow-Methods": "POST, GET, OPTIONS",
"Access-Control-Allow-Headers": "Content-Type",
},
Expand All @@ -45,6 +51,7 @@ export async function middleware(request: NextRequest) {
const rateLimitResponse = await handleRateLimit(
request,
resetPasswordRatelimiter,
allowedOrigin,
);

if (rateLimitResponse) {
Expand All @@ -62,13 +69,17 @@ export async function middleware(request: NextRequest) {
status: 500,
headers: {
"Content-Type": "application/json",
"Access-Control-Allow-Origin": ALLOWED_ORIGIN,
"Access-Control-Allow-Origin": allowedOrigin,
"Access-Control-Allow-Methods": "POST, GET, OPTIONS",
"Access-Control-Allow-Headers": "Content-Type",
},
});
} else if (pathname.startsWith("/api")) {
const rateLimitResponse = await handleRateLimit(request, ratelimit);
const rateLimitResponse = await handleRateLimit(
request,
ratelimit,
allowedOrigin,
);

if (rateLimitResponse) {
return rateLimitResponse;
Expand All @@ -85,7 +96,7 @@ export async function middleware(request: NextRequest) {
status: 500,
headers: {
"Content-Type": "application/json",
"Access-Control-Allow-Origin": ALLOWED_ORIGIN,
"Access-Control-Allow-Origin": allowedOrigin,
"Access-Control-Allow-Methods": "POST, GET, OPTIONS",
"Access-Control-Allow-Headers": "Content-Type",
},
Expand All @@ -102,6 +113,7 @@ export const config = {
const handleRateLimit = async (
request: NextRequest,
ratelimiter: Ratelimit,
allowedOrigin: string,
): Promise<NextResponse> => {
const ip =
request.headers.get("x-real-ip") ??
Expand All @@ -119,7 +131,7 @@ const handleRateLimit = async (
status: 429,
headers: {
"Content-Type": "application/json",
"Access-Control-Allow-Origin": ALLOWED_ORIGIN,
"Access-Control-Allow-Origin": allowedOrigin,
"Access-Control-Allow-Methods": "POST, GET, OPTIONS",
"Access-Control-Allow-Headers": "Content-Type",
"Retry-After": reset
Expand All @@ -132,7 +144,7 @@ const handleRateLimit = async (

const response = NextResponse.next();

response.headers.set("Access-Control-Allow-Origin", ALLOWED_ORIGIN);
response.headers.set("Access-Control-Allow-Origin", allowedOrigin);
response.headers.set("Access-Control-Allow-Methods", "POST, GET, OPTIONS");
response.headers.set("Access-Control-Allow-Headers", "Content-Type");

Expand Down