@@ -7,10 +7,7 @@ import {
77 Level ,
88 FormError ,
99 ProposalInput ,
10- Status ,
11- ProposalExisting ,
1210} from '@/lib/proposal/types'
13- import { getProposalSanity } from '@/lib/proposal/server'
1411import { countActiveProposals } from '@/lib/proposal/utils'
1512import { Speaker } from '@/lib/speaker/types'
1613import { ProposalForm } from '@/components/cfp/ProposalForm'
@@ -21,32 +18,28 @@ import { headers } from 'next/headers'
2118import { getSpeaker } from '@/lib/speaker/sanity'
2219import { getConferenceForCurrentDomain } from '@/lib/conference/sanity'
2320
24- export default async function ProposalPage ( {
25- params,
21+ export default async function NewProposalPage ( {
2622 searchParams,
2723} : {
28- params : Promise < { id ?: string [ ] } >
2924 searchParams : Promise < { id ?: string } >
3025} ) {
3126 await connection ( )
3227
33- // Support both /cfp/proposal/[id] and /cfp/proposal?id=[id] patterns
34- const routeParams = await params
35- const queryParams = await searchParams
36- const proposalId = routeParams . id ?. [ 0 ] || queryParams . id
28+ // Redirect old ?id= URLs to the path-based route
29+ const { id } = await searchParams
30+ if ( id ) {
31+ redirect ( `/cfp/proposal/${ id } ` )
32+ }
3733
3834 const headersList = await headers ( )
3935 const fullUrl = headersList . get ( 'x-url' ) || ''
4036 const session = await getAuthSession ( { url : fullUrl } )
4137
4238 if ( ! session ?. speaker ) {
43- const callbackUrl = proposalId
44- ? `/cfp/proposal/${ proposalId } `
45- : '/cfp/proposal'
46- return redirect ( `/api/auth/signin?callbackUrl=${ callbackUrl } ` )
39+ return redirect ( '/api/auth/signin?callbackUrl=/cfp/proposal' )
4740 }
4841
49- let proposal : ProposalInput = {
42+ const proposal : ProposalInput = {
5043 title : '' ,
5144 language : Language . norwegian ,
5245 description : [ ] ,
@@ -60,7 +53,6 @@ export default async function ProposalPage({
6053 let speaker = { name : '' , email : '' }
6154 let loadingError : FormError | null = null
6255 let currentUserSpeaker : Speaker | null = null
63- let proposalStatus : Status | undefined
6456
6557 const { conference, error } = await getConferenceForCurrentDomain ( {
6658 topics : true ,
@@ -74,7 +66,7 @@ export default async function ProposalPage({
7466 }
7567 }
7668
77- if ( conference && ! proposalId ) {
69+ if ( conference ) {
7870 const { isCfpOpen } = await import ( '@/lib/conference/state' )
7971 if ( ! isCfpOpen ( conference ) ) {
8072 const contactEmail = conference . cfpEmail || conference . contactEmail
@@ -104,8 +96,9 @@ export default async function ProposalPage({
10496 }
10597 } else {
10698 currentUserSpeaker = fetchedSpeaker
99+ speaker = fetchedSpeaker
107100
108- if ( ! proposalId && conference && ! loadingError ) {
101+ if ( conference && ! loadingError ) {
109102 const { getProposals } = await import ( '@/lib/proposal/data/sanity' )
110103 const { proposals : existingProposals } = await getProposals ( {
111104 speakerId : session . speaker . _id ,
@@ -133,69 +126,14 @@ export default async function ProposalPage({
133126 }
134127 }
135128
136- try {
137- if ( proposalId ) {
138- const { proposal : fetchedProposal , proposalError } =
139- await getProposalSanity ( {
140- id : proposalId ,
141- speakerId : session . speaker . _id ,
142- isOrganizer : false ,
143- } )
144- if ( proposalError ) {
145- console . error ( 'Error loading proposal:' , proposalError )
146- loadingError = {
147- type : 'Server Error' ,
148- message : 'Failed to load proposal.' ,
149- }
150- } else if ( ! fetchedProposal ) {
151- loadingError = { type : 'Not Found' , message : 'Proposal not found.' }
152- } else {
153- proposal = fetchedProposal
154- proposalStatus = ( fetchedProposal as ProposalExisting ) . status
155- if (
156- fetchedProposal . speakers &&
157- Array . isArray ( fetchedProposal . speakers ) &&
158- fetchedProposal . speakers . length > 0
159- ) {
160- const currentUserSpeakerData = fetchedProposal . speakers . find (
161- ( s ) : s is Speaker =>
162- typeof s === 'object' &&
163- s !== null &&
164- '_id' in s &&
165- s . _id === session . speaker . _id ,
166- )
167-
168- if ( currentUserSpeakerData ) {
169- speaker = currentUserSpeakerData
170- } else if ( currentUserSpeaker ) {
171- speaker = currentUserSpeaker
172- }
173- }
174- }
175- } else if ( currentUserSpeaker ) {
176- speaker = currentUserSpeaker
177- }
178- } catch ( error ) {
179- console . error ( 'Error loading data:' , error )
180- loadingError = { type : 'Server Error' , message : 'Failed to load data.' }
181- }
182-
183129 return (
184130 < div className = "mx-auto max-w-7xl" >
185131 < div className = "mb-6" >
186132 < h1 className = "font-space-grotesk text-2xl font-bold tracking-tight text-gray-900 dark:text-white" >
187- { proposalId
188- ? proposalStatus === Status . draft
189- ? 'Edit Draft'
190- : 'Edit Proposal'
191- : 'Submit Presentation' }
133+ Submit Presentation
192134 </ h1 >
193135 < p className = "mt-1 text-sm text-gray-600 dark:text-gray-400" >
194- { proposalId
195- ? proposalStatus === Status . draft
196- ? 'Continue working on your draft. Save your progress or submit when ready.'
197- : 'Update your proposal details'
198- : 'Become our next speaker and share your knowledge with the community!' }
136+ Become our next speaker and share your knowledge with the community!
199137 </ p >
200138 </ div >
201139
@@ -235,15 +173,13 @@ export default async function ProposalPage({
235173 < div className = "flex-1" >
236174 < div className = "rounded-lg border border-gray-200 bg-white p-6 shadow-sm dark:border-gray-700 dark:bg-gray-800" >
237175 < ProposalForm
238- key = { proposalId || ' new' }
176+ key = " new"
239177 initialProposal = { proposal }
240178 initialSpeaker = { speaker }
241- proposalId = { proposalId }
242179 userEmail = { session . speaker . email }
243180 conference = { conference }
244181 allowedFormats = { conference . formats }
245182 currentUserSpeaker = { currentUserSpeaker }
246- initialStatus = { proposalStatus }
247183 />
248184 </ div >
249185 </ div >
0 commit comments