Skip to content

Commit d2cf6ae

Browse files
Added toastr (#24)
1 parent 1bde608 commit d2cf6ae

File tree

6 files changed

+65
-0
lines changed

6 files changed

+65
-0
lines changed

components/Toastr.jsx

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
2+
import { toast } from "react-toastify";
3+
import { TOASTR_OPTIONS } from "../constants/toastr";
4+
5+
const ToastrComponent = ({ message }) => {
6+
return (
7+
<div className="flex flex-row items-start justify-start">
8+
<p className="text-medium text-black dark:text-white">{message}</p>
9+
</div>
10+
)
11+
}
12+
13+
const showToastr = message => {
14+
toast( <ToastrComponent message={message}/>, TOASTR_OPTIONS)
15+
}
16+
17+
const isError = e => e && e.stack && e.message;
18+
19+
const showErrorToastr = error => {
20+
const errorMessage = isError(error) ? error.message : error;
21+
toast.error( <ToastrComponent message={errorMessage}/>, TOASTR_OPTIONS)
22+
}
23+
24+
const Toastr = {
25+
success: showToastr,
26+
error: showErrorToastr
27+
}
28+
29+
export default Toastr;

constants/toastr.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { toast, Slide } from "react-toastify";
2+
3+
const TOASTR_OPTIONS = {
4+
position: toast.POSITION.TOP_CENTER,
5+
transition: Slide,
6+
autoClose: 5000,
7+
hideProgressBar: false,
8+
newestOnTop: false,
9+
closeOnClick: true,
10+
rtl: false,
11+
pauseOnFocusLoss: true,
12+
draggable: true,
13+
pauseOnHover: true
14+
};
15+
16+
export { TOASTR_OPTIONS };

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"next": "13.0.6",
2121
"react": "18.2.0",
2222
"react-dom": "18.2.0",
23+
"react-toastify": "^9.1.1",
2324
"sass": "^1.57.1"
2425
},
2526
"devDependencies": {

pages/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { createTheme } from "@uiw/codemirror-themes";
55
import { EditorView } from "@codemirror/view";
66

77
import Head from "next/head";
8+
import { ToastContainer } from 'react-toastify';
89
import Button from "../components/Button";
910

1011
import { CODE_EDITOR_THEME } from "../constants/theme";
@@ -31,6 +32,11 @@ export default function Home() {
3132
</Head>
3233

3334
<main>
35+
<ToastContainer
36+
// @Shreya defining this here instead of TOAST_OPTIONS to make implementing dark mode easier
37+
// Global state pole vekkam ivide
38+
theme="dark"
39+
/>
3440
<p className="text-2xl text-center">JSON STYLE</p>
3541
<div className="space-y-3 flex-col">
3642
<div className="flex space-x-3 h-90">

styles/application.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@
88
// components
99
@import "./components/button";
1010
@import "./components/textarea";
11+
@import "react-toastify/dist/ReactToastify.min.css";

yarn.lock

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -689,6 +689,11 @@ client-only@0.0.1:
689689
resolved "https://registry.yarnpkg.com/client-only/-/client-only-0.0.1.tgz#38bba5d403c41ab150bff64a95c85013cf73bca1"
690690
integrity sha512-IV3Ou0jSMzZrd3pZ48nLkT9DA7Ag1pnPzaiQhpW7c3RbcqqzvzzVu+L8gfqMp/8IM2MQtSiqaCxrrcfu8I8rMA==
691691

692+
clsx@^1.1.1:
693+
version "1.2.1"
694+
resolved "https://registry.yarnpkg.com/clsx/-/clsx-1.2.1.tgz#0ddc4a20a549b59c93a4116bb26f5294ca17dc12"
695+
integrity sha512-EcR6r5a8bj6pu3ycsa/E/cKVGuTgZJZdsyUYHOksG/UHIiKfjxzRxYJpyVBwYaQeOvghal9fcc4PidlgzugAQg==
696+
692697
codemirror@^6.0.0:
693698
version "6.0.1"
694699
resolved "https://registry.yarnpkg.com/codemirror/-/codemirror-6.0.1.tgz#62b91142d45904547ee3e0e0e4c1a79158035a29"
@@ -2003,6 +2008,13 @@ react-is@^16.13.1:
20032008
resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.13.1.tgz#789729a4dc36de2999dc156dd6c1d9c18cea56a4"
20042009
integrity sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ==
20052010

2011+
react-toastify@^9.1.1:
2012+
version "9.1.1"
2013+
resolved "https://registry.yarnpkg.com/react-toastify/-/react-toastify-9.1.1.tgz#9280caea4a13dc1739c350d90660a630807bf10b"
2014+
integrity sha512-pkFCla1z3ve045qvjEmn2xOJOy4ZciwRXm1oMPULVkELi5aJdHCN/FHnuqXq8IwGDLB7PPk2/J6uP9D8ejuiRw==
2015+
dependencies:
2016+
clsx "^1.1.1"
2017+
20062018
react@18.2.0:
20072019
version "18.2.0"
20082020
resolved "https://registry.yarnpkg.com/react/-/react-18.2.0.tgz#555bd98592883255fa00de14f1151a917b5d77d5"

0 commit comments

Comments
 (0)