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

View File

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