diff --git a/components/clinics/head/SearchBar.js b/components/clinics/head/SearchBar.js index 7063f2d..20f14ba 100644 --- a/components/clinics/head/SearchBar.js +++ b/components/clinics/head/SearchBar.js @@ -44,9 +44,13 @@ function SearchBar({ selected, setSelected, state, handleSearch }) {
{text}
, - { prop }, + { prop } ); }; @@ -105,10 +105,19 @@ export const addLabelToList = (list) => }); export const formatPhoneNumber = (input) => { - const digits = input.replace(/\D/g, ""); + if (typeof input !== 'string') input = String(input); + + const normalized = input + .replace(/[\u06F0-\u06F9]/g, d => String(d.charCodeAt(0) - 0x06F0)) + .replace(/[\u0660-\u0669]/g, d => String(d.charCodeAt(0) - 0x0660)); + + const digits = normalized.replace(/\D/g, ""); + const trimmed = digits.substring(0, 9); + const match = trimmed.match(/^(\d{0,2})(\d{0,3})(\d{0,4})$/); if (!match) return trimmed; + return [match[1], match[2], match[3]].filter(Boolean).join(" "); }; @@ -175,3 +184,19 @@ export const filterList = (data) => { childrenList: filteredChildrenList, }; }; + +export function getCleanNumberValue(value, defaultValue = 0) { + if (typeof value !== 'string') value = String(value); + + // Convert Persian and Arabic digits to English digits + const persianArabicToEnglish = value + .replace(/[\u06F0-\u06F9]/g, d => String(d.charCodeAt(0) - 0x06F0)) + .replace(/[\u0660-\u0669]/g, d => String(d.charCodeAt(0) - 0x0660)); + + // Remove non-numeric characters except dots (for decimal support) + const cleaned = persianArabicToEnglish.replace(/[^0-9.]/g, ''); + + // Return number or default if invalid + const number = parseFloat(cleaned); + return isNaN(number) ? defaultValue : number; +} diff --git a/services/api.js b/services/api.js index 2682e3e..46d6b0f 100644 --- a/services/api.js +++ b/services/api.js @@ -28,7 +28,7 @@ api.interceptors.request.use( } return request; }, - (err) => Promise.reject(err), + (err) => Promise.reject(err) ); api.interceptors.response.use( @@ -41,7 +41,7 @@ api.interceptors.response.use( window.location.pathname = "/login"; } else { } - }, + } ); export default api;