Skip to content

Commit

Permalink
feature(web/dashboard): add device label to notifs
Browse files Browse the repository at this point in the history
  • Loading branch information
djey47 committed Dec 8, 2023
1 parent 2840ceb commit 8252117
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions web/src/components/business/device/Device.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const Device = ({ deviceInfo }: DeviceProps) => {
const [isPerformingPowerOn, setPerformingPowerOn] = useState(false);
const [isPerformingPowerOff, setPerformingPowerOff] = useState(false);

const deviceId = deviceInfo.id;
const { id: deviceId, network: { hostname: deviceName } } = deviceInfo;
const { data: diagsQueryData, isFetching: isFetchingDiags} = useQuery({
queryKey: ['diags', deviceId],
queryFn: ({ queryKey }) => getDiagnosticsForDevice(queryKey[1]),
Expand All @@ -44,13 +44,17 @@ const Device = ({ deviceInfo }: DeviceProps) => {
const devicePowerState = diagsQueryData?.power?.state || STATUS_UNAVAIL;

const handlePowerClick = async () => {
const deviceLabel = `${deviceName}(${deviceId})`;
const infoCommandMessage = `Command has already been sent to device ${deviceLabel}`;
const successCommandMessage = `Command has been sent to device ${deviceLabel}`;

if (devicePowerState === 'off') {
await postPowerOnForDevice(deviceId);

if (isPerformingPowerOn) {
showAlert('info', 'Power ON', 'Command has already been sent to the device');
showAlert('info', 'Power ON', infoCommandMessage);
} else {
showAlert('success', 'Power ON', 'Command has been sent to the device');
showAlert('success', 'Power ON', successCommandMessage);
}

setPerformingPowerOn(true);
Expand All @@ -59,9 +63,9 @@ const Device = ({ deviceInfo }: DeviceProps) => {
await postPowerOffForDevice(deviceId);

if (isPerformingPowerOff) {
showAlert('info', 'Power OFF', 'Command has already been sent to the device');
showAlert('info', 'Power OFF', infoCommandMessage);
} else {
showAlert('success', 'Power OFF', 'Command has been sent to the device');
showAlert('success', 'Power OFF', successCommandMessage);
}

setPerformingPowerOff(true);
Expand Down

0 comments on commit 8252117

Please sign in to comment.