import React from 'react'; import type { UseFormRegisterReturn } from 'react-hook-form'; import { useIsDeviceLargerThanMd } from '~/stores/ui'; import type { Scope } from '../../../interfaces/scope'; import styles from './AccessTokenScopeList.module.scss'; const moduleClass = styles['access-token-scope-list'] ?? ''; interface scopeObject { [key: string]: Scope | scopeObject; } interface AccessTokenScopeListProps { scopeObject: scopeObject; register: UseFormRegisterReturn<'scopes'>; disabledScopes: Set level?: number; } /** * Renders the permission object recursively as nested checkboxes. */ export const AccessTokenScopeList: React.FC = ({ scopeObject, register, disabledScopes, level = 0, }) => { const { data: isDeviceLargerThanMd } = useIsDeviceLargerThanMd(); // Convert object into an array to determine "first vs. non-first" elements const entries = Object.entries(scopeObject); return ( <> {entries.map(([scopeKey, scopeValue], idx) => { // Get indentation class based on level // Example: Insert
only for levels 0 or 1, except for the first item const showHr = (level === 0 || level === 1) && idx !== 0; if (typeof scopeValue === 'object') { return (
{showHr &&
}
desc for {scopeKey}
{/* Render recursively */}
); } // If it's a string, render a checkbox return (
desc for {scopeKey}
); })} ); };