Skip to content

Commit

Permalink
feat: new page to show past-event detail (#199)
Browse files Browse the repository at this point in the history
* feat: new page to show past-event detail

* fix: missing import header

* fix: update stats naming
  • Loading branch information
ghaniswara authored Apr 1, 2024
1 parent 92a6057 commit 5273228
Show file tree
Hide file tree
Showing 7 changed files with 517 additions and 41 deletions.
56 changes: 56 additions & 0 deletions app/(pages)/past-events/[eventID]/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { eventService } from '@/(server)/api/_index';
import EventPastDashboard from '@/_features/event/components/event-past-dashboard';
import AppContainer from '@/_shared/components/containers/app-container';
import HTTPError from '@/_shared/components/errors/http-error';
import { AuthType } from '@/_shared/types/auth';
import { headers } from 'next/headers';
import { notFound } from 'next/navigation';

type PageProps = {
params: {
eventID: string;
};
};
export default async function Page({ params: { eventID } }: PageProps) {
const headersList = headers();
const userAuthHeader = headersList.get('user-auth');

const user: AuthType.CurrentAuthData | null =
typeof userAuthHeader === 'string'
? JSON.parse(userAuthHeader)
: userAuthHeader;

if (!user || !user.id) {
return (
<AppContainer user={user}>
<HTTPError
code={401}
title="Login Required"
description="You need to be logged in to access this page"
/>
</AppContainer>
);
}

const event = await eventService.getEventBySlugOrID(eventID, user.id);

if (!event) {
return notFound();
}

const isHost = user.id === event.createdBy;

if (!isHost) {
return (
<AppContainer user={user}>
<HTTPError
code={403}
title="You are not authorized"
description="You don't have permission to access this page. Please use an account which has access to this page."
/>
</AppContainer>
);
}

return <EventPastDashboard event={event} />;
}
2 changes: 1 addition & 1 deletion app/(server)/api/events/[slugOrId]/stat/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export async function GET(
const registeredAttendance =
await eventRepo.getParticipantAttendancePercentage(existingEvent?.id);

const data: EventType.Stat['data'] = {
const data: EventType.GetStatsResponse['data'] = {
count: {
registeree: countRegistirees || 0,

Expand Down
Loading

0 comments on commit 5273228

Please sign in to comment.