Refactor organization and user management components/tests for simplification and improved clarity
- Removed unused properties (`slug`, `is_active`, etc.) in organization and user-related components and test data. - Simplified function data typing by removing redundant `any` usage. - Updated `params` in `OrganizationMembersPage` for Promise resolution and async handling. - Cleaned up unused variables and streamlined form handling in `AddMemberDialog`.
This commit is contained in:
@@ -17,12 +17,14 @@ export const metadata: Metadata = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
interface PageProps {
|
interface PageProps {
|
||||||
params: {
|
params: Promise<{
|
||||||
id: string;
|
id: string;
|
||||||
};
|
}>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function OrganizationMembersPage({ params }: PageProps) {
|
export default async function OrganizationMembersPage({ params }: PageProps) {
|
||||||
|
const { id } = await params;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="container mx-auto px-6 py-8">
|
<div className="container mx-auto px-6 py-8">
|
||||||
<div className="space-y-6">
|
<div className="space-y-6">
|
||||||
@@ -36,7 +38,7 @@ export default function OrganizationMembersPage({ params }: PageProps) {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Organization Members Content */}
|
{/* Organization Members Content */}
|
||||||
<OrganizationMembersContent organizationId={params.id} />
|
<OrganizationMembersContent organizationId={id} />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ export function AddMemberDialog({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const { register, handleSubmit, formState: { errors }, setValue, watch } = form;
|
const { handleSubmit, formState: { errors }, setValue, watch } = form;
|
||||||
const selectedRole = watch('role');
|
const selectedRole = watch('role');
|
||||||
const selectedEmail = watch('userEmail');
|
const selectedEmail = watch('userEmail');
|
||||||
|
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ import { OrganizationFormDialog } from './OrganizationFormDialog';
|
|||||||
export function OrganizationManagementContent() {
|
export function OrganizationManagementContent() {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const searchParams = useSearchParams();
|
const searchParams = useSearchParams();
|
||||||
const { user: currentUser } = useAuth();
|
|
||||||
|
|
||||||
// URL state
|
// URL state
|
||||||
const page = parseInt(searchParams.get('page') || '1', 10);
|
const page = parseInt(searchParams.get('page') || '1', 10);
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ interface OrganizationMembersContentProps {
|
|||||||
export function OrganizationMembersContent({ organizationId }: OrganizationMembersContentProps) {
|
export function OrganizationMembersContent({ organizationId }: OrganizationMembersContentProps) {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const searchParams = useSearchParams();
|
const searchParams = useSearchParams();
|
||||||
const { user: currentUser } = useAuth();
|
|
||||||
|
|
||||||
// URL state
|
// URL state
|
||||||
const page = parseInt(searchParams.get('page') || '1', 10);
|
const page = parseInt(searchParams.get('page') || '1', 10);
|
||||||
|
|||||||
@@ -168,7 +168,7 @@ export function UserFormDialog({
|
|||||||
|
|
||||||
await updateUser.mutateAsync({
|
await updateUser.mutateAsync({
|
||||||
userId: user.id,
|
userId: user.id,
|
||||||
userData: updateData as any,
|
userData: updateData,
|
||||||
});
|
});
|
||||||
|
|
||||||
toast.success(`User ${data.first_name} ${data.last_name || ''} updated successfully`);
|
toast.success(`User ${data.first_name} ${data.last_name || ''} updated successfully`);
|
||||||
@@ -181,9 +181,8 @@ export function UserFormDialog({
|
|||||||
first_name: data.first_name,
|
first_name: data.first_name,
|
||||||
last_name: data.last_name || undefined,
|
last_name: data.last_name || undefined,
|
||||||
password: data.password,
|
password: data.password,
|
||||||
is_active: data.is_active,
|
|
||||||
is_superuser: data.is_superuser,
|
is_superuser: data.is_superuser,
|
||||||
} as any);
|
});
|
||||||
|
|
||||||
toast.success(`User ${data.first_name} ${data.last_name || ''} created successfully`);
|
toast.success(`User ${data.first_name} ${data.last_name || ''} created successfully`);
|
||||||
onOpenChange(false);
|
onOpenChange(false);
|
||||||
|
|||||||
@@ -76,7 +76,6 @@ export function UserListTable({
|
|||||||
|
|
||||||
const allSelected =
|
const allSelected =
|
||||||
users.length > 0 && users.every((user) => selectedUsers.includes(user.id));
|
users.length > 0 && users.every((user) => selectedUsers.includes(user.id));
|
||||||
const someSelected = users.some((user) => selectedUsers.includes(user.id));
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="space-y-4">
|
<div className="space-y-4">
|
||||||
|
|||||||
@@ -86,8 +86,8 @@ export function UserManagementContent() {
|
|||||||
const handleSelectAll = (selected: boolean) => {
|
const handleSelectAll = (selected: boolean) => {
|
||||||
if (selected) {
|
if (selected) {
|
||||||
const selectableUsers = users
|
const selectableUsers = users
|
||||||
.filter((u: any) => u.id !== currentUser?.id)
|
.filter((u) => u.id !== currentUser?.id)
|
||||||
.map((u: any) => u.id);
|
.map((u) => u.id);
|
||||||
setSelectedUsers(selectableUsers);
|
setSelectedUsers(selectableUsers);
|
||||||
} else {
|
} else {
|
||||||
setSelectedUsers([]);
|
setSelectedUsers([]);
|
||||||
|
|||||||
@@ -32,7 +32,6 @@ describe('OrganizationActionMenu', () => {
|
|||||||
const mockOrganization: Organization = {
|
const mockOrganization: Organization = {
|
||||||
id: '1',
|
id: '1',
|
||||||
name: 'Acme Corporation',
|
name: 'Acme Corporation',
|
||||||
slug: 'acme-corporation',
|
|
||||||
description: 'Leading provider',
|
description: 'Leading provider',
|
||||||
is_active: true,
|
is_active: true,
|
||||||
created_at: '2025-01-01T00:00:00Z',
|
created_at: '2025-01-01T00:00:00Z',
|
||||||
|
|||||||
@@ -39,7 +39,6 @@ describe('OrganizationFormDialog', () => {
|
|||||||
const mockOrganization: Organization = {
|
const mockOrganization: Organization = {
|
||||||
id: 'org-1',
|
id: 'org-1',
|
||||||
name: 'Test Organization',
|
name: 'Test Organization',
|
||||||
slug: 'test-org',
|
|
||||||
description: 'Test description',
|
description: 'Test description',
|
||||||
is_active: true,
|
is_active: true,
|
||||||
created_at: '2025-01-01',
|
created_at: '2025-01-01',
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ describe('OrganizationListTable', () => {
|
|||||||
{
|
{
|
||||||
id: '1',
|
id: '1',
|
||||||
name: 'Acme Corporation',
|
name: 'Acme Corporation',
|
||||||
slug: 'acme-corporation',
|
|
||||||
description: 'Leading provider of innovative solutions',
|
description: 'Leading provider of innovative solutions',
|
||||||
is_active: true,
|
is_active: true,
|
||||||
created_at: '2025-01-01T00:00:00Z',
|
created_at: '2025-01-01T00:00:00Z',
|
||||||
@@ -32,7 +31,6 @@ describe('OrganizationListTable', () => {
|
|||||||
{
|
{
|
||||||
id: '2',
|
id: '2',
|
||||||
name: 'Tech Startup Inc',
|
name: 'Tech Startup Inc',
|
||||||
slug: 'tech-startup-inc',
|
|
||||||
description: null,
|
description: null,
|
||||||
is_active: false,
|
is_active: false,
|
||||||
created_at: '2025-01-15T00:00:00Z',
|
created_at: '2025-01-15T00:00:00Z',
|
||||||
|
|||||||
@@ -487,7 +487,6 @@ describe('useAdmin hooks', () => {
|
|||||||
first_name: 'New',
|
first_name: 'New',
|
||||||
last_name: 'User',
|
last_name: 'User',
|
||||||
password: 'Password123',
|
password: 'Password123',
|
||||||
is_active: true,
|
|
||||||
is_superuser: false,
|
is_superuser: false,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -498,7 +497,6 @@ describe('useAdmin hooks', () => {
|
|||||||
first_name: 'New',
|
first_name: 'New',
|
||||||
last_name: 'User',
|
last_name: 'User',
|
||||||
password: 'Password123',
|
password: 'Password123',
|
||||||
is_active: true,
|
|
||||||
is_superuser: false,
|
is_superuser: false,
|
||||||
},
|
},
|
||||||
throwOnError: false,
|
throwOnError: false,
|
||||||
@@ -516,7 +514,6 @@ describe('useAdmin hooks', () => {
|
|||||||
email: 'test@example.com',
|
email: 'test@example.com',
|
||||||
first_name: 'Test',
|
first_name: 'Test',
|
||||||
password: 'Password123',
|
password: 'Password123',
|
||||||
is_active: true,
|
|
||||||
is_superuser: false,
|
is_superuser: false,
|
||||||
})
|
})
|
||||||
).rejects.toThrow('Failed to create user');
|
).rejects.toThrow('Failed to create user');
|
||||||
@@ -536,7 +533,6 @@ describe('useAdmin hooks', () => {
|
|||||||
await result.current.mutateAsync({
|
await result.current.mutateAsync({
|
||||||
userId: '1',
|
userId: '1',
|
||||||
userData: {
|
userData: {
|
||||||
email: 'updated@example.com',
|
|
||||||
first_name: 'Updated',
|
first_name: 'Updated',
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@@ -545,7 +541,6 @@ describe('useAdmin hooks', () => {
|
|||||||
expect(mockUpdateUser).toHaveBeenCalledWith({
|
expect(mockUpdateUser).toHaveBeenCalledWith({
|
||||||
path: { user_id: '1' },
|
path: { user_id: '1' },
|
||||||
body: {
|
body: {
|
||||||
email: 'updated@example.com',
|
|
||||||
first_name: 'Updated',
|
first_name: 'Updated',
|
||||||
},
|
},
|
||||||
throwOnError: false,
|
throwOnError: false,
|
||||||
@@ -561,7 +556,7 @@ describe('useAdmin hooks', () => {
|
|||||||
await expect(
|
await expect(
|
||||||
result.current.mutateAsync({
|
result.current.mutateAsync({
|
||||||
userId: '1',
|
userId: '1',
|
||||||
userData: { email: 'test@example.com' },
|
userData: { first_name: 'Test' },
|
||||||
})
|
})
|
||||||
).rejects.toThrow('Failed to update user');
|
).rejects.toThrow('Failed to update user');
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user