@@ -3,7 +3,7 @@ import { Event, Faq, FaqCategory } from '../../../types'
33import { useFaq } from '../../../services/hooks/useFaq'
44import { FirestoreQueryLoaderAndErrorDisplay } from '../../../components/FirestoreQueryLoaderAndErrorDisplay'
55import { Box , Button , IconButton , Typography } from '@mui/material'
6- import { ExpandLessSharp , ExpandMore } from '@mui/icons-material'
6+ import { ExpandLessSharp , ExpandMore , PictureAsPdf } from '@mui/icons-material'
77import { LoadingButton } from '@mui/lab'
88import {
99 useFirestoreCollectionMutation ,
@@ -13,6 +13,7 @@ import { collections } from '../../../services/firebase'
1313import { collection } from '@firebase/firestore'
1414import { generateFirestoreId } from '../../../utils/generateFirestoreId'
1515import { FaqCategoryItemContent } from './FaqCategoryItemContent'
16+ import { generateFaqPdf } from '../../../utils/faqPdfGenerator'
1617
1718export type FaqCategoryProps = {
1819 event : Event
@@ -30,6 +31,7 @@ export const FaqCategoryItem = (props: FaqCategoryProps) => {
3031 const deletionMutation = useFirestoreDocumentDeletion (
3132 collection ( collections . faq ( props . event . id ) , categoryId , 'items' )
3233 )
34+ const [ isExporting , setIsExporting ] = useState ( false )
3335
3436 useEffect ( ( ) => {
3537 if ( queryResult . loaded ) {
@@ -73,20 +75,38 @@ export const FaqCategoryItem = (props: FaqCategoryProps) => {
7375 setDidChange ( false )
7476 }
7577
78+ const exportToPdf = async ( ) => {
79+ try {
80+ setIsExporting ( true )
81+ await generateFaqPdf ( props . event , props . category , data )
82+ } catch ( error ) {
83+ console . error ( 'Failed to generate PDF:' , error )
84+ } finally {
85+ setIsExporting ( false )
86+ }
87+ }
88+
7689 return (
7790 < Box width = "100%" mb = { 4 } >
78- < Box display = "flex" >
79- < Typography variant = "h4" justifyContent = "space-between" alignItems = "center" marginBottom = { 1 } >
91+ < Box display = "flex" justifyContent = "space-between" alignItems = "center" >
92+ < Typography variant = "h4" marginBottom = { 1 } >
8093 { props . category . name } ({ data . length } )
94+ </ Typography >
95+ < Box >
8196 < IconButton onClick = { ( ) => setOpen ( ! isOpen ) } >
8297 { isOpen ? < ExpandLessSharp /> : < ExpandMore /> }
8398 </ IconButton >
99+ { isOpen && (
100+ < IconButton onClick = { exportToPdf } title = "Export to PDF" disabled = { isExporting } >
101+ < PictureAsPdf />
102+ </ IconButton >
103+ ) }
84104 { didChange && (
85105 < LoadingButton variant = "contained" onClick = { save } loading = { mutation . isLoading } >
86106 Save
87107 </ LoadingButton >
88108 ) }
89- </ Typography >
109+ </ Box >
90110 </ Box >
91111 { isOpen ? (
92112 < >
0 commit comments