feat: add guilds and channels CRUD (#14)
This commit is contained in:
92
pages/application/[guildId]/[channelId]/settings.tsx
Normal file
92
pages/application/[guildId]/[channelId]/settings.tsx
Normal file
@ -0,0 +1,92 @@
|
||||
import { NextPage } from 'next'
|
||||
|
||||
import { Head } from 'components/Head'
|
||||
import { Application } from 'components/Application'
|
||||
import {
|
||||
authenticationFromServerSide,
|
||||
AuthenticationProvider,
|
||||
PagePropsWithAuthentication
|
||||
} from 'tools/authentication'
|
||||
import { GuildMember, GuildMemberProvider } from 'contexts/GuildMember'
|
||||
import { GuildLeftSidebar } from 'components/Application/GuildLeftSidebar'
|
||||
import { ChannelSettings } from 'components/Application/ChannelSettings'
|
||||
import { ChannelsProvider } from 'contexts/Channels'
|
||||
import { GuildsProvider } from 'contexts/Guilds'
|
||||
import { Channel } from 'models/Channel'
|
||||
import { MembersProviders } from 'contexts/Members'
|
||||
|
||||
export interface ChannelSettingsPageProps extends PagePropsWithAuthentication {
|
||||
channelId: number
|
||||
guildId: number
|
||||
guildMember: GuildMember
|
||||
selectedChannel: Channel
|
||||
}
|
||||
|
||||
const ChannelSettingsPage: NextPage<ChannelSettingsPageProps> = (props) => {
|
||||
const { channelId, guildId, authentication, guildMember, selectedChannel } =
|
||||
props
|
||||
|
||||
const path = {
|
||||
channelId,
|
||||
guildId
|
||||
}
|
||||
|
||||
return (
|
||||
<AuthenticationProvider authentication={authentication}>
|
||||
<GuildsProvider>
|
||||
<GuildMemberProvider guildMember={guildMember} path={path}>
|
||||
<MembersProviders path={path}>
|
||||
<ChannelsProvider path={path}>
|
||||
<Head title='Thream | Application' />
|
||||
<Application
|
||||
path={path}
|
||||
guildLeftSidebar={<GuildLeftSidebar path={path} />}
|
||||
title={`# ${selectedChannel.name}`}
|
||||
>
|
||||
<ChannelSettings channel={selectedChannel} />
|
||||
</Application>
|
||||
</ChannelsProvider>
|
||||
</MembersProviders>
|
||||
</GuildMemberProvider>
|
||||
</GuildsProvider>
|
||||
</AuthenticationProvider>
|
||||
)
|
||||
}
|
||||
|
||||
export const getServerSideProps = authenticationFromServerSide({
|
||||
shouldBeAuthenticated: true,
|
||||
fetchData: async (context, api) => {
|
||||
const channelId = Number(context?.params?.channelId)
|
||||
const guildId = Number(context?.params?.guildId)
|
||||
if (isNaN(channelId) || isNaN(guildId)) {
|
||||
return {
|
||||
redirect: {
|
||||
destination: '/404',
|
||||
permanent: false
|
||||
}
|
||||
}
|
||||
}
|
||||
const { data: guildMember } = await api.get<GuildMember>(
|
||||
`/guilds/${guildId}`
|
||||
)
|
||||
if (!guildMember.member.isOwner) {
|
||||
return {
|
||||
redirect: {
|
||||
destination: '/404',
|
||||
permanent: false
|
||||
}
|
||||
}
|
||||
}
|
||||
const { data: selectedChannelData } = await api.get(
|
||||
`/channels/${channelId}`
|
||||
)
|
||||
return {
|
||||
channelId,
|
||||
guildId,
|
||||
guildMember,
|
||||
selectedChannel: selectedChannelData.channel
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
export default ChannelSettingsPage
|
61
pages/application/[guildId]/channels/create.tsx
Normal file
61
pages/application/[guildId]/channels/create.tsx
Normal file
@ -0,0 +1,61 @@
|
||||
import { NextPage } from 'next'
|
||||
|
||||
import { Head } from 'components/Head'
|
||||
import { Application } from 'components/Application'
|
||||
import {
|
||||
authenticationFromServerSide,
|
||||
AuthenticationProvider,
|
||||
PagePropsWithAuthentication
|
||||
} from 'tools/authentication'
|
||||
import { CreateChannel } from 'components/Application/CreateChannel'
|
||||
import { GuildsProvider } from 'contexts/Guilds'
|
||||
import { GuildMember, GuildMemberProvider } from 'contexts/GuildMember'
|
||||
|
||||
export interface CreateChannelPageProps extends PagePropsWithAuthentication {
|
||||
guildId: number
|
||||
guildMember: GuildMember
|
||||
}
|
||||
|
||||
const CreateChannelPage: NextPage<CreateChannelPageProps> = (props) => {
|
||||
const { guildId, authentication, guildMember } = props
|
||||
|
||||
const path = { guildId }
|
||||
|
||||
return (
|
||||
<AuthenticationProvider authentication={authentication}>
|
||||
<GuildsProvider>
|
||||
<GuildMemberProvider guildMember={guildMember} path={path}>
|
||||
<Head
|
||||
title={`Thream | Crée un channel`}
|
||||
description={'Crée un nouveau channel'}
|
||||
/>
|
||||
<Application path={path} title={'Crée un channel'}>
|
||||
<CreateChannel />
|
||||
</Application>
|
||||
</GuildMemberProvider>
|
||||
</GuildsProvider>
|
||||
</AuthenticationProvider>
|
||||
)
|
||||
}
|
||||
|
||||
export const getServerSideProps = authenticationFromServerSide({
|
||||
shouldBeAuthenticated: true,
|
||||
fetchData: async (context, api) => {
|
||||
const guildId = Number(context?.params?.guildId)
|
||||
if (isNaN(guildId)) {
|
||||
return {
|
||||
redirect: {
|
||||
destination: '/404',
|
||||
permanent: false
|
||||
}
|
||||
}
|
||||
}
|
||||
const { data: guildMember } = await api.get(`/guilds/${guildId}`)
|
||||
return {
|
||||
guildId,
|
||||
guildMember
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
export default CreateChannelPage
|
60
pages/application/[guildId]/settings.tsx
Normal file
60
pages/application/[guildId]/settings.tsx
Normal file
@ -0,0 +1,60 @@
|
||||
import { NextPage } from 'next'
|
||||
|
||||
import { Head } from 'components/Head'
|
||||
import { Application } from 'components/Application'
|
||||
import {
|
||||
authenticationFromServerSide,
|
||||
AuthenticationProvider,
|
||||
PagePropsWithAuthentication
|
||||
} from 'tools/authentication'
|
||||
import { GuildMember, GuildMemberProvider } from 'contexts/GuildMember'
|
||||
import { GuildsProvider } from 'contexts/Guilds'
|
||||
import { GuildSettings } from 'components/Application/GuildSettings'
|
||||
|
||||
export interface GuildSettingsPageProps extends PagePropsWithAuthentication {
|
||||
guildId: number
|
||||
guildMember: GuildMember
|
||||
}
|
||||
|
||||
const GuildSettingsPage: NextPage<GuildSettingsPageProps> = (props) => {
|
||||
const { guildId, authentication, guildMember } = props
|
||||
|
||||
const path = { guildId }
|
||||
|
||||
return (
|
||||
<AuthenticationProvider authentication={authentication}>
|
||||
<GuildsProvider>
|
||||
<GuildMemberProvider guildMember={guildMember} path={path}>
|
||||
<Head title='Thream | Guild settings' />
|
||||
<Application path={path} title='Guild settings'>
|
||||
<GuildSettings />
|
||||
</Application>
|
||||
</GuildMemberProvider>
|
||||
</GuildsProvider>
|
||||
</AuthenticationProvider>
|
||||
)
|
||||
}
|
||||
|
||||
export const getServerSideProps = authenticationFromServerSide({
|
||||
shouldBeAuthenticated: true,
|
||||
fetchData: async (context, api) => {
|
||||
const guildId = Number(context?.params?.guildId)
|
||||
if (isNaN(guildId)) {
|
||||
return {
|
||||
redirect: {
|
||||
destination: '/404',
|
||||
permanent: false
|
||||
}
|
||||
}
|
||||
}
|
||||
const { data: guildMember } = await api.get<GuildMember>(
|
||||
`/guilds/${guildId}`
|
||||
)
|
||||
return {
|
||||
guildId,
|
||||
guildMember
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
export default GuildSettingsPage
|
Reference in New Issue
Block a user