Skip to content

Commit

Permalink
feat: update requestedRole filter
Browse files Browse the repository at this point in the history
  • Loading branch information
drewlyton committed Oct 1, 2024
1 parent 8a8fbe2 commit 3117cb9
Showing 1 changed file with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,18 @@ export function RequestPermissionDialog({
const requestedRole$: Observable<'administrator' | 'editor'> = useMemo(() => {
const adminRole = 'administrator' as const
if (!projectId || !client) return of(adminRole)
return client.observable.request<Role[]>({url: `/projects/${projectId}/roles`}).pipe(
map((roles) => {
const hasEditor = roles.find((role) => role.name === 'editor')
return hasEditor ? 'editor' : adminRole
}),
startWith(adminRole),
catchError(() => of(adminRole)),
)
return client.observable
.request<(Role & {appliesToUsers?: boolean})[]>({url: `/projects/${projectId}/roles`})
.pipe(
map((roles) => {
const hasEditor = roles
.filter((role) => role?.appliesToUsers)
.find((role) => role.name === 'editor')
return hasEditor ? 'editor' : adminRole
}),
startWith(adminRole),
catchError(() => of(adminRole)),
)
}, [projectId, client])

const requestedRole = useObservable(requestedRole$)
Expand Down

0 comments on commit 3117cb9

Please sign in to comment.