Skip to content

Commit

Permalink
Fix build errors
Browse files Browse the repository at this point in the history
  • Loading branch information
RubenOlano committed Nov 21, 2024
1 parent 17da572 commit adde50c
Show file tree
Hide file tree
Showing 21 changed files with 101 additions and 64 deletions.
5 changes: 3 additions & 2 deletions src/app/admin/clubs/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import { db } from '@src/server/db';
import { eq } from 'drizzle-orm';
import { notFound } from 'next/navigation';

type Props = { params: { id: string } };
type PageProps = { searchParams: Promise<{ id: string }> };

export default async function Page({ params: { id } }: Props) {
export default async function Page({ searchParams }: PageProps) {
const { id } = await searchParams;
const org = await db.query.club.findFirst({
where: (club) => eq(club.id, id),
});
Expand Down
9 changes: 5 additions & 4 deletions src/app/directory/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ import { eq } from 'drizzle-orm';
import { type Metadata } from 'next';
import NotFound from '@src/components/NotFound';

const ClubPage = async ({ params }: { params: { id: string } }) => {
const club = await api.club.getDirectoryInfo({ id: params.id });
const ClubPage = async ({ params }: { params: Promise<{ id: string }> }) => {
const { id } = await params;
const club = await api.club.getDirectoryInfo({ id });
if (!club) return <NotFound elementType="Club" />;

return (
Expand All @@ -29,9 +30,9 @@ export default ClubPage;
export async function generateMetadata({
params,
}: {
params: { id: string };
params: Promise<{ id: string }>;
}): Promise<Metadata> {
const id = params.id;
const { id } = await params;

const found = await db.query.club.findFirst({
where: (club) => eq(club.id, id),
Expand Down
5 changes: 4 additions & 1 deletion src/app/directory/create/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ import { signInRoute } from '@src/utils/redirect';

export default async function Page() {
const session = await getServerAuthSession();
if (!session) redirect(signInRoute('directory/create'));
if (!session) {
const route = await signInRoute('directory/create');
redirect(route);
}
return (
<main>
<div className="md:pl-72">
Expand Down
9 changes: 5 additions & 4 deletions src/app/event/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ import Link from 'next/link';
import { getServerAuthSession } from '@src/server/auth';
import RegisterButton from '@src/app/event/[id]/RegisterButton';

type Params = { params: { id: string } };
type Params = { params: Promise<{ id: string }> };

export default async function EventsPage({ params }: Params) {
const { id } = await params;
const session = await getServerAuthSession();
const res = await db.query.events.findFirst({
where: (events) => eq(events.id, params.id),
where: (events) => eq(events.id, id),
with: { club: true },
});

Expand Down Expand Up @@ -114,9 +115,9 @@ export default async function EventsPage({ params }: Params) {
export async function generateMetadata({
params,
}: {
params: { id: string };
params: Promise<{ id: string }>;
}): Promise<Metadata> {
const id = params.id;
const { id } = await params;

const found = await db.query.events.findFirst({
where: (events) => eq(events.id, id),
Expand Down
15 changes: 9 additions & 6 deletions src/app/events/eventView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,20 @@ type Props = {
};

const EventView = ({ children, searchParams }: Props) => {

return (
<main className="w-full px-6">
<div className="flex flex-col pt-4 md:flex-row md:items-end md:pb-12 md:pr-7.5">
<h1 className="h-min align-middle text-2xl font-bold text-[#4D5E80]"
id="events-heading">
<h1
className="h-min align-middle text-2xl font-bold text-[#4D5E80]"
id="events-heading"
>
Events
</h1>
<nav className="relative z-0 mt-2.5 flex flex-row justify-center gap-x-16 md:ml-auto md:mt-0"
aria-label="Event date filter">
<DateBrowser filterState={searchParams}/>
<nav
className="relative z-0 mt-2.5 flex flex-row justify-center gap-x-16 md:ml-auto md:mt-0"
aria-label="Event date filter"
>
<DateBrowser filterState={searchParams} />
</nav>
</div>

Expand Down
12 changes: 8 additions & 4 deletions src/app/events/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,20 @@ export const metadata: Metadata = {
description: 'Get connected on campus.',
},
};
const Events = async ({ searchParams: paramsPromise }: { searchParams: Promise<(typeof eventParamsSchema)['_input']> }) => {
const searchParams = await paramsPromise
const Events = async ({
searchParams: paramsPromise,
}: {
searchParams: Promise<(typeof eventParamsSchema)['_input']>;
}) => {
const searchParams = await paramsPromise;
const parsed = eventParamsSchema.parse(searchParams);
const { events } = await api.event.findByDate({ date: parsed.date });
return (
<main className="pb-10 md:pl-72">
<EventHeader />
<EventView searchParams={parsed}>
{ events.length === 0 && <div>No events found for this date</div>}
{ events.map((event) => {
{events.length === 0 && <div>No events found for this date</div>}
{events.map((event) => {
return <EventCard key={event.id} event={event} />;
})}
</EventView>
Expand Down
5 changes: 3 additions & 2 deletions src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,16 @@ export const viewport = {
themeColor: '#573DFF',
};

export default function RootLayout({
export default async function RootLayout({
children,
}: {
children: React.ReactNode;
}) {
const headersList = await headers();
return (
<html lang="en">
<body className={`font-sans ${inter.variable}`}>
<TRPCReactProvider headers={headers()}>
<TRPCReactProvider headers={headersList}>
<Sidebar />
<div className="max-h-screen overflow-y-scroll">{children}</div>
</TRPCReactProvider>
Expand Down
14 changes: 7 additions & 7 deletions src/app/loading.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,32 @@ export default function Loading() {
<main className="md:pl-72">
<div className="px-2 md:px-5">
{/* Carousel skeleton */}
<div className="relative block w-full mb-8">
<div className="w-full h-[300px] rounded-xl animate-pulse bg-gray-200" />
<div className="relative mb-8 block w-full">
<div className="h-[300px] w-full animate-pulse rounded-xl bg-gray-200" />
</div>

{/* Tag filter skeleton */}
<div className="mb-8">
<div className="flex gap-2 flex-wrap">
<div className="flex flex-wrap gap-2">
{Array.from({ length: 6 }).map((_, i) => (
<div
key={i}
className="h-8 w-24 rounded-full animate-pulse bg-gray-200"
className="h-8 w-24 animate-pulse rounded-full bg-gray-200"
/>
))}
</div>
</div>

{/* Club grid skeleton */}
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4">
<div className="grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-3">
{Array.from({ length: 6 }).map((_, i) => (
<div
key={i}
className="h-[280px] rounded-xl animate-pulse bg-gray-200"
className="h-[280px] animate-pulse rounded-xl bg-gray-200"
/>
))}
</div>
</div>
</main>
);
}
}
5 changes: 4 additions & 1 deletion src/app/manage/[clubId]/(dashboard)/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ const Layout = async ({
events: ReactNode;
}) => {
const session = await getServerAuthSession();
if (!session) redirect(signInRoute(`manage/${params.clubId}`));
if (!session) {
const route = await signInRoute(`manage/${params.clubId}`);
redirect(route);
}
const canAccess = await api.club.isOfficer({ id: params.clubId });
if (!canAccess) {
return <div className="md:pl-72">You can&apos;t access this 😢</div>;
Expand Down
8 changes: 5 additions & 3 deletions src/app/manage/[clubId]/create/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@ import { signInRoute } from '@src/utils/redirect';
import { redirect, notFound } from 'next/navigation';
import CreateEventForm from './CreateEventForm';

const Page = async ({ params }: { params: { clubId: string } }) => {
const Page = async ({ params }: { params: Promise<{ clubId: string }> }) => {
const session = await getServerAuthSession();
const { clubId } = await params;
if (!session) {
redirect(signInRoute(`manage/${params.clubId}/create`));
const route = await signInRoute(`manage/${clubId}/create`);
redirect(route);
}

const officerClubs = await api.club.getOfficerClubs();
const currentClub = officerClubs.filter((val) => {
return val.id == params.clubId;
return val.id == clubId;
})[0];
if (!currentClub) {
notFound();
Expand Down
10 changes: 7 additions & 3 deletions src/app/manage/[clubId]/edit/officers/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,16 @@ import { signInRoute } from '@src/utils/redirect';
import EditListedOfficerForm from './EditListedOfficerForm';

export default async function Page({
params: { clubId },
params,
}: {
params: { clubId: string };
params: Promise<{ clubId: string }>;
}) {
const { clubId } = await params;
const session = await getServerAuthSession();
if (!session) redirect(signInRoute(`manage/${clubId}/edit/officers`));
if (!session) {
const route = await signInRoute(`manage/${clubId}/edit/officers`);
redirect(route);
}
const role = await api.club.memberType({ id: clubId });
const officers = await api.club.getOfficers({ id: clubId });
const listedOfficers = await api.club.getListedOfficers({ id: clubId });
Expand Down
5 changes: 3 additions & 2 deletions src/app/manage/[clubId]/edit/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ import EditContactForm from './EditContactForm';
import { BlueBackButton } from '@src/components/backButton';

export default async function Page({
params: { clubId },
params,
}: {
params: { clubId: string };
params: Promise<{ clubId: string }>;
}) {
const { clubId } = await params;
const club = await api.club.byId({ id: clubId });
if (!club) notFound();
return (
Expand Down
3 changes: 2 additions & 1 deletion src/app/manage/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import { signInRoute } from '@src/utils/redirect';
export default async function Page() {
const session = await getServerAuthSession();
if (!session) {
redirect(signInRoute('manage'));
const route = await signInRoute('manage');
redirect(route);
}
const clubs = await api.club.getOfficerClubs();
return (
Expand Down
4 changes: 2 additions & 2 deletions src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ export const metadata: Metadata = {
};

type Props = {
searchParams: Promise<{ [key: string]: string | undefined }>
searchParams: Promise<{ [key: string]: string | undefined }>;
};

const Home = async ({ searchParams }: Props) => {
const params = await searchParams;
void api.club.all.prefetch({ tag: params.tag});
void api.club.all.prefetch({ tag: params.tag });
const [tags, featured, session] = await Promise.all([
api.club.distinctTags(),
api.club.getCarousel(),
Expand Down
3 changes: 2 additions & 1 deletion src/app/settings/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ const Settings = async () => {
const session = await getServerAuthSession();

if (!session) {
redirect(signInRoute('settings'));
const route = await signInRoute('settings');
redirect(route);
}

return (
Expand Down
12 changes: 7 additions & 5 deletions src/components/club/directory/ClubDirectoryGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default function ClubDirectoryGrid({ session }: Props) {

const { data, refetch } = api.club.all.useQuery(
{ tag: tag ?? undefined },
{ staleTime: 1000 * 60 * 5 }
{ staleTime: 1000 * 60 * 5 },
);

useEffect(() => {
Expand All @@ -26,7 +26,7 @@ export default function ClubDirectoryGrid({ session }: Props) {
if (!data) return <ClubDirectoryGridSkeleton />;

return (
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4">
<div className="grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-3">
{data?.clubs.map((club) => (
<ClubCard key={club.id} club={club} session={session} priority />
))}
Expand All @@ -35,9 +35,11 @@ export default function ClubDirectoryGrid({ session }: Props) {
}

function ClubDirectoryGridSkeleton() {
return <div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4">
{Array.from({ length: 12 }).map((_, index) => (
<ClubCardSkeleton key={index} />
return (
<div className="grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-3">
{Array.from({ length: 12 }).map((_, index) => (
<ClubCardSkeleton key={index} />
))}
</div>
);
}
3 changes: 1 addition & 2 deletions src/components/club/directory/TagFilter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ const scrollAmount = 300;
type Props = {
tags: string[];
selectedTag?: string;
}
};

const TagFilter = ({ tags, selectedTag }: Props) => {

const scrollContainerRef = useRef<HTMLDivElement>(null);

const handleScrollLeft = () => {
Expand Down
20 changes: 12 additions & 8 deletions src/components/events/DateBrowser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,14 @@ const DATE_FORMAT = 'MM/dd/yyyy';

const DateBrowser = ({ filterState }: DateBrowserProps) => {
const inputId = useId();
const [month, setMonth] = useState<Date>(() => filterState.date ?? new Date());
const [selectedDate, setSelectedDate] = useState<Date | undefined>(filterState.date);
const [month, setMonth] = useState<Date>(
() => filterState.date ?? new Date(),
);
const [selectedDate, setSelectedDate] = useState<Date | undefined>(
filterState.date,
);
const [inputValue, setInputValue] = useState(() =>
filterState.date ? format(filterState.date, DATE_FORMAT) : ''
filterState.date ? format(filterState.date, DATE_FORMAT) : '',
);
const router = useRouter();

Expand All @@ -51,15 +55,16 @@ const DateBrowser = ({ filterState }: DateBrowserProps) => {

const handleNavigateDate = (direction: 'forward' | 'back') => {
const baseDate = selectedDate ?? new Date();
const newDate = direction === 'forward'
? addDays(baseDate, 1)
: subDays(baseDate, 1);
const newDate =
direction === 'forward' ? addDays(baseDate, 1) : subDays(baseDate, 1);
handleDateChange(newDate);
};

useEffect(() => {
if (!selectedDate) return;
router.push(`/events?date=${encodeURIComponent(selectedDate.toISOString())}`);
router.push(
`/events?date=${encodeURIComponent(selectedDate.toISOString())}`,
);
}, [selectedDate, router]);

return (
Expand Down Expand Up @@ -105,7 +110,6 @@ const DateBrowser = ({ filterState }: DateBrowserProps) => {
mode="single"
className="rounded-md border p-2"
/>

</div>
</PopoverContent>
</PopoverPortal>
Expand Down
6 changes: 5 additions & 1 deletion src/server/api/routers/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,11 @@ export const eventRouter = createTRPCRouter({
.insert(events)
.values({ ...input })
.returning({ id: events.id });
if (res.length == 0) throw 'Failed to add event';
if (res.length == 0)
throw new TRPCError({
code: 'INTERNAL_SERVER_ERROR',
message: 'Failed to add event',
});
return res[0]?.id;
}),
byName: publicProcedure.input(byNameSchema).query(async ({ input, ctx }) => {
Expand Down
Loading

0 comments on commit adde50c

Please sign in to comment.