fix: resolve course/class fields, surname i18n, optional nationalId, auto class end date, login styling, and mobile sidebar navigation

This commit is contained in:
2026-08-21 15:03:28 +03:30
parent b1c3dd6218
commit 86f1f9bab0
13 changed files with 348 additions and 117 deletions
+43
View File
@@ -1,3 +1,5 @@
import moment from 'jalali-moment';
export const WEEKDAYS = [
{ label: 'شنبه', value: 6 },
{ label: 'یکشنبه', value: 0 },
@@ -39,3 +41,44 @@ export function formatClassSchedule(cls) {
if (days && time) return `${days} | ${time}`;
return days || time || '';
}
/**
* Calculates the class end date in Jalali (jYYYY/jMM/jDD) based on start date, selected days, and number of sessions.
* @param {string|Date} startDate - Jalali string (e.g. 1403/01/01) or ISO string / Date
* @param {number[]} days - Array of weekday indexes (0=Sun, 1=Mon, ..., 6=Sat)
* @param {number} numberOfSessions - Total number of sessions
* @returns {string} Jalali formatted date string, or empty string if not calculable
*/
export function calculateClassEndDate(startDate, days = [], numberOfSessions = 0) {
const countNeeded = parseInt(numberOfSessions, 10);
if (!startDate || isNaN(countNeeded) || countNeeded < 1) return '';
const validDays = Array.isArray(days)
? [...new Set(days.map(Number).filter((d) => d >= 0 && d <= 6))]
: [];
if (!validDays.length) return '';
const latinStartDate = String(startDate)
.replace(/[۰-۹]/g, (d) => '۰۱۲۳۴۵۶۷۸۹'.indexOf(d))
.replace(/[٠-٩]/g, (d) => '٠١٢٣٤٥٦٧٨٩'.indexOf(d))
.trim();
let current = moment(latinStartDate, ['jYYYY/jMM/jDD', 'YYYY-MM-DD', 'YYYY/MM/DD', moment.ISO_8601]);
if (!current.isValid()) return '';
let count = 0;
let lastMatchingDate = null;
let safetyLimit = 365 * 5;
while (count < countNeeded && safetyLimit > 0) {
safetyLimit--;
if (validDays.includes(current.day())) {
count++;
lastMatchingDate = current.clone();
}
if (count >= countNeeded) break;
current.add(1, 'day');
}
return lastMatchingDate ? lastMatchingDate.locale('fa').format('jYYYY/jMM/jDD') : '';
}