Create API routes to request relay information
This commit is contained in:
		@@ -1,5 +1,5 @@
 | 
			
		||||
import { APIClient } from "./ApiClient";
 | 
			
		||||
import { DeviceRelay } from "./DeviceApi";
 | 
			
		||||
import { Device, DeviceRelay } from "./DeviceApi";
 | 
			
		||||
 | 
			
		||||
export class RelayApi {
 | 
			
		||||
  /**
 | 
			
		||||
@@ -13,4 +13,29 @@ export class RelayApi {
 | 
			
		||||
      })
 | 
			
		||||
    ).data;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Create a new relay
 | 
			
		||||
   */
 | 
			
		||||
  static async Create(device: Device, relay: DeviceRelay): Promise<void> {
 | 
			
		||||
    await APIClient.exec({
 | 
			
		||||
      method: "POST",
 | 
			
		||||
      uri: "/relay/create",
 | 
			
		||||
      jsonData: {
 | 
			
		||||
        ...relay,
 | 
			
		||||
        device_id: device.id,
 | 
			
		||||
      },
 | 
			
		||||
    });
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Update a relay information
 | 
			
		||||
   */
 | 
			
		||||
  static async Update(relay: DeviceRelay): Promise<void> {
 | 
			
		||||
    await APIClient.exec({
 | 
			
		||||
      method: "PUT",
 | 
			
		||||
      uri: `/relay/${relay.id}`,
 | 
			
		||||
      jsonData: relay,
 | 
			
		||||
    });
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -10,6 +10,7 @@ import {
 | 
			
		||||
import { TimePicker } from "@mui/x-date-pickers";
 | 
			
		||||
import React from "react";
 | 
			
		||||
import { Device, DeviceRelay } from "../api/DeviceApi";
 | 
			
		||||
import { RelayApi } from "../api/RelayApi";
 | 
			
		||||
import { ServerApi } from "../api/ServerApi";
 | 
			
		||||
import { useAlert } from "../hooks/context_providers/AlertDialogProvider";
 | 
			
		||||
import { useLoadingMessage } from "../hooks/context_providers/LoadingMessageProvider";
 | 
			
		||||
@@ -53,7 +54,8 @@ export function EditDeviceRelaysDialog(p: {
 | 
			
		||||
        `${creating ? "Creating" : "Updating"} relay information`
 | 
			
		||||
      );
 | 
			
		||||
 | 
			
		||||
      // TODO
 | 
			
		||||
      if (creating) await RelayApi.Create(p.device, relay);
 | 
			
		||||
      else await RelayApi.Update(relay);
 | 
			
		||||
 | 
			
		||||
      snackbar(
 | 
			
		||||
        `The relay have been successfully ${creating ? "created" : "updated"}!`
 | 
			
		||||
@@ -73,7 +75,9 @@ export function EditDeviceRelaysDialog(p: {
 | 
			
		||||
 | 
			
		||||
  return (
 | 
			
		||||
    <Dialog open>
 | 
			
		||||
      <DialogTitle>Edit relay information</DialogTitle>
 | 
			
		||||
      <DialogTitle>
 | 
			
		||||
        {creating ? "Create a new relay" : "Edit relay information"}
 | 
			
		||||
      </DialogTitle>
 | 
			
		||||
      <DialogContent>
 | 
			
		||||
        <DialogFormTitle>General info</DialogFormTitle>
 | 
			
		||||
        <Grid container spacing={2}>
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user