diff --git a/src/App.tsx b/src/App.tsx index a074381..d025d7a 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,8 +1,10 @@ -import { Alert, Grow, Rating, Typography } from "@mui/material"; +import { Alert, Grow, IconButton, Rating, Typography } from "@mui/material"; +import SettingsIcon from "@mui/icons-material/Settings"; import "./App.css"; import ButtonRow, { ActionProps } from "./components/ButtonRow"; import ReviewField, { ReviewFieldProps } from "./components/ReviewField"; import { useState } from "react"; +import EndpointDialog from "./components/EndpointDialong"; function App() { const [rating, setNewRating] = useState(0); @@ -37,7 +39,7 @@ function App() { }; const showThenHide = async () => { - await fetch("http://localhost:8080/post", { + await fetch(endpoint, { method: "POST", body: JSON.stringify({ rating: rating, @@ -88,41 +90,50 @@ function App() { const info = {infoText}; const alert = {alertText}; + const [endpoint, setEndpoint] = useState(""); return ( <> - Simple Review Client +
+ +
-
+
+ Simple Review Client - { - setNewRating(newRating); - }} - /> +
-
-
+ { + setNewRating(newRating); + }} + /> - +
+
-
+ - +
-
+ - - {alert} - +
- - {info} - +
+ + {alert} + + + + {info} + +
+
); } diff --git a/src/components/EndpointDialong.tsx b/src/components/EndpointDialong.tsx new file mode 100644 index 0000000..a8df60f --- /dev/null +++ b/src/components/EndpointDialong.tsx @@ -0,0 +1,91 @@ +import { + Button, + Dialog, + DialogActions, + DialogContent, + DialogTitle, + IconButton, + TextField, +} from "@mui/material"; +import SettingsIcon from "@mui/icons-material/Settings"; +import React, { FormEvent, useState } from "react"; + +export interface EndpointDialogProps { + endpoint: [string, React.Dispatch>]; +} + +const EndpointDialog = ({ endpoint }: EndpointDialogProps) => { + const [open, setOpen] = useState(false); + const [error, setError] = useState(false); + const [errorText, setErrorText] = useState(""); + + const openSettings = () => { + setOpen(true); + }; + + const closeSettings = () => { + setOpen(false); + + setError(false); + setErrorText(""); + }; + + const setEndpoint = (newEndpoint: any) => { + endpoint[1](newEndpoint); + }; + + return ( + <> + + + + + ) => { + setError(false); + setErrorText(""); + + event.preventDefault(); + const formData = new FormData(event.currentTarget); + const json = Object.fromEntries(formData.entries()); + + // @ts-ignore + if ( + json.endpointBox.includes("http") || + json.endpointBox.includes("https") + ) { + setEndpoint(json.endpointBox); + closeSettings(); + } else { + setError(true); + setErrorText("Please enter a valid endpoint."); + } + }, + }} + > + Endpoint URL + + + + + + + + + + + ); +}; + +export default EndpointDialog; diff --git a/src/index.css b/src/index.css index 682fbc8..f681de1 100644 --- a/src/index.css +++ b/src/index.css @@ -16,11 +16,25 @@ body { margin: 0; display: flex; +} + +#app { + display: flexbox; place-items: center; min-width: 320px; min-height: 100vh; } +#settings { + text-align: right; +} + +#alert-box { + text-align: center; + height: 50px; + min-width: 600px; +} + @media (prefers-color-scheme: light) { :root { /*color: #213547;*/