Skip to content

Commit fce0d5a

Browse files
committed
fix: Restore approval API call in client share page
The approval API call was lost when ProjectInfo was extracted from VideoPlayer in 0.8.4. The handleApprove function was only calling the onApprove callback (fetchProjectData) without making the actual POST request to /api/projects/[id]/approve. Changes: - Add projectId prop to ProjectInfo component - Restore fetch call to /api/projects/[id]/approve in handleApprove - Pass projectId to ProjectInfo in all usages
1 parent 7dba3f6 commit fce0d5a

4 files changed

Lines changed: 31 additions & 4 deletions

File tree

src/app/admin/projects/[id]/share/page.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,7 @@ export default function AdminSharePage() {
505505
selectedVideo={videoState.selectedVideo}
506506
displayLabel={videoState.displayLabel}
507507
isVideoApproved={videoState.isVideoApproved}
508+
projectId={project.id}
508509
projectTitle={project.title}
509510
projectDescription={project.description}
510511
clientName={project.clientName}

src/app/share/[token]/SharePageClient.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -862,6 +862,7 @@ export default function SharePageClient({ token }: SharePageClientProps) {
862862
selectedVideo={videoState.selectedVideo}
863863
displayLabel={videoState.displayLabel}
864864
isVideoApproved={videoState.isVideoApproved}
865+
projectId={project.id}
865866
projectTitle={project.title}
866867
projectDescription={project.description}
867868
clientName={project.clientName}

src/components/ProjectInfo.tsx

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ interface ProjectInfoProps {
2121
selectedVideo: Video & { name?: string; approved?: boolean; downloadUrl?: string; cleanPreview720Path?: string | null; cleanPreview1080Path?: string | null }
2222
displayLabel: string
2323
isVideoApproved: boolean
24+
projectId: string
2425
projectTitle?: string
2526
projectDescription?: string
2627
clientName?: string
@@ -44,6 +45,7 @@ export default function ProjectInfo({
4445
selectedVideo,
4546
displayLabel,
4647
isVideoApproved,
48+
projectId,
4749
projectTitle,
4850
projectDescription,
4951
clientName,
@@ -131,13 +133,35 @@ export default function ProjectInfo({
131133
}
132134

133135
const handleApprove = async () => {
134-
if (!onApprove) return
135-
136136
setLoading(true)
137+
138+
const authHeaders = buildAuthHeaders(shareToken)
139+
137140
try {
138-
await onApprove()
141+
const response = await fetch(`/api/projects/${projectId}/approve`, {
142+
method: 'POST',
143+
headers: { 'Content-Type': 'application/json', ...authHeaders },
144+
body: JSON.stringify({
145+
selectedVideoId: selectedVideo.id,
146+
}),
147+
})
148+
149+
if (!response.ok) {
150+
const errorData = await response.json()
151+
throw new Error(errorData.error || 'Failed to approve project')
152+
}
153+
154+
// Store the current video group name in sessionStorage to restore after reload
155+
if (activeVideoName) {
156+
sessionStorage.setItem('approvedVideoName', activeVideoName)
157+
}
158+
159+
// Call the optional callback if provided (for parent component to refresh data)
160+
if (onApprove) {
161+
await onApprove()
162+
}
139163
} catch (error) {
140-
alert('Failed to approve project')
164+
alert(error instanceof Error ? error.message : 'Failed to approve project')
141165
} finally {
142166
setLoading(false)
143167
setShowApprovalConfirm(false)

src/components/VideoPlayer.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,7 @@ export default function VideoPlayer({
750750
selectedVideo={selectedVideo}
751751
displayLabel={displayLabel}
752752
isVideoApproved={isVideoApproved}
753+
projectId={projectId}
753754
projectTitle={projectTitle}
754755
projectDescription={projectDescription}
755756
clientName={clientName}

0 commit comments

Comments
 (0)