utopia-ui/src/Components/Map/Permissions.tsx
Anton Tranelis 67a5e6e22d
docs(docu): improved documentation (#169)
* rollup - fail when typescript has warnings or errors

Currently this is detected when building the docu. Since the developer
rarely does that the problem is detected on github.
This change allows the developer to discover the error early by failing
the build.

* cleand up types of UtopiaMap and UtopiaMapInner

* documented UtopiaMap, Tags, Tag and  Permissions

---------

Co-authored-by: Ulf Gebhardt <ulf.gebhardt@webcraft-media.de>
2025-04-21 23:21:11 +00:00

64 lines
1.8 KiB
TypeScript

import { useEffect } from 'react'
import { useAuth } from '#components/Auth/useAuth'
import { useSetPermissionData, useSetPermissionApi, useSetAdminRole } from './hooks/usePermissions'
import type { ItemsApi } from '#types/ItemsApi'
import type { Permission } from '#types/Permission'
export type { Permission } from '#types/Permission'
export type { ItemsApi } from '#types/ItemsApi'
/**
* This Components injects Permissions comming from an {@link ItemsApi | `API`}
* ```tsx
* <Permissions api={itemsApiInstance} adminRole="8141dee8-8e10-48d0-baf1-680aea271298" />
* ```
* or from on {@link Permission| `Array`}
* ```tsx
* <Permissions data={permissions} adminRole="8141dee8-8e10-48d0-baf1-680aea271298" />
* ```
* Can be child of {@link AppShell | `AppShell`}
* ```tsx
* <AppShell>
* ...
* <Permissions api={itemsApiInstance} adminRole="8141dee8-8e10-48d0-baf1-680aea271298" />
* </AppShell>
* ```
* Or child of {@link UtopiaMap | `UtopiaMap`}
* ```tsx
* <UtopiaMap>
* ...
* <Permissions api={itemsApiInstance} adminRole="8141dee8-8e10-48d0-baf1-680aea271298" />
* </UtopiaMap>
* ```
* @category Map
*/
export function Permissions({
data,
api,
adminRole,
}: {
/** Array with all the permissions inside */
data?: Permission[]
/** API to fetch all the permissions from a server */
api?: ItemsApi<Permission>
/** UUID of the admin role which has always all the permissions */
adminRole?: string
}) {
const setPermissionData = useSetPermissionData()
const setPermissionApi = useSetPermissionApi()
const setAdminRole = useSetAdminRole()
const { user } = useAuth()
useEffect(() => {
adminRole && setAdminRole(adminRole)
data && setPermissionData(data)
api && setPermissionApi(api)
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [api, data, adminRole, user])
return <></>
}