import React, { useEffect, useState } from 'react'; import { RouteComponentProps } from 'react-router-dom'; import { Schedule } from '@/api/server/schedules/getServerSchedules'; import getServerSchedule from '@/api/server/schedules/getServerSchedule'; import { ServerContext } from '@/state/server'; import Spinner from '@/components/elements/Spinner'; import FlashMessageRender from '@/components/FlashMessageRender'; import { Actions, useStoreActions } from 'easy-peasy'; import { ApplicationStore } from '@/state'; import { httpErrorToHuman } from '@/api/http'; import ScheduleRow from '@/components/server/schedules/ScheduleRow'; import ScheduleTaskRow from '@/components/server/schedules/ScheduleTaskRow'; import EditScheduleModal from '@/components/server/schedules/EditScheduleModal'; import NewTaskButton from '@/components/server/schedules/NewTaskButton'; import DeleteScheduleButton from '@/components/server/schedules/DeleteScheduleButton'; import Can from '@/components/elements/Can'; interface Params { id: string; } interface State { schedule?: Schedule; } export default ({ match, history, location: { state } }: RouteComponentProps) => { const { id, uuid } = ServerContext.useStoreState(state => state.server.data!); const [ isLoading, setIsLoading ] = useState(true); const [ showEditModal, setShowEditModal ] = useState(false); const [ schedule, setSchedule ] = useState(state?.schedule); const { clearFlashes, addError } = useStoreActions((actions: Actions) => actions.flashes); useEffect(() => { if (schedule?.id === Number(match.params.id)) { setIsLoading(false); return; } clearFlashes('schedules'); getServerSchedule(uuid, Number(match.params.id)) .then(schedule => setSchedule(schedule)) .catch(error => { console.error(error); addError({ message: httpErrorToHuman(error), key: 'schedules' }); }) .then(() => setIsLoading(false)); }, [ schedule, match ]); return (
{!schedule || isLoading ? : <>
setSchedule(schedule)} onDismissed={() => setShowEditModal(false)} />

Configured Tasks

{schedule?.tasks.length > 0 ? <> { schedule.tasks .sort((a, b) => a.sequenceId - b.sequenceId) .map(task => ( setSchedule(s => ({ ...s!, tasks: s!.tasks.map(t => t.id === task.id ? task : t), }))} onTaskRemoved={() => setSchedule(s => ({ ...s!, tasks: s!.tasks.filter(t => t.id !== task.id), }))} /> )) } {schedule.tasks.length > 1 &&

Task delays are relative to the previous task in the listing.

} :

There are no tasks configured for this schedule.

}
history.push(`/server/${id}/schedules`)} /> setSchedule(s => ({ ...s!, tasks: [ ...s!.tasks, task ], }))} />
}
); };