Skip to content

Commit f140f69

Browse files
authored
feat(frontend): add toast system (#34)
* build(frontend): add toast system This commit introduces the toast system which can be used across all pages by a function. Fixes #27 * feat(frontend): add responsive toast message This commit introduces responsive toast message for better user experience on all devices. Fixes #27
1 parent 9a9cd16 commit f140f69

File tree

8 files changed

+202
-15
lines changed

8 files changed

+202
-15
lines changed

package-lock.json

Lines changed: 24 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
"lottie-react": "^2.4.1",
2121
"react": "^19.1.0",
2222
"react-dom": "^19.1.0",
23-
"react-router-dom": "^7.6.0"
23+
"react-router-dom": "^7.6.0",
24+
"react-toastify": "^11.0.5"
2425
},
2526
"lint-staged": {
2627
"src/**/*.{ts,html}": [

src/App.jsx

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,31 @@ import MainLayout from "./layouts/MainLayout.jsx";
99
import Preloader from "./pages/Preloader/Preloader";
1010
import ProfilePage from "./pages/Profile/ProfilePage.jsx";
1111
import PrivateRoutesWrapper from "./components/ProtectedRoutes/PrivateRoutesWrapper.jsx";
12+
import { ToastContainer } from "react-toastify";
13+
import 'react-toastify/dist/ReactToastify.css'
1214

1315
function App() {
1416
return (
15-
<Routes>
16-
<Route element={<MainLayout />}>
17-
<Route path="/" element={<Landingpage />} />
18-
<Route path="/login" element={<Login />} />
19-
<Route element={<PrivateRoutesWrapper />}>
20-
<Route path="/home" element={<Home />} />
21-
<Route path="/profile" element={<ProfilePage />} />
22-
<Route path="/preloader" element={<Preloader />} />
23-
{/* Add more protected routes here */}
17+
<>
18+
<ToastContainer />
19+
20+
<Routes>
21+
<Route element={<MainLayout />}>
22+
<Route path="/" element={<Landingpage />} />
23+
<Route path="/login" element={<Login />} />
24+
<Route element={<PrivateRoutesWrapper />}>
25+
<Route path="/home" element={<Home />} />
26+
<Route path="/profile" element={<ProfilePage />} />
27+
<Route path="/preloader" element={<Preloader />} />
28+
{/* Add more protected routes here */}
29+
</Route>
30+
<Route path="/callback" element={<Callback />} />
2431
</Route>
25-
<Route path="/callback" element={<Callback />} />
26-
</Route>
2732

2833

29-
<Route path="*" element={<NotFound />} />
30-
</Routes>
34+
<Route path="*" element={<NotFound />} />
35+
</Routes>
36+
</>
3137
);
3238
}
3339

Lines changed: 11 additions & 0 deletions
Loading
Lines changed: 11 additions & 0 deletions
Loading
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
.Toastify__toast {
2+
background: transparent !important;
3+
padding: 0 !important;
4+
width: 0.5vw !important;
5+
height: 0.1vw !important;
6+
display: flex;
7+
justify-content: center;
8+
align-items: center;
9+
position: relative;
10+
text-align: center;
11+
white-space: nowrap;
12+
}
13+
14+
.toast-message {
15+
font-family: 'Poppins';
16+
font-weight: 400;
17+
font-style: 'regular';
18+
font-size: 1.8vw;
19+
white-space: nowrap;
20+
letter-spacing: 2%;
21+
}
22+
23+
.like-toast {
24+
background: #D96C81 !important;
25+
color: #541312 !important;
26+
width: 42vw !important;
27+
height: 1vw !important;
28+
top: 3vw;
29+
border: 0.245rem solid;
30+
opacity: 90%;
31+
box-shadow: 0px 0.8vw 0.8vw #731d1c4f !important;
32+
display: flex;
33+
border-color: #ffffff;
34+
border-bottom-color: #999999;
35+
border-radius: 78.65px !important;
36+
padding-top: 1.5vw;
37+
padding-right: 8vw;
38+
padding-bottom: 1.5vw;
39+
padding-left: 8vw;
40+
justify-content: center;
41+
align-items: center;
42+
position: relative;
43+
text-align: center;
44+
white-space: nowrap;
45+
}
46+
47+
.toast-icon.left,
48+
.toast-icon.right {
49+
width: 7vw;
50+
height: 10vw;
51+
position: absolute;
52+
top: 50%;
53+
transform: translateY(-50%);
54+
opacity: 0;
55+
animation: fadeIn 0.6s ease forwards 0.4s;
56+
z-index: 0;
57+
}
58+
59+
.toast-icon.left {
60+
left: -3.5vw;
61+
}
62+
63+
.toast-icon.right {
64+
right: -3.5vw;
65+
66+
}
67+
68+
@keyframes fadeIn {
69+
from {
70+
opacity: 0;
71+
transform: translateY(-50%) scale(0.8);
72+
}
73+
to {
74+
opacity: 1;
75+
transform: translateY(-50%) scale(1);
76+
}
77+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import React, { useEffect, useState } from "react";
2+
import './ToastContent.css';
3+
import heartLeftIcon from '../../assets/Toast/Like/heart_left.svg';
4+
import heartRightIcon from '../../assets/Toast/Like/heart_right.svg';
5+
6+
const ToastTemplate = {
7+
like: {
8+
className: 'like-toast',
9+
leftIcon: heartLeftIcon,
10+
rightIcon: heartRightIcon,
11+
message: "Crush initiated. Let’s hope it’s mutual ✨",
12+
}
13+
// more templates will be added here
14+
}
15+
16+
const ToastContent = ({ type }) => {
17+
const [showIcons, setShowIcons] = useState(false);
18+
const ToastTemplates = ToastTemplate[type];
19+
20+
useEffect(() => {
21+
const timer = setTimeout(() => setShowIcons(true), 400);
22+
return () => clearTimeout(timer);
23+
}, []);
24+
25+
return (
26+
<div className={`toast-content ${ToastTemplates.className}`}>
27+
{showIcons && <img src={ToastTemplates.leftIcon} className="toast-icon left" />}
28+
<p className="toast-message">{ToastTemplates.message}</p>
29+
{showIcons && <img src={ToastTemplates.rightIcon} className="toast-icon right" />}
30+
</div>
31+
);
32+
33+
};
34+
35+
export default ToastContent;
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { toast } from 'react-toastify';
2+
import ToastContent from './ToastContent';
3+
4+
const useCustomToast = () => {
5+
const showToast = (type) => {
6+
toast(<ToastContent type={type} />, {
7+
toastClassName: ({type}) => `toast-shell ${type}-toast`,
8+
position: "top-center",
9+
autoClose: 3000,
10+
hideProgressBar: true,
11+
closeOnClick: false,
12+
pauseOnHover: false,
13+
draggable: false,
14+
closeButton: false,
15+
});
16+
17+
18+
};
19+
20+
return { showToast };
21+
};
22+
23+
export default useCustomToast;

0 commit comments

Comments
 (0)