forked from pterodactyl/panel
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEditScheduleModal.tsx
More file actions
98 lines (90 loc) · 3.42 KB
/
EditScheduleModal.tsx
File metadata and controls
98 lines (90 loc) · 3.42 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import React from 'react';
import { Schedule } from '@/api/server/schedules/getServerSchedules';
import Modal, { RequiredModalProps } from '@/components/elements/Modal';
import Field from '@/components/elements/Field';
import { connect } from 'react-redux';
import { Form, FormikProps, withFormik } from 'formik';
import { Actions } from 'easy-peasy';
import { ApplicationStore } from '@/state';
import Switch from '@/components/elements/Switch';
import { boolean, object, string } from 'yup';
type OwnProps = { schedule: Schedule } & RequiredModalProps;
interface ReduxProps {
addError: ApplicationStore['flashes']['addError'];
}
type ComponentProps = OwnProps & ReduxProps;
interface Values {
name: string;
dayOfWeek: string;
dayOfMonth: string;
hour: string;
minute: string;
enabled: boolean;
}
const EditScheduleModal = ({ values, schedule, ...props }: ComponentProps & FormikProps<Values>) => {
return (
<Modal {...props}>
<Form>
<Field
name={'name'}
label={'Schedule name'}
description={'A human readable identifer for this schedule.'}
/>
<div className={'flex mt-6'}>
<div className={'flex-1 mr-4'}>
<Field name={'dayOfWeek'} label={'Day of week'}/>
</div>
<div className={'flex-1 mr-4'}>
<Field name={'dayOfMonth'} label={'Day of month'}/>
</div>
<div className={'flex-1 mr-4'}>
<Field name={'hour'} label={'Hour'}/>
</div>
<div className={'flex-1'}>
<Field name={'minute'} label={'Minute'}/>
</div>
</div>
<p className={'input-help'}>
The schedule system supports the use of Cronjob syntax when defining when tasks should begin
running. Use the fields above to specify when these tasks should begin running.
</p>
<div className={'mt-6 bg-neutral-700 border border-neutral-800 shadow-inner p-4 rounded'}>
<Switch
name={'enabled'}
description={'If disabled, this schedule and it\'s associated tasks will not run.'}
label={'Enabled'}
/>
</div>
<div className={'mt-6 text-right'}>
<button className={'btn btn-lg btn-primary'} type={'button'}>
Save
</button>
</div>
</Form>
</Modal>
);
};
export default connect(
null,
// @ts-ignore
(dispatch: Actions<ApplicationStore>) => ({
addError: dispatch.flashes.addError,
}),
)(
withFormik<ComponentProps, Values>({
handleSubmit: (values, { props }) => {
},
mapPropsToValues: ({ schedule }) => ({
name: schedule.name,
dayOfWeek: schedule.cron.dayOfWeek,
dayOfMonth: schedule.cron.dayOfMonth,
hour: schedule.cron.hour,
minute: schedule.cron.minute,
enabled: schedule.isActive,
}),
validationSchema: object().shape({
name: string().required(),
enabled: boolean().required(),
}),
})(EditScheduleModal),
);