@@ -33,6 +33,7 @@ import BarChartIcon from '@mui/icons-material/BarChart';
3333import Dialog from '@mui/material/Dialog' ;
3434import DialogTitle from '@mui/material/DialogTitle' ;
3535import DialogContent from '@mui/material/DialogContent' ;
36+ import DialogContentText from '@mui/material/DialogContentText' ;
3637import DialogActions from '@mui/material/DialogActions' ;
3738import TextField from '@mui/material/TextField' ;
3839import Checkbox from '@mui/material/Checkbox' ;
@@ -146,6 +147,7 @@ export default function Forum_Post() {
146147 const [ pollOptions , setPollOptions ] = useState ( [ '' , '' ] ) ;
147148 const [ pollAllowMultiple , setPollAllowMultiple ] = useState ( false ) ;
148149 const [ submittingPoll , setSubmittingPoll ] = useState ( false ) ;
150+ const [ deletePollId , setDeletePollId ] = useState ( null ) ;
149151
150152 const isCreatorOrAdmin = post && auth . user && ( post . creator === auth . user || auth . roles === 'Admin' ) ;
151153
@@ -213,6 +215,31 @@ export default function Forum_Post() {
213215 } ) ;
214216 } ;
215217
218+ const handleDeletePoll = ( pollId ) => {
219+ setDeletePollId ( pollId ) ;
220+ } ;
221+
222+ const handleConfirmDeletePoll = ( ) => {
223+ if ( ! deletePollId ) return ;
224+ const pollId = deletePollId ;
225+ setDeletePollId ( null ) ;
226+
227+ api . delete ( `/forum/poll/delete?poll=${ pollId } ` )
228+ . then ( ( ) => {
229+ alertsManagerRef . current . showAlert ( 'success' , 'Umfrage erfolgreich gelöscht' ) ;
230+ fetchData ( true ) ;
231+ } )
232+ . catch ( error => {
233+ console . error ( "Failed to delete poll" , error ) ;
234+ const status = error . response ?. status || 500 ;
235+ const rawData = error . response ?. data ;
236+ const msg = typeof rawData === 'object'
237+ ? ( rawData . message || rawData . details || JSON . stringify ( rawData ) )
238+ : ( rawData || 'Fehler beim Löschen der Umfrage' ) ;
239+ alertsManagerRef . current . showAlert ( 'error' , `${ status } : ${ msg } ` ) ;
240+ } ) ;
241+ } ;
242+
216243 // Fetch post, answers, and associated event
217244 const fetchData = useCallback ( ( silent = false ) => {
218245 if ( ! silent ) {
@@ -382,7 +409,7 @@ export default function Forum_Post() {
382409 </ AccordionSummary >
383410 < Divider />
384411 < AccordionDetails sx = { { p : 0 } } >
385- < Post post = { post } onUpdate = { ( ) => fetchData ( true ) } onDelete = { ( ) => navigate ( "/Forum/Topic/" + post . topicId ) } />
412+ < Post post = { post } onUpdate = { ( ) => fetchData ( true ) } onDelete = { ( ) => navigate ( "/Forum/Topic/" + post . topicId ) } onAddPoll = { ( ) => setCreatePollOpen ( true ) } />
386413 </ AccordionDetails >
387414 </ Accordion >
388415
@@ -392,27 +419,13 @@ export default function Forum_Post() {
392419 < Grid container spacing = { 3 } >
393420 { post . polls . map ( poll => (
394421 < Grid key = { poll . id } size = { post . polls . length === 1 ? { xs : 12 } : { xs : 12 , md : 6 } } >
395- < PollWidget pollData = { poll } />
422+ < PollWidget pollData = { poll } canDelete = { isCreatorOrAdmin } onDelete = { ( ) => handleDeletePoll ( poll . id ) } />
396423 </ Grid >
397424 ) ) }
398425 </ Grid >
399426 </ Box >
400427 ) }
401428
402- { /* Button to add a new poll */ }
403- { isCreatorOrAdmin && (
404- < Box sx = { { mb : 4 , display : 'flex' , justifyContent : 'flex-start' } } >
405- < Button
406- variant = "outlined"
407- color = "primary"
408- startIcon = { < BarChartIcon /> }
409- onClick = { ( ) => setCreatePollOpen ( true ) }
410- >
411- Umfrage hinzufügen
412- </ Button >
413- </ Box >
414- ) }
415-
416429 { /* Associated Event Details & Attendance */ }
417430 { associatedEvent && (
418431 < Card sx = { { mb : 4 , border : '1px solid rgba(255, 255, 255, 0.08)' , bgcolor : 'rgba(255, 255, 255, 0.02)' , borderRadius : 2 } } >
@@ -422,7 +435,6 @@ export default function Forum_Post() {
422435 < Typography variant = "h6" sx = { { fontWeight : 'bold' } } >
423436 Zugehöriges Event: { associatedEvent . title }
424437 </ Typography >
425- </ Stack >
426438 < Typography variant = "body2" color = "text.secondary" sx = { { mb : 2.5 } } >
427439 Ort: < strong > { associatedEvent . location } </ strong > | Datum: < strong > { ( ( ) => {
428440 if ( ! associatedEvent . eventDate ) return '' ;
@@ -455,6 +467,7 @@ export default function Forum_Post() {
455467 }
456468 } ) ( ) } </ strong >
457469 </ Typography >
470+ </ Stack >
458471
459472 < Grid container spacing = { 2 } sx = { { mt : 2.5 } } >
460473 { /* YES / Zusagen */ }
@@ -465,7 +478,8 @@ export default function Forum_Post() {
465478 p : 2 ,
466479 borderRadius : 2 ,
467480 bgcolor : userStatus === 'YES' ? 'rgba(76, 175, 80, 0.12)' : 'rgba(76, 175, 80, 0.03)' ,
468- border : userStatus === 'YES' ? '2px solid rgba(76, 175, 80, 0.5)' : '1px solid rgba(76, 175, 80, 0.12)' ,
481+ border : '2px solid' ,
482+ borderColor : userStatus === 'YES' ? 'rgba(76, 175, 80, 0.5)' : 'rgba(76, 175, 80, 0.12)' ,
469483 height : '100%' ,
470484 cursor : isLoggedIn ? 'pointer' : 'default' ,
471485 transition : 'all 0.2s ease-in-out' ,
@@ -495,7 +509,8 @@ export default function Forum_Post() {
495509 p : 2 ,
496510 borderRadius : 2 ,
497511 bgcolor : userStatus === 'NO' ? 'rgba(244, 67, 54, 0.12)' : 'rgba(244, 67, 54, 0.03)' ,
498- border : userStatus === 'NO' ? '2px solid rgba(244, 67, 54, 0.5)' : '1px solid rgba(244, 67, 54, 0.12)' ,
512+ border : '2px solid' ,
513+ borderColor : userStatus === 'NO' ? 'rgba(244, 67, 54, 0.5)' : 'rgba(244, 67, 54, 0.12)' ,
499514 height : '100%' ,
500515 cursor : isLoggedIn ? 'pointer' : 'default' ,
501516 transition : 'all 0.2s ease-in-out' ,
@@ -525,7 +540,8 @@ export default function Forum_Post() {
525540 p : 2 ,
526541 borderRadius : 2 ,
527542 bgcolor : userStatus === 'MAYBE' ? 'rgba(255, 152, 0, 0.12)' : 'rgba(255, 152, 0, 0.03)' ,
528- border : userStatus === 'MAYBE' ? '2px solid rgba(255, 152, 0, 0.5)' : '1px solid rgba(255, 152, 0, 0.12)' ,
543+ border : '2px solid' ,
544+ borderColor : userStatus === 'MAYBE' ? 'rgba(255, 152, 0, 0.5)' : 'rgba(255, 152, 0, 0.12)' ,
529545 height : '100%' ,
530546 cursor : isLoggedIn ? 'pointer' : 'default' ,
531547 transition : 'all 0.2s ease-in-out' ,
@@ -549,7 +565,7 @@ export default function Forum_Post() {
549565
550566 { /* NO RESPONSE / Ausstehend */ }
551567 < Grid size = { { xs : 12 , sm : 3 } } >
552- < Box sx = { { p : 2 , borderRadius : 2 , bgcolor : 'rgba(255, 255, 255, 0.02)' , border : '1px solid rgba(255, 255, 255, 0.1)' , height : '100%' } } >
568+ < Box sx = { { p : 2 , borderRadius : 2 , bgcolor : 'rgba(255, 255, 255, 0.02)' , border : '2px solid rgba(255, 255, 255, 0.1)' , height : '100%' } } >
553569 < Typography variant = "subtitle2" sx = { { fontWeight : 'bold' , mb : 1 , color : 'text.primary' } } >
554570 ⚪ Rückmeldung ausstehend ({ associatedEvent . nonRespondents ?. length || 0 } )
555571 </ Typography >
@@ -625,6 +641,42 @@ export default function Forum_Post() {
625641 ) }
626642 </ Grid >
627643
644+ { /* Dialog for confirming poll deletion */ }
645+ < Dialog
646+ open = { deletePollId !== null }
647+ onClose = { ( ) => setDeletePollId ( null ) }
648+ PaperProps = { {
649+ sx : {
650+ bgcolor : 'background.paper' ,
651+ backgroundImage : 'none' ,
652+ border : '1px solid rgba(255,255,255,0.08)' ,
653+ borderRadius : 2 ,
654+ minWidth : 320
655+ }
656+ } }
657+ >
658+ < DialogTitle sx = { { fontWeight : 'bold' , color : 'error.main' } } >
659+ Umfrage löschen
660+ </ DialogTitle >
661+ < DialogContent >
662+ < DialogContentText >
663+ Möchtest du diese Umfrage wirklich unwiderruflich löschen? Alle Stimmen gehen dabei verloren.
664+ </ DialogContentText >
665+ </ DialogContent >
666+ < DialogActions sx = { { p : 2 } } >
667+ < Button onClick = { ( ) => setDeletePollId ( null ) } color = "inherit" >
668+ Abbrechen
669+ </ Button >
670+ < Button
671+ onClick = { handleConfirmDeletePoll }
672+ variant = "contained"
673+ color = "error"
674+ >
675+ Löschen
676+ </ Button >
677+ </ DialogActions >
678+ </ Dialog >
679+
628680 { /* Dialog for creating a poll */ }
629681 < Dialog
630682 open = { createPollOpen }
0 commit comments