Skip to content

Commit

Permalink
more toasts
Browse files Browse the repository at this point in the history
  • Loading branch information
Fisico committed Dec 26, 2023
1 parent e293dd1 commit 20a9734
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 31 deletions.
18 changes: 3 additions & 15 deletions src/views/HA.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { useState, useEffect } from "react";
import axios from "axios";
import Flash from "../containers/Flash";
import { toast } from 'react-hot-toast';

const HA = ({ HOST_IP, API_KEY }) => {
const [type, setType] = useState("none");
const [message, setMessage] = useState("no message");
const [enable, setEnable] = useState(false);
const [homeAssistantIp, setHomeAssistantIp] = useState("127.0.0.1");
const [homeAssistantPort, setHomeAssistantPort] = useState(8123);
Expand Down Expand Up @@ -50,26 +48,16 @@ const HA = ({ HOST_IP, API_KEY }) => {
})
.then((fetchedData) => {
console.log(fetchedData.data);
setMessage("Successfully saved, please restart the service");
setType("success");
toast.success("Successfully saved, please restart the service");
})
.catch((error) => {
console.error(error);
setMessage("Error occured, check browser console");
setType("error");
toast.error(`Error occurred: ${error.message}`);
});
};

return (
<div className="inner">
{type !== "none" && (
<Flash
type={type}
message={message}
duration="5000"
setType={setType}
/>
)}
<div className="contentContainer">
<div className="headline">Home Assistant config</div>
<form className="add-form" onSubmit={(e) => onSubmit(e)}>
Expand Down
21 changes: 5 additions & 16 deletions src/views/Mqtt.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { useState, useEffect } from "react";
import axios from "axios";
import Flash from "../containers/Flash";
import { toast } from 'react-hot-toast';

const Mqtt = ({ HOST_IP, API_KEY }) => {
const [type, setType] = useState("none");
const [message, setMessage] = useState("no message");
const [enable, setEnable] = useState(false);
const [mqttServer, setMqttServer] = useState("mqtt");
const [mqttPort, setMqttPort] = useState(1883);
Expand All @@ -30,6 +28,7 @@ const Mqtt = ({ HOST_IP, API_KEY }) => {
})
.catch((error) => {
console.error(error);
toast.error(`Error occurred: ${error.message}`);
});
}, [HOST_IP, API_KEY]);

Expand All @@ -49,26 +48,16 @@ const Mqtt = ({ HOST_IP, API_KEY }) => {
})
.then((fetchedData) => {
console.log(fetchedData.data);
setMessage("Successfully saved, please restart the service");
setType("success");
toast.success("Successfully saved, please restart the service");
})
.catch((error) => {
console.error(error);
setMessage("Error occured, check browser console");
setType("error");
toast.error(`Error occurred: ${error.message}`);
});
};

return (
<div className="inner">
{type !== "none" && (
<Flash
type={type}
message={message}
duration="5000"
setType={setType}
/>
)}
<div className="contentContainer">
<div className="headline">ZigBee2MQTT config</div>
<form className="add-form" method="POST" onSubmit={(e) => onSubmit(e)}>
Expand Down Expand Up @@ -137,4 +126,4 @@ const Mqtt = ({ HOST_IP, API_KEY }) => {
);
};

export default Mqtt;
export default Mqtt;

0 comments on commit 20a9734

Please sign in to comment.