refactor: remove scope filtering functionality from roles table and service layer
This commit is contained in:
parent
fe707216f6
commit
8c0c92865e
@ -64,7 +64,7 @@ export const RolesTable = ({ tenantId, showHeader = true, compact = false }: Rol
|
||||
});
|
||||
|
||||
// Filter state
|
||||
const [scopeFilter, setScopeFilter] = useState<string | null>(null);
|
||||
// const [scopeFilter, setScopeFilter] = useState<string | null>(null);
|
||||
const [orderBy, setOrderBy] = useState<string[] | null>(null);
|
||||
|
||||
// View, Edit, Delete modals
|
||||
@ -79,15 +79,15 @@ export const RolesTable = ({ tenantId, showHeader = true, compact = false }: Rol
|
||||
const fetchRoles = async (
|
||||
page: number,
|
||||
itemsPerPage: number,
|
||||
scope: string | null = null,
|
||||
// scope: string | null = null,
|
||||
sortBy: string[] | null = null
|
||||
): Promise<void> => {
|
||||
try {
|
||||
setIsLoading(true);
|
||||
setError(null);
|
||||
const response = tenantId
|
||||
? await roleService.getByTenant(tenantId, page, itemsPerPage, scope, sortBy)
|
||||
: await roleService.getAll(page, itemsPerPage, scope, sortBy);
|
||||
? await roleService.getByTenant(tenantId, page, itemsPerPage, sortBy)
|
||||
: await roleService.getAll(page, itemsPerPage, sortBy);
|
||||
if (response.success) {
|
||||
setRoles(response.data);
|
||||
setPagination(response.pagination);
|
||||
@ -102,8 +102,8 @@ export const RolesTable = ({ tenantId, showHeader = true, compact = false }: Rol
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
fetchRoles(currentPage, limit, scopeFilter, orderBy);
|
||||
}, [currentPage, limit, scopeFilter, orderBy, tenantId]);
|
||||
fetchRoles(currentPage, limit, orderBy);
|
||||
}, [currentPage, limit, orderBy, tenantId]);
|
||||
|
||||
const handleCreateRole = async (data: CreateRoleRequest): Promise<void> => {
|
||||
try {
|
||||
@ -113,7 +113,7 @@ export const RolesTable = ({ tenantId, showHeader = true, compact = false }: Rol
|
||||
const description = response.message ? undefined : `${data.name} has been added`;
|
||||
showToast.success(message, description);
|
||||
setIsModalOpen(false);
|
||||
await fetchRoles(currentPage, limit, scopeFilter, orderBy);
|
||||
await fetchRoles(currentPage, limit, orderBy);
|
||||
} catch (err: any) {
|
||||
throw err;
|
||||
} finally {
|
||||
@ -145,7 +145,7 @@ export const RolesTable = ({ tenantId, showHeader = true, compact = false }: Rol
|
||||
setEditModalOpen(false);
|
||||
setSelectedRoleId(null);
|
||||
setSelectedRoleName('');
|
||||
await fetchRoles(currentPage, limit, scopeFilter, orderBy);
|
||||
await fetchRoles(currentPage, limit, orderBy);
|
||||
} catch (err: any) {
|
||||
throw err;
|
||||
} finally {
|
||||
@ -170,7 +170,7 @@ export const RolesTable = ({ tenantId, showHeader = true, compact = false }: Rol
|
||||
setDeleteModalOpen(false);
|
||||
setSelectedRoleId(null);
|
||||
setSelectedRoleName('');
|
||||
await fetchRoles(currentPage, limit, scopeFilter, orderBy);
|
||||
await fetchRoles(currentPage, limit, orderBy);
|
||||
} catch (err: any) {
|
||||
throw err; // Let the modal handle the error display
|
||||
} finally {
|
||||
@ -291,7 +291,7 @@ export const RolesTable = ({ tenantId, showHeader = true, compact = false }: Rol
|
||||
<div className="flex items-center justify-between">
|
||||
<h3 className="text-lg font-semibold text-[#0f1724]"></h3>
|
||||
<div className="flex items-center gap-2">
|
||||
<FilterDropdown
|
||||
{/* <FilterDropdown
|
||||
label="Scope"
|
||||
options={[
|
||||
{ value: '', label: 'All Scope' },
|
||||
@ -305,7 +305,7 @@ export const RolesTable = ({ tenantId, showHeader = true, compact = false }: Rol
|
||||
setCurrentPage(1);
|
||||
}}
|
||||
placeholder="Filter by scope"
|
||||
/>
|
||||
/> */}
|
||||
<PrimaryButton
|
||||
size="default"
|
||||
className="flex items-center gap-2"
|
||||
@ -403,7 +403,7 @@ export const RolesTable = ({ tenantId, showHeader = true, compact = false }: Rol
|
||||
{/* Filters */}
|
||||
<div className="flex flex-wrap items-center gap-3">
|
||||
{/* Scope Filter */}
|
||||
<FilterDropdown
|
||||
{/* <FilterDropdown
|
||||
label="Scope"
|
||||
options={[
|
||||
{ value: 'platform', label: 'Platform' },
|
||||
@ -416,7 +416,7 @@ export const RolesTable = ({ tenantId, showHeader = true, compact = false }: Rol
|
||||
setCurrentPage(1);
|
||||
}}
|
||||
placeholder="All"
|
||||
/>
|
||||
/> */}
|
||||
|
||||
{/* Sort Filter */}
|
||||
<FilterDropdown
|
||||
|
||||
@ -33,16 +33,16 @@ export const roleService = {
|
||||
tenantId: string,
|
||||
page: number = 1,
|
||||
limit: number = 20,
|
||||
scope?: string | null,
|
||||
// scope?: string | null,
|
||||
orderBy?: string[] | null
|
||||
): Promise<RolesResponse> => {
|
||||
const params = new URLSearchParams();
|
||||
params.append('page', String(page));
|
||||
params.append('limit', String(limit));
|
||||
params.append('tenant_id', tenantId);
|
||||
if (scope) {
|
||||
params.append('scope', scope);
|
||||
}
|
||||
// if (scope) {
|
||||
// params.append('scope', scope);
|
||||
// }
|
||||
if (orderBy && Array.isArray(orderBy) && orderBy.length === 2) {
|
||||
params.append('orderBy[]', orderBy[0]);
|
||||
params.append('orderBy[]', orderBy[1]);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user