Skip to content

Commit

Permalink
Merge branch 'main' into feat/blog
Browse files Browse the repository at this point in the history
  • Loading branch information
Metololo committed Jul 21, 2024
2 parents 9c7aece + 2f9004a commit cb2498a
Show file tree
Hide file tree
Showing 18 changed files with 677 additions and 58 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ NEXT_PUBLIC_API_URL=
STRIPE_API_KEY=sk_test_xxx
STRIPE_WEBHOOK_SECRET=whsec_xxx
RESEND_KEY=re_xxx
ENABLE_EMAILS='false'
ENABLE_EMAILS=false
12 changes: 9 additions & 3 deletions apps/admin/app/(dashboard)/dashboard/documents/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,19 @@ function AddFileDialog({
type="text"
name="name"
required
placeholder="Nom du fichier"
defaultValue={editFile ? editFile.name : ''}
readOnly={!!editFile}
/>
</div>
<div>
<Label htmlFor="description">Description</Label>
<Textarea id="description" name="description" defaultValue={editFile ? editFile.description : ''} />
<Textarea
id="description"
name="description"
defaultValue={editFile ? editFile.description : ''}
placeholder="Description du fichier"
/>
</div>
<div className="flex items-center space-x-2">
<Label
Expand Down Expand Up @@ -181,7 +187,7 @@ function AddFolderDialog({
<div className="grid gap-4 py-4">
<div>
<Label htmlFor="foldername">Nom</Label>
<Input id="foldername" type="text" name="name" required />
<Input id="foldername" type="text" name="name" required placeholder="Nom du dossier" />
</div>
<div className="flex items-center space-x-2">
<Label
Expand All @@ -194,7 +200,7 @@ function AddFolderDialog({
</div>
</div>
<DialogFooter>
<Button type="submit" disabled={isUploading}>
<Button type="submit" disabled={isUploading} onClick={() => setOpen(false)}>
Enregistrer
</Button>
</DialogFooter>
Expand Down
47 changes: 47 additions & 0 deletions apps/admin/app/(dashboard)/dashboard/proposals/actions.ts
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 apps/admin/app/(dashboard)/dashboard/proposals/page.tsx
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>
);
}
24 changes: 21 additions & 3 deletions apps/admin/app/(dashboard)/dashboard/sports/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export default function SportsPage(): JSX.Element {
<h1 className="text-xl font-bold">Sports</h1>
<Dialog open={open} onOpenChange={setOpen}>
<DialogTrigger asChild>
<Button>Ajouter un sport</Button>
<Button onClick={() => setEditSport(null)}>Ajouter un sport</Button>
</DialogTrigger>
<DialogContent className="sm:max-w-md">
<DialogHeader>
Expand All @@ -82,13 +82,21 @@ export default function SportsPage(): JSX.Element {
<div className="grid gap-4 py-4">
<div>
<Label htmlFor="name">Nom</Label>
<Input id="name" type="text" name="name" required defaultValue={editSport ? editSport.name : ''} />
<Input
id="name"
type="text"
name="name"
required
defaultValue={editSport ? editSport.name : ''}
placeholder="Nom du sport"
/>
</div>
<div>
<Label htmlFor="description">Description</Label>
<Textarea
id="description"
name="description"
placeholder="Description du sport"
defaultValue={editSport?.description ? editSport.description : ''}
/>
</div>
Expand All @@ -98,6 +106,8 @@ export default function SportsPage(): JSX.Element {
id="min_players"
type="number"
name="min_players"
placeholder="0"
min="0"
required
defaultValue={editSport ? Number(editSport.min_players) : ''}
/>
Expand All @@ -108,12 +118,20 @@ export default function SportsPage(): JSX.Element {
id="max_players"
type="number"
name="max_players"
placeholder="10"
min="1"
defaultValue={editSport?.max_players ? Number(editSport.max_players) : ''}
/>
</div>
<div>
<Label htmlFor="image">Image</Label>
<Input id="image" type="text" name="image" defaultValue={editSport?.image ? editSport.image : ''} />
<Input
id="image"
type="text"
name="image"
defaultValue={editSport?.image ? editSport.image : ''}
placeholder='URL de l"image'
/>
</div>
</div>
<DialogFooter>
Expand Down
8 changes: 8 additions & 0 deletions apps/admin/app/(dashboard)/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
LandPlot,
Landmark,
Newspaper,
PackageOpen,
PencilRuler,
Trophy,
Users,
Expand Down Expand Up @@ -139,6 +140,13 @@ export default function RootLayout({
<PencilRuler className="h-4 w-4" />
Matériaux & Fournitures
</Link>
<Link
href="/dashboard/proposals"
className="flex items-center gap-3 rounded-lg px-3 py-2 text-muted-foreground transition-all hover:text-primary"
>
<PackageOpen className="h-4 w-4" />
Boite à idées
</Link>
</nav>
</div>
</div>
Expand Down
6 changes: 5 additions & 1 deletion apps/admin/app/ui/dashboard/votes/AddPoll.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,11 @@ function AddPoll({ polls, setPolls, assemblies }: Props) {
</Button>
</div>
<div className="flex gap-4 mt-4">
<Button type="submit" className="w-full">
<Button
type="submit"
className="w-full"
disabled={form.formState.isSubmitting || !form.formState.isValid}
>
Créer
</Button>
<Button variant="secondary" type="button" onClick={() => setOpen(false)} className="w-full">
Expand Down
7 changes: 6 additions & 1 deletion apps/admin/app/ui/dashboard/votes/EditPoll.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ function EditPoll({ poll, setter, assemblies }: Props) {
setter.title(data.title);
setter.description(data.description);
setter.maxChoices(data.max_choices);
setOpen(false);
toast.success('Succès', { duration: 2000, description: 'Le vote a été modifié avec succès' });
})
.catch((error: Error) => {
Expand Down Expand Up @@ -190,7 +191,11 @@ function EditPoll({ poll, setter, assemblies }: Props) {
/>
</div>
<div className="flex gap-4 mt-4">
<Button type="submit" className="w-full">
<Button
type="submit"
className="w-full"
disabled={form.formState.isSubmitting || !form.formState.isValid}
>
Modifier
</Button>
<Button variant="secondary" type="button" className="w-full">
Expand Down
Loading

0 comments on commit cb2498a

Please sign in to comment.