Add HTTPS checkbox
This commit is contained in:
parent
42bbb67639
commit
c4c3316e33
|
@ -1,20 +1,24 @@
|
|||
import {
|
||||
Button,
|
||||
Checkbox,
|
||||
Dialog,
|
||||
DialogActions,
|
||||
DialogContent,
|
||||
DialogTitle,
|
||||
FormControlLabel,
|
||||
IconButton,
|
||||
TextField,
|
||||
} from "@mui/material";
|
||||
import SettingsIcon from "@mui/icons-material/Settings";
|
||||
import React, { useState } from "react";
|
||||
import { CheckBox } from "@mui/icons-material";
|
||||
|
||||
export interface EndpointDialogProps {
|
||||
endpoint: [string, React.Dispatch<React.SetStateAction<string>>];
|
||||
secure: [boolean, React.Dispatch<React.SetStateAction<boolean>>];
|
||||
}
|
||||
|
||||
const EndpointDialog = ({ endpoint }: EndpointDialogProps) => {
|
||||
const EndpointDialog = ({ endpoint, secure }: EndpointDialogProps) => {
|
||||
const [open, setOpen] = useState(false);
|
||||
const [error, setError] = useState(false);
|
||||
const [errorText, setErrorText] = useState("");
|
||||
|
@ -35,7 +39,7 @@ const EndpointDialog = ({ endpoint }: EndpointDialogProps) => {
|
|||
};
|
||||
|
||||
const showTheError = () => {
|
||||
setErrorText("Please enter a valid URL.");
|
||||
setErrorText('Please omit "http://" or "https://" from the endpoint.');
|
||||
setError(true);
|
||||
}
|
||||
|
||||
|
@ -45,7 +49,7 @@ const EndpointDialog = ({ endpoint }: EndpointDialogProps) => {
|
|||
}
|
||||
|
||||
const isValidEndpoint = () => {
|
||||
return endpoint[0].startsWith("http://") || endpoint[0].startsWith("https://");
|
||||
return !(endpoint[0].startsWith("http://") || endpoint[0].startsWith("https://"));
|
||||
}
|
||||
|
||||
const saveEndpoint = () => {
|
||||
|
@ -80,6 +84,19 @@ const EndpointDialog = ({ endpoint }: EndpointDialogProps) => {
|
|||
error={error}
|
||||
helperText={errorText}
|
||||
/>
|
||||
|
||||
<br />
|
||||
|
||||
<FormControlLabel
|
||||
control={
|
||||
<Checkbox
|
||||
checked={secure[0]}
|
||||
onClick={() => secure[1](!secure[0])}
|
||||
/>
|
||||
}
|
||||
label="HTTPS"
|
||||
/>
|
||||
|
||||
</DialogContent>
|
||||
<DialogActions>
|
||||
<Button
|
||||
|
@ -90,7 +107,9 @@ const EndpointDialog = ({ endpoint }: EndpointDialogProps) => {
|
|||
closeTheError();
|
||||
saveEndpoint();
|
||||
|
||||
console.log(`Endpoint set to ${endpoint[0]}.\n\nPOST URI: ${endpoint[0]}/post\nGET URI: ${endpoint[0]}/reviews`);
|
||||
const fullUri = `${secure[0] ? "https" : "http"}://${endpoint[0]}`;
|
||||
|
||||
console.log(`Endpoint set to ${fullUri}.\n\nPOST URI: ${fullUri}/post\nGET URI: ${fullUri}/reviews`);
|
||||
} else {
|
||||
showTheError();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue