mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-02-16 20:13:49 +00:00
Refactor: Organize api requests by type and remove toastContext
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
import ToastContext from '@/contexts/ToastContext';
|
||||
import { FC, ReactNode } from 'react';
|
||||
import toast, { Toast, Toaster, resolveValue } from 'react-hot-toast';
|
||||
import { FaTimes } from 'react-icons/fa';
|
||||
@@ -22,29 +21,31 @@ const toastToClassName = (toastType: Toast['type']) => {
|
||||
|
||||
const CustomToast: FC<{ children: ReactNode }> = ({ children }) => {
|
||||
return (
|
||||
<ToastContext.Provider value={{ toast }}>
|
||||
<>
|
||||
<Toaster>
|
||||
{(t) => {
|
||||
const alertType = toastToClassName(t.type);
|
||||
return (
|
||||
<div className="flex w-full items-center justify-center">
|
||||
<div
|
||||
className={`alert ${alertType} w-11/12 flex-row items-center py-[0.5rem] shadow-lg animate-in fade-in duration-200 lg:w-6/12`}
|
||||
>
|
||||
<div>{resolveValue(t.message, t)}</div>
|
||||
<button
|
||||
className="btn-ghost btn-circle btn"
|
||||
onClick={() => toast.dismiss(t.id)}
|
||||
>
|
||||
<FaTimes />
|
||||
</button>
|
||||
</div>
|
||||
<div
|
||||
className={`alert ${alertType} w-11/12 flex-row items-center shadow-lg animate-in fade-in duration-200 lg:w-6/12`}
|
||||
>
|
||||
<p>{resolveValue(t.message, t)}</p>
|
||||
{t.type !== 'loading' && (
|
||||
<div>
|
||||
<button
|
||||
className="btn-ghost btn-xs btn-circle btn"
|
||||
onClick={() => toast.dismiss(t.id)}
|
||||
>
|
||||
<FaTimes />
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}}
|
||||
</Toaster>
|
||||
{children}
|
||||
</ToastContext.Provider>
|
||||
</>
|
||||
);
|
||||
};
|
||||
export default CustomToast;
|
||||
|
||||
Reference in New Issue
Block a user