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 anvilState from '../../lib/consts/ANVILS';
import { AnvilContext } from '../AnvilContext'; import { AnvilContext } from '../AnvilContext';
import Decorator, { Colours } from '../Decorator'; import Decorator, { Colours } from '../Decorator';
import putJSON from '../../lib/fetchers/putJSON'; import putFetch from '../../lib/fetchers/putFetch';
const useStyles = makeStyles(() => ({ const useStyles = makeStyles(() => ({
root: { root: {
@ -67,7 +67,7 @@ const SelectedAnvil = ({ list }: { list: AnvilListItem[] }): JSX.Element => {
<Switch <Switch
checked={isAnvilOn(list[index])} checked={isAnvilOn(list[index])}
onChange={() => 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, anvil_uuid: list[index].anvil_uuid,
is_on: !isAnvilOn(list[index]), is_on: !isAnvilOn(list[index]),
}) })

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

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

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