feat: interact with user settings/profile (#9)

This commit is contained in:
Divlo
2022-02-19 23:20:33 +01:00
committed by GitHub
parent 48debe8638
commit 7ac4f86cd5
101 changed files with 6705 additions and 9777 deletions

View File

@ -66,7 +66,7 @@ export const getServerSideProps = authenticationFromServerSide({
if (isNaN(channelId) || isNaN(guildId)) {
return {
redirect: {
destination: '/application',
destination: '/404',
permanent: false
}
}

View File

@ -9,17 +9,23 @@ import {
} from 'tools/authentication'
import { UserProfile } from 'components/Application/UserProfile'
import { GuildsProvider } from 'contexts/Guilds'
import { UserPublic } from 'models/User'
import { Guild } from 'models/Guild'
export interface UserProfilePageProps extends PagePropsWithAuthentication {
user: UserPublic
guilds: Guild[]
}
const UserProfilePage: NextPage<UserProfilePageProps> = (props) => {
const { user, guilds, authentication } = props
const UserProfilePage: NextPage<PagePropsWithAuthentication> = (props) => {
return (
<AuthenticationProvider authentication={props.authentication}>
<AuthenticationProvider authentication={authentication}>
<GuildsProvider>
<Head title={`Thream | ${props.authentication.user.name}`} />
<Application
path={`/application/users/${props.authentication.user.id}`}
title={props.authentication.user.name}
>
<UserProfile user={props.authentication.user} />
<Head title={`Thream | ${user.name}`} />
<Application path={`/application/users/${user.id}`} title={user.name}>
<UserProfile user={user} guilds={guilds} />
</Application>
</GuildsProvider>
</AuthenticationProvider>
@ -27,7 +33,23 @@ const UserProfilePage: NextPage<PagePropsWithAuthentication> = (props) => {
}
export const getServerSideProps = authenticationFromServerSide({
shouldBeAuthenticated: true
shouldBeAuthenticated: true,
fetchData: async (context, api) => {
const userId = Number(context?.params?.userId)
if (isNaN(userId)) {
return {
redirect: {
destination: '/404',
permanent: false
}
}
}
const { data } = await api.get(`/users/${userId}`)
return {
user: data.user,
guilds: data.guilds
}
}
})
export default UserProfilePage

View File

@ -15,11 +15,8 @@ const UserSettingsPage: NextPage<PagePropsWithAuthentication> = (props) => {
<AuthenticationProvider authentication={props.authentication}>
<GuildsProvider>
<Head title='Thream | Settings' />
<Application
path={`/application/users/${props.authentication.user.id}/settings`}
title='Settings'
>
<UserSettings user={props.authentication.user} />
<Application path={`/application/users/settings`} title='Settings'>
<UserSettings />
</Application>
</GuildsProvider>
</AuthenticationProvider>