-
-
Notifications
You must be signed in to change notification settings - Fork 2
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
986 additions
and
33 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
58 changes: 58 additions & 0 deletions
58
src/app/[locale]/(main)/community/[communityId]/admin/page.client.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,58 @@ | ||
'use client' | ||
import { Community } from '@/utils/types/models' | ||
import { TabsContent } from '@/components/ui/tabs' | ||
import CommunityAdminMain from '@/components/community/admin/main' | ||
import MyCommunities from '@/components/community/myCommunities' | ||
import { functions } from '@/app/appwrite-client' | ||
import { ExecutionMethod } from 'node-appwrite' | ||
import { useEffect, useState } from 'react' | ||
import NoAccess from '@/components/static/noAccess' | ||
import { hasAdminPanelAccess } from '@/utils/actions/community/checkRoles' | ||
import { toast } from 'sonner' | ||
|
||
export default function PageClient({ | ||
community, | ||
}: { | ||
community: Community.CommunityDocumentsType | ||
}) { | ||
const [hasPermission, setHasPermission] = useState(false) | ||
const [isLoading, setIsLoading] = useState(true) | ||
|
||
const getOwnerStatus = async () => { | ||
const data = await functions.createExecution( | ||
'community-endpoints', | ||
'', | ||
false, | ||
`/community/isFollowing?communityId=${community.$id}`, | ||
ExecutionMethod.GET | ||
) | ||
|
||
const response = JSON.parse(data.responseBody) | ||
|
||
if (response.code === 500) { | ||
toast.error('Error fetching community data. Please try again later.') | ||
} | ||
|
||
setHasPermission(await hasAdminPanelAccess(response.roles)) | ||
} | ||
|
||
useEffect(() => { | ||
getOwnerStatus().then(() => setIsLoading(false)) | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [community]) | ||
|
||
if (!isLoading && !hasPermission) { | ||
return <NoAccess /> | ||
} | ||
|
||
return ( | ||
<> | ||
<TabsContent value="general"> | ||
<CommunityAdminMain community={community} /> | ||
</TabsContent> | ||
<TabsContent value="settings"> | ||
<MyCommunities /> | ||
</TabsContent> | ||
</> | ||
) | ||
} |
54 changes: 54 additions & 0 deletions
54
src/app/[locale]/(main)/community/[communityId]/admin/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,54 @@ | ||
import PageLayout from '@/components/pageLayout' | ||
import { getCommunity } from '@/utils/server-api/communities/getCommunity' | ||
import { notFound } from 'next/navigation' | ||
import { Tabs, TabsList, TabsTrigger } from '@/components/ui/tabs' | ||
import PageClient from './page.client' | ||
|
||
export const runtime = 'edge' | ||
|
||
export async function generateMetadata({ | ||
params: { communityId }, | ||
}: { | ||
params: { communityId: string } | ||
}) { | ||
const community = await getCommunity(communityId) | ||
|
||
if (!community.$id) { | ||
return notFound() | ||
} | ||
|
||
return { | ||
title: community?.name || 'Community Admin', | ||
description: community?.description, | ||
icons: { | ||
icon: '/logos/Headpat_Logo_web_1024x1024_240518-02.png', | ||
}, | ||
openGraph: { | ||
title: community?.name || 'Community Admin', | ||
description: community?.description, | ||
images: '/logos/Headpat_Logo_web_1024x1024_240518-02.png', | ||
}, | ||
} | ||
} | ||
|
||
export default async function Page({ | ||
params: { communityId }, | ||
}: { | ||
params: { communityId: string } | ||
}) { | ||
const community = await getCommunity(communityId) | ||
|
||
return ( | ||
<PageLayout title={`${community.name} Admin`}> | ||
<Tabs defaultValue="general" className="w-full"> | ||
<div className="flex flex-col items-center justify-center"> | ||
<TabsList className="grid w-full sm:max-w-4xl grid-cols-2"> | ||
<TabsTrigger value="general">General</TabsTrigger> | ||
<TabsTrigger value="settings">Settings</TabsTrigger> | ||
</TabsList> | ||
</div> | ||
<PageClient community={community} /> | ||
</Tabs> | ||
</PageLayout> | ||
) | ||
} |
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
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.