UPdate remainder of screens with basic permissions checking

This commit is contained in:
Dane Everitt 2020-03-29 22:20:27 -07:00
parent 171b21e7ee
commit 7f0a05c192
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
5 changed files with 94 additions and 71 deletions

View file

@ -9,6 +9,7 @@ import { httpErrorToHuman } from '@/api/http';
import { Actions, useStoreActions } from 'easy-peasy';
import { ApplicationStore } from '@/state';
import EditScheduleModal from '@/components/server/schedules/EditScheduleModal';
import Can from '@/components/elements/Can';
export default ({ match, history }: RouteComponentProps) => {
const { uuid } = ServerContext.useStoreState(state => state.server.data!);
@ -35,9 +36,8 @@ export default ({ match, history }: RouteComponentProps) => {
<>
{
schedules.length === 0 ?
<p className={'text-sm text-neutral-400'}>
There are no schedules configured for this server. Click the button below to get
started.
<p className={'text-sm text-center text-neutral-400'}>
There are no schedules configured for this server.
</p>
:
schedules.map(schedule => (
@ -54,21 +54,23 @@ export default ({ match, history }: RouteComponentProps) => {
</a>
))
}
<div className={'mt-8 flex justify-end'}>
{visible && <EditScheduleModal
appear={true}
visible={true}
onScheduleUpdated={schedule => setSchedules(s => [...(s || []), schedule])}
onDismissed={() => setVisible(false)}
/>}
<button
type={'button'}
className={'btn btn-lg btn-primary'}
onClick={() => setVisible(true)}
>
Create schedule
</button>
</div>
<Can action={'schedule.create'}>
<div className={'mt-8 flex justify-end'}>
{visible && <EditScheduleModal
appear={true}
visible={true}
onScheduleUpdated={schedule => setSchedules(s => [ ...(s || []), schedule ])}
onDismissed={() => setVisible(false)}
/>}
<button
type={'button'}
className={'btn btn-sm btn-primary'}
onClick={() => setVisible(true)}
>
Create schedule
</button>
</div>
</Can>
</>
}
</div>

View file

@ -13,6 +13,7 @@ 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;
@ -93,24 +94,27 @@ export default ({ match, history, location: { state } }: RouteComponentProps<Par
</>
:
<p className={'text-sm text-neutral-400'}>
There are no tasks configured for this schedule. Consider adding a new one using the
button below.
There are no tasks configured for this schedule.
</p>
}
<div className={'mt-8 flex justify-end'}>
<DeleteScheduleButton
scheduleId={schedule.id}
onDeleted={() => history.push(`/server/${id}/schedules`)}
/>
<button className={'btn btn-primary btn-sm mr-4'} onClick={() => setShowEditModal(true)}>
Edit
</button>
<NewTaskButton
scheduleId={schedule.id}
onTaskAdded={task => setSchedule(s => ({
...s!, tasks: [ ...s!.tasks, task ],
}))}
/>
<Can action={'schedule.delete'}>
<DeleteScheduleButton
scheduleId={schedule.id}
onDeleted={() => history.push(`/server/${id}/schedules`)}
/>
</Can>
<Can action={'schedule.update'}>
<button className={'btn btn-primary btn-sm mr-4'} onClick={() => setShowEditModal(true)}>
Edit
</button>
<NewTaskButton
scheduleId={schedule.id}
onTaskAdded={task => setSchedule(s => ({
...s!, tasks: [ ...s!.tasks, task ],
}))}
/>
</Can>
</div>
</>
}

View file

@ -13,6 +13,7 @@ import { httpErrorToHuman } from '@/api/http';
import SpinnerOverlay from '@/components/elements/SpinnerOverlay';
import TaskDetailsModal from '@/components/server/schedules/TaskDetailsModal';
import { faPencilAlt } from '@fortawesome/free-solid-svg-icons/faPencilAlt';
import Can from '@/components/elements/Can';
interface Props {
schedule: number;
@ -75,22 +76,26 @@ export default ({ schedule, task, onTaskUpdated, onTaskRemoved }: Props) => {
</p>
</div>
}
<button
type={'button'}
aria-label={'Edit scheduled task'}
className={'block text-sm p-2 text-neutral-500 hover:text-neutral-100 transition-colors duration-150 mr-4'}
onClick={() => setIsEditing(true)}
>
<FontAwesomeIcon icon={faPencilAlt}/>
</button>
<button
type={'button'}
aria-label={'Delete scheduled task'}
className={'block text-sm p-2 text-neutral-500 hover:text-red-600 transition-colors duration-150'}
onClick={() => setVisible(true)}
>
<FontAwesomeIcon icon={faTrashAlt}/>
</button>
<Can action={'schedule.update'}>
<button
type={'button'}
aria-label={'Edit scheduled task'}
className={'block text-sm p-2 text-neutral-500 hover:text-neutral-100 transition-colors duration-150 mr-4'}
onClick={() => setIsEditing(true)}
>
<FontAwesomeIcon icon={faPencilAlt}/>
</button>
</Can>
<Can action={'schedule.update'}>
<button
type={'button'}
aria-label={'Delete scheduled task'}
className={'block text-sm p-2 text-neutral-500 hover:text-red-600 transition-colors duration-150'}
onClick={() => setVisible(true)}
>
<FontAwesomeIcon icon={faTrashAlt}/>
</button>
</Can>
</div>
);
};