-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
282 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
'use client' | ||
|
||
import { Card, CardBody, CardHeader, Tab, Tabs } from '@nextui-org/react' | ||
import NextLink from 'next/link' | ||
import { usePathname } from 'next/navigation' | ||
import { ReactNode } from 'react' | ||
|
||
export default function Layout({ children }: { children: ReactNode }) { | ||
const pathname = usePathname() | ||
|
||
return ( | ||
<> | ||
<Card className="flex flex-col gap-2 w-full p-1"> | ||
<CardHeader> | ||
<div className="h1 font-bold text-2xl">Gestión de usuarios</div> | ||
</CardHeader> | ||
<CardBody className="overflow-hidden"> | ||
<Tabs | ||
size="lg" | ||
aria-label="Options" | ||
selectedKey={pathname} | ||
classNames={{ | ||
tab: 'max-w-fit', | ||
tabList: 'w-full', | ||
}} | ||
> | ||
<Tab | ||
key="/admin/users" | ||
href="/admin/users" | ||
title="Usuarios" | ||
as={NextLink} | ||
/> | ||
</Tabs> | ||
<div className="mt-4">{children}</div> | ||
</CardBody> | ||
</Card> | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
'use server' | ||
|
||
import UsersTable from '@/components/users-table/users-table' | ||
import { findUsers } from '@/core/user/infrastructure/actions/find-users' | ||
|
||
export default async function Page() { | ||
const users = await findUsers() | ||
return ( | ||
<> | ||
<UsersTable users={users} /> | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
'use client' | ||
|
||
import { Switch } from '@nextui-org/react' | ||
|
||
import UserResponse from '@/core/user/dto/responses/user.response' | ||
import enableUser from '@/core/user/infrastructure/actions/enable-user' | ||
|
||
interface UsersTableCellActionProperties { | ||
user: UserResponse | ||
} | ||
|
||
export function UsersTableCellAction( | ||
properties: UsersTableCellActionProperties, | ||
) { | ||
const { user } = properties | ||
const enabled = user.roles.includes('ROLE_MEMBER') | ||
if (user.roles.includes('ROLE_ADMIN')) { | ||
return null | ||
} | ||
|
||
const selectHandler = async (isSelected: boolean) => { | ||
await enableUser(user.email, isSelected) | ||
} | ||
|
||
return ( | ||
<Switch defaultSelected={enabled} onValueChange={selectHandler}> | ||
Activar | ||
</Switch> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
'use client' | ||
|
||
import { User } from '@nextui-org/react' | ||
import { Key } from 'react' | ||
|
||
import { UsersTableCellAction } from '@/components/users-table/users-table-cell-action' | ||
import UserResponse from '@/core/user/dto/responses/user.response' | ||
import gravatar from '@/lib/utils/gravatar' | ||
|
||
interface UsersTableCellProperties { | ||
columnKey: Key | ||
user: UserResponse | ||
} | ||
|
||
export default function UsersTableCell(properties: UsersTableCellProperties) { | ||
const { columnKey, user } = properties | ||
|
||
switch (columnKey) { | ||
case 'email': { | ||
return ( | ||
<User | ||
avatarProps={{ radius: 'lg', src: gravatar(user.email) }} | ||
description={user.email} | ||
name={user.name} | ||
> | ||
{user.email} | ||
</User> | ||
) | ||
} | ||
case 'roles': { | ||
return ( | ||
<div className="flex flex-col"> | ||
<p className="text-bold text-sm capitalize pl-1"> | ||
{user.roles.join(', ')} | ||
</p> | ||
</div> | ||
) | ||
} | ||
case 'actions': { | ||
return <UsersTableCellAction user={user} /> | ||
} | ||
default: { | ||
return user[columnKey as keyof UserResponse] | ||
} | ||
} | ||
} |
Oops, something went wrong.