-
Notifications
You must be signed in to change notification settings - Fork 13
Add iframe fixes #504
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add iframe fixes #504
Changes from all commits
2a2b479
1674a18
e3485dc
e90adcf
ee82201
ac2fb73
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,21 @@ | ||
import { useEffect } from 'react' | ||
import { useEffect, useState } from 'react' | ||
import Modal from '../Modal' | ||
|
||
export type IFrameWrapperProps = { | ||
src: string | ||
visible: boolean | ||
onClose: () => void | ||
closeConfirmMessage?: string | ||
} | ||
|
||
const IframeWrapper = ({ | ||
src, | ||
style, | ||
visible, | ||
onClose, | ||
}: { | ||
src: string | ||
style?: React.CSSProperties | ||
visible: boolean | ||
onClose: () => void | ||
}) => { | ||
closeConfirmMessage | ||
}: IFrameWrapperProps) => { | ||
const enableConfirmationPrompt = closeConfirmMessage !== undefined | ||
const [showCloseConfirmMessage, setShowCloseConfirmMessage] = useState(false) | ||
useEffect(() => { | ||
const handleMessage = (event: MessageEvent) => { | ||
const expectedOrigin = window.location.origin | ||
|
@@ -28,11 +32,39 @@ const IframeWrapper = ({ | |
} | ||
}, [onClose]) | ||
|
||
const areYouSurePromptRow = showCloseConfirmMessage ? ( | ||
<div className='flex flex-col text-center sm:text-left sm:flex-row justify-between sm:items-center gap-4 p-2 sm:p-0 w-full'> | ||
<p className="text-sm ml-1">{closeConfirmMessage}</p> | ||
<div className="flex flex-row items-center gap-2"> | ||
<button className='btn-stroke w-full' onClick={() => { | ||
setShowCloseConfirmMessage(false) | ||
}}>Cancel</button> | ||
<button className='btn-purple w-full' onClick={() => { | ||
onClose() | ||
setShowCloseConfirmMessage(false) | ||
}}>Close</button> | ||
</div> | ||
</div> | ||
) : <button className="btn-purple w-full rounded-none" onClick={() => { | ||
setShowCloseConfirmMessage(true) | ||
}}> | ||
CLOSE | ||
</button> | ||
|
||
return ( | ||
<Modal | ||
visible={visible} | ||
onClose={onClose} | ||
classWrap="w-full max-w-2xl border-none sm:border" | ||
onClose={() => { | ||
/** | ||
* If the confirmation prompt is disabled, close the modal directly | ||
*/ | ||
if (!enableConfirmationPrompt) { | ||
onClose() | ||
return | ||
} | ||
setShowCloseConfirmMessage(true) | ||
}} | ||
classWrap="h-[75%] sm:h-full w-full sm:min-w-[600px] border-none" | ||
classOverlay="bg-black bg-opacity-50" | ||
video={false} | ||
/** | ||
|
@@ -42,25 +74,29 @@ const IframeWrapper = ({ | |
className="z-[1000001]" | ||
classButtonClose="hidden" | ||
> | ||
<div className="flex flex-col gap-2 p-0 sm:p-5"> | ||
<div className="flex flex-col h-full gap-2 p-0 sm:p-2"> | ||
<div className="w-full sm:hidden"> | ||
<button className="btn-purple w-full rounded-none" onClick={onClose}> | ||
{enableConfirmationPrompt ? areYouSurePromptRow : <button className="btn-purple w-full rounded-none" onClick={() => { | ||
onClose() | ||
}}> | ||
CLOSE | ||
</button> | ||
</button>} | ||
</div> | ||
<div className="h-[550px] overflow-hidden rounded-sm sm:h-[500px] sm:border sm:border-black"> | ||
<div className="overflow-hidden h-full"> | ||
<iframe | ||
src={src} | ||
allow="camera;" | ||
style={{ ...style, width: '100%', height: '100%', border: 'none' }} | ||
style={{ width: '100%', height: '100%', border: 'none' }} | ||
className="rounded-md" | ||
sandbox="allow-same-origin allow-scripts allow-forms allow-popups allow-modals allow-top-navigation-by-user-activation" | ||
/> | ||
</div> | ||
<div className="hidden w-full sm:flex"> | ||
<button className="btn-purple w-full" onClick={onClose}> | ||
Close | ||
</button> | ||
<div className="hidden sm:flex flex-row w-full items-center"> | ||
{enableConfirmationPrompt ? areYouSurePromptRow : <button className="btn-purple w-full rounded-none" onClick={() => { | ||
onClose() | ||
}}> | ||
CLOSE | ||
</button>} | ||
Comment on lines
+77
to
+99
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Consider consolidating mobile and desktop view logic. The close button implementation is duplicated between mobile and desktop views. Consider using CSS to handle the visibility instead of duplicating the JSX. -<div className="w-full sm:hidden">
- {enableConfirmationPrompt ? areYouSurePromptRow : <button className="btn-purple w-full rounded-none" onClick={() => {
- onClose()
- }}>
- CLOSE
- </button>}
-</div>
-// ... iframe ...
-<div className="hidden sm:flex flex-row w-full items-center">
- {enableConfirmationPrompt ? areYouSurePromptRow : <button className="btn-purple w-full rounded-none" onClick={() => {
- onClose()
- }}>
- CLOSE
- </button>}
-</div>
+<div className="w-full sm:hidden">
+ <CloseButtonSection
+ enableConfirmationPrompt={enableConfirmationPrompt}
+ areYouSurePromptRow={areYouSurePromptRow}
+ onClose={onClose}
+ />
+</div>
+// ... iframe ...
+<div className="hidden sm:flex flex-row w-full items-center">
+ <CloseButtonSection
+ enableConfirmationPrompt={enableConfirmationPrompt}
+ areYouSurePromptRow={areYouSurePromptRow}
+ onClose={onClose}
+ />
+</div>
|
||
</div> | ||
</div> | ||
</Modal> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Consider extracting close button to reduce duplication.
The close button implementation is repeated multiple times with similar logic. Consider extracting it into a reusable component.