1
- import Button from "@material-ui/core/Button"
2
- import Link from "@material-ui/core/Link"
3
1
import { makeStyles } from "@material-ui/core/styles"
4
- import AddCircleOutline from "@material-ui/icons/AddCircleOutline"
5
- import SettingsOutlined from "@material-ui/icons/SettingsOutlined"
6
2
import { useMachine } from "@xstate/react"
7
- import {
8
- PageHeader ,
9
- PageHeaderSubtitle ,
10
- PageHeaderTitle ,
11
- } from "components/PageHeader/PageHeader"
12
3
import { useOrganizationId } from "hooks/useOrganizationId"
13
4
import { createContext , FC , Suspense , useContext } from "react"
14
- import {
15
- Link as RouterLink ,
16
- NavLink ,
17
- Outlet ,
18
- useParams ,
19
- } from "react-router-dom"
5
+ import { NavLink , Outlet , useNavigate , useParams } from "react-router-dom"
20
6
import { combineClasses } from "util/combineClasses"
21
7
import {
22
8
TemplateContext ,
@@ -27,14 +13,7 @@ import { Stack } from "components/Stack/Stack"
27
13
import { Permissions } from "xServices/auth/authXService"
28
14
import { Loader } from "components/Loader/Loader"
29
15
import { usePermissions } from "hooks/usePermissions"
30
- import { Avatar } from "components/Avatar/Avatar"
31
-
32
- const Language = {
33
- settingsButton : "Settings" ,
34
- editButton : "Edit" ,
35
- createButton : "Create workspace" ,
36
- noDescription : "" ,
37
- }
16
+ import { TemplatePageHeader } from "./TemplatePageHeader"
38
17
39
18
const useTemplateName = ( ) => {
40
19
const { template } = useParams ( )
@@ -65,38 +44,10 @@ export const useTemplateLayoutContext = (): TemplateLayoutContextValue => {
65
44
return context
66
45
}
67
46
68
- const TemplateSettingsButton : FC < { templateName : string } > = ( {
69
- templateName,
70
- } ) => (
71
- < Link
72
- underline = "none"
73
- component = { RouterLink }
74
- to = { `/templates/${ templateName } /settings` }
75
- >
76
- < Button variant = "outlined" startIcon = { < SettingsOutlined /> } >
77
- { Language . settingsButton }
78
- </ Button >
79
- </ Link >
80
- )
81
-
82
- const CreateWorkspaceButton : FC < {
83
- templateName : string
84
- className ?: string
85
- } > = ( { templateName, className } ) => (
86
- < Link
87
- underline = "none"
88
- component = { RouterLink }
89
- to = { `/templates/${ templateName } /workspace` }
90
- >
91
- < Button className = { className ?? "" } startIcon = { < AddCircleOutline /> } >
92
- { Language . createButton }
93
- </ Button >
94
- </ Link >
95
- )
96
-
97
47
export const TemplateLayout : FC < { children ?: JSX . Element } > = ( {
98
48
children = < Outlet /> ,
99
49
} ) => {
50
+ const navigate = useNavigate ( )
100
51
const styles = useStyles ( )
101
52
const organizationId = useOrganizationId ( )
102
53
const templateName = useTemplateName ( )
@@ -108,58 +59,20 @@ export const TemplateLayout: FC<{ children?: JSX.Element }> = ({
108
59
} )
109
60
const { template, permissions : templatePermissions } = templateState . context
110
61
const permissions = usePermissions ( )
111
- const hasIcon = template && template . icon && template . icon !== ""
112
62
113
- if ( ! template ) {
63
+ if ( ! template || ! templatePermissions ) {
114
64
return < Loader />
115
65
}
116
66
117
- const generatePageHeaderActions = ( ) : JSX . Element [ ] => {
118
- const pageActions : JSX . Element [ ] = [ ]
119
-
120
- if ( templatePermissions ?. canUpdateTemplate ) {
121
- pageActions . push ( < TemplateSettingsButton templateName = { template . name } /> )
122
- }
123
-
124
- pageActions . push ( < CreateWorkspaceButton templateName = { template . name } /> )
125
-
126
- return pageActions
127
- }
128
-
129
67
return (
130
68
< >
131
- < Margins >
132
- < PageHeader
133
- actions = {
134
- < >
135
- { generatePageHeaderActions ( ) . map ( ( action , i ) => (
136
- < div key = { i } > { action } </ div >
137
- ) ) }
138
- </ >
139
- }
140
- >
141
- < Stack direction = "row" spacing = { 3 } className = { styles . pageTitle } >
142
- { hasIcon ? (
143
- < Avatar size = "xl" src = { template . icon } variant = "square" fitImage />
144
- ) : (
145
- < Avatar size = "xl" > { template . name } </ Avatar >
146
- ) }
147
-
148
- < div >
149
- < PageHeaderTitle >
150
- { template . display_name . length > 0
151
- ? template . display_name
152
- : template . name }
153
- </ PageHeaderTitle >
154
- < PageHeaderSubtitle condensed >
155
- { template . description === ""
156
- ? Language . noDescription
157
- : template . description }
158
- </ PageHeaderSubtitle >
159
- </ div >
160
- </ Stack >
161
- </ PageHeader >
162
- </ Margins >
69
+ < TemplatePageHeader
70
+ template = { template }
71
+ permissions = { templatePermissions }
72
+ onDeleteTemplate = { ( ) => {
73
+ navigate ( "/templates" )
74
+ } }
75
+ />
163
76
164
77
< div className = { styles . tabs } >
165
78
< Margins >
@@ -204,17 +117,6 @@ export const TemplateLayout: FC<{ children?: JSX.Element }> = ({
204
117
205
118
export const useStyles = makeStyles ( ( theme ) => {
206
119
return {
207
- pageTitle : {
208
- alignItems : "center" ,
209
- } ,
210
- iconWrapper : {
211
- width : theme . spacing ( 6 ) ,
212
- height : theme . spacing ( 6 ) ,
213
- "& img" : {
214
- width : "100%" ,
215
- } ,
216
- } ,
217
-
218
120
tabs : {
219
121
borderBottom : `1px solid ${ theme . palette . divider } ` ,
220
122
marginBottom : theme . spacing ( 5 ) ,
0 commit comments