fix(dashboard): resolve loop and datepicker issues in class and session edit forms
This commit is contained in:
@@ -299,11 +299,9 @@ const props = defineProps({
|
||||
endTime: { type: String, default: '' }
|
||||
});
|
||||
|
||||
const { toPersianDigits, toLatinDigits, formatJalali, getTodayJalali } = usePersianDate();
|
||||
const { toPersianDigits, toLatinDigits, toGregorianIso, formatJalali, getTodayJalali } = usePersianDate();
|
||||
const { showSuccess, showError } = useToast();
|
||||
|
||||
const todayJalali = () => moment().locale('fa').format('jYYYY/jMM/jDD');
|
||||
|
||||
const sessions = ref([]);
|
||||
const selectedSessions = ref([]);
|
||||
const loadingSessions = ref(false);
|
||||
@@ -315,7 +313,7 @@ const bulkDeleteMode = ref(false);
|
||||
const sessionToDelete = ref(null);
|
||||
const bulkStatus = ref(null);
|
||||
const generatedSessions = ref([]);
|
||||
const manualSessions = ref([{ date: todayJalali(), startTime: '19:00', endTime: '20:30', topic: '' }]);
|
||||
const manualSessions = ref([{ date: getTodayJalali(), startTime: '19:00', endTime: '20:30', topic: '' }]);
|
||||
|
||||
const notifyDialogVisible = ref(false);
|
||||
const selectedSessionForNotify = ref(null);
|
||||
@@ -409,7 +407,7 @@ const weekdays = [
|
||||
|
||||
const autoForm = reactive({
|
||||
sessionCount: props.defaultSessionCount || 12,
|
||||
startDate: todayJalali(),
|
||||
startDate: getTodayJalali(),
|
||||
startTime: props.startTime || '19:00',
|
||||
endTime: props.endTime || '20:30',
|
||||
selectedDays: props.days?.length ? [...props.days] : [6, 2]
|
||||
@@ -428,9 +426,7 @@ watch(
|
||||
|
||||
const toSessionDayIso = (value) => {
|
||||
if (!value) return null;
|
||||
const latin = toLatinDigits(String(value));
|
||||
const m = moment(latin, ['jYYYY/jMM/jDD', 'YYYY/MM/DD', moment.ISO_8601], true);
|
||||
return m.isValid() ? m.toDate().toISOString() : null;
|
||||
return toGregorianIso(value) || null;
|
||||
};
|
||||
|
||||
const fetchSessions = async () => {
|
||||
@@ -509,7 +505,7 @@ const applyBulkStatus = async () => {
|
||||
|
||||
const resetCreationForms = () => {
|
||||
generatedSessions.value = [];
|
||||
manualSessions.value = [{ date: todayJalali(), startTime: '19:00', endTime: '20:30', topic: '' }];
|
||||
manualSessions.value = [{ date: getTodayJalali(), startTime: '19:00', endTime: '20:30', topic: '' }];
|
||||
};
|
||||
|
||||
const generateSessionsPreview = () => {
|
||||
@@ -524,21 +520,29 @@ const generateSessionsPreview = () => {
|
||||
|
||||
const list = [];
|
||||
const latinStartDate = toLatinDigits(autoForm.startDate);
|
||||
let currentMoment = moment(latinStartDate, 'jYYYY/jMM/jDD');
|
||||
let count = 0;
|
||||
const targetCount = autoForm.sessionCount || 12;
|
||||
let currentMoment = moment(latinStartDate, ['jYYYY/jMM/jDD', 'YYYY-MM-DD', 'YYYY/MM/DD', moment.ISO_8601]);
|
||||
if (!currentMoment.isValid()) {
|
||||
showError('تاریخ شروع نامعتبر است');
|
||||
return;
|
||||
}
|
||||
|
||||
while (count < targetCount) {
|
||||
let count = 0;
|
||||
let safetyLimit = 365 * 5;
|
||||
const targetCount = Math.max(1, parseInt(autoForm.sessionCount, 10) || 12);
|
||||
|
||||
while (count < targetCount && safetyLimit > 0) {
|
||||
safetyLimit--;
|
||||
if (autoForm.selectedDays.includes(currentMoment.day())) {
|
||||
count++;
|
||||
list.push({
|
||||
sessionNumber: count,
|
||||
date: currentMoment.locale('fa').format('YYYY/MM/DD'),
|
||||
date: toLatinDigits(currentMoment.locale('fa').format('jYYYY/jMM/jDD')),
|
||||
startTime: autoForm.startTime,
|
||||
endTime: autoForm.endTime,
|
||||
topic: `جلسه ${count}`
|
||||
});
|
||||
}
|
||||
if (count >= targetCount) break;
|
||||
currentMoment.add(1, 'day');
|
||||
}
|
||||
generatedSessions.value = list;
|
||||
|
||||
Reference in New Issue
Block a user