import React, { useState } from 'react'; import { Schedule, Task } from '@/api/server/schedules/getServerSchedules'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { faClock, faCode, faFileArchive, faPencilAlt, faToggleOn, faTrashAlt } from '@fortawesome/free-solid-svg-icons'; import deleteScheduleTask from '@/api/server/schedules/deleteScheduleTask'; import { httpErrorToHuman } from '@/api/http'; import SpinnerOverlay from '@/components/elements/SpinnerOverlay'; import TaskDetailsModal from '@/components/server/schedules/TaskDetailsModal'; import Can from '@/components/elements/Can'; import useFlash from '@/plugins/useFlash'; import { ServerContext } from '@/state/server'; import tw from 'twin.macro'; import ConfirmationModal from '@/components/elements/ConfirmationModal'; import Icon from '@/components/elements/Icon'; interface Props { schedule: Schedule; task: Task; } const getActionDetails = (action: string): [ string, any ] => { switch (action) { case 'command': return [ 'Send Command', faCode ]; case 'power': return [ 'Send Power Action', faToggleOn ]; case 'backup': return [ 'Create Backup', faFileArchive ]; default: return [ 'Unknown Action', faCode ]; } }; export default ({ schedule, task }: Props) => { const uuid = ServerContext.useStoreState(state => state.server.data!.uuid); const { clearFlashes, addError } = useFlash(); const [ visible, setVisible ] = useState(false); const [ isLoading, setIsLoading ] = useState(false); const [ isEditing, setIsEditing ] = useState(false); const appendSchedule = ServerContext.useStoreActions(actions => actions.schedules.appendSchedule); const onConfirmDeletion = () => { setIsLoading(true); clearFlashes('schedules'); deleteScheduleTask(uuid, schedule.id, task.id) .then(() => appendSchedule({ ...schedule, tasks: schedule.tasks.filter(t => t.id !== task.id), })) .catch(error => { console.error(error); setIsLoading(false); addError({ message: httpErrorToHuman(error), key: 'schedules' }); }); }; const [ title, icon ] = getActionDetails(task.action); return (
{title}
{task.payload &&Ignoring files & folders:
}