@@ -10,7 +10,7 @@ import { Label } from "ui/label";
10
10
11
11
import { ContentLayout } from "~/app/c/[communitySlug]/ContentLayout" ;
12
12
import { FormSwitcher } from "~/app/components/FormSwitcher/FormSwitcher" ;
13
- import { PageTitleWithStatus } from "~/app/components/pubs/PubEditor/PageTitleWithStatus" ;
13
+ import { PubPageTitleWithStatus } from "~/app/components/pubs/PubEditor/PageTitleWithStatus" ;
14
14
import { PubEditor } from "~/app/components/pubs/PubEditor/PubEditor" ;
15
15
import { getPageLoginData } from "~/lib/authentication/loginData" ;
16
16
import { getAuthorizedUpdateForms , userCanEditPub } from "~/lib/authorization/capabilities" ;
@@ -79,35 +79,36 @@ export default async function Page(props: {
79
79
const params = await props . params ;
80
80
const { pubId, communitySlug } = params ;
81
81
82
- const { user } = await getPageLoginData ( ) ;
83
-
84
82
if ( ! pubId || ! communitySlug ) {
85
- return null ;
86
- }
87
-
88
- const canUpdatePub = await userCanEditPub ( { userId : user . id , pubId } ) ;
89
-
90
- if ( ! canUpdatePub ) {
91
- redirect ( `/c/${ communitySlug } /unauthorized` ) ;
83
+ return notFound ( ) ;
92
84
}
93
85
94
- const community = await findCommunityBySlug ( communitySlug ) ;
86
+ const [ { user } , community ] = await Promise . all ( [
87
+ getPageLoginData ( ) ,
88
+ findCommunityBySlug ( communitySlug ) ,
89
+ ] ) ;
95
90
96
91
if ( ! community ) {
97
92
notFound ( ) ;
98
93
}
99
94
100
- const pub = await getPubsWithRelatedValuesCached ( {
101
- pubId : params . pubId as PubsId ,
102
- communityId : community . id ,
103
- userId : user . id ,
104
- } ) ;
95
+ const [ canUpdatePub , pub , availableForms ] = await Promise . all ( [
96
+ userCanEditPub ( { userId : user . id , pubId } ) ,
97
+ getPubsWithRelatedValuesCached ( {
98
+ pubId : params . pubId as PubsId ,
99
+ communityId : community . id ,
100
+ userId : user . id ,
101
+ } ) ,
102
+ getAuthorizedUpdateForms ( user . id , params . pubId ) . execute ( ) ,
103
+ ] ) ;
105
104
106
- if ( ! pub ) {
107
- return null ;
105
+ if ( ! canUpdatePub ) {
106
+ redirect ( `/c/ ${ communitySlug } /unauthorized` ) ;
108
107
}
109
108
110
- const availableForms = await getAuthorizedUpdateForms ( user . id , pub . id ) . execute ( ) ;
109
+ if ( ! pub ) {
110
+ return notFound ( ) ;
111
+ }
111
112
112
113
const htmlFormId = `edit-pub-${ pub . id } ` ;
113
114
@@ -118,7 +119,13 @@ export default async function Page(props: {
118
119
Save
119
120
</ Button >
120
121
}
121
- title = { < PageTitleWithStatus title = "Edit pub" /> }
122
+ title = {
123
+ < PubPageTitleWithStatus
124
+ title = "Edit pub"
125
+ defaultFormSlug = { searchParams . form }
126
+ forms = { availableForms }
127
+ />
128
+ }
122
129
right = {
123
130
< Button variant = "link" asChild >
124
131
< Link href = { `/c/${ communitySlug } /pubs/${ pub . id } ` } > View Pub</ Link >
@@ -127,12 +134,6 @@ export default async function Page(props: {
127
134
>
128
135
< div className = "flex justify-center py-10" >
129
136
< div className = "max-w-prose flex-1" >
130
- < Label htmlFor = "edit-page-form-switcher" > Current form</ Label >
131
- < FormSwitcher
132
- htmlId = "edit-page-form-switcher"
133
- defaultFormSlug = { searchParams . form }
134
- forms = { availableForms }
135
- />
136
137
{ /** TODO: Add suspense */ }
137
138
< PubEditor
138
139
searchParams = { searchParams }
0 commit comments