Skip to content

Commit

Permalink
Merge pull request #86 from ReCoded-Org/i84-add_notifications
Browse files Browse the repository at this point in the history
feat: notifications added for signin signup and logout
  • Loading branch information
gizemhaspolat authored Aug 28, 2022
2 parents 31508d9 + 93beb80 commit 219fb38
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 25 deletions.
5 changes: 4 additions & 1 deletion public/locales/de/sign.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,8 @@
"university": "Universität",
"confirm-password": "Passwort bestätigen",
"Sign-up-with": "Melden Sie sich an",
"already-have-an-account": "Sie haben bereits ein Konto"
"already-have-an-account": "Sie haben bereits ein Konto",
"succesfully-signed-in-redirecting": "Erfolgreich angemeldet! Weiterleitung...",
"invalid-credentials": "Ungültige Anmeldeinformationen.",
"your-account-has-been-created": "Ihr Konto wurde erstellt!"
}
5 changes: 4 additions & 1 deletion public/locales/en/sign.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,8 @@
"university": "University",
"confirm-password": "Confirm password",
"Sign-up-with": "Sign up with",
"already-have-an-account": "Already Have an account"
"already-have-an-account": "Already Have an account",
"succesfully-signed-in-redirecting": "Successfully signed in! Redirecting...",
"invalid-credentials": "Invalid Credentials.",
"your-account-has-been-created": "Your account has been created!"
}
5 changes: 4 additions & 1 deletion public/locales/tr/sign.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,8 @@
"university": "üniversite",
"confirm-password": "şifreyi Onayla",
"Sign-up-with": "ile kayıt olun",
"already-have-an-account": "zaten hesabınız var mı"
"already-have-an-account": "zaten hesabınız var mı",
"succesfully-signed-in-redirecting": "Başarıyla giriş yaptınız! Yönlendiriliyorsunuz...",
"invalid-credentials": "Geçersiz kimlik bilgileri.",
"your-account-has-been-created": "Hesabınız oluşturuldu!"
}
22 changes: 18 additions & 4 deletions src/components/header/Header.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ import { BiSearchAlt } from "react-icons/bi";
import { IoIosArrowDown } from "react-icons/io";
import { RiUser3Line } from "react-icons/ri";
import { TbWorld } from "react-icons/tb";
import { toast, ToastContainer } from "react-toastify";
import { injectStyle } from "react-toastify/dist/inject-style";

if (typeof window !== "undefined") {
injectStyle();
}

