-
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
3 changed files
with
60 additions
and
1 deletion.
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
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,57 @@ | ||
--- | ||
import { GroupPage } from '../../../components/User/GroupPage'; | ||
import ErrorBox from '../../../components/common/ErrorBox.tsx'; | ||
import NeedToLogin from '../../../components/common/NeedToLogin.astro'; | ||
import { getRuntimeConfig } from '../../../config'; | ||
import BaseLayout from '../../../layouts/BaseLayout.astro'; | ||
import { GroupManagementClient } from '../../../services/groupManagementClient'; | ||
import { getAccessToken } from '../../../utils/getAccessToken'; | ||
const session = Astro.locals.session!; | ||
const accessToken = getAccessToken(session)!; | ||
const username = session.user?.username ?? ''; | ||
const groupId = parseInt(Astro.params.groupId!, 10); | ||
const clientConfig = getRuntimeConfig().public; | ||
if (isNaN(groupId)) { | ||
return new Response(undefined, { | ||
status: 404, | ||
}); | ||
} | ||
const groupManagementClient = GroupManagementClient.create(); | ||
const groupDetailsResult = await groupManagementClient.getGroupDetails(accessToken, groupId); | ||
const userGroupsResponse = await groupManagementClient.getGroupsOfUser(accessToken); | ||
const userGroups = userGroupsResponse.match( | ||
(groups) => groups, | ||
() => [], | ||
); | ||
--- | ||
|
||
<BaseLayout | ||
title={groupDetailsResult.match( | ||
(groupDetails) => groupDetails.group.groupName, | ||
() => 'Group error', | ||
)} | ||
> | ||
{ | ||
!accessToken ? ( | ||
<NeedToLogin message='You need to be logged in to edit this group.' /> | ||
) : ( | ||
groupDetailsResult.match( | ||
(groupDetails) => ( | ||
<GroupPage | ||
prefetchedGroupDetails={groupDetails} | ||
accessToken={accessToken} | ||
clientConfig={clientConfig} | ||
username={username} | ||
userGroups={userGroups} | ||
client:load | ||
/> | ||
), | ||
() => <ErrorBox>Failed to fetch group details, sorry for the inconvenience!</ErrorBox>, | ||
) | ||
) | ||
} | ||
</BaseLayout> |
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