Add a landing page classes section fed by the public classes API with pricing and availability details.
36 lines
1.2 KiB
JavaScript
36 lines
1.2 KiB
JavaScript
import moment from 'jalali-moment'
|
||
|
||
const persianDigits = ['۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹']
|
||
|
||
export function toPersianDigits(value) {
|
||
if (value == null) return ''
|
||
return String(value).replace(/\d/g, (d) => persianDigits[Number(d)])
|
||
}
|
||
|
||
export function formatJalali(date, format = 'jYYYY/jMM/jDD') {
|
||
if (!date) return '—'
|
||
return toPersianDigits(moment(date).locale('fa').format(format))
|
||
}
|
||
|
||
export function formatPrice(amount) {
|
||
if (amount == null || Number.isNaN(Number(amount))) return '—'
|
||
return `${toPersianDigits(Number(amount).toLocaleString('en-US'))} تومان`
|
||
}
|
||
|
||
export function formatDaysUntilStart(days) {
|
||
if (days == null || Number.isNaN(Number(days))) return null
|
||
const value = Number(days)
|
||
if (value > 0) return `${toPersianDigits(value)} روز تا شروع`
|
||
if (value === 0) return 'امروز شروع میشود'
|
||
return `${toPersianDigits(Math.abs(value))} روز از شروع گذشته`
|
||
}
|
||
|
||
export function getApiErrorMessage(error, fallback = 'خطایی رخ داد. دوباره تلاش کنید.') {
|
||
return (
|
||
error?.response?.data?.error?.message ||
|
||
error?.response?.data?.message ||
|
||
error?.message ||
|
||
fallback
|
||
)
|
||
}
|