2020-06-05 14:31:48 +02:00
|
|
|
import * as React from "react";
|
2020-06-08 20:10:20 +02:00
|
|
|
import { ViewState, IntegratedEditing, EditingState } from "@devexpress/dx-react-scheduler";
|
2020-06-05 14:31:48 +02:00
|
|
|
import { AppointmentModel } from "@devexpress/dx-react-scheduler";
|
|
|
|
import {
|
|
|
|
Scheduler,
|
|
|
|
WeekView,
|
|
|
|
Appointments,
|
2020-06-07 15:57:51 +02:00
|
|
|
AppointmentTooltip,
|
2020-06-08 20:10:20 +02:00
|
|
|
AppointmentForm,
|
2020-06-05 14:31:48 +02:00
|
|
|
} from "@devexpress/dx-react-scheduler-material-ui";
|
|
|
|
import moment from "moment";
|
|
|
|
import "moment/locale/pl";
|
|
|
|
import "./index.scss";
|
2020-06-06 13:17:56 +02:00
|
|
|
import { makeStyles, Theme, createStyles } from "@material-ui/core/styles";
|
2020-06-05 14:31:48 +02:00
|
|
|
|
2020-06-07 15:57:51 +02:00
|
|
|
interface CalendarProps {
|
2020-06-05 14:31:48 +02:00
|
|
|
data: Array<AppointmentModel>;
|
|
|
|
}
|
|
|
|
|
2020-06-08 20:10:20 +02:00
|
|
|
interface CalendarState {
|
|
|
|
currentDate: Date;
|
|
|
|
}
|
2020-06-07 15:57:51 +02:00
|
|
|
|
2020-06-05 14:31:48 +02:00
|
|
|
const formatDayScaleDate = (
|
|
|
|
date: moment.MomentInput,
|
|
|
|
options: { weekday: any }
|
|
|
|
) => {
|
|
|
|
const momentDate = moment(date).locale("pl");
|
|
|
|
const { weekday } = options;
|
|
|
|
return momentDate.format(weekday ? "dddd" : " ").toUpperCase();
|
|
|
|
};
|
|
|
|
|
2020-06-05 14:58:52 +02:00
|
|
|
const useStyles = makeStyles((theme: Theme) =>
|
2020-06-05 14:31:48 +02:00
|
|
|
createStyles({
|
2020-06-06 13:17:56 +02:00
|
|
|
dayScaleCell: {
|
|
|
|
paddingTop: 10,
|
|
|
|
paddingBottom: 10,
|
|
|
|
},
|
|
|
|
timeTableLayout: {
|
|
|
|
border: "1px solid rgba(224, 224, 224, 1);",
|
2020-06-07 15:57:51 +02:00
|
|
|
borderCollapse: "separate",
|
2020-06-06 13:17:56 +02:00
|
|
|
},
|
|
|
|
timeTableCell: {
|
2020-06-07 16:31:35 +02:00
|
|
|
//borderRadius: 15,
|
2020-06-07 15:57:51 +02:00
|
|
|
},
|
|
|
|
appointmentLayer: {
|
|
|
|
borderRadius: 15,
|
|
|
|
marginLeft: 5,
|
|
|
|
textAlign: "center",
|
2020-06-06 13:17:56 +02:00
|
|
|
},
|
|
|
|
})
|
2020-06-05 14:31:48 +02:00
|
|
|
);
|
|
|
|
|
2020-06-05 14:58:52 +02:00
|
|
|
//don't know how to set proper type of function arguments
|
2020-06-06 13:17:56 +02:00
|
|
|
const DayScaleCell = ({ formatDate, ...restProps }: any) => {
|
2020-06-05 14:58:52 +02:00
|
|
|
const classes = useStyles();
|
|
|
|
return (
|
2020-06-06 13:17:56 +02:00
|
|
|
<WeekView.DayScaleCell
|
|
|
|
{...restProps}
|
|
|
|
formatDate={formatDayScaleDate}
|
|
|
|
today={false}
|
|
|
|
className={classes.dayScaleCell}
|
|
|
|
/>
|
2020-06-05 14:58:52 +02:00
|
|
|
);
|
2020-06-06 13:17:56 +02:00
|
|
|
};
|
2020-06-05 14:58:52 +02:00
|
|
|
|
2020-06-06 13:17:56 +02:00
|
|
|
const TimeTableCell = ({ ...restProps }: any) => {
|
|
|
|
const classes = useStyles();
|
|
|
|
return (
|
|
|
|
<WeekView.TimeTableCell {...restProps} className={classes.timeTableCell} />
|
|
|
|
);
|
|
|
|
};
|
2020-06-05 14:58:52 +02:00
|
|
|
|
2020-06-06 13:17:56 +02:00
|
|
|
const TimeTableLayout = ({ ...restProps }: any) => {
|
|
|
|
const classes = useStyles();
|
|
|
|
return (
|
|
|
|
<WeekView.TimeTableLayout
|
|
|
|
{...restProps}
|
|
|
|
className={classes.timeTableLayout}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
};
|
2020-06-05 14:31:48 +02:00
|
|
|
|
2020-06-07 15:57:51 +02:00
|
|
|
const Appointment = ({ ...restProps }: any) => {
|
|
|
|
const classes = useStyles();
|
|
|
|
return (
|
|
|
|
<Appointments.Appointment
|
|
|
|
{...restProps}
|
|
|
|
className={classes.appointmentLayer}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2020-06-05 14:31:48 +02:00
|
|
|
export default class Calendar extends React.PureComponent<
|
|
|
|
CalendarProps,
|
|
|
|
CalendarState
|
|
|
|
> {
|
|
|
|
|
2020-06-07 16:31:35 +02:00
|
|
|
constructor(props: CalendarProps) {
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
this.state = {
|
|
|
|
currentDate: new Date("2020-06-01"),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-06-08 20:10:20 +02:00
|
|
|
commitChanges() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-06-05 14:31:48 +02:00
|
|
|
render() {
|
2020-06-07 16:31:35 +02:00
|
|
|
const { data } = this.props;
|
|
|
|
const { currentDate } = this.state;
|
2020-06-05 14:31:48 +02:00
|
|
|
|
|
|
|
return (
|
2020-06-08 20:10:20 +02:00
|
|
|
<Scheduler data={data} locale={"PL-PL"} firstDayOfWeek={1}>
|
|
|
|
<ViewState defaultCurrentDate={currentDate} />
|
|
|
|
<EditingState
|
|
|
|
onCommitChanges={this.commitChanges}
|
|
|
|
/>
|
|
|
|
<WeekView
|
|
|
|
startDayHour={8}
|
|
|
|
endDayHour={20}
|
|
|
|
excludedDays={[0, 6]}
|
|
|
|
cellDuration={60}
|
|
|
|
dayScaleCellComponent={DayScaleCell}
|
|
|
|
timeTableLayoutComponent={TimeTableLayout}
|
|
|
|
timeTableCellComponent={TimeTableCell}
|
|
|
|
/>
|
|
|
|
<IntegratedEditing/>
|
|
|
|
<Appointments appointmentComponent={Appointment} />
|
|
|
|
<AppointmentTooltip />
|
|
|
|
<AppointmentForm/>
|
|
|
|
</Scheduler>
|
2020-06-05 14:31:48 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|