diff --git a/src/app/virtual-lab/lab/[virtualLabId]/(project)/project/[projectId]/(pages)/team/page.tsx b/src/app/virtual-lab/lab/[virtualLabId]/(project)/project/[projectId]/(pages)/team/page.tsx index 5ba7d01d9..fe351f859 100644 --- a/src/app/virtual-lab/lab/[virtualLabId]/(project)/project/[projectId]/(pages)/team/page.tsx +++ b/src/app/virtual-lab/lab/[virtualLabId]/(project)/project/[projectId]/(pages)/team/page.tsx @@ -1,9 +1,17 @@ +'use client'; + import VirtualLabTeamTable from '@/components/VirtualLab/VirtualLabTeamTable'; +import withVirtualLabProjectUsers from '@/components/VirtualLab/data/WithVirtualLabProjectUsers'; import { ServerSideComponentProp } from '@/types/common'; export default function VirtualLabProjectTeamPage({ params, }: ServerSideComponentProp<{ virtualLabId: string; projectId: string }>) { const { virtualLabId, projectId } = params; - return ; + const WithVirtualLabProjectUsers = withVirtualLabProjectUsers( + VirtualLabTeamTable, + virtualLabId, + projectId + ); + return ; } diff --git a/src/components/VirtualLab/data/WithVirtualLabProjectUsers.tsx b/src/components/VirtualLab/data/WithVirtualLabProjectUsers.tsx new file mode 100644 index 000000000..b4071ebb4 --- /dev/null +++ b/src/components/VirtualLab/data/WithVirtualLabProjectUsers.tsx @@ -0,0 +1,44 @@ +'use client'; + +import { LoadingOutlined } from '@ant-design/icons'; +import { Spin } from 'antd'; +import { useAtomValue } from 'jotai'; +import { loadable } from 'jotai/utils'; +import { ComponentType } from 'react'; + +import { VirtualLabMember } from '@/types/virtual-lab/members'; +import { virtualLabProjectUsersAtomFamily } from '@/state/virtual-lab/projects'; + +type WithVirtualLabUsersProps = { + users: VirtualLabMember[]; +}; + +export default function withVirtualLabProjectUsers( + WrappedComponent: ComponentType, + virtualLabId: string, + projectId: string +) { + function WithVirtualLabProjectUsers() { + const projectMembers = useAtomValue( + loadable(virtualLabProjectUsersAtomFamily({ virtualLabId, projectId })) + ); + if (projectMembers.state === 'loading') { + return ( +
+ } /> +
+ ); + } + if (projectMembers.state === 'hasError') { + return ( +
+
+ Something went wrong when fetching virtual lab project users +
+
+ ); + } + return ; + } + return WithVirtualLabProjectUsers; +}