Skip to content

Commit 850464a

Browse files
Merge pull request #530 from CodeForAfrica/ft/preload-airtable
refactor(ActNowCard): Preload Airtable Embed form
2 parents a5ab86b + 9b7a189 commit 850464a

File tree

1 file changed

+79
-40
lines changed

1 file changed

+79
-40
lines changed

src/components/ActNowCard/UpdateDialog.tsx

Lines changed: 79 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import { Box, Dialog, DialogContent, IconButton } from "@mui/material";
1+
import { Box, Dialog, IconButton } from "@mui/material";
22
import CloseIcon from "@mui/icons-material/Close";
3+
import { useMemo } from "react";
34

45
type UpdateDialogProps = {
56
open: boolean;
@@ -8,53 +9,91 @@ type UpdateDialogProps = {
89
};
910

1011
const UpdateDialog = ({ open, onClose, embedCode }: UpdateDialogProps) => {
12+
const iframeSrc = useMemo(() => {
13+
const match = embedCode.match(/<iframe[^>]*src=["']([^"']+)["']/i);
14+
return match?.[1] ?? "";
15+
}, [embedCode]);
16+
1117
return (
12-
<Dialog
13-
open={open}
14-
onClose={onClose}
15-
scroll="body"
16-
maxWidth="md"
17-
fullWidth
18-
PaperProps={{
19-
sx: {
20-
position: "relative",
21-
borderRadius: 2,
22-
overflow: "hidden",
23-
mx: { xs: 1.5, sm: 0 },
24-
},
25-
}}
26-
>
27-
<IconButton
28-
onClick={onClose}
29-
aria-label="Close update dialog"
30-
sx={{
31-
position: "absolute",
32-
top: 12,
33-
right: 12,
34-
zIndex: 1,
35-
bgcolor: "rgba(255,255,255,0.9)",
36-
boxShadow: "0px 2px 10px rgba(0,0,0,0.15)",
37-
"&:hover": {
38-
bgcolor: "common.white",
18+
<>
19+
<Dialog
20+
open={open}
21+
onClose={onClose}
22+
scroll="body"
23+
maxWidth="md"
24+
fullWidth
25+
keepMounted
26+
disableAutoFocus
27+
disableEnforceFocus
28+
PaperProps={{
29+
sx: {
30+
display: "none",
3931
},
4032
}}
33+
/>
34+
<Box
35+
aria-hidden={!open}
36+
sx={(theme) => ({
37+
position: "fixed",
38+
top: "50%",
39+
left: "50%",
40+
transform: "translate(-50%, -50%)",
41+
width: { xs: "calc(100% - 24px)", sm: "calc(100% - 48px)" },
42+
maxWidth: theme.breakpoints.values.md,
43+
maxHeight: "calc(100% - 48px)",
44+
bgcolor: "common.white",
45+
borderRadius: 2,
46+
boxShadow: "0px 12px 40px rgba(0,0,0,0.2)",
47+
overflow: "hidden",
48+
opacity: open ? 1 : 0,
49+
pointerEvents: open ? "auto" : "none",
50+
transition: "opacity 160ms ease",
51+
zIndex: theme.zIndex.modal + 1,
52+
})}
4153
>
42-
<CloseIcon />
43-
</IconButton>
44-
<DialogContent sx={{ p: 0 }}>
45-
<Box
54+
<IconButton
55+
onClick={onClose}
56+
aria-label="Close update dialog"
4657
sx={{
47-
width: "100%",
48-
"& iframe": {
58+
position: "absolute",
59+
top: 12,
60+
right: 12,
61+
zIndex: 1,
62+
bgcolor: "rgba(255,255,255,0.9)",
63+
boxShadow: "0px 2px 10px rgba(0,0,0,0.15)",
64+
"&:hover": {
65+
bgcolor: "common.white",
66+
},
67+
}}
68+
>
69+
<CloseIcon />
70+
</IconButton>
71+
{iframeSrc ? (
72+
<Box
73+
component="iframe"
74+
title="Update promise form"
75+
src={iframeSrc}
76+
sx={{
4977
width: "100%",
5078
minHeight: { xs: 640, md: 760 },
5179
border: "none",
52-
},
53-
}}
54-
dangerouslySetInnerHTML={{ __html: embedCode }}
55-
/>
56-
</DialogContent>
57-
</Dialog>
80+
}}
81+
/>
82+
) : (
83+
<Box
84+
sx={{
85+
width: "100%",
86+
"& iframe": {
87+
width: "100%",
88+
minHeight: { xs: 640, md: 760 },
89+
border: "none",
90+
},
91+
}}
92+
dangerouslySetInnerHTML={{ __html: embedCode }}
93+
/>
94+
)}
95+
</Box>
96+
</>
5897
);
5998
};
6099

0 commit comments

Comments
 (0)