Multi-tenant factory inspection system (SpiFox, Enkid, Alpet): - FastAPI backend with JWT auth, PostgreSQL (asyncpg) - Next.js 16 frontend with App Router, SWR data fetching - Machines CRUD with equipment parts management - Part lifecycle tracking (hours/count/date) with counters - Partial unique index for soft-delete support - 24 pytest tests passing, E2E verified Co-Authored-By: Claude Opus 4 <noreply@anthropic.com>
50 lines
1.2 KiB
TypeScript
50 lines
1.2 KiB
TypeScript
'use client';
|
|
|
|
import React, { useEffect, useState } from 'react';
|
|
|
|
export type ToastType = 'success' | 'error' | 'info';
|
|
|
|
export interface ToastProps {
|
|
id: string;
|
|
message: string;
|
|
type: ToastType;
|
|
duration?: number;
|
|
onClose: (id: string) => void;
|
|
}
|
|
|
|
export const Toast: React.FC<ToastProps> = ({ id, message, type, duration = 3000, onClose }) => {
|
|
const [isExiting, setIsExiting] = useState(false);
|
|
|
|
useEffect(() => {
|
|
if (duration > 0) {
|
|
const timer = setTimeout(() => {
|
|
handleClose();
|
|
}, duration);
|
|
return () => clearTimeout(timer);
|
|
}
|
|
}, [duration]);
|
|
|
|
const handleClose = () => {
|
|
setIsExiting(true);
|
|
setTimeout(() => {
|
|
onClose(id);
|
|
}, 300);
|
|
};
|
|
|
|
const iconMap: Record<ToastType, string> = {
|
|
success: 'check_circle',
|
|
error: 'error',
|
|
info: 'info',
|
|
};
|
|
|
|
return (
|
|
<div className={`toast toast-${type} ${isExiting ? 'toast-exit' : 'toast-enter'}`}>
|
|
<span className="material-symbols-outlined toast-icon">{iconMap[type]}</span>
|
|
<span className="toast-message">{message}</span>
|
|
<button className="toast-close" onClick={handleClose}>
|
|
<span className="material-symbols-outlined">close</span>
|
|
</button>
|
|
</div>
|
|
);
|
|
};
|