Skip to content

Commit

Permalink
Add edit page stub and routing
Browse files Browse the repository at this point in the history
  • Loading branch information
fhennig committed Sep 30, 2024
1 parent a4169a4 commit 3abcfaf
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 1 deletion.
3 changes: 2 additions & 1 deletion website/src/components/User/GroupPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const InnerGroupPage: FC<GroupPageProps> = ({
userGroups,
}) => {
const groupName = prefetchedGroupDetails.group.groupName;
const groupId = prefetchedGroupDetails.group.groupId;
const [newUserName, setNewUserName] = useState<string>('');

const [errorMessage, setErrorMessage] = useState<string | undefined>(undefined);
Expand Down Expand Up @@ -100,7 +101,7 @@ const InnerGroupPage: FC<GroupPageProps> = ({
<button
className='object-right p-2 loculusColor text-white rounded px-4 mr-2'
onClick={() => {
console.log("TODO");
window.location.href = routes.editGroupPage(groupId);
}}
>
Edit group
Expand Down
57 changes: 57 additions & 0 deletions website/src/pages/group/[groupId]/edit.astro
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>
1 change: 1 addition & 0 deletions website/src/routes/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export const routes = {
return organism === undefined ? userPagePath : withOrganism(organism, userPagePath);
},
groupOverviewPage: (groupId: number) => `/group/${groupId}`,
editGroupPage: (groupId: number) => `/group/${groupId}/edit`,
userSequenceReviewPage: (organism: string, groupId: number) =>
SubmissionRouteUtils.toUrl({ name: 'review', organism, groupId }),
versionPage: (accession: string) => `/seq/${accession}/versions`,
Expand Down

0 comments on commit 3abcfaf

Please sign in to comment.