54 lines
1.6 KiB
TypeScript
54 lines
1.6 KiB
TypeScript
|
|
import {FC} from "react";
|
||
|
|
import {RecurrenceType} from "@/types/ScheduleType";
|
||
|
|
|
||
|
|
interface Props {
|
||
|
|
recurrences: RecurrenceType[];
|
||
|
|
}
|
||
|
|
|
||
|
|
const RecurrenceLabels: FC<Props> = ({recurrences}) => {
|
||
|
|
const weeklyRecurrences = recurrences.filter(recurrence => recurrence.type === 'App\\Models\\WeeklyRecurrence');
|
||
|
|
const minimumRecurrences = recurrences.filter(recurrence => recurrence.type === 'App\\Models\\MinimumRecurrence');
|
||
|
|
|
||
|
|
const renderWeeklyRecurrence = () => {
|
||
|
|
if (weeklyRecurrences == undefined || weeklyRecurrences.length == 0) {
|
||
|
|
return '';
|
||
|
|
}
|
||
|
|
|
||
|
|
const weekdayString = (() => {
|
||
|
|
switch (weeklyRecurrences[0].value) {
|
||
|
|
case 0: return "Sunday"
|
||
|
|
case 1: return "Monday"
|
||
|
|
case 2: return "Tuesday";
|
||
|
|
case 3: return "Wednesday";
|
||
|
|
case 4: return "Thursday";
|
||
|
|
case 5: return "Friday";
|
||
|
|
case 6: return "Saturday";
|
||
|
|
default: return "Invalid day";
|
||
|
|
}
|
||
|
|
})
|
||
|
|
|
||
|
|
return (
|
||
|
|
<div className="text-xs p-1 inline mx-1 text-accent-yellow">
|
||
|
|
{ weekdayString() }
|
||
|
|
</div>
|
||
|
|
)
|
||
|
|
}
|
||
|
|
const renderMinimumRecurrence = () => {
|
||
|
|
if (minimumRecurrences == undefined || minimumRecurrences.length == 0) {
|
||
|
|
return '';
|
||
|
|
}
|
||
|
|
|
||
|
|
return (
|
||
|
|
<div className="text-xs p-1 inline mx-1 text-accent-yellow">
|
||
|
|
min: { minimumRecurrences[0].value }
|
||
|
|
</div>
|
||
|
|
)
|
||
|
|
}
|
||
|
|
|
||
|
|
return <>
|
||
|
|
{ renderWeeklyRecurrence() }
|
||
|
|
{ renderMinimumRecurrence() }
|
||
|
|
</>;
|
||
|
|
};
|
||
|
|
|
||
|
|
export default RecurrenceLabels;
|