forked from pterodactyl/panel
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScheduleContainer.tsx
More file actions
79 lines (74 loc) · 3.47 KB
/
ScheduleContainer.tsx
File metadata and controls
79 lines (74 loc) · 3.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import React, { useEffect, useState } from 'react';
import getServerSchedules from '@/api/server/schedules/getServerSchedules';
import { ServerContext } from '@/state/server';
import Spinner from '@/components/elements/Spinner';
import { useHistory, useRouteMatch } from 'react-router-dom';
import FlashMessageRender from '@/components/FlashMessageRender';
import ScheduleRow from '@/components/server/schedules/ScheduleRow';
import { httpErrorToHuman } from '@/api/http';
import EditScheduleModal from '@/components/server/schedules/EditScheduleModal';
import Can from '@/components/elements/Can';
import useFlash from '@/plugins/useFlash';
import tw from 'twin.macro';
import GreyRowBox from '@/components/elements/GreyRowBox';
import { Button } from '@/components/elements/button/index';
import ServerContentBlock from '@/components/elements/ServerContentBlock';
export default () => {
const match = useRouteMatch();
const history = useHistory();
const uuid = ServerContext.useStoreState((state) => state.server.data!.uuid);
const { clearFlashes, addError } = useFlash();
const [loading, setLoading] = useState(true);
const [visible, setVisible] = useState(false);
const schedules = ServerContext.useStoreState((state) => state.schedules.data);
const setSchedules = ServerContext.useStoreActions((actions) => actions.schedules.setSchedules);
useEffect(() => {
clearFlashes('schedules');
getServerSchedules(uuid)
.then((schedules) => setSchedules(schedules))
.catch((error) => {
addError({ message: httpErrorToHuman(error), key: 'schedules' });
console.error(error);
})
.then(() => setLoading(false));
}, []);
return (
<ServerContentBlock title={'Schedules'}>
<FlashMessageRender byKey={'schedules'} css={tw`mb-4`} />
{!schedules.length && loading ? (
<Spinner size={'large'} centered />
) : (
<>
{schedules.length === 0 ? (
<p css={tw`text-sm text-center text-neutral-300`}>
There are no schedules configured for this server.
</p>
) : (
schedules.map((schedule) => (
<GreyRowBox
as={'a'}
key={schedule.id}
href={`${match.url}/${schedule.id}`}
css={tw`cursor-pointer mb-2 flex-wrap`}
onClick={(e: any) => {
e.preventDefault();
history.push(`${match.url}/${schedule.id}`);
}}
>
<ScheduleRow schedule={schedule} />
</GreyRowBox>
))
)}
<Can action={'schedule.create'}>
<div css={tw`mt-8 flex justify-end`}>
<EditScheduleModal visible={visible} onModalDismissed={() => setVisible(false)} />
<Button type={'button'} onClick={() => setVisible(true)}>
Create schedule
</Button>
</div>
</Can>
</>
)}
</ServerContentBlock>
);
};