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