Skip to content

Commit

Permalink
change FondApplications to server side
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrir committed Nov 29, 2024
1 parent 7e8d5d1 commit 1676d12
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 13 deletions.
16 changes: 5 additions & 11 deletions components/Submissions/FondApplications.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,16 @@
'use client';
import useSWR from 'swr';
import ErrorPage from '../all/Error';
import ApplicationCard, { SkeletonApplication } from './ApplicationCard';
import { ApplicationType } from '@/lib/types';
import { prisma } from '@/lib/prisma';

const fetcher = (url: string) => fetch(url).then((res) => res.json());

const FondApplications = () => {
const { data, error } = useSWR('/api/admin/application', fetcher);

if (error) return <ErrorPage error="Søknader" />;
const FondApplications = async () => {
const applications = await prisma.application.findMany({});

return (
<section className="flex flex-col gap-4">
<h1 className="mb-4 text-2xl font-semibold">Søknader til fondet</h1>

{data
? data.applications.map((application: ApplicationType) => (
{applications
? applications.map((application: ApplicationType) => (
<ApplicationCard key={application.id} application={application} />
))
: Array.from({ length: 2 }).map((_, index) => (
Expand Down
4 changes: 2 additions & 2 deletions lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ export type MemberType = {
export type ApplicationType = {
id: number;
purpose: string;
description?: string;
description?: string | null;
grantedAmount: number;
amountApplied: number;
recipient: string;
dateApplied: Date;
dateGranted: Date;
attachment: string;
attachment: string | null;
};

export type CompositionType = {
Expand Down

0 comments on commit 1676d12

Please sign in to comment.