Inner Contradictions error display as snackbar

This commit is contained in:
AG
2025-10-15 07:45:34 +03:00
parent 9096e7db38
commit 3c996ceec6
5 changed files with 19 additions and 11 deletions

View File

@@ -1,11 +1,12 @@
import React, { useState } from 'react';
import React, { useState, useEffect } from 'react';
import { TextField, Button, Box, Typography, Snackbar, Alert } from '@mui/material';
interface DesireFormProps {
onSubmit: (desires: { wants: string[], accepts: string[], noGoes: string[], afraidToAsk: string }) => void;
externalError?: string | null;
}
const DesireForm: React.FC<DesireFormProps> = ({ onSubmit }) => {
const DesireForm: React.FC<DesireFormProps> = ({ onSubmit, externalError }) => {
const [wants, setWants] = useState('');
const [accepts, setAccepts] = useState('');
const [noGoes, setNoGoes] = useState('');
@@ -14,6 +15,15 @@ const DesireForm: React.FC<DesireFormProps> = ({ onSubmit }) => {
const [alertMessage, setAlertMessage] = useState('');
const [alertSeverity, setAlertSeverity] = useState<'error' | 'warning' | 'info' | 'success'>('error');
// Effect to handle external errors
useEffect(() => {
if (externalError) {
setAlertMessage(externalError);
setAlertSeverity('error');
setAlertOpen(true);
}
}, [externalError]);
const handleCloseAlert = (event?: React.SyntheticEvent | Event, reason?: string) => {
if (reason === 'clickaway') {
return;