File tree 2 files changed +19
-4
lines changed
components/pubs/PubEditor
2 files changed +19
-4
lines changed Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ import type { Metadata } from "next";
2
2
3
3
import { notFound , redirect } from "next/navigation" ;
4
4
5
- import { type PubTypesId } from "db/public" ;
5
+ import { type PubsId , type PubTypesId } from "db/public" ;
6
6
import { Button } from "ui/button" ;
7
7
import { Label } from "ui/label" ;
8
8
@@ -31,12 +31,20 @@ export async function generateMetadata(props: {
31
31
32
32
export default async function Page ( props : {
33
33
params : Promise < { communitySlug : string } > ;
34
- searchParams : Promise < Record < string , string > & { pubTypeId : PubTypesId ; form ?: string } > ;
34
+ searchParams : Promise <
35
+ Record < string , string > & { pubTypeId : PubTypesId ; form ?: string ; pubId ?: PubsId }
36
+ > ;
35
37
} ) {
36
38
const searchParams = await props . searchParams ;
37
39
const params = await props . params ;
38
40
const { communitySlug } = params ;
39
41
42
+ if ( ! searchParams . pubId ) {
43
+ const sparams = new URLSearchParams ( searchParams ) ;
44
+ sparams . set ( "pubId" , crypto . randomUUID ( ) ) ;
45
+ redirect ( `/c/${ communitySlug } /pubs/create?${ sparams . toString ( ) } ` ) ;
46
+ }
47
+
40
48
const { user } = await getPageLoginData ( ) ;
41
49
42
50
const community = await findCommunityBySlug ( communitySlug ) ;
Original file line number Diff line number Diff line change @@ -103,7 +103,14 @@ const getRelatedPubData = async ({
103
103
} ;
104
104
105
105
export type PubEditorProps = {
106
- searchParams : { relatedPubId ?: PubsId ; slug ?: string ; pubTypeId ?: PubTypesId ; form ?: string } ;
106
+ searchParams : {
107
+ relatedPubId ?: PubsId ;
108
+ slug ?: string ;
109
+ pubTypeId ?: PubTypesId ;
110
+ form ?: string ;
111
+ // used when creating a new pub
112
+ pubId ?: PubsId ;
113
+ } ;
107
114
htmlFormId ?: string ;
108
115
formSlug ?: string ;
109
116
} & (
@@ -189,7 +196,7 @@ export async function PubEditor(props: PubEditorProps) {
189
196
// Create the pubId before inserting into the DB if one doesn't exist.
190
197
// FileUpload needs the pubId when uploading the file before the pub exists
191
198
const isUpdating = ! ! pub ?. id ;
192
- const pubId = pub ?. id ?? ( randomUUID ( ) as PubsId ) ;
199
+ const pubId = pub ?. id ?? props . searchParams . pubId ?? ( randomUUID ( ) as PubsId ) ;
193
200
194
201
if ( pub === undefined ) {
195
202
if ( props . searchParams . pubTypeId ) {
You can’t perform that action at this time.
0 commit comments