better idiom (#221)

This commit is contained in:
Michael Quigley 2024-11-19 21:39:33 -05:00
parent 569dfce1ce
commit 2770090d84
No known key found for this signature in database
GPG Key ID: 9B60314A9DD20A62
2 changed files with 9 additions and 7 deletions

View File

@ -3,6 +3,7 @@ import {useFormik} from "formik";
import {GetAgentApi} from "./model/api.ts";
import {Box, Button, Modal, TextField, Typography} from "@mui/material";
import {modalStyle} from "./model/theme.ts";
import * as React from "react";
interface NewAccessModalProps {
close: () => void;
@ -10,7 +11,7 @@ interface NewAccessModalProps {
}
const NewAccessModal = ({ close, isOpen }: NewAccessModalProps) => {
const [errorMessage, setErrorMessage] = useState(<></>);
const [errorMessage, setErrorMessage] = useState(null as React.JSX.Element);
const newAccessForm = useFormik({
initialValues: {
@ -18,14 +19,14 @@ const NewAccessModal = ({ close, isOpen }: NewAccessModalProps) => {
bindAddress: "",
},
onSubmit: v => {
setErrorMessage(<></>);
setErrorMessage(null as React.JSX.Element);
GetAgentApi().agentAccessPrivate(v)
.then(r => {
close();
})
.catch(e => {
e.response.json().then(ex => {
setErrorMessage(<p>{ex.message}</p>);
setErrorMessage(<span>{ex.message}</span>);
console.log(ex.message);
})
});
@ -38,7 +39,7 @@ const NewAccessModal = ({ close, isOpen }: NewAccessModalProps) => {
<Typography>
<h2>Access...</h2>
</Typography>
{errorMessage}
<Typography color={"red"}><h3>{errorMessage}</h3></Typography>
<form onSubmit={newAccessForm.handleSubmit}>
<TextField
fullWidth

View File

@ -3,6 +3,7 @@ import {GetAgentApi} from "./model/api.ts";
import {useState} from "react";
import {Box, Button, Checkbox, FormControlLabel, MenuItem, Modal, TextField, Typography} from "@mui/material";
import {modalStyle} from "./model/theme.ts";
import * as React from "react";
interface NewShareModalProps {
close: () => void;
@ -10,7 +11,7 @@ interface NewShareModalProps {
}
const NewShareModal = ({ close, isOpen }: NewShareModalProps) => {
const [errorMessage, setErrorMessage] = useState(<></>);
const [errorMessage, setErrorMessage] = useState(null as React.JSX.Element);
const form = useFormik({
initialValues: {
@ -20,7 +21,7 @@ const NewShareModal = ({ close, isOpen }: NewShareModalProps) => {
insecure: false,
},
onSubmit: v => {
setErrorMessage(<></>);
setErrorMessage(null as React.JSX.Element);
switch(v.shareMode) {
case "public":
GetAgentApi().agentSharePublic(v)
@ -29,7 +30,7 @@ const NewShareModal = ({ close, isOpen }: NewShareModalProps) => {
})
.catch(e => {
e.response().json().then(ex => {
setErrorMessage(<p>{ex.message}</p>);
setErrorMessage(<span>{ex.message}</span>);
console.log(ex.message);
})
});