change format all file

This commit is contained in:
Ehsan
2025-05-18 01:18:35 +03:30
parent 4a57468e26
commit 254d5d4ebd
84 changed files with 721 additions and 651 deletions
+28 -31
View File
@@ -92,41 +92,40 @@ export const alert = (type, text, prop) => {
</p>
<p className="text-[14px] font-normal">{text}</p>
</div>,
{ prop }
{ prop },
);
};
export const addLabelToList = (list) =>
list.map(item => {
list.map((item) => {
return {
...item,
label: item.name
}
})
label: item.name,
};
});
export const formatPhoneNumber = (input) => {
const digits = input.replace(/\D/g, '');
const digits = input.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(' ');
return [match[1], match[2], match[3]].filter(Boolean).join(" ");
};
export function validatePhoneNumber(input) {
const digits = input.replace(/\D/g, '');
const digits = input.replace(/\D/g, "");
if (!digits) {
return { valid: false, text: 'شماره موبایل نمی‌تواند خالی باشد.' };
return { valid: false, text: "شماره موبایل نمی‌تواند خالی باشد." };
}
if (digits.length !== 9) {
return { valid: false, text: 'شماره موبایل باید دقیقا 11 رقم باشد.' };
return { valid: false, text: "شماره موبایل باید دقیقا 11 رقم باشد." };
}
const isValid = /^[1-9]\d{8}$/.test(digits);
if (!isValid) {
return { valid: false, text: 'شماره موبایل نامعتبر است.' };
return { valid: false, text: "شماره موبایل نامعتبر است." };
}
return { valid: true, text: null };
@@ -134,47 +133,45 @@ export function validatePhoneNumber(input) {
export const searchOnList = (list, value, name) => {
let newList = list;
newList = list.filter(item =>
item[name].toLowerCase().includes(value)
)
newList = list.filter((item) => item[name].toLowerCase().includes(value));
return newList;
}
};
export const addKeyToList = (list, nameKey, nameValue) => {
const newList = list.map(item => {
const newList = list.map((item) => {
return {
...item,
[nameKey]: item[nameValue]
}
[nameKey]: item[nameValue],
};
});
return newList;
}
};
export function clearFilterParams(router, listRemove) {
const currentParams = new URLSearchParams(window.location.search);
const keysToRemove = listRemove;
keysToRemove.forEach((key) => currentParams.delete(key));
const queryString = currentParams.toString();
const newUrl = queryString ? `/doctors?${queryString}` : '/doctors';
const newUrl = queryString ? `/doctors?${queryString}` : "/doctors";
router.push(newUrl);
}
export const filterList = (data) => {
const parentList = specialties.filter(item => !item.parent);
const childrenList = specialties.filter(item => item.parent);
const parentList = specialties.filter((item) => !item.parent);
const childrenList = specialties.filter((item) => item.parent);
const changedParentList = addKeyToList(parentList, 'label', 'name') || [];
const changedChildrenList = addKeyToList(childrenList, 'label', 'name') || [];
const changedParentList = addKeyToList(parentList, "label", "name") || [];
const changedChildrenList = addKeyToList(childrenList, "label", "name") || [];
const filteredChildrenList =
data && data.category ?
changedChildrenList.filter(item => item.parent === data.category.id) :
[];
data && data.category
? changedChildrenList.filter((item) => item.parent === data.category.id)
: [];
return {
parentList: changedParentList,
childrenList: filteredChildrenList
}
}
childrenList: filteredChildrenList,
};
};