import React, { useMemo, useState } from 'react'; import getServerSchedules, { Schedule } from '@/api/server/schedules/getServerSchedules'; import { ServerContext } from '@/state/server'; import Spinner from '@/components/elements/Spinner'; import { RouteComponentProps } from 'react-router-dom'; import FlashMessageRender from '@/components/FlashMessageRender'; import ScheduleRow from '@/components/server/schedules/ScheduleRow'; import { httpErrorToHuman } from '@/api/http'; import { Actions, useStoreActions } from 'easy-peasy'; import { ApplicationStore } from '@/state'; import EditScheduleModal from '@/components/server/schedules/EditScheduleModal'; export default ({ match, history }: RouteComponentProps) => { const { uuid } = ServerContext.useStoreState(state => state.server.data!); const [ schedules, setSchedules ] = useState(null); const [ visible, setVisible ] = useState(false); const { clearFlashes, addError } = useStoreActions((actions: Actions) => actions.flashes); useMemo(() => { clearFlashes('schedules'); getServerSchedules(uuid) .then(schedules => setSchedules(schedules)) .catch(error => { addError({ message: httpErrorToHuman(error), key: 'schedules' }); console.error(error); }); }, [ setSchedules ]); return (
{!schedules ? : <> { schedules.length === 0 ?

There are no schedules configured for this server. Click the button below to get started.

: schedules.map(schedule => ( { e.preventDefault(); history.push(`${match.url}/${schedule.id}`, { schedule }); }} > )) }
{visible && setSchedules(s => [...(s || []), schedule])} onDismissed={() => setVisible(false)} />}
}
); };