mirror of
https://github.com/Unleash/unleash.git
synced 2025-10-13 11:17:26 +02:00
* feat: update useProjectApi hook * fix: refactor to hooks * fix: remove some ts errors * fix: set message if error exists directly on response * fix: remove console logs * fix: typo * delete: context2 * feat: filter added user from user add list * fix: cleanup PR based on feedback * fix: handle undefined roles in ProjectRoleSelect * fix: use target value * fix: type event * fix: conflict * fix: add appropriate types * fix conflicts * fix: explicit query * fix: refactor list * refactor: permission icon button * fix: conflict * fix: ts errors * refactor: break list into its own component * fix: use stringifed deps * fix: explicit export * fix: update pr according to comments Co-authored-by: Fredrik Oseberg <fredrik.no@gmail.com>
75 lines
2.1 KiB
TypeScript
75 lines
2.1 KiB
TypeScript
import { FormControl, InputLabel, Select, MenuItem } from '@material-ui/core';
|
|
import React from 'react';
|
|
import { IProjectRole } from '../../../../interfaces/role';
|
|
|
|
import { useStyles } from '../ProjectAccess.styles';
|
|
|
|
interface IProjectRoleSelect {
|
|
roles: IProjectRole[];
|
|
labelId: string;
|
|
id: string;
|
|
placeholder?: string;
|
|
onChange: (
|
|
evt: React.ChangeEvent<{
|
|
name?: string | undefined;
|
|
value: unknown;
|
|
}>
|
|
) => void;
|
|
value: any;
|
|
}
|
|
|
|
export const ProjectRoleSelect: React.FC<IProjectRoleSelect> = ({
|
|
roles,
|
|
onChange,
|
|
labelId,
|
|
id,
|
|
value,
|
|
placeholder,
|
|
children,
|
|
}) => {
|
|
const styles = useStyles();
|
|
return (
|
|
<FormControl variant="outlined" size="small">
|
|
<InputLabel
|
|
style={{ backgroundColor: '#fff' }}
|
|
id="add-user-select-role-label"
|
|
>
|
|
Role
|
|
</InputLabel>
|
|
<Select
|
|
labelId={labelId}
|
|
id={id}
|
|
classes={{ root: styles.projectRoleSelect }}
|
|
placeholder={placeholder}
|
|
value={value || ''}
|
|
onChange={onChange}
|
|
renderValue={roleId => {
|
|
const role = roles?.find(role => {
|
|
return role.id === roleId;
|
|
});
|
|
return role?.name || '';
|
|
}}
|
|
>
|
|
{children}
|
|
{roles?.map(role => (
|
|
<MenuItem
|
|
key={role.id}
|
|
value={role.id}
|
|
classes={{
|
|
root: styles.menuItem,
|
|
}}
|
|
>
|
|
<div>
|
|
<span className={styles.roleName}>{role.name}</span>
|
|
<p>
|
|
{role.description ||
|
|
'No role description available.'}
|
|
</p>
|
|
</div>
|
|
</MenuItem>
|
|
))}
|
|
</Select>
|
|
</FormControl>
|
|
);
|
|
};
|