From eb2c8daeee5f0b26058a9b4c732929a5aea49b46 Mon Sep 17 00:00:00 2001 From: leko Date: Mon, 9 May 2022 15:31:09 +0200 Subject: [PATCH] feat: add subsequent validation callback --- app/components/ErrorAlert.tsx | 22 +++++++ app/components/ValidationResult.tsx | 99 +++++++++++++++++++---------- app/pages/index.tsx | 22 +------ 3 files changed, 90 insertions(+), 53 deletions(-) create mode 100644 app/components/ErrorAlert.tsx diff --git a/app/components/ErrorAlert.tsx b/app/components/ErrorAlert.tsx new file mode 100644 index 0000000..27aacb9 --- /dev/null +++ b/app/components/ErrorAlert.tsx @@ -0,0 +1,22 @@ +import { Alert, Snackbar } from '@mui/material'; + +export type ErrorAlertProps = { + message: string; + open: boolean; + onClose: () => void; +} + +const ErrorAlert = (props: ErrorAlertProps) => { + const { message, open, onClose } = props; + + return ( + + {message} + + ); +}; + +export default ErrorAlert; diff --git a/app/components/ValidationResult.tsx b/app/components/ValidationResult.tsx index b7d5734..3b11791 100644 --- a/app/components/ValidationResult.tsx +++ b/app/components/ValidationResult.tsx @@ -1,11 +1,14 @@ import ArrowDropDownIcon from '@mui/icons-material/ArrowDropDown'; -import { Box, Button, ButtonGroup, Menu, MenuItem, Skeleton, Stack, Typography } from '@mui/material'; +import { Box, Button, ButtonGroup, Grid, Menu, MenuItem, Skeleton, Stack, Typography } from '@mui/material'; import Link from 'next/link'; +import { useRouter } from 'next/router'; import React from 'react'; +import ErrorAlert from './ErrorAlert'; import TaskRow from './TaskRow'; import { Session } from '../api/client'; import useApiClient from '../hooks/useApiClient'; import { useSubscription } from '../hooks/useMqttClient'; +import useSessionStore from '../hooks/useSessionStore'; import theme from '../styles/theme'; function truncName(name: string) { @@ -27,12 +30,31 @@ type ValidationResultProps = { const ValidationResult = (props: ValidationResultProps) => { const { session } = props; + const router = useRouter(); const message = useSubscription(session ? `progress/${session.id}` : ''); const [tasks, setTasks] = React.useState([]); + const { setSession } = useSessionStore(); + const [ errorOpen, setErrorOpen ] = React.useState(false); + const [ errorMessage, setErrorMessage ] = React.useState('test'); const apiClient = useApiClient(); const [anchorEl, setAnchorEl] = React.useState(null); const open = Boolean(anchorEl); + const handleValidateAnother = () => { + apiClient.createSession() + .then(session => { + setSession(session); + router.push('/jobs/' + session.id); + }) + .catch(err => { + setSession(undefined); + setErrorOpen(true); + setErrorMessage(err.message); + }); + }; + + const handleCloseError = () => setErrorOpen(false); + const handleClick = (event: React.MouseEvent) => { setAnchorEl(event.currentTarget); }; @@ -87,6 +109,7 @@ const ValidationResult = (props: ValidationResultProps) => { return ( + Validation result { session && [{session.id}] } @@ -109,42 +132,52 @@ const ValidationResult = (props: ValidationResultProps) => { )} - - - - - - - - - - - - - json - - - + + + - - csv - + - - - + + + + + + json + + + + + + + csv + + + + + + + + + + ); }; diff --git a/app/pages/index.tsx b/app/pages/index.tsx index 2850ac0..d9d58fc 100644 --- a/app/pages/index.tsx +++ b/app/pages/index.tsx @@ -1,6 +1,6 @@ import EmailIcon from '@mui/icons-material/Email'; import GitHubIcon from '@mui/icons-material/GitHub'; -import { Alert, Box, Button, Grid, Snackbar, SnackbarContent, Stack, Typography } from '@mui/material'; +import { Box, Button, Grid, Stack, Typography } from '@mui/material'; import { ThemeProvider } from '@mui/material/styles'; import { NextPage } from 'next'; import Head from 'next/head'; @@ -8,30 +8,12 @@ import Image from 'next/image'; import Link from 'next/link'; import { useRouter } from 'next/router'; import React from 'react'; +import ErrorAlert from '../components/ErrorAlert'; import MainContent from '../components/MainContent'; import useApiClient from '../hooks/useApiClient'; import useSessionStore from '../hooks/useSessionStore'; import theme from '../styles/theme'; -type ErrorAlertProps = { - message: string; - open: boolean; - onClose: () => void; -} - -const ErrorAlert = (props: ErrorAlertProps) => { - const { message, open, onClose } = props; - - return ( - - {message} - - ); -}; - const Home: NextPage = () => { const apiClient = useApiClient(); const router = useRouter();