feat: interact with user settings/profile (#9)
This commit is contained in:
@ -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
|
||||
|
@ -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>
|
Reference in New Issue
Block a user