Skip to content

Commit

Permalink
+ manage posts permission
Browse files Browse the repository at this point in the history
  • Loading branch information
Arakasi21 committed Jun 13, 2024
1 parent de4483f commit 2d12ed6
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 25 deletions.
50 changes: 32 additions & 18 deletions src/app/clubs/[clubID]/posts/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@ import { DialogCreatePost } from '@/components/clubs/posts/DialogCreatePost'
import PostItem from '@/app/clubs/[clubID]/posts/_components/PostItem'
import Link from 'next/link'
import { Button } from '@/components/ui/button'
import useUserRolesStore from '@/store/useUserRoles'
import { hasPermission } from '@/helpers/permissions'
import { Permissions } from '@/types/permissions'

function Page({ params }: { params: { clubID: number } }) {
const axiosAuth = useAxiosInterceptor()
const { user } = useUserStore()
const { permissions } = useUserRolesStore()

const [posts, setPosts] = useState<Post[]>([])
const [loading, setLoading] = useState(true)
Expand Down Expand Up @@ -109,29 +113,39 @@ function Page({ params }: { params: { clubID: number } }) {
</div>
<div className="flex flex-row gap-3">
<div className="flex gap-3">
{club && <DialogCreatePost club={club} onCreateSuccess={fetchClubPosts} />}
{hasPermission(permissions, Permissions.manage_posts) ? (
club && <DialogCreatePost club={club} onCreateSuccess={fetchClubPosts} />
) : (
<Button size="sm" variant="secondary" disabled>
Create Post
</Button>
)}
</div>
</div>
</div>
</CardHeader>
<CardContent>
<div className="grid gap-6">
{posts.length === 0 ? (
<div>No posts available.</div>
) : (
posts
?.slice()
.reverse()
.map((post) => (
<PostItem
post={post}
key={post.id}
onUpdate={onUpdate}
onDelete={handleDeletePost}
/>
))
)}
</div>
{hasPermission(permissions, Permissions.manage_posts) ? (
<div className="grid gap-6">
{posts.length === 0 ? (
<div>No posts available.</div>
) : (
posts
?.slice()
.reverse()
.map((post) => (
<PostItem
post={post}
key={post.id}
onUpdate={onUpdate}
onDelete={handleDeletePost}
/>
))
)}
</div>
) : (
<p>no access</p>
)}
</CardContent>
</Card>
</div>
Expand Down
17 changes: 10 additions & 7 deletions src/components/clubs/ClubPageButtons.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { Permissions } from '@/types/permissions'
import { hasPermission } from '@/helpers/permissions'
import Link from 'next/link'
import { Button } from '@/components/ui/button'
import React from 'react'
import { Club } from '@/types/club'
import { hasPermission } from '@/helpers/permissions'
import { Permissions } from '@/types/permissions'
import useUserRolesStore from '@/store/useUserRoles'

export default function ClubPageButtons(props: {
memberPerms: Permissions
Expand All @@ -29,13 +30,15 @@ export default function ClubPageButtons(props: {
Settings
</Button>
</Link>
<Link href={`/clubs/${props.club?.id}/posts`}>
<Button className="bg-blue-200 text-gray-900 hover:bg-blue-200/70 dark:bg-[#ffffff] dark:hover:bg-[#ffffff]/90">
Posts
</Button>
</Link>
</div>
)}
{hasPermission(props.memberPerms, Permissions.manage_posts) && (
<Link href={`/clubs/${props.club?.id}/posts`}>
<Button className="bg-blue-200 text-gray-900 hover:bg-blue-200/70 dark:bg-[#ffffff] dark:hover:bg-[#ffffff]/90">
Posts
</Button>
</Link>
)}
<div>
{props.memberStatus === 'NOT_MEMBER' && (
<Button
Expand Down

0 comments on commit 2d12ed6

Please sign in to comment.