diff --git a/src/components/Alert.jsx b/src/components/Alert.jsx
new file mode 100644
index 0000000..efd5d50
--- /dev/null
+++ b/src/components/Alert.jsx
@@ -0,0 +1,25 @@
+import PropTypes from "prop-types";
+import { Alert as _Alert } from "@material-tailwind/react";
+
+import { DEFAULT_CONFIG } from "../hooks";
+
+export function Alert({ notifyConfig = DEFAULT_CONFIG }) {
+ return (
+ <_Alert
+ open={notifyConfig.message !== ""}
+ animate={{
+ mount: { y: 0 },
+ unmount: { y: -100 },
+ }}
+ variant={notifyConfig.config.variant}
+ color={notifyConfig.config.color}
+ className="fixed top-5 right-10 min-w-[350px] w-fit"
+ >
+ {notifyConfig.message}
+
+ );
+}
+
+Alert.propTypes = {
+ notifyConfig: PropTypes.object,
+};
diff --git a/src/components/index.js b/src/components/index.js
new file mode 100644
index 0000000..b8e17a0
--- /dev/null
+++ b/src/components/index.js
@@ -0,0 +1 @@
+export * from "./Alert";
diff --git a/src/hooks/index.js b/src/hooks/index.js
new file mode 100644
index 0000000..9f215cb
--- /dev/null
+++ b/src/hooks/index.js
@@ -0,0 +1 @@
+export * from "./useNotify";
diff --git a/src/hooks/useNotify.js b/src/hooks/useNotify.js
new file mode 100644
index 0000000..0a97860
--- /dev/null
+++ b/src/hooks/useNotify.js
@@ -0,0 +1,30 @@
+import { useState } from "react";
+
+export const DEFAULT_CONFIG = {
+ message: "",
+ config: {
+ variant: "ghost",
+ color: "gray",
+ duration: 2500,
+ },
+};
+
+export function useNotify() {
+ const [notifyConfig, setNotifyConfig] = useState(DEFAULT_CONFIG);
+
+ const clearNotification = async () => {
+ setTimeout(() => {
+ setNotifyConfig(DEFAULT_CONFIG);
+ }, [notifyConfig.config.duration]);
+ };
+
+ const notify = (message, updatedConfig = {}) => {
+ setNotifyConfig({
+ message,
+ config: { ...DEFAULT_CONFIG.config, ...updatedConfig },
+ });
+ clearNotification();
+ };
+
+ return [notify, notifyConfig];
+}
diff --git a/src/pages/login/Login.jsx b/src/pages/login/Login.jsx
index 72888ae..7842628 100644
--- a/src/pages/login/Login.jsx
+++ b/src/pages/login/Login.jsx
@@ -1,18 +1,24 @@
import { GoogleAuthProvider } from "firebase/auth";
import { ManualLoginForm } from "./ManualLoginForm";
+import { Alert } from "../../components";
+
+import { useNotify } from "../../hooks";
+import { useAuth } from "../../security/hooks";
import imageLogin from "../../assets/images/form.jpg";
import googleIcon from "../../assets/images/google.svg";
import formekouLogo from "../../assets/images/formekou.png";
-import { useAuth } from "../../security/hooks";
-
-//TODO: create useNotify() hooks and gen api client to call properly the user
export function Login() {
const authentification = useAuth();
+ const [notify, notifyConfig] = useNotify();
const loginWithGoogle = async () => {
- await authentification.login(GoogleAuthProvider);
+ try {
+ await authentification.login(GoogleAuthProvider);
+ } catch (error) {
+ notify("Oops, An error occured, please try again !!", { color: "red" });
+ }
};
return (
@@ -42,6 +48,7 @@ export function Login() {