Skip to content

Commit 3b0e731

Browse files
committed
fix: updated <'ErrorPopup /> so it now blurs background and pops up mid-screen
1 parent d1f272a commit 3b0e731

File tree

1 file changed

+46
-45
lines changed

1 file changed

+46
-45
lines changed
Lines changed: 46 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,73 @@
1-
"use client";
21
import React, { useState, useEffect } from 'react';
3-
import { useDelayedClickListener } from "../../hooks";
42
import { useQuickForm } from "../../state/QuickFormContext";
53
import { quickformtokens } from '../../style/quickFormTokensDefinition';
64

75
type ErrorPopupProps = {
86
readonly message: string;
97
};
108

11-
export const ErrorPopup: React.FC<ErrorPopupProps> = ({ message }: ErrorPopupProps) => {
9+
export const ErrorPopup: React.FC<ErrorPopupProps> = ({ message }) => {
1210
const [isVisible, setIsVisible] = useState(false);
13-
const { dispatch, state } = useQuickForm();
11+
const [opacity, setOpacity] = useState(0);
12+
const { dispatch } = useQuickForm();
1413

15-
/**
16-
* DISCUSS - What cases is there for resetting error and can it be handled in reducer all alone?.
17-
* When an error is shown, upon next answer it can be cleared.
18-
* Possible a dissmis button - but i dont think it should automatically just remove when clicked.
19-
*/
20-
21-
22-
//const resetErrorMessage = () => {
23-
// if (state.errorMsg !== "") {
24-
// dispatch({ type: "SET_ERROR_MSG", msg: "" })
25-
// }
26-
//}
27-
28-
// useDelayedClickListener(resetErrorMessage);
14+
const resetErrorPopup = () => {
15+
dispatch({ type: 'SET_ERROR_MSG', msg: "" });
16+
setIsVisible(false);
17+
setOpacity(0);
18+
}
2919

3020
useEffect(() => {
21+
let timer: NodeJS.Timeout;
3122
if (message) {
3223
setIsVisible(true);
33-
setTimeout(() => setIsVisible(false), 350);
24+
setOpacity(0);
25+
setTimeout(() => setOpacity(1), 10);
26+
27+
timer = setTimeout(() => {
28+
resetErrorPopup();
29+
}, 3000);
30+
} else {
31+
resetErrorPopup();
3432
}
33+
34+
return () => {
35+
clearTimeout(timer);
36+
setOpacity(0);
37+
};
3538
}, [message]);
3639

37-
if (message === "") {
38-
return <></>;
39-
}
40+
if (!isVisible) return null;
4041

41-
const errorStyle: React.CSSProperties = {
42-
alignItems: 'flex-end',
43-
animation: isVisible ? 'slide-up 0.35s linear 1 forwards' : '',
44-
backgroundColor: quickformtokens.error,
45-
borderRadius: '3px',
46-
color: quickformtokens.onError,
47-
display: 'flex',
48-
fontSize: '1.5rem',
49-
marginTop: '15px',
50-
padding: '8px 12px',
51-
width: 'max-content',
52-
};
53-
54-
const mobileErrorStyle: React.CSSProperties = {
55-
...errorStyle,
56-
fontSize: '1.75rem',
57-
marginTop: '22px',
42+
const backdropStyle: React.CSSProperties = {
43+
position: 'fixed',
44+
top: 0,
45+
left: 0,
5846
width: '100%',
47+
height: '100%',
48+
backgroundColor: 'rgba(0, 0, 0, 0.5)',
49+
display: 'flex',
50+
justifyContent: 'center',
51+
alignItems: 'center',
52+
zIndex: 1000,
5953
};
6054

61-
const imgStyle: React.CSSProperties = {
62-
marginRight: '4px',
55+
const toastStyle: React.CSSProperties = {
56+
padding: '20px',
57+
borderRadius: '10px',
58+
backgroundColor: quickformtokens.error,
59+
color: quickformtokens.onError,
60+
fontSize: '16px',
61+
boxShadow: '0 4px 6px rgba(0, 0, 0, 0.1)',
62+
opacity: opacity,
63+
transition: 'opacity 0.5s ease-in',
6364
};
6465

6566
return (
66-
<div style={window.innerWidth <= 599 ? mobileErrorStyle : errorStyle}>
67-
{/* If there's an image you want to include inside the error message */}
68-
{/* <img src="path_to_your_image" alt="Error" style={imgStyle} /> */}
69-
{message}
67+
<div style={backdropStyle} onClick={resetErrorPopup}>
68+
<div style={toastStyle} onClick={(e) => e.stopPropagation()}>
69+
{message}
70+
</div>
7071
</div>
7172
);
7273
};

0 commit comments

Comments
 (0)