function Header({
products,
Expand Down Expand Up @@ -216,7 +222,7 @@ function Header({

<div
className={`
absolute right-2 z-10 mt-2 flex rounded-md
absolute right-2 z-10 mt-2 flex rounded-md
bg-white
shadow-md ring-1
ring-black ring-opacity-5 focus:outline-none
Expand Down Expand Up @@ -310,7 +316,7 @@ function Header({

<div
className={`
absolute left-1 z-10 mt-2 flex rounded-md
absolute left-1 z-10 mt-2 flex rounded-md
bg-white
shadow-md ring-2
ring-lightpurple ring-opacity-5
Expand Down Expand Up @@ -368,7 +374,14 @@ function Header({
// localStorage.removeItem(
// "token"
// );
alert(t("logout-success"));
toast.success(
t("logout-succes"),
{
position:
toast.POSITION
.TOP_CENTER,
}
);
setTimeout(() => {
Router.push("/");
}, 2000);
Expand Down Expand Up @@ -420,7 +433,7 @@ function Header({
display: block;
width: 100%;
height: auto;
}
.hideLanguage {
display: none;
Expand All @@ -435,6 +448,7 @@ function Header({
display: none;
}
`}</style>
<ToastContainer />
</nav>
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ exports[`renders correctly 1`] = `
aria-labelledby="menu-button"
aria-orientation="vertical"
className="
absolute right-2 z-10 mt-2 flex rounded-md
absolute right-2 z-10 mt-2 flex rounded-md
bg-white
shadow-md ring-1
ring-black ring-opacity-5 focus:outline-none
Expand Down Expand Up @@ -499,7 +499,7 @@ exports[`renders correctly 1`] = `
display: block;
width: 100%;
height: auto;
}
.hideLanguage {
display: none;
Expand All @@ -515,5 +515,8 @@ exports[`renders correctly 1`] = `
}
</style>
<div
className="Toastify"
/>
</nav>
`;
21 changes: 17 additions & 4 deletions src/pages/sign-in.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import {
BsGoogle,
BsTwitter,
} from "react-icons/bs";
import { toast, ToastContainer } from "react-toastify";
import { injectStyle } from "react-toastify/dist/inject-style";

import Button from "@/components/button";
import Input from "@/components/input";
Expand All @@ -20,6 +22,10 @@ import logoOutline from "/public/images/logoOutline.png";
import sunSkyLg from "/public/images/sunSkyLg.png";
import sunSkyOrg from "/public/images/sunSkyOrg.png";

if (typeof window !== "undefined") {
injectStyle();
}

export default function SignInPage() {
const { t } = useTranslation("sign");

Expand Down Expand Up @@ -61,17 +67,23 @@ export default function SignInPage() {
})
.then((res) => {
if (res.status === 200) {
alert("Successfully signed in! Redirecting...");
toast.success(t("successfully-signed-in-redirecting"), {
position: toast.POSITION.TOP_CENTER,
});

// setTimeout(() => {
// Router.push("/");
// }, 1000);
} else if (res.status === 401) {
alert("Invalid credentials");
toast.error(t("invalid-credentials"), {
position: toast.POSITION.TOP_CENTER,
});
}
})
.catch((error) => {
console.log(error);
.catch(() => {
toast.error(t("invalid-credentials"), {
position: toast.POSITION.TOP_CENTER,
});
});
};

Expand Down Expand Up @@ -290,6 +302,7 @@ export default function SignInPage() {
</div>
</div>
</div>
<ToastContainer />
</Layout>
</>
);
Expand Down
21 changes: 17 additions & 4 deletions src/pages/sign-up.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,17 @@ import {
BsGoogle,
BsTwitter,
} from "react-icons/bs";
import { toast, ToastContainer } from "react-toastify";
import { injectStyle } from "react-toastify/dist/inject-style";

import Button from "@/components/button";
import Input from "@/components/input";
import Layout from "@/components/layout/Layout";

if (typeof window !== "undefined") {
injectStyle();
}

export default function Signup() {
const { t } = useTranslation("sign");
const [userSignUp, setUserSignUp] = useState({
Expand Down Expand Up @@ -69,18 +75,24 @@ export default function Signup() {
)
.then((res) => {
if (res.status === 201) {
alert("Your account has been created!");
toast.success(t("your-account-has-been-created"), {
position: toast.POSITION.TOP_CENTER,
});
// localStorage.setItem("token", res.headers["token"]);
// localStorage.setItem("user", res.headers.user);
setTimeout(() => {
Router.push("/sign-in");
}, 1000);
} else if (res.status === 400) {
alert("Invalid credentials");
toast.error(t("invalid-credentials"), {
position: toast.POSITION.TOP_CENTER,
});
}
})
.catch((error) => {
console.log(error);
.catch(() => {
toast.error(t("invalid-credentials"), {
position: toast.POSITION.TOP_CENTER,
});
});
};

Expand Down Expand Up @@ -260,6 +272,7 @@ export default function Signup() {
</div>
</div>
</div>
<ToastContainer />
</Layout>
);
}
Expand Down
11 changes: 3 additions & 8 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1508,9 +1508,9 @@
dependencies:
"glob" "7.1.7"

"@next/swc-darwin[email protected]":
"integrity" "sha512-dztDtvfkhUqiqpXvrWVccfGhLe44yQ5tQ7B4tBfnsOR6vxzI9DNPHTlEOgRN9qDqTAcFyPxvg86mn4l8bB9Jcw=="
"resolved" "https://registry.npmjs.org/@next/swc-darwin-x64/-/swc-darwin-x64-12.2.2.tgz"
"@next/swc-win32-x64-msvc@12.2.2":
"integrity" "sha512-2D2iinWUL6xx8D9LYVZ5qi7FP6uLAoWymt8m8aaG2Ld/Ka8/k723fJfiklfuAcwOxfufPJI+nRbT5VcgHGzHAQ=="
"resolved" "https://registry.npmjs.org/@next/swc-win32-x64-msvc/-/swc-win32-x64-msvc-12.2.2.tgz"
"version" "12.2.2"

"@nodelib/[email protected]":
Expand Down Expand Up @@ -4154,11 +4154,6 @@
"resolved" "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz"
"version" "1.0.0"

"fsevents@^2.3.2", "fsevents@~2.3.2":
"integrity" "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA=="
"resolved" "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz"
"version" "2.3.2"

"function-bind@^1.1.1":
"integrity" "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A=="
"resolved" "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz"
Expand Down

0 comments on commit 219fb38

Please sign in to comment.