@@ -42,13 +42,6 @@ const fetchTemplate = async (orgId: string, templateName: string) => {
42
42
}
43
43
}
44
44
45
- const useTemplateData = ( orgId : string , templateName : string ) => {
46
- return useQuery ( {
47
- queryKey : [ "template" , templateName ] ,
48
- queryFn : ( ) => fetchTemplate ( orgId , templateName ) ,
49
- } )
50
- }
51
-
52
45
type TemplateLayoutContextValue = Awaited < ReturnType < typeof fetchTemplate > >
53
46
54
47
const TemplateLayoutContext = createContext <
@@ -71,28 +64,31 @@ export const TemplateLayout: FC<{ children?: JSX.Element }> = ({
71
64
const navigate = useNavigate ( )
72
65
const styles = useStyles ( )
73
66
const orgId = useOrganizationId ( )
74
- const { template } = useParams ( ) as { template : string }
75
- const templateData = useTemplateData ( orgId , template )
67
+ const { template : templateName } = useParams ( ) as { template : string }
68
+ const { data, error, isLoading } = useQuery ( {
69
+ queryKey : [ "template" , templateName ] ,
70
+ queryFn : ( ) => fetchTemplate ( orgId , templateName ) ,
71
+ } )
76
72
const dashboard = useDashboard ( )
77
73
78
- if ( templateData . error ) {
74
+ if ( error ) {
79
75
return (
80
76
< div className = { styles . error } >
81
- < AlertBanner severity = "error" error = { templateData . error } />
77
+ < AlertBanner severity = "error" error = { error } />
82
78
</ div >
83
79
)
84
80
}
85
81
86
- if ( templateData . isLoading || ! templateData . data ) {
82
+ if ( isLoading || ! data ) {
87
83
return < Loader />
88
84
}
89
85
90
86
return (
91
87
< >
92
88
< TemplatePageHeader
93
- template = { templateData . data . template }
94
- activeVersion = { templateData . data . activeVersion }
95
- permissions = { templateData . data . permissions }
89
+ template = { data . template }
90
+ activeVersion = { data . activeVersion }
91
+ permissions = { data . permissions }
96
92
canEditFiles = { dashboard . experiments . includes ( "template_editor" ) }
97
93
onDeleteTemplate = { ( ) => {
98
94
navigate ( "/templates" )
@@ -104,7 +100,7 @@ export const TemplateLayout: FC<{ children?: JSX.Element }> = ({
104
100
< Stack direction = "row" spacing = { 0.25 } >
105
101
< NavLink
106
102
end
107
- to = { `/templates/${ template } ` }
103
+ to = { `/templates/${ templateName } ` }
108
104
className = { ( { isActive } ) =>
109
105
combineClasses ( [
110
106
styles . tabItem ,
@@ -115,18 +111,7 @@ export const TemplateLayout: FC<{ children?: JSX.Element }> = ({
115
111
Summary
116
112
</ NavLink >
117
113
< NavLink
118
- to = { `/templates/${ template } /permissions` }
119
- className = { ( { isActive } ) =>
120
- combineClasses ( [
121
- styles . tabItem ,
122
- isActive ? styles . tabItemActive : undefined ,
123
- ] )
124
- }
125
- >
126
- Permissions
127
- </ NavLink >
128
- < NavLink
129
- to = { `/templates/${ template } /files` }
114
+ to = { `/templates/${ templateName } /files` }
130
115
className = { ( { isActive } ) =>
131
116
combineClasses ( [
132
117
styles . tabItem ,
@@ -141,7 +126,7 @@ export const TemplateLayout: FC<{ children?: JSX.Element }> = ({
141
126
</ div >
142
127
143
128
< Margins >
144
- < TemplateLayoutContext . Provider value = { templateData . data } >
129
+ < TemplateLayoutContext . Provider value = { data } >
145
130
< Suspense fallback = { < Loader /> } > { children } </ Suspense >
146
131
</ TemplateLayoutContext . Provider >
147
132
</ Margins >
0 commit comments