@@ -12,14 +12,15 @@ import { Column, Table } from "../../components/Table"
12
12
import { useUser } from "../../contexts/UserContext"
13
13
import { FullScreenLoader } from "../../components/Loader/FullScreenLoader"
14
14
15
- import { Project } from "./../../api"
15
+ import { Organization , Project } from "./../../api"
16
16
import useSWR from "swr"
17
17
18
18
const ProjectsPage : React . FC = ( ) => {
19
19
const styles = useStyles ( )
20
20
const router = useRouter ( )
21
21
const { me, signOut } = useUser ( true )
22
22
const { data, error } = useSWR < Project [ ] | null , Error > ( "/api/v2/projects" )
23
+ const { data : orgs , error : orgsError } = useSWR < Organization [ ] , Error > ( "/api/v2/users/me/organizations" )
23
24
24
25
// TODO: The API call is currently returning `null`, which isn't ideal
25
26
// - it breaks checking for data presence with SWR.
@@ -29,7 +30,11 @@ const ProjectsPage: React.FC = () => {
29
30
return < ErrorSummary error = { error } />
30
31
}
31
32
32
- if ( ! me || ! projects ) {
33
+ if ( orgsError ) {
34
+ return < ErrorSummary error = { error } />
35
+ }
36
+
37
+ if ( ! me || ! projects || ! orgs ) {
33
38
return < FullScreenLoader />
34
39
}
35
40
@@ -42,12 +47,21 @@ const ProjectsPage: React.FC = () => {
42
47
onClick : createProject ,
43
48
}
44
49
50
+ // Create a dictionary of organization ID -> organization Name
51
+ // Needed to properly construct links to dive into a project
52
+ const orgDictionary = orgs . reduce ( ( acc : Record < string , string > , curr : Organization ) => {
53
+ return {
54
+ ...acc ,
55
+ [ curr . id ] : curr . name ,
56
+ }
57
+ } , { } )
58
+
45
59
const columns : Column < Project > [ ] = [
46
60
{
47
61
key : "name" ,
48
62
name : "Name" ,
49
63
renderer : ( nameField : string , data : Project ) => {
50
- return < Link href = { `/projects/${ data . organization_id } /${ data . id } ` } > { nameField } </ Link >
64
+ return < Link href = { `/projects/${ orgDictionary [ data . organization_id ] } /${ nameField } ` } > { nameField } </ Link >
51
65
} ,
52
66
} ,
53
67
]
0 commit comments