@@ -12,23 +12,30 @@ import Loading from 'src/common/Loading'
12
12
import Link from 'src/Link'
13
13
import MessageAlert from 'src/MessageAlert'
14
14
import SchemaButton from 'src/schemas/SchemaButton'
15
- import { EntryInterface , EntryKind , SchemaInterface , SchemaKind , SchemaKindKeys , SchemaKindLabel } from 'types/types'
15
+ import {
16
+ EntryInterface ,
17
+ EntryKind ,
18
+ EntryKindLabel ,
19
+ SchemaInterface ,
20
+ SchemaKind ,
21
+ SchemaKindKeys ,
22
+ SchemaKindLabel ,
23
+ } from 'types/types'
16
24
17
25
type SchemaSelectProps = {
18
26
schemaKind : SchemaKindKeys
19
- entry ?: EntryInterface
20
- id ?: string
27
+ entry : EntryInterface
21
28
}
22
29
23
- export default function SchemaSelect ( { schemaKind, entry, id } : SchemaSelectProps ) {
30
+ export default function SchemaSelect ( { schemaKind, entry } : SchemaSelectProps ) {
24
31
const router = useRouter ( )
25
32
const [ loading , setLoading ] = useState ( false )
26
33
const [ errorMessage , setErrorMessage ] = useState ( '' )
27
34
28
35
const { schemas, isSchemasLoading, isSchemasError } = useGetSchemas ( schemaKind )
29
36
const { currentUser, isCurrentUserLoading, isCurrentUserError } = useGetCurrentUser ( )
30
37
31
- const { mutateModel : mutateEntry } = useGetModel ( id , EntryKind [ schemaKind ] )
38
+ const { mutateModel : mutateEntry } = useGetModel ( entry . id , EntryKind [ schemaKind ] )
32
39
33
40
const isLoadingData = useMemo (
34
41
( ) => isSchemasLoading || isCurrentUserLoading ,
@@ -41,9 +48,9 @@ export default function SchemaSelect({ schemaKind, entry, id }: SchemaSelectProp
41
48
const accessRequestCallback = useCallback (
42
49
async ( newSchema : SchemaInterface ) => {
43
50
setLoading ( true )
44
- router . push ( `/model/${ id } /access-request/new?schemaId=${ newSchema . id } ` )
51
+ router . push ( `/model/${ entry . id } /access-request/new?schemaId=${ newSchema . id } ` )
45
52
} ,
46
- [ id , router ] ,
53
+ [ entry . id , router ] ,
47
54
)
48
55
49
56
const entryCallback = useCallback (
@@ -66,11 +73,10 @@ export default function SchemaSelect({ schemaKind, entry, id }: SchemaSelectProp
66
73
[ currentUser , entry , mutateEntry , router ] ,
67
74
)
68
75
69
- let selectionCallback = entryCallback
70
-
71
- if ( schemaKind === SchemaKind . ACCESS_REQUEST ) {
72
- selectionCallback = accessRequestCallback
73
- }
76
+ const selectionCallback = useMemo (
77
+ ( ) => ( schemaKind === SchemaKind . ACCESS_REQUEST ? accessRequestCallback : entryCallback ) ,
78
+ [ schemaKind , accessRequestCallback , entryCallback ] ,
79
+ )
74
80
75
81
const activeSchemaButtons = useMemo (
76
82
( ) =>
@@ -106,8 +112,6 @@ export default function SchemaSelect({ schemaKind, entry, id }: SchemaSelectProp
106
112
[ inactiveSchemas , selectionCallback , loading ] ,
107
113
)
108
114
109
- const link = schemaKind === SchemaKind . ACCESS_REQUEST ? `/model/${ id } ` : `/${ schemaKind } /${ id } `
110
-
111
115
if ( isSchemasError ) {
112
116
return < MessageAlert message = { isSchemasError . info . message } severity = 'error' />
113
117
}
@@ -122,9 +126,9 @@ export default function SchemaSelect({ schemaKind, entry, id }: SchemaSelectProp
122
126
{ ! isLoadingData && (
123
127
< Container maxWidth = 'md' >
124
128
< Card sx = { { mx : 'auto' , my : 4 , p : 4 } } >
125
- < Link href = { link } >
129
+ < Link href = { `/ ${ entry . kind } / ${ entry . id } ` } >
126
130
< Button sx = { { width : 'fit-content' } } startIcon = { < ArrowBack /> } >
127
- { `Back to ${ SchemaKindLabel [ schemaKind ] } ` }
131
+ { `Back to ${ EntryKindLabel [ entry . kind ] } ` }
128
132
</ Button >
129
133
</ Link >
130
134
< Stack spacing = { 2 } justifyContent = 'center' alignItems = 'center' >
0 commit comments