diff --git a/src/features/custom-trip/CustomTripOrderDetailPage.tsx b/src/features/custom-trip/CustomTripOrderDetailPage.tsx index 035fdc2..f607de8 100644 --- a/src/features/custom-trip/CustomTripOrderDetailPage.tsx +++ b/src/features/custom-trip/CustomTripOrderDetailPage.tsx @@ -8,7 +8,7 @@ import { Textarea } from '@/components/ui/textarea' import { Shimmer, ShimmerBox, ShimmerLine } from '@/components/shared/shimmer_frontend' import { Ic } from '@/icons' import { toFa, toEn, formatAmount } from '@/lib/utils' -import { formatDualDate } from '@/lib/date-utils' +import { formatDualDate, formatDateRangeByLanguage, parseTravelDateRange } from '@/lib/date-utils' import { UniversalDatePicker } from '@/components/shared/UniversalDatePicker' import { useTranslation } from '@/i18n' import { useBillingBadgeStore } from '@/stores/billing-badge' @@ -1712,33 +1712,37 @@ export default function CustomTripOrderDetailPage() { -
- {t('customTrip.tripStartDate')}: -
- - {(editLegs[0]?.departureDate || order.startDate) - ? formatDualDate((editLegs[0]?.departureDate || order.startDate) as string, language) - : '—'} - - {order.travelDateText && !/^\d{4}-\d{2}-\d{2}/.test(order.travelDateText) && ( - - ({order.travelDateText === 'This Month' - ? t('customTrip.quickDateThisMonth') - : order.travelDateText === 'Next Month' - ? t('customTrip.quickDateNextMonth') - : order.travelDateText === 'Arbaeen Pilgrimage Season' - ? t('customTrip.quickDateArbaeen') - : order.travelDateText === 'Arafah & Eid al-Adha' - ? t('customTrip.quickDateArafah') - : order.travelDateText === 'Nisfu Shaban Season' - ? t('customTrip.quickDateShaban') - : order.travelDateText === 'Date Not Decided Yet' - ? t('customTrip.quickDateUndecided') - : order.travelDateText}) + {(() => { + const parsedRange = parseTravelDateRange( + order.travelDateText, + (editLegs[0]?.departureDate || order.startDate) as string | null + ) + return ( +
+ + {parsedRange.endIso + ? t('customTrip.approxTravelRange') + : t('customTrip.tripStartDate')}: - )} -
-
+
+ + {parsedRange.startIso && parsedRange.endIso + ? formatDateRangeByLanguage(parsedRange.startIso, parsedRange.endIso, language) + : (editLegs[0]?.departureDate || order.startDate) + ? formatDualDate((editLegs[0]?.departureDate || order.startDate) as string, language) + : '—'} + + {!parsedRange.endIso && + order.travelDateText && + !/^\d{4}-\d{2}-\d{2}/.test(order.travelDateText) && ( + + ({order.travelDateText}) + + )} +
+
+ ) + })()}
{t('customTrip.createdDate')}: diff --git a/src/features/custom-trip/components/CustomTripOrderReviewDialog.tsx b/src/features/custom-trip/components/CustomTripOrderReviewDialog.tsx index 5fe2b49..4dbe8d4 100644 --- a/src/features/custom-trip/components/CustomTripOrderReviewDialog.tsx +++ b/src/features/custom-trip/components/CustomTripOrderReviewDialog.tsx @@ -14,7 +14,7 @@ import { Input } from '@/components/ui/input' import { Textarea } from '@/components/ui/textarea' import { Ic } from '@/icons' import { toFa, toEn, formatAmount } from '@/lib/utils' -import { formatDualDate } from '@/lib/date-utils' +import { formatDualDate, formatDateRangeByLanguage, parseTravelDateRange } from '@/lib/date-utils' import { UniversalDatePicker } from '@/components/shared/UniversalDatePicker' import { useTranslation } from '@/i18n' import { useBillingBadgeStore } from '@/stores/billing-badge' @@ -776,14 +776,28 @@ export function CustomTripOrderReviewDialog({ {order.infantsCount > 0 && `، ${toFa(order.infantsCount)} ${t('customTrip.infants')}`}
-
- {t('customTrip.tripStartDate')}: - - {(editLegs[0]?.departureDate || order.startDate) - ? formatDualDate((editLegs[0]?.departureDate || order.startDate) as string, language) - : '—'} - -
+ {(() => { + const parsedRange = parseTravelDateRange( + order.travelDateText, + (editLegs[0]?.departureDate || order.startDate) as string | null + ) + return ( +
+ + {parsedRange.endIso + ? t('customTrip.approxTravelRange') + : t('customTrip.tripStartDate')}: + + + {parsedRange.startIso && parsedRange.endIso + ? formatDateRangeByLanguage(parsedRange.startIso, parsedRange.endIso, language) + : (editLegs[0]?.departureDate || order.startDate) + ? formatDualDate((editLegs[0]?.departureDate || order.startDate) as string, language) + : '—'} + +
+ ) + })()} {/* Origin City Selector */} diff --git a/src/features/custom-trip/components/CustomTripOrdersTab.tsx b/src/features/custom-trip/components/CustomTripOrdersTab.tsx index abccbc2..fa0d5a4 100644 --- a/src/features/custom-trip/components/CustomTripOrdersTab.tsx +++ b/src/features/custom-trip/components/CustomTripOrdersTab.tsx @@ -15,7 +15,7 @@ import { import { Ic } from '@/icons' import { toFa } from '@/lib/utils' import { useTranslation } from '@/i18n' -import { formatDateByLanguage } from '@/lib/date-utils' +import { formatDateByLanguage, formatDateRangeByLanguage, parseTravelDateRange } from '@/lib/date-utils' import type { CustomTripOrderItem, CustomTripOrderStatus, @@ -392,15 +392,24 @@ export function CustomTripOrdersTab({ .join(' | ')} )} - {(order.startDate || order.legs?.[0]?.departureDate) && ( -
- - - {t('customTrip.tripStartDate')}:{' '} - {formatDateByLanguage((order.startDate || order.legs?.[0]?.departureDate) as string, language)} - -
- )} + {(order.startDate || order.legs?.[0]?.departureDate || order.travelDateText) && (() => { + const parsedRange = parseTravelDateRange( + order.travelDateText, + (order.startDate || order.legs?.[0]?.departureDate) as string | null + ) + const fallbackDate = (order.startDate || order.legs?.[0]?.departureDate) as string | undefined + if (!parsedRange.startIso && !fallbackDate) return null + return ( +
+ + + {parsedRange.endIso + ? `${t('customTrip.approxTravelRange')}: ${formatDateRangeByLanguage(parsedRange.startIso, parsedRange.endIso, language)}` + : `${t('customTrip.tripStartDate')}: ${formatDateByLanguage(fallbackDate || parsedRange.startIso, language)}`} + +
+ ) + })()} diff --git a/src/features/services/components/DuasServiceView.tsx b/src/features/services/components/DuasServiceView.tsx index b4c3307..2d7fce6 100644 --- a/src/features/services/components/DuasServiceView.tsx +++ b/src/features/services/components/DuasServiceView.tsx @@ -1,4 +1,5 @@ import React, { useState, useEffect, useMemo } from 'react' +import { useTranslation } from '@/i18n' import { Ic } from '@/icons' import { Button } from '@/components/ui/button' import { Input } from '@/components/ui/input' @@ -60,6 +61,7 @@ function normalizeCityName(rawName: string): string { } export function DuasServiceView() { + const { t } = useTranslation() const [duas, setDuas] = useState([]) const [isLoading, setIsLoading] = useState(true) const [isRefreshing, setIsRefreshing] = useState(false) @@ -95,6 +97,14 @@ export function DuasServiceView() { const [formNameEn, setFormNameEn] = useState('') const [formNameRu, setFormNameRu] = useState('') const [formNameId, setFormNameId] = useState('') + const [formDescriptions, setFormDescriptions] = useState>({ + fa: '', + ar: '', + en: '', + ru: '', + id: '', + }) + const [activeDescLang, setActiveDescLang] = useState<'fa' | 'ar' | 'en' | 'ru' | 'id'>('fa') const [formCityIds, setFormCityIds] = useState([]) // نگهداری دسته‌بندی‌های انتخاب‌شده به تفکیک هر شهر (cityId -> categoryIds[]) جهت استقلال کامل هر شهر const [cityCategoryMap, setCityCategoryMap] = useState>({}) @@ -125,8 +135,19 @@ export function DuasServiceView() { // Tab 2 Verses states const [verseSearch, setVerseSearch] = useState('') const [activeTranslationLang, setActiveTranslationLang] = useState<'fa' | 'en' | 'ru' | 'id'>('fa') + const [activeVerseDescLang, setActiveVerseDescLang] = useState<'fa' | 'ar' | 'en' | 'ru' | 'id'>('fa') const [copiedVerseIndex, setCopiedVerseIndex] = useState(null) - const [verseDrafts, setVerseDrafts] = useState }>>({}) + const [verseDrafts, setVerseDrafts] = useState< + Record< + number, + { + text: string + translations: Record + descriptions: Record + repeat_count: number | null + } + > + >({}) const [savingVerseIndex, setSavingVerseIndex] = useState(null) const [savedVerseSuccessIndex, setSavedVerseSuccessIndex] = useState(null) @@ -352,6 +373,14 @@ export function DuasServiceView() { setFormNameEn(enVal) setFormNameRu(ruVal) setFormNameId(idVal) + const initDesc = (dua.description && typeof dua.description === 'object') ? dua.description : {} + setFormDescriptions({ + fa: initDesc.fa || '', + ar: initDesc.ar || '', + en: initDesc.en || '', + ru: initDesc.ru || '', + id: initDesc.id || '', + }) setHasAttemptedSaveGeneral(false) // Cities: فقط شهرهای معتبر که در سامانه دسته‌بندی دارند به صورت اولیه انتخاب شوند @@ -405,12 +434,37 @@ export function DuasServiceView() { const detail = await fetchDuaDetail(dua.index) setDuaDetail(detail) + const detDesc = (detail.description && typeof detail.description === 'object') ? detail.description : {} + setFormDescriptions({ + fa: detDesc.fa || '', + ar: detDesc.ar || '', + en: detDesc.en || '', + ru: detDesc.ru || '', + id: detDesc.id || '', + }) + // Initialize verse drafts - const drafts: Record }> = {} + const drafts: Record< + number, + { + text: string + translations: Record + descriptions: Record + repeat_count: number | null + } + > = {} detail.verses?.forEach((v) => { drafts[v.index] = { text: v.text, translations: { ...(v.translations || {}) }, + descriptions: { + fa: v.descriptions?.fa || '', + ar: v.descriptions?.ar || '', + en: v.descriptions?.en || '', + ru: v.descriptions?.ru || '', + id: v.descriptions?.id || '', + }, + repeat_count: v.repeat_count ?? null, } }) setVerseDrafts(drafts) @@ -617,8 +671,15 @@ export function DuasServiceView() { ]) ) + const descriptionObj: Record = {} + ;(['fa', 'ar', 'en', 'ru', 'id'] as const).forEach((l) => { + const val = (formDescriptions[l] || '').trim() + if (val) descriptionObj[l] = val + }) + const updated = await updateDua(selectedDuaForModal.index, { name: nameObj, + description: descriptionObj, city_ids: activeCityIds, category_ids: allActiveCategoryIds, city_allocations: cityAllocations, @@ -636,6 +697,7 @@ export function DuasServiceView() { ...d, name: updated.name, name_display: updated.name_display || formNameFa || formNameAr, + description: updated.description || descriptionObj, cities: updated.cities, city_ids: Array.isArray(updated.city_ids) ? updated.city_ids : activeCityIds, categories: updated.categories, @@ -647,7 +709,7 @@ export function DuasServiceView() { ) // بستن مدال پس از ذخیره‌سازی موفقیت‌آمیز setSelectedDuaForModal(null) - toast.success('اطلاعات عمومی دعا با موفقیت در دیتابیس ذخیره شد.') + toast.success(t('duasAdmin.saveGeneralSuccess')) // تازه‌سازی خودکار داده‌های صفحه از سرور await loadDuas(true) @@ -667,9 +729,11 @@ export function DuasServiceView() { await updateVerse(verseIndex, { text: draft.text, translations: draft.translations, + descriptions: draft.descriptions, + repeat_count: draft.repeat_count && draft.repeat_count > 0 ? draft.repeat_count : null, }) setSavedVerseSuccessIndex(verseIndex) - toast.success(`فراز با موفقیت در دیتابیس ذخیره شد.`) + toast.success(t('duasAdmin.saveVerseSuccess')) setTimeout(() => setSavedVerseSuccessIndex(null), 2500) } catch (err: any) { toast.error(err?.message || 'خطا در ذخیره‌سازی فراز در سرور.') @@ -1455,6 +1519,50 @@ export function DuasServiceView() { + {/* ۱.۵. توضیحات و فضیلت مفاتیح‌الجنان (۵ زبانه) */} +
+
+
+ + + {t('duasAdmin.mafatihIntroTitle')} + + + {t('duasAdmin.mafatihIntroHint')} + +
+
+ {(['fa', 'ar', 'en', 'ru', 'id'] as const).map((lang) => ( + + ))} +
+
+