-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
677 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
'use server'; | ||
import { cookies } from 'next/headers'; | ||
|
||
export type Proposal = { | ||
id: number; | ||
proposal: string; | ||
id_user: number; | ||
created_at: string; | ||
user: { | ||
first_name: string; | ||
last_name: string; | ||
} | null; | ||
}; | ||
|
||
export async function getAllProposals(): Promise<{ data: Proposal[]; count: number }> { | ||
const API_URL = process.env.ATHLONIX_API_URL; | ||
const token = cookies().get('access_token')?.value; | ||
if (!token || !API_URL) { | ||
return { data: [], count: 0 }; | ||
} | ||
const response = await fetch(`${API_URL}/proposals`, { | ||
headers: { | ||
Authorization: `Bearer ${token}`, | ||
}, | ||
}); | ||
if (!response.ok) { | ||
throw new Error('Failed to get proposals'); | ||
} | ||
return await response.json(); | ||
} | ||
|
||
export async function deleteProposal(id: number): Promise<void> { | ||
const API_URL = process.env.ATHLONIX_API_URL; | ||
const token = cookies().get('access_token')?.value; | ||
if (!token || !API_URL) { | ||
throw new Error('Missing data'); | ||
} | ||
const response = await fetch(`${API_URL}/proposals/${id}`, { | ||
method: 'DELETE', | ||
headers: { | ||
Authorization: `Bearer ${token}`, | ||
}, | ||
}); | ||
if (!response.ok) { | ||
throw new Error('Failed to delete proposal'); | ||
} | ||
} |
105 changes: 105 additions & 0 deletions
105
apps/admin/app/(dashboard)/dashboard/proposals/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
'use client'; | ||
import { Button } from '@repo/ui/components/ui/button'; | ||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@repo/ui/components/ui/card'; | ||
import { | ||
Dialog, | ||
DialogContent, | ||
DialogDescription, | ||
DialogHeader, | ||
DialogTitle, | ||
DialogTrigger, | ||
} from '@repo/ui/components/ui/dialog'; | ||
import { ScrollArea } from '@repo/ui/components/ui/scroll-area'; | ||
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '@repo/ui/components/ui/table'; | ||
import { toast } from '@ui/components/ui/sonner'; | ||
import { useEffect, useState } from 'react'; | ||
import { type Proposal, deleteProposal, getAllProposals } from './actions'; | ||
|
||
export default function AdminIdeasPage() { | ||
const [ideas, setIdeas] = useState<Proposal[]>([]); | ||
|
||
useEffect(() => { | ||
async function fetchIdeas() { | ||
const ideas = await getAllProposals(); | ||
setIdeas(ideas.data); | ||
} | ||
|
||
fetchIdeas(); | ||
}, []); | ||
|
||
const handleDelete = async (id: number) => { | ||
try { | ||
await deleteProposal(id); | ||
setIdeas(ideas.filter((idea) => idea.id !== id)); | ||
toast.success("L'idée a été supprimée avec succès."); | ||
} catch (_error) { | ||
toast.error("Une erreur s'est produite lors de la suppression de l'idée."); | ||
} | ||
}; | ||
|
||
if (ideas.length === 0 || !ideas) { | ||
return ( | ||
<div className="container mx-auto p-4"> | ||
<Card> | ||
<CardHeader> | ||
<CardTitle>Boite à idées</CardTitle> | ||
<CardDescription>Gérez les idées soumises par les membres.</CardDescription> | ||
</CardHeader> | ||
<CardContent> | ||
<p>Aucune idée n'a été soumise pour le moment.</p> | ||
</CardContent> | ||
</Card> | ||
</div> | ||
); | ||
} | ||
|
||
return ( | ||
<div className="container mx-auto p-4"> | ||
<Card> | ||
<CardHeader> | ||
<CardTitle>Boite à idées</CardTitle> | ||
<CardDescription>Gérez les idées soumises par les membres.</CardDescription> | ||
</CardHeader> | ||
<CardContent> | ||
<ScrollArea className="h-[600px]"> | ||
<Table> | ||
<TableHeader> | ||
<TableRow> | ||
<TableHead>Proposition</TableHead> | ||
<TableHead>Actions</TableHead> | ||
</TableRow> | ||
</TableHeader> | ||
<TableBody> | ||
{ideas.map((idea) => ( | ||
<TableRow key={idea.id}> | ||
<TableCell className="max-w-md">{idea.proposal}</TableCell> | ||
<TableCell> | ||
<div className="flex space-x-2"> | ||
<Dialog> | ||
<DialogTrigger asChild> | ||
<Button variant="outline">Voir</Button> | ||
</DialogTrigger> | ||
<DialogContent> | ||
<DialogHeader> | ||
<DialogTitle>Détails de la proposition</DialogTitle> | ||
<DialogDescription> | ||
{idea.proposal.length > 50 ? `${idea.proposal.slice(0, 50)}...` : idea.proposal} | ||
</DialogDescription> | ||
</DialogHeader> | ||
</DialogContent> | ||
</Dialog> | ||
<Button onClick={() => handleDelete(idea.id)} variant="destructive"> | ||
Supprimer | ||
</Button> | ||
</div> | ||
</TableCell> | ||
</TableRow> | ||
))} | ||
</TableBody> | ||
</Table> | ||
</ScrollArea> | ||
</CardContent> | ||
</Card> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.