refactor(font-end): rename fetcher

main
Josue 3 years ago
parent ae628edb24
commit 92601e532e
  1. 4
      striker-ui/components/Anvils/SelectedAnvil.tsx
  2. 6
      striker-ui/components/Hosts/AnvilHost.tsx
  3. 4
      striker-ui/components/Servers.tsx
  4. 5
      striker-ui/lib/fetchers/putFetch.ts

@ -6,7 +6,7 @@ import { SELECTED_ANVIL } from '../../lib/consts/DEFAULT_THEME';
import anvilState from '../../lib/consts/ANVILS';
import { AnvilContext } from '../AnvilContext';
import Decorator, { Colours } from '../Decorator';
import putJSON from '../../lib/fetchers/putJSON';
import putFetch from '../../lib/fetchers/putFetch';
const useStyles = makeStyles(() => ({
root: {
@ -67,7 +67,7 @@ const SelectedAnvil = ({ list }: { list: AnvilListItem[] }): JSX.Element => {
<Switch
checked={isAnvilOn(list[index])}
onChange={() =>
putJSON(`${process.env.NEXT_PUBLIC_API_URL}/set_power`, {
putFetch(`${process.env.NEXT_PUBLIC_API_URL}/set_power`, {
anvil_uuid: list[index].anvil_uuid,
is_on: !isAnvilOn(list[index]),
})

@ -6,7 +6,7 @@ import { BodyText } from '../Text';
import Decorator, { Colours } from '../Decorator';
import HOST_STATUS from '../../lib/consts/NODES';
import putJSON from '../../lib/fetchers/putJSON';
import putFetch from '../../lib/fetchers/putFetch';
import { LARGE_MOBILE_BREAKPOINT } from '../../lib/consts/DEFAULT_THEME';
const useStyles = makeStyles((theme) => ({
@ -104,7 +104,7 @@ const AnvilHost = ({
<Switch
checked={host.state === 'online'}
onChange={() =>
putJSON(
putFetch(
`${process.env.NEXT_PUBLIC_API_URL}/set_power`,
{
host_uuid: host.host_uuid,
@ -122,7 +122,7 @@ const AnvilHost = ({
checked={host.state === 'online'}
disabled={!(host.state === 'online')}
onChange={() =>
putJSON(
putFetch(
`${process.env.NEXT_PUBLIC_API_URL}/set_membership`,
{
host_uuid: host.host_uuid,

@ -34,7 +34,7 @@ import Decorator, { Colours } from './Decorator';
import Spinner from './Spinner';
import hostsSanitizer from '../lib/sanitizers/hostsSanitizer';
import putJSON from '../lib/fetchers/putJSON';
import putFetch from '../lib/fetchers/putFetch';
const useStyles = makeStyles((theme) => ({
root: {
@ -145,7 +145,7 @@ const Servers = ({ anvil }: { anvil: AnvilListItem[] }): JSX.Element => {
const handlePower = (label: ButtonLabels) => {
setAnchorEl(null);
if (selected.length) {
putJSON(`${process.env.NEXT_PUBLIC_API_URL}/set_power`, {
putFetch(`${process.env.NEXT_PUBLIC_API_URL}/set_power`, {
server_uuid_list: selected,
is_on: label === 'on',
});

@ -1,13 +1,12 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
const putJSON = <T>(uri: string, data: T): Promise<any> => {
const putFetch = <T>(uri: string, data: T): Promise<any> => {
return fetch(uri, {
method: 'PUT',
headers: {
'Content-Type': 'application/json',
'Keep-Alive': 'timeout=60',
},
body: JSON.stringify(data),
});
};
export default putJSON;
export default putFetch;
Loading…
Cancel
Save