index.tsx 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. import { usePermissionModules } from '@/hooks/permissions/usePermissionModules'
  2. import { Badge } from '@/components/ui/badge'
  3. import {
  4. Card,
  5. CardContent,
  6. CardDescription,
  7. CardHeader,
  8. CardTitle,
  9. } from '@/components/ui/card'
  10. import { ConfigDrawer } from '@/components/config-drawer'
  11. import { Header } from '@/components/layout/header'
  12. import { Main } from '@/components/layout/main'
  13. import { ProfileDropdown } from '@/components/profile-dropdown'
  14. import { Search } from '@/components/search'
  15. import { ThemeSwitch } from '@/components/theme-switch'
  16. export function Permissions() {
  17. const { data: modules, isLoading, isError } = usePermissionModules()
  18. return (
  19. <>
  20. <Header fixed>
  21. <Search className='me-auto' />
  22. <ThemeSwitch />
  23. <ConfigDrawer />
  24. <ProfileDropdown />
  25. </Header>
  26. <Main className='flex flex-1 flex-col gap-4 sm:gap-6'>
  27. <div>
  28. <h2 className='text-2xl font-bold tracking-tight'>دسترسی‌ها</h2>
  29. <p className='text-muted-foreground'>
  30. فهرست دسترسی‌هایی که می‌توان به نقش‌ها اختصاص داد.
  31. </p>
  32. </div>
  33. {isLoading ? (
  34. <div>در حال دریافت...</div>
  35. ) : isError ? (
  36. <div className='text-sm text-destructive'>
  37. دریافت دسترسی‌ها ممکن نشد.
  38. </div>
  39. ) : (
  40. <div className='grid gap-4'>
  41. {modules?.map((module) => (
  42. <Card key={module.key}>
  43. <CardHeader>
  44. <CardTitle>{module.label}</CardTitle>
  45. <CardDescription>{module.key}</CardDescription>
  46. </CardHeader>
  47. <CardContent className='space-y-4'>
  48. {module.actions.length > 0 && (
  49. <div className='space-y-2'>
  50. <p className='text-sm font-medium'>عملیات</p>
  51. <div className='flex flex-wrap gap-2'>
  52. {module.actions.map((action) => (
  53. <Badge key={action.name} variant='secondary'>
  54. {action.label}
  55. </Badge>
  56. ))}
  57. </div>
  58. </div>
  59. )}
  60. {module.fields.length > 0 && (
  61. <div className='space-y-3'>
  62. <p className='text-sm font-medium'>فیلدها</p>
  63. {module.fields.map((field) => (
  64. <div key={field.key} className='space-y-2'>
  65. <p className='text-sm text-muted-foreground'>
  66. {field.label}
  67. </p>
  68. <div className='flex flex-wrap gap-2'>
  69. {field.permissions.map((permission) => (
  70. <Badge key={permission.name} variant='outline'>
  71. {permission.label}
  72. </Badge>
  73. ))}
  74. </div>
  75. </div>
  76. ))}
  77. </div>
  78. )}
  79. </CardContent>
  80. </Card>
  81. ))}
  82. </div>
  83. )}
  84. </Main>
  85. </>
  86. )
  87. }