Extract admin dashboard from ghabilee-frontend2 into a dedicated Next.js app for backoffice.ghabilee.ir (no SEO indexing / Clarity).
28 lines
1.1 KiB
TypeScript
28 lines
1.1 KiB
TypeScript
const PERSIAN_DIGITS = '۰۱۲۳۴۵۶۷۸۹'
|
||
const ARABIC_DIGITS = '٠١٢٣٤٥٦٧٨٩'
|
||
|
||
export const MOBILE_CHANGE_FINAL_CONFIRMATION = 'تغییر شماره'
|
||
|
||
const toEnglishDigits = (value: string) =>
|
||
value.replace(/[۰-۹٠-٩]/g, (digit) => {
|
||
const persianIndex = PERSIAN_DIGITS.indexOf(digit)
|
||
|
||
return String(persianIndex >= 0 ? persianIndex : ARABIC_DIGITS.indexOf(digit))
|
||
})
|
||
|
||
export const normalizeAdminMobile = (raw: string): string | null => {
|
||
let value = toEnglishDigits(raw).trim().replace(/[\s-]/g, '')
|
||
|
||
if (value.startsWith('+')) value = value.slice(1)
|
||
else if (value.startsWith('00')) value = value.slice(2)
|
||
|
||
if (value.startsWith('0') && value.length === 11) value = `98${value.slice(1)}`
|
||
else if (value.startsWith('9') && value.length === 10) value = `98${value}`
|
||
|
||
return /^989\d{9}$/.test(value) ? value : null
|
||
}
|
||
|
||
export const confirmsCurrentMobile = (confirmation: string, currentMobile: string) => normalizeAdminMobile(confirmation) === currentMobile
|
||
|
||
export const confirmsFinalMobileChange = (confirmation: string) => confirmation.trim() === MOBILE_CHANGE_FINAL_CONFIRMATION
|