* WIP: add scheduler commands * refactor scheduler commands page * WIP on CRUD for ScheduledCommands * more refactoring, finish CRUD On scheduled pages * Add info text about Scheduler service * Finish recurring commands add/edit * add more texts * fix server status behavior on not-loaded-yet state; adjust texts; lint fixes * add link to the help pages in the commands palette * Move Commands Panel to ServerSchedulesPage * Rename Server Schedules to Server Actions * more texts, a bit changed visual of the actions page, lint fix * add docs * fix tests * Add UTC label to scheduled command create/edit
30 lines
1.0 KiB
TypeScript
30 lines
1.0 KiB
TypeScript
import { useState, useEffect } from "react";
|
|
import { useDataProvider } from "react-admin";
|
|
|
|
import { useAppContext } from "../../../Context";
|
|
import { ServerCommand } from "../../../synapse/dataProvider";
|
|
|
|
export const useServerCommands = () => {
|
|
const { etkeccAdmin } = useAppContext();
|
|
const [isLoading, setLoading] = useState(true);
|
|
const [serverCommands, setServerCommands] = useState<Record<string, ServerCommand>>({});
|
|
const dataProvider = useDataProvider();
|
|
|
|
useEffect(() => {
|
|
const fetchServerCommands = async () => {
|
|
const serverCommandsResponse = await dataProvider.getServerCommands(etkeccAdmin);
|
|
if (serverCommandsResponse) {
|
|
const serverCommands = serverCommandsResponse;
|
|
Object.keys(serverCommandsResponse).forEach((command: string) => {
|
|
serverCommands[command].additionalArgs = "";
|
|
});
|
|
setServerCommands(serverCommands);
|
|
}
|
|
setLoading(false);
|
|
};
|
|
fetchServerCommands();
|
|
}, [dataProvider, etkeccAdmin]);
|
|
|
|
return { isLoading, serverCommands, setServerCommands };
|
|
};
|