mirror of
https://github.com/dstotijn/hetty.git
synced 2025-07-01 18:47:29 -04:00
Add "New request" button to Sender page
This commit is contained in:
@ -1,4 +1,5 @@
|
|||||||
import { Alert, Box, Button, Typography } from "@mui/material";
|
import AddIcon from "@mui/icons-material/Add";
|
||||||
|
import { Alert, Box, Button, Fab, Tooltip, Typography, useTheme } from "@mui/material";
|
||||||
import { useRouter } from "next/router";
|
import { useRouter } from "next/router";
|
||||||
import React, { useState } from "react";
|
import React, { useState } from "react";
|
||||||
|
|
||||||
@ -17,15 +18,21 @@ import { queryParamsFromURL } from "lib/queryParamsFromURL";
|
|||||||
import updateKeyPairItem from "lib/updateKeyPairItem";
|
import updateKeyPairItem from "lib/updateKeyPairItem";
|
||||||
import updateURLQueryParams from "lib/updateURLQueryParams";
|
import updateURLQueryParams from "lib/updateURLQueryParams";
|
||||||
|
|
||||||
|
const defaultMethod = HttpMethod.Get;
|
||||||
|
const defaultProto = HttpProto.Http20;
|
||||||
|
const emptyKeyPair = [{ key: "", value: "" }];
|
||||||
|
|
||||||
function EditRequest(): JSX.Element {
|
function EditRequest(): JSX.Element {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const reqId = router.query.id as string | undefined;
|
const reqId = router.query.id as string | undefined;
|
||||||
|
|
||||||
const [method, setMethod] = useState(HttpMethod.Get);
|
const theme = useTheme();
|
||||||
|
|
||||||
|
const [method, setMethod] = useState(defaultMethod);
|
||||||
const [url, setURL] = useState("");
|
const [url, setURL] = useState("");
|
||||||
const [proto, setProto] = useState(HttpProto.Http20);
|
const [proto, setProto] = useState(defaultProto);
|
||||||
const [queryParams, setQueryParams] = useState<KeyValuePair[]>([{ key: "", value: "" }]);
|
const [queryParams, setQueryParams] = useState<KeyValuePair[]>(emptyKeyPair);
|
||||||
const [headers, setHeaders] = useState<KeyValuePair[]>([{ key: "", value: "" }]);
|
const [headers, setHeaders] = useState<KeyValuePair[]>(emptyKeyPair);
|
||||||
const [body, setBody] = useState("");
|
const [body, setBody] = useState("");
|
||||||
|
|
||||||
const handleQueryParamChange = (key: string, value: string, idx: number) => {
|
const handleQueryParamChange = (key: string, value: string, idx: number) => {
|
||||||
@ -131,8 +138,26 @@ function EditRequest(): JSX.Element {
|
|||||||
createOrUpdateRequestAndSend();
|
createOrUpdateRequestAndSend();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleNewRequest = () => {
|
||||||
|
setURL("");
|
||||||
|
setMethod(defaultMethod);
|
||||||
|
setProto(defaultProto);
|
||||||
|
setQueryParams(emptyKeyPair);
|
||||||
|
setHeaders(emptyKeyPair);
|
||||||
|
setBody("");
|
||||||
|
setResponse(null);
|
||||||
|
router.push(`/sender`);
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box display="flex" flexDirection="column" height="100%" gap={2}>
|
<Box display="flex" flexDirection="column" height="100%" gap={2}>
|
||||||
|
<Box sx={{ position: "absolute", bottom: theme.spacing(2), right: theme.spacing(2) }}>
|
||||||
|
<Tooltip title="New request">
|
||||||
|
<Fab color="primary" onClick={handleNewRequest}>
|
||||||
|
<AddIcon />
|
||||||
|
</Fab>
|
||||||
|
</Tooltip>
|
||||||
|
</Box>
|
||||||
<Box component="form" autoComplete="off" onSubmit={handleFormSubmit}>
|
<Box component="form" autoComplete="off" onSubmit={handleFormSubmit}>
|
||||||
<Box sx={{ display: "flex", gap: 1, flexWrap: "wrap" }}>
|
<Box sx={{ display: "flex", gap: 1, flexWrap: "wrap" }}>
|
||||||
<UrlBar
|
<UrlBar
|
||||||
|
Reference in New Issue
Block a user