overleaf/services/web/frontend/js/shared/hooks/use-contact-us-modal.tsx
Tim Down 34fc43d59a Merge pull request #19126 from overleaf/td-bs5-contact-modal-react
React version of Contact Us modal

GitOrigin-RevId: 0bef3095f36daa88afdc6172a5531ed11e892047
2024-08-14 08:04:37 +00:00

36 lines
1.1 KiB
TypeScript

import importOverleafModules from '../../../macros/import-overleaf-module.macro'
import { JSXElementConstructor, useCallback, useState } from 'react'
import { HelpSuggestionSearchProvider } from '../../../../modules/support/frontend/js/context/help-suggestion-search-context'
const [contactUsModalModules] = importOverleafModules('contactUsModal')
const ContactUsModal: JSXElementConstructor<{
show: boolean
handleHide: () => void
autofillProjectUrl: boolean
}> = contactUsModalModules?.import.default
export const useContactUsModal = (options = { autofillProjectUrl: true }) => {
const [show, setShow] = useState(false)
const hideModal = useCallback((event?: Event) => {
event?.preventDefault()
setShow(false)
}, [])
const showModal = useCallback((event?: Event) => {
event?.preventDefault()
setShow(true)
}, [])
const modal = ContactUsModal && (
<HelpSuggestionSearchProvider>
<ContactUsModal
show={show}
handleHide={hideModal}
autofillProjectUrl={options.autofillProjectUrl}
/>
</HelpSuggestionSearchProvider>
)
return { modal, hideModal, showModal }
}