EverydayTech Platform - Developer Reference
Complete Source Code Documentation - All Applications
Loading...
Searching...
No Matches
TabServices.jsx
Go to the documentation of this file.
1import React from "react";
2import { apiFetch } from "../../lib/api";
3
4export default function TabServices({ agentId }) {
5 const [services, setServices] = React.useState([]);
6
7 function load() {
8 if (!agentId) return;
9 apiFetch(`/agent/${agentId}/services`).then(setServices);
10 }
11 React.useEffect(load, [agentId]);
12
13 function action(name, type) {
14 if (!agentId) return;
15 apiFetch(`/agent/${agentId}/service/${name}/${type}`, { method: "POST" })
16 .then(load);
17 }
18
19 // Defensive: ensure services is an array
20 const safeServices = Array.isArray(services) ? services : [];
21
22 if (!Array.isArray(services)) {
23 return (
24 <div className="tab-container">
25 <h2>Windows Services</h2>
26 <div className="card error">Service data is not available or invalid.</div>
27 </div>
28 );
29 }
30
31 return (
32 <div className="tab-container">
33 <h2>Windows Services</h2>
34 <div className="card-grid">
35 {safeServices.map((s) => (
36 <div key={s.name} className="card">
37 <strong>{s.name}</strong> ({s.status})
38 <div className="flex-row">
39 <button className="btn-sm" onClick={() => action(s.name, "start")}>
40 Start
41 </button>
42 <button className="btn-sm" onClick={() => action(s.name, "stop")}>
43 Stop
44 </button>
45 <button className="btn-sm" onClick={() => action(s.name, "restart")}>
46 Restart
47 </button>
48 </div>
49 </div>
50 ))}
51 </div>
52 </div>
53 );
54}