forked from cardosofelipe/fast-next-template
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 {
|
||||
params: {
|
||||
params: Promise<{
|
||||
id: string;
|
||||
};
|
||||
}>;
|
||||
}
|
||||
|
||||
export default function OrganizationMembersPage({ params }: PageProps) {
|
||||
export default async function OrganizationMembersPage({ params }: PageProps) {
|
||||
const { id } = await params;
|
||||
|
||||
return (
|
||||
<div className="container mx-auto px-6 py-8">
|
||||
<div className="space-y-6">
|
||||
@@ -36,7 +38,7 @@ export default function OrganizationMembersPage({ params }: PageProps) {
|
||||
</div>
|
||||
|
||||
{/* Organization Members Content */}
|
||||
<OrganizationMembersContent organizationId={params.id} />
|
||||
<OrganizationMembersContent organizationId={id} />
|
||||
</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 selectedEmail = watch('userEmail');
|
||||
|
||||
|
||||
@@ -21,7 +21,6 @@ import { OrganizationFormDialog } from './OrganizationFormDialog';
|
||||
export function OrganizationManagementContent() {
|
||||
const router = useRouter();
|
||||
const searchParams = useSearchParams();
|
||||
const { user: currentUser } = useAuth();
|
||||
|
||||
// URL state
|
||||
const page = parseInt(searchParams.get('page') || '1', 10);
|
||||
|
||||
@@ -26,7 +26,6 @@ interface OrganizationMembersContentProps {
|
||||
export function OrganizationMembersContent({ organizationId }: OrganizationMembersContentProps) {
|
||||
const router = useRouter();
|
||||
const searchParams = useSearchParams();
|
||||
const { user: currentUser } = useAuth();
|
||||
|
||||
// URL state
|
||||
const page = parseInt(searchParams.get('page') || '1', 10);
|
||||
|
||||
@@ -168,7 +168,7 @@ export function UserFormDialog({
|
||||
|
||||
await updateUser.mutateAsync({
|
||||
userId: user.id,
|
||||
userData: updateData as any,
|
||||
userData: updateData,
|
||||
});
|
||||
|
||||
toast.success(`User ${data.first_name} ${data.last_name || ''} updated successfully`);
|
||||
@@ -181,9 +181,8 @@ export function UserFormDialog({
|
||||
first_name: data.first_name,
|
||||
last_name: data.last_name || undefined,
|
||||
password: data.password,
|
||||
is_active: data.is_active,
|
||||
is_superuser: data.is_superuser,
|
||||
} as any);
|
||||
});
|
||||
|
||||
toast.success(`User ${data.first_name} ${data.last_name || ''} created successfully`);
|
||||
onOpenChange(false);
|
||||
|
||||
@@ -76,7 +76,6 @@ export function UserListTable({
|
||||
|
||||
const allSelected =
|
||||
users.length > 0 && users.every((user) => selectedUsers.includes(user.id));
|
||||
const someSelected = users.some((user) => selectedUsers.includes(user.id));
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
|
||||
@@ -86,8 +86,8 @@ export function UserManagementContent() {
|
||||
const handleSelectAll = (selected: boolean) => {
|
||||
if (selected) {
|
||||
const selectableUsers = users
|
||||
.filter((u: any) => u.id !== currentUser?.id)
|
||||
.map((u: any) => u.id);
|
||||
.filter((u) => u.id !== currentUser?.id)
|
||||
.map((u) => u.id);
|
||||
setSelectedUsers(selectableUsers);
|
||||
} else {
|
||||
setSelectedUsers([]);
|
||||
|
||||
@@ -32,7 +32,6 @@ describe('OrganizationActionMenu', () => {
|
||||
const mockOrganization: Organization = {
|
||||
id: '1',
|
||||
name: 'Acme Corporation',
|
||||
slug: 'acme-corporation',
|
||||
description: 'Leading provider',
|
||||
is_active: true,
|
||||
created_at: '2025-01-01T00:00:00Z',
|
||||
|
||||
@@ -39,7 +39,6 @@ describe('OrganizationFormDialog', () => {
|
||||
const mockOrganization: Organization = {
|
||||
id: 'org-1',
|
||||
name: 'Test Organization',
|
||||
slug: 'test-org',
|
||||
description: 'Test description',
|
||||
is_active: true,
|
||||
created_at: '2025-01-01',
|
||||
|
||||
@@ -22,7 +22,6 @@ describe('OrganizationListTable', () => {
|
||||
{
|
||||
id: '1',
|
||||
name: 'Acme Corporation',
|
||||
slug: 'acme-corporation',
|
||||
description: 'Leading provider of innovative solutions',
|
||||
is_active: true,
|
||||
created_at: '2025-01-01T00:00:00Z',
|
||||
@@ -32,7 +31,6 @@ describe('OrganizationListTable', () => {
|
||||
{
|
||||
id: '2',
|
||||
name: 'Tech Startup Inc',
|
||||
slug: 'tech-startup-inc',
|
||||
description: null,
|
||||
is_active: false,
|
||||
created_at: '2025-01-15T00:00:00Z',
|
||||
|
||||
@@ -487,7 +487,6 @@ describe('useAdmin hooks', () => {
|
||||
first_name: 'New',
|
||||
last_name: 'User',
|
||||
password: 'Password123',
|
||||
is_active: true,
|
||||
is_superuser: false,
|
||||
});
|
||||
});
|
||||
@@ -498,7 +497,6 @@ describe('useAdmin hooks', () => {
|
||||
first_name: 'New',
|
||||
last_name: 'User',
|
||||
password: 'Password123',
|
||||
is_active: true,
|
||||
is_superuser: false,
|
||||
},
|
||||
throwOnError: false,
|
||||
@@ -516,7 +514,6 @@ describe('useAdmin hooks', () => {
|
||||
email: 'test@example.com',
|
||||
first_name: 'Test',
|
||||
password: 'Password123',
|
||||
is_active: true,
|
||||
is_superuser: false,
|
||||
})
|
||||
).rejects.toThrow('Failed to create user');
|
||||
@@ -536,7 +533,6 @@ describe('useAdmin hooks', () => {
|
||||
await result.current.mutateAsync({
|
||||
userId: '1',
|
||||
userData: {
|
||||
email: 'updated@example.com',
|
||||
first_name: 'Updated',
|
||||
},
|
||||
});
|
||||
@@ -545,7 +541,6 @@ describe('useAdmin hooks', () => {
|
||||
expect(mockUpdateUser).toHaveBeenCalledWith({
|
||||
path: { user_id: '1' },
|
||||
body: {
|
||||
email: 'updated@example.com',
|
||||
first_name: 'Updated',
|
||||
},
|
||||
throwOnError: false,
|
||||
@@ -561,7 +556,7 @@ describe('useAdmin hooks', () => {
|
||||
await expect(
|
||||
result.current.mutateAsync({
|
||||
userId: '1',
|
||||
userData: { email: 'test@example.com' },
|
||||
userData: { first_name: 'Test' },
|
||||
})
|
||||
).rejects.toThrow('Failed to update user');
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user