import { useFormikContext } from 'formik' import { UserAccessPermission } from '@prisma/client' import IVInputField from '~/components/IVInputField' import IVSelect from '~/components/IVSelect' import { EXPOSED_ROLES } from '~/utils/permissions' import { userAccessPermissionToString } from '~/utils/text' export interface PermissionSelectorProps { label?: string name: string helpText?: string disabled?: boolean isOwner?: boolean isUser?: boolean allowEmpty?: boolean } export default function PermissionSelector({ label = 'Role', name, helpText, disabled, isOwner, isUser, allowEmpty = false, }: PermissionSelectorProps) { const { values, setFieldValue } = useFormikContext<{ role: UserAccessPermission | '' }>() return (
Learn more {' '} about the different access levels of Interval roles } helpText={ helpText ?? (isUser ? 'You cannot edit your own permissions.' : isOwner ? "You cannot edit the organization owner's permissions." : undefined) } > ({ label: userAccessPermissionToString(role), value: role, }))} defaultLabel={allowEmpty ? '(No additional permission)' : undefined} onChange={e => setFieldValue('role', e.target.value)} />
) }