Backend modules from tastefully 8bd93d15: core-libs, core-session, api-gateway, mobile-api, services-auth, services-system, services-counter, services-member, services-log, services-email. solvway-admin-portal from babyboo f64d096ea, solvway-customer-portal from tastefully 8bd93d15. Copied as tracked files only. Literal secrets replaced with environment placeholders: - services-email: SMTP_PASSWORD, MAILGUN_API_KEY, SENDGRID_API_KEY, MAILJET_API_KEY, MAILJET_SECRET_KEY (optional, empty default) - services-system: JUMIO_TOKEN, JUMIO_SECRET (optional) - services-auth: USER_AUTH_API_SECRET (required); commented JWT secret removed - core-libs: JWT_TOKEN default removed (required), XXL_JOB_TOKEN default removed, ipgeolocation key read from IPGEOLOCATION_API_KEY - services-system EkycAppConfig: commented Jumio credentials removed Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
78 lines
2.5 KiB
TypeScript
78 lines
2.5 KiB
TypeScript
"use client";
|
|
|
|
import { createContext, useCallback, useContext, useRef, useState, type ReactNode } from "react";
|
|
import { AnimatePresence, motion } from "framer-motion";
|
|
import { CheckCircle2 } from "lucide-react";
|
|
import { useTheme } from "./ThemeContext";
|
|
|
|
interface ToastCtx {
|
|
showToast: (message: string) => void;
|
|
}
|
|
|
|
// Default no-op so useToast() works outside a provider (mirrors ThemeContext /
|
|
// MessagesContext) — keeps components and tests simple.
|
|
const ToastContext = createContext<ToastCtx>({ showToast: () => {} });
|
|
|
|
const AUTO_DISMISS_MS = 4000;
|
|
|
|
export function ToastProvider({ children }: { children: ReactNode }) {
|
|
const { isDark } = useTheme();
|
|
const [message, setMessage] = useState<string | null>(null);
|
|
const timer = useRef<ReturnType<typeof setTimeout> | null>(null);
|
|
|
|
const clear = () => {
|
|
if (timer.current) {
|
|
clearTimeout(timer.current);
|
|
timer.current = null;
|
|
}
|
|
};
|
|
|
|
const dismiss = useCallback(() => {
|
|
clear();
|
|
setMessage(null);
|
|
}, []);
|
|
|
|
const showToast = useCallback((msg: string) => {
|
|
clear();
|
|
setMessage(msg);
|
|
timer.current = setTimeout(() => {
|
|
timer.current = null;
|
|
setMessage(null);
|
|
}, AUTO_DISMISS_MS);
|
|
}, []);
|
|
|
|
return (
|
|
<ToastContext.Provider value={{ showToast }}>
|
|
{children}
|
|
<AnimatePresence>
|
|
{message && (
|
|
<motion.div
|
|
key="toast"
|
|
role="status"
|
|
aria-live="polite"
|
|
onClick={dismiss}
|
|
initial={{ opacity: 0, x: "-50%", y: -16 }}
|
|
animate={{ opacity: 1, x: "-50%", y: 0 }}
|
|
exit={{ opacity: 0, x: "-50%", y: -16 }}
|
|
transition={{ type: "spring", stiffness: 380, damping: 30 }}
|
|
className="fixed z-[100] left-1/2 flex items-center gap-2 px-4 py-3 rounded-2xl text-sm font-semibold text-white cursor-pointer"
|
|
style={{
|
|
top: "calc(env(safe-area-inset-top, 0px) + 1rem)",
|
|
maxWidth: "calc(100vw - 2rem)",
|
|
background: "linear-gradient(135deg, #22c55e 0%, #16a34a 100%)",
|
|
boxShadow: isDark
|
|
? "0 8px 28px rgba(34,197,94,0.4)"
|
|
: "0 8px 24px rgba(34,197,94,0.35)",
|
|
}}
|
|
>
|
|
<CheckCircle2 strokeWidth={2} className="w-4 h-4 shrink-0" />
|
|
<span className="truncate">{message}</span>
|
|
</motion.div>
|
|
)}
|
|
</AnimatePresence>
|
|
</ToastContext.Provider>
|
|
);
|
|
}
|
|
|
|
export const useToast = () => useContext(ToastContext);
|