refactor: replace inline notification handling with Notification component in LockerStatus

This commit is contained in:
Md Asif 2024-12-24 00:01:29 +05:30
parent f4b7027708
commit dea0047007

View File

@ -9,7 +9,8 @@ import clsx from "clsx";
import Button from "../components/Button"; import Button from "../components/Button";
import { lockerService } from "../services/locker.service"; import { lockerService } from "../services/locker.service";
import { useLoading } from "../hooks/useLoading"; import { useLoading } from "../hooks/useLoading";
import { AnimatePresence, motion } from "motion/react"; import { AnimatePresence } from "motion/react";
import Notification from "../components/Notification";
function LockerStatus() { function LockerStatus() {
const { t } = useTranslation(); const { t } = useTranslation();
@ -93,7 +94,11 @@ function LockerStatus() {
type: "success", type: "success",
}); });
} catch (error) { } catch (error) {
showToast(error.response.data.message, "error"); setNotification({
visible: true,
message: error.message,
type: "error",
});
} finally { } finally {
setIsLoading(false); setIsLoading(false);
} }
@ -130,21 +135,7 @@ function LockerStatus() {
return ( return (
<div> <div>
<AnimatePresence> <AnimatePresence>
{notification.visible && ( {notification.visible && <Notification notification={notification} />}
<motion.div
initial={{ opacity: 0 }}
animate={{ opacity: 1 }}
exit={{ opacity: 0 }}
className={clsx(
"p-4 mb-8 font-body text-center text-xl rounded-2xl flex items-center justify-center gap-2",
notification.type === "error"
? "bg-error-surface text-error"
: "bg-success-surface text-success"
)}
>
{notification.message}
</motion.div>
)}
</AnimatePresence> </AnimatePresence>
<div className="relative"> <div className="relative">
{notification.type === "success" && ( {notification.type === "success" && (