Attempting to get an edit modal to display without a re-render
This commit is contained in:
parent
40c377f2e0
commit
f180e3ef0b
4 changed files with 97 additions and 52 deletions
|
@ -0,0 +1,15 @@
|
|||
import React from 'react';
|
||||
import { Schedule } from '@/api/server/schedules/getServerSchedules';
|
||||
import Modal, { RequiredModalProps } from '@/components/elements/Modal';
|
||||
|
||||
type Props = {
|
||||
schedule?: Schedule;
|
||||
} & RequiredModalProps;
|
||||
|
||||
export default ({ schedule, ...props }: Props) => {
|
||||
return (
|
||||
<Modal {...props}>
|
||||
<p>Testing</p>
|
||||
</Modal>
|
||||
);
|
||||
};
|
|
@ -1,24 +1,25 @@
|
|||
import React, { useEffect, useState } from 'react';
|
||||
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 { 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 { Link, 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 { httpErrorToHuman } from '@/api/http';
|
||||
import EditScheduleModal from '@/components/server/schedules/EditScheduleModal';
|
||||
|
||||
export default () => {
|
||||
interface Params {
|
||||
schedule?: string;
|
||||
}
|
||||
|
||||
export default ({ history, match, location: { hash } }: RouteComponentProps<Params>) => {
|
||||
const { id, uuid } = ServerContext.useStoreState(state => state.server.data!);
|
||||
const [ schedules, setSchedules ] = useState<Schedule[] | null>(null);
|
||||
const { clearFlashes, addError } = useStoreActions((actions: Actions<ApplicationStore>) => actions.flashes);
|
||||
|
||||
const { addError, clearFlashes } = useStoreActions((actions: Actions<ApplicationStore>) => actions.flashes);
|
||||
|
||||
useEffect(() => {
|
||||
useMemo(() => {
|
||||
clearFlashes('schedules');
|
||||
getServerSchedules(uuid)
|
||||
.then(schedules => setSchedules(schedules))
|
||||
|
@ -26,7 +27,9 @@ export default () => {
|
|||
addError({ message: httpErrorToHuman(error), key: 'schedules' });
|
||||
console.error(error);
|
||||
});
|
||||
}, [ uuid, setSchedules ]);
|
||||
}, [ setSchedules ]);
|
||||
|
||||
const matched = (schedules || []).find(schedule => schedule.id === Number(hash.match(/\d+$/) || 0));
|
||||
|
||||
return (
|
||||
<div className={'my-10 mb-6'}>
|
||||
|
@ -35,49 +38,23 @@ export default () => {
|
|||
<Spinner size={'large'} centered={true}/>
|
||||
:
|
||||
schedules.map(schedule => (
|
||||
<Link key={schedule.id} to={`/servers/${id}/schedules/${schedule.id}`} className={'grey-row-box'}>
|
||||
<div className={'icon'}>
|
||||
<FontAwesomeIcon icon={faCalendarAlt} fixedWidth={true}/>
|
||||
</div>
|
||||
<div className={'flex-1 ml-4'}>
|
||||
<p>{schedule.name}</p>
|
||||
<p className={'text-xs text-neutral-400'}>
|
||||
Last run at: {schedule.lastRunAt ? format(schedule.lastRunAt, 'MMM Do [at] h:mma') : 'never'}
|
||||
</p>
|
||||
</div>
|
||||
<div className={'flex items-center mx-8'}>
|
||||
<div>
|
||||
<p className={'font-medium text-center'}>{schedule.cron.minute}</p>
|
||||
<p className={'text-2xs text-neutral-500 uppercase'}>Minute</p>
|
||||
</div>
|
||||
<div className={'ml-4'}>
|
||||
<p className={'font-medium text-center'}>{schedule.cron.hour}</p>
|
||||
<p className={'text-2xs text-neutral-500 uppercase'}>Hour</p>
|
||||
</div>
|
||||
<div className={'ml-4'}>
|
||||
<p className={'font-medium text-center'}>{schedule.cron.dayOfMonth}</p>
|
||||
<p className={'text-2xs text-neutral-500 uppercase'}>Day (Month)</p>
|
||||
</div>
|
||||
<div className={'ml-4'}>
|
||||
<p className={'font-medium text-center'}>*</p>
|
||||
<p className={'text-2xs text-neutral-500 uppercase'}>Month</p>
|
||||
</div>
|
||||
<div className={'ml-4'}>
|
||||
<p className={'font-medium text-center'}>{schedule.cron.dayOfWeek}</p>
|
||||
<p className={'text-2xs text-neutral-500 uppercase'}>Day (Week)</p>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<p className={classNames('py-1 px-3 rounded text-xs uppercase', {
|
||||
'bg-green-600': schedule.isActive,
|
||||
'bg-neutral-400': !schedule.isActive,
|
||||
})}>
|
||||
{schedule.isActive ? 'Active' : 'Inactive'}
|
||||
</p>
|
||||
</div>
|
||||
<Link
|
||||
key={schedule.id}
|
||||
to={`/server/${id}/schedules/#/schedule/${schedule.id}`}
|
||||
className={'grey-row-box'}
|
||||
>
|
||||
<ScheduleRow schedule={schedule}/>
|
||||
</Link>
|
||||
))
|
||||
}
|
||||
{matched &&
|
||||
<EditScheduleModal
|
||||
schedule={matched}
|
||||
visible={true}
|
||||
appear={true}
|
||||
onDismissed={() => history.push(match.url)}
|
||||
/>
|
||||
}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
|
|
@ -0,0 +1,53 @@
|
|||
import React from 'react';
|
||||
import { Schedule } from '@/api/server/schedules/getServerSchedules';
|
||||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
||||
import { faCalendarAlt } from '@fortawesome/free-solid-svg-icons/faCalendarAlt';
|
||||
import format from 'date-fns/format';
|
||||
import classNames from 'classnames';
|
||||
|
||||
export default ({ schedule }: { schedule: Schedule }) => (
|
||||
<>
|
||||
<div className={'icon'}>
|
||||
<FontAwesomeIcon icon={faCalendarAlt} fixedWidth={true}/>
|
||||
</div>
|
||||
<div className={'flex-1 ml-4'}>
|
||||
<p>{schedule.name}</p>
|
||||
<p className={'text-xs text-neutral-400'}>
|
||||
Last run
|
||||
at: {schedule.lastRunAt ? format(schedule.lastRunAt, 'MMM Do [at] h:mma') : 'never'}
|
||||
</p>
|
||||
</div>
|
||||
<div className={'flex items-center mx-8'}>
|
||||
<div>
|
||||
<p className={'font-medium text-center'}>{schedule.cron.minute}</p>
|
||||
<p className={'text-2xs text-neutral-500 uppercase'}>Minute</p>
|
||||
</div>
|
||||
<div className={'ml-4'}>
|
||||
<p className={'font-medium text-center'}>{schedule.cron.hour}</p>
|
||||
<p className={'text-2xs text-neutral-500 uppercase'}>Hour</p>
|
||||
</div>
|
||||
<div className={'ml-4'}>
|
||||
<p className={'font-medium text-center'}>{schedule.cron.dayOfMonth}</p>
|
||||
<p className={'text-2xs text-neutral-500 uppercase'}>Day (Month)</p>
|
||||
</div>
|
||||
<div className={'ml-4'}>
|
||||
<p className={'font-medium text-center'}>*</p>
|
||||
<p className={'text-2xs text-neutral-500 uppercase'}>Month</p>
|
||||
</div>
|
||||
<div className={'ml-4'}>
|
||||
<p className={'font-medium text-center'}>{schedule.cron.dayOfWeek}</p>
|
||||
<p className={'text-2xs text-neutral-500 uppercase'}>Day (Week)</p>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<p
|
||||
className={classNames('py-1 px-3 rounded text-xs uppercase', {
|
||||
'bg-green-600': schedule.isActive,
|
||||
'bg-neutral-400': !schedule.isActive,
|
||||
})}
|
||||
>
|
||||
{schedule.isActive ? 'Active' : 'Inactive'}
|
||||
</p>
|
||||
</div>
|
||||
</>
|
||||
);
|
Loading…
Reference in a new issue