@@ -7,23 +7,41 @@ import { pageTitle } from "../../util/page"
7
7
import { Loader } from "components/Loader/Loader"
8
8
import { Outlet , useParams } from "react-router-dom"
9
9
import { Margins } from "components/Margins/Margins"
10
- import { getTemplateByName } from "api/api"
10
+ import { checkAuthorization , getTemplateByName } from "api/api"
11
11
import { useQuery } from "@tanstack/react-query"
12
12
import { useOrganizationId } from "hooks/useOrganizationId"
13
13
14
- const fetchTemplate = ( orgId : string , name : string ) => {
15
- return getTemplateByName ( orgId , name )
14
+ const templatePermissions = ( templateId : string ) => ( {
15
+ canUpdateTemplate : {
16
+ object : {
17
+ resource_type : "template" ,
18
+ resource_id : templateId ,
19
+ } ,
20
+ action : "update" ,
21
+ } ,
22
+ } )
23
+
24
+ const fetchTemplateSettings = async ( orgId : string , name : string ) => {
25
+ const template = await getTemplateByName ( orgId , name )
26
+ const permissions = await checkAuthorization ( {
27
+ checks : templatePermissions ( template . id ) ,
28
+ } )
29
+
30
+ return {
31
+ template,
32
+ permissions,
33
+ }
16
34
}
17
35
18
36
const useTemplate = ( orgId : string , name : string ) => {
19
37
return useQuery ( {
20
- queryKey : [ "template" , orgId , name ] ,
21
- queryFn : ( ) => fetchTemplate ( orgId , name ) ,
38
+ queryKey : [ "template" , name , "settings" ] ,
39
+ queryFn : ( ) => fetchTemplateSettings ( orgId , name ) ,
22
40
} )
23
41
}
24
42
25
43
const TemplateSettingsContext = createContext <
26
- Awaited < ReturnType < typeof fetchTemplate > > | undefined
44
+ Awaited < ReturnType < typeof fetchTemplateSettings > > | undefined
27
45
> ( undefined )
28
46
29
47
export const useTemplateSettingsContext = ( ) => {
@@ -42,19 +60,19 @@ export const TemplateSettingsLayout: FC = () => {
42
60
const styles = useStyles ( )
43
61
const orgId = useOrganizationId ( )
44
62
const { template : templateName } = useParams ( ) as { template : string }
45
- const { data : template } = useTemplate ( orgId , templateName )
63
+ const { data : settings } = useTemplate ( orgId , templateName )
46
64
47
65
return (
48
66
< >
49
67
< Helmet >
50
68
< title > { pageTitle ( "Settings" ) } </ title >
51
69
</ Helmet >
52
70
53
- { template ? (
54
- < TemplateSettingsContext . Provider value = { template } >
71
+ { settings ? (
72
+ < TemplateSettingsContext . Provider value = { settings } >
55
73
< Margins >
56
74
< Stack className = { styles . wrapper } direction = "row" spacing = { 10 } >
57
- < Sidebar template = { template } />
75
+ < Sidebar template = { settings . template } />
58
76
< Suspense fallback = { < Loader /> } >
59
77
< main className = { styles . content } >
60
78
< Outlet />
0 commit comments