36 lines
808 B
JavaScript
36 lines
808 B
JavaScript
export const sortRoles = (roles) => {
|
|
if (roles) {
|
|
const priorityRoles = [
|
|
"AdminX",
|
|
"SuperAdmin",
|
|
"ProvinceOperator",
|
|
"LiveStockProvinceJahad",
|
|
"Union",
|
|
"Cooperative",
|
|
"Rancher",
|
|
"KillHouse",
|
|
"KillHouseVet",
|
|
"VetFarm",
|
|
"VetSupervisor",
|
|
"CityVet",
|
|
"ParentCompany",
|
|
"Steward",
|
|
"Guilds",
|
|
"ProvinceSupervisor",
|
|
"Commerce",
|
|
"PoultryScience",
|
|
];
|
|
return [...roles].sort((a, b) => {
|
|
const aIndex = priorityRoles.indexOf(a);
|
|
const bIndex = priorityRoles.indexOf(b);
|
|
if (aIndex !== -1 && bIndex !== -1) {
|
|
return aIndex - bIndex;
|
|
}
|
|
if (aIndex !== -1) return -1;
|
|
if (bIndex !== -1) return 1;
|
|
return a.localeCompare(b);
|
|
});
|
|
}
|
|
return [];
|
|
};
|