import React, { useEffect, useState } from 'react'; import getServerSchedules, { Schedule } from '@/api/server/schedules/getServerSchedules'; import { ServerContext } from '@/state/server'; import Spinner from '@/components/elements/Spinner'; import { Link } from 'react-router-dom'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { faCalendarAlt } from '@fortawesome/free-solid-svg-icons/faCalendarAlt'; import classNames from 'classnames'; import format from 'date-fns/format'; import FlashMessageRender from '@/components/FlashMessageRender'; import { Actions, useStoreActions } from 'easy-peasy'; import { ApplicationStore } from '@/state'; import { httpErrorToHuman } from '@/api/http'; export default () => { const { id, uuid } = ServerContext.useStoreState(state => state.server.data!); const [ schedules, setSchedules ] = useState(null); const { addError, clearFlashes } = useStoreActions((actions: Actions) => actions.flashes); useEffect(() => { clearFlashes('schedules'); getServerSchedules(uuid) .then(schedules => setSchedules(schedules)) .catch(error => { addError({ message: httpErrorToHuman(error), key: 'schedules' }); console.error(error); }); }, [ uuid, setSchedules ]); return (
{!schedules ? : schedules.map(schedule => (

{schedule.name}

Last run at: {schedule.lastRunAt ? format(schedule.lastRunAt, 'MMM Do [at] h:mma') : 'never'}

{schedule.cron.minute}

Minute

{schedule.cron.hour}

Hour

{schedule.cron.dayOfMonth}

Day (Month)

*

Month

{schedule.cron.dayOfWeek}

Day (Week)

{schedule.isActive ? 'Active' : 'Inactive'}

)) }
); };