@@ -30,6 +30,7 @@ import Image from "next/image";
3030import { config } from "@community/config" ;
3131import { buildPublicUrl } from "@community/lib-client/uploads/client" ;
3232import { cn } from "@community/lib-shared/utils" ;
33+ import { useConfirmationAlert } from "@/modules/shared/components/ConfirmationAlertProvider" ;
3334
3435interface Photo {
3536 id : string ;
@@ -93,6 +94,7 @@ export default function EventPhotosPage() {
9394 const router = useRouter ( ) ;
9495 const { data : session } = useSession ( ) ;
9596 const queryClient = useQueryClient ( ) ;
97+ const { confirm } = useConfirmationAlert ( ) ;
9698
9799 const eventId = params . eventId as string ;
98100 const [ activeTab , setActiveTab ] = useState < "all" | "my" > ( "all" ) ;
@@ -562,33 +564,39 @@ export default function EventPhotosPage() {
562564
563565 // Handle photo delete
564566 const handleDeletePhoto = async ( photoId : string ) => {
565- if ( ! confirm ( "确定要删除这张照片吗?" ) ) return ;
566-
567- try {
568- const res = await fetch ( `/api/events/${ eventId } /photos` , {
569- method : "DELETE" ,
570- headers : { "Content-Type" : "application/json" } ,
571- body : JSON . stringify ( { photoId } ) ,
572- } ) ;
567+ confirm ( {
568+ title : "确定要删除这张照片吗?" ,
569+ destructive : true ,
570+ onConfirm : async ( ) => {
571+ try {
572+ const res = await fetch ( `/api/events/${ eventId } /photos` , {
573+ method : "DELETE" ,
574+ headers : { "Content-Type" : "application/json" } ,
575+ body : JSON . stringify ( { photoId } ) ,
576+ } ) ;
573577
574- if ( ! res . ok ) {
575- const errorData = await res . json ( ) . catch ( ( ) => ( { } ) ) ;
576- throw new Error ( errorData . error || "删除失败" ) ;
577- }
578+ if ( ! res . ok ) {
579+ const errorData = await res . json ( ) . catch ( ( ) => ( { } ) ) ;
580+ throw new Error ( errorData . error || "删除失败" ) ;
581+ }
578582
579- toast . success ( "照片已删除" ) ;
580- queryClient . invalidateQueries ( {
581- queryKey : [ "event-photos" , eventId ] ,
582- } ) ;
583- queryClient . invalidateQueries ( {
584- queryKey : [ "my-event-photos" , eventId ] ,
585- } ) ;
586- } catch ( error ) {
587- console . error ( "Delete error:" , error ) ;
588- toast . error (
589- error instanceof Error ? error . message : "删除失败,请重试" ,
590- ) ;
591- }
583+ toast . success ( "照片已删除" ) ;
584+ queryClient . invalidateQueries ( {
585+ queryKey : [ "event-photos" , eventId ] ,
586+ } ) ;
587+ queryClient . invalidateQueries ( {
588+ queryKey : [ "my-event-photos" , eventId ] ,
589+ } ) ;
590+ } catch ( error ) {
591+ console . error ( "Delete error:" , error ) ;
592+ toast . error (
593+ error instanceof Error
594+ ? error . message
595+ : "删除失败,请重试" ,
596+ ) ;
597+ }
598+ } ,
599+ } ) ;
592600 } ;
593601
594602 const handleBatchDelete = async ( ) => {
@@ -597,40 +605,54 @@ export default function EventPhotosPage() {
597605 toast . error ( "请先选择要删除的照片" ) ;
598606 return ;
599607 }
600- if ( ! confirm ( `确定删除选中的 ${ ids . length } 张照片吗?` ) ) return ;
601- setIsBatchDeleting ( true ) ;
608+ confirm ( {
609+ title : `确定删除选中的 ${ ids . length } 张照片吗?` ,
610+ destructive : true ,
611+ onConfirm : async ( ) => {
612+ setIsBatchDeleting ( true ) ;
602613
603- try {
604- await Promise . all (
605- ids . map ( async ( photoId ) => {
606- const res = await fetch ( `/api/events/${ eventId } /photos` , {
607- method : "DELETE" ,
608- headers : { "Content-Type" : "application/json" } ,
609- body : JSON . stringify ( { photoId } ) ,
610- } ) ;
611- if ( ! res . ok ) {
612- const errorData = await res . json ( ) . catch ( ( ) => ( { } ) ) ;
613- throw new Error ( errorData . error || "删除失败" ) ;
614- }
615- } ) ,
616- ) ;
614+ try {
615+ await Promise . all (
616+ ids . map ( async ( photoId ) => {
617+ const res = await fetch (
618+ `/api/events/${ eventId } /photos` ,
619+ {
620+ method : "DELETE" ,
621+ headers : {
622+ "Content-Type" : "application/json" ,
623+ } ,
624+ body : JSON . stringify ( { photoId } ) ,
625+ } ,
626+ ) ;
627+ if ( ! res . ok ) {
628+ const errorData = await res
629+ . json ( )
630+ . catch ( ( ) => ( { } ) ) ;
631+ throw new Error ( errorData . error || "删除失败" ) ;
632+ }
633+ } ) ,
634+ ) ;
617635
618- toast . success ( `已删除 ${ ids . length } 张照片` ) ;
619- clearSelection ( ) ;
620- queryClient . invalidateQueries ( {
621- queryKey : [ "event-photos" , eventId ] ,
622- } ) ;
623- queryClient . invalidateQueries ( {
624- queryKey : [ "my-event-photos" , eventId ] ,
625- } ) ;
626- } catch ( error ) {
627- console . error ( "Batch delete error:" , error ) ;
628- toast . error (
629- error instanceof Error ? error . message : "删除失败,请重试" ,
630- ) ;
631- } finally {
632- setIsBatchDeleting ( false ) ;
633- }
636+ toast . success ( `已删除 ${ ids . length } 张照片` ) ;
637+ clearSelection ( ) ;
638+ queryClient . invalidateQueries ( {
639+ queryKey : [ "event-photos" , eventId ] ,
640+ } ) ;
641+ queryClient . invalidateQueries ( {
642+ queryKey : [ "my-event-photos" , eventId ] ,
643+ } ) ;
644+ } catch ( error ) {
645+ console . error ( "Batch delete error:" , error ) ;
646+ toast . error (
647+ error instanceof Error
648+ ? error . message
649+ : "删除失败,请重试" ,
650+ ) ;
651+ } finally {
652+ setIsBatchDeleting ( false ) ;
653+ }
654+ } ,
655+ } ) ;
634656 } ;
635657
636658 // Share album
0 commit comments