feat(classes): add class days and meeting times to class forms
Let admins set the weekly schedule on the class and show it in lists, details, and session generation.
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
export const WEEKDAYS = [
|
||||
{ label: 'شنبه', value: 6 },
|
||||
{ label: 'یکشنبه', value: 0 },
|
||||
{ label: 'دوشنبه', value: 1 },
|
||||
{ label: 'سهشنبه', value: 2 },
|
||||
{ label: 'چهارشنبه', value: 3 },
|
||||
{ label: 'پنجشنبه', value: 4 },
|
||||
{ label: 'جمعه', value: 5 }
|
||||
];
|
||||
|
||||
const IRAN_WEEK_ORDER = [6, 0, 1, 2, 3, 4, 5];
|
||||
const LABEL_BY_VALUE = Object.fromEntries(WEEKDAYS.map((day) => [day.value, day.label]));
|
||||
|
||||
const joinFaList = (items) => {
|
||||
if (!items.length) return '';
|
||||
if (items.length === 1) return items[0];
|
||||
if (items.length === 2) return `${items[0]} و ${items[1]}`;
|
||||
return `${items.slice(0, -1).join('، ')} و ${items[items.length - 1]}`;
|
||||
};
|
||||
|
||||
export function formatClassDays(days = []) {
|
||||
const unique = [...new Set((days || []).map(Number).filter((day) => day >= 0 && day <= 6))];
|
||||
unique.sort((a, b) => IRAN_WEEK_ORDER.indexOf(a) - IRAN_WEEK_ORDER.indexOf(b));
|
||||
return joinFaList(unique.map((day) => LABEL_BY_VALUE[day]).filter(Boolean));
|
||||
}
|
||||
|
||||
export function formatClassTime(startTime, endTime) {
|
||||
const start = String(startTime || '').trim();
|
||||
const end = String(endTime || '').trim();
|
||||
if (!start && !end) return '';
|
||||
if (!end) return start;
|
||||
if (!start) return end;
|
||||
return `${start} – ${end}`;
|
||||
}
|
||||
|
||||
export function formatClassSchedule(cls) {
|
||||
const days = formatClassDays(cls?.days);
|
||||
const time = formatClassTime(cls?.startTime, cls?.endTime);
|
||||
if (days && time) return `${days} | ${time}`;
|
||||
return days || time || '';
|
||||
}
|
||||
Reference in New Issue
Block a user