2022-08-31 21:44:33 +02:00
|
|
|
import type { NextPage } from 'next'
|
2022-04-09 01:03:15 +02:00
|
|
|
import useTranslation from 'next-translate/useTranslation'
|
2022-03-05 18:22:30 +01:00
|
|
|
|
2022-03-16 12:18:09 +01:00
|
|
|
import { Head } from '../../../../components/Head'
|
|
|
|
import { Application } from '../../../../components/Application'
|
2022-08-31 21:44:33 +02:00
|
|
|
import type { PagePropsWithAuthentication } from '../../../../tools/authentication'
|
2022-03-05 18:22:30 +01:00
|
|
|
import {
|
|
|
|
authenticationFromServerSide,
|
2022-08-31 21:44:33 +02:00
|
|
|
AuthenticationProvider
|
2022-03-16 12:18:09 +01:00
|
|
|
} from '../../../../tools/authentication'
|
|
|
|
import { CreateChannel } from '../../../../components/Application/CreateChannel'
|
|
|
|
import { GuildsProvider } from '../../../../contexts/Guilds'
|
2022-08-31 21:44:33 +02:00
|
|
|
import type { GuildMember } from '../../../../contexts/GuildMember'
|
|
|
|
import { GuildMemberProvider } from '../../../../contexts/GuildMember'
|
2022-03-05 18:22:30 +01:00
|
|
|
|
|
|
|
export interface CreateChannelPageProps extends PagePropsWithAuthentication {
|
|
|
|
guildId: number
|
|
|
|
guildMember: GuildMember
|
|
|
|
}
|
|
|
|
|
|
|
|
const CreateChannelPage: NextPage<CreateChannelPageProps> = (props) => {
|
|
|
|
const { guildId, authentication, guildMember } = props
|
2022-04-09 01:03:15 +02:00
|
|
|
const { t } = useTranslation()
|
2022-03-05 18:22:30 +01:00
|
|
|
|
|
|
|
const path = { guildId }
|
|
|
|
|
|
|
|
return (
|
|
|
|
<AuthenticationProvider authentication={authentication}>
|
|
|
|
<GuildsProvider>
|
|
|
|
<GuildMemberProvider guildMember={guildMember} path={path}>
|
|
|
|
<Head
|
2022-04-09 01:03:15 +02:00
|
|
|
title={`Thream | ${t('application:create-a-channel')}`}
|
|
|
|
description={t('application:create-a-channel')}
|
2022-03-05 18:22:30 +01:00
|
|
|
/>
|
2022-04-09 01:03:15 +02:00
|
|
|
<Application path={path} title={t('application:create-a-channel')}>
|
2022-03-05 18:22:30 +01:00
|
|
|
<CreateChannel />
|
|
|
|
</Application>
|
|
|
|
</GuildMemberProvider>
|
|
|
|
</GuildsProvider>
|
|
|
|
</AuthenticationProvider>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export const getServerSideProps = authenticationFromServerSide({
|
|
|
|
shouldBeAuthenticated: true,
|
|
|
|
fetchData: async (context, api) => {
|
2023-01-11 17:39:09 +01:00
|
|
|
const guildId = Number(context?.params?.['guildId'])
|
2023-07-22 16:34:23 +02:00
|
|
|
if (Number.isNaN(guildId)) {
|
2022-03-05 18:22:30 +01:00
|
|
|
return {
|
2022-08-30 21:30:06 +02:00
|
|
|
notFound: true
|
2022-03-05 18:22:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
const { data: guildMember } = await api.get(`/guilds/${guildId}`)
|
|
|
|
return {
|
|
|
|
guildId,
|
|
|
|
guildMember
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
export default CreateChannelPage
|