Skip to content

Commit

Permalink
..
Browse files Browse the repository at this point in the history
  • Loading branch information
ggazzo committed May 24, 2022
1 parent 5fea66e commit c154709
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ const query = (
selector: string;
} => ({ selector: JSON.stringify({ name: term }) });

type RoomAutoCompleteProps = Omit<ComponentProps<typeof AutoComplete>, 'value' | 'filter'> & {
value: any;
type RoomAutoCompleteProps<T> = Omit<ComponentProps<typeof AutoComplete>, 'value' | 'filter' | 'onChange'> & {
value: T;
onChange: (value: TemplateStringsArray) => void;
};

/* @deprecated */
const RoomAutoComplete = (props: RoomAutoCompleteProps): ReactElement => {
const RoomAutoComplete = <T,>(props: RoomAutoCompleteProps<T>): ReactElement => {
const [filter, setFilter] = useState('');
const { value: data } = useEndpointData(
'rooms.autocomplete.channelAndPrivate',
Expand All @@ -33,7 +34,8 @@ const RoomAutoComplete = (props: RoomAutoCompleteProps): ReactElement => {

return (
<AutoComplete
{...props}
value={props.value as any}
onChange={props.onChange as any}
filter={filter}
setFilter={setFilter}
renderSelected={({ value, label }): ReactElement => (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ const query = (
selector: string;
} => ({ selector: JSON.stringify({ term, conditions }) });

type UserAutoCompleteProps = Omit<ComponentProps<typeof AutoComplete>, 'value' | 'filter'> &
type UserAutoCompleteProps = Omit<ComponentProps<typeof AutoComplete>, 'value' | 'filter' | 'onChange'> &
Omit<ComponentProps<typeof Option>, 'value' | 'onChange'> & {
conditions?: { [key: string]: unknown };
filter?: string;
value: string;
onChange?: (value: string) => void;
};

const UserAutoComplete = ({ value, ...props }: UserAutoCompleteProps): ReactElement => {
Expand All @@ -33,8 +34,8 @@ const UserAutoComplete = ({ value, ...props }: UserAutoCompleteProps): ReactElem

return (
<AutoComplete
{...props}
value={value as any}
onChange={props.onChange as any}
filter={filter}
setFilter={setFilter}
renderSelected={({ value, label }): ReactElement => {
Expand All @@ -43,7 +44,7 @@ const UserAutoComplete = ({ value, ...props }: UserAutoCompleteProps): ReactElem
}

return (
<Chip height='x20' value={value} onClick={(_e: any): void => props.onChange?.(value, 'remove')} mie='x4'>
<Chip height='x20' value={value} onClick={(_e: any): void => props.onChange?.(value)} mie='x4'>
<UserAvatar size='x20' username={value} />
<Box verticalAlign='middle' is='span' margin='none' mi='x4'>
{label}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import UsersInRoleTable from './UsersInRoleTable';
const UsersInRolePage = ({ role }: { role: IRole }): ReactElement => {
const t = useTranslation();
const reload = useRef<() => void>(() => undefined);
const [user, setUser] = useState<string | undefined>('');
const [rid, setRid] = useState<string>();
const [user, setUser] = useState<string>('');
const [rid, setRid] = useState<string>('');
const [userError, setUserError] = useState<string>();
const dispatchToastMessage = useToastMessageDispatch();

Expand All @@ -39,7 +39,7 @@ const UsersInRolePage = ({ role }: { role: IRole }): ReactElement => {
setUser(undefined);
reload.current?.();
} catch (error) {
dispatchToastMessage({ type: 'error', message: String(error) });
dispatchToastMessage({ type: 'error', message: error });
}
});

Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/client/views/omnichannel/agents/AddAgent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const AddAgent: FC<AddAgentProps> = ({ reload, ...props }) => {
<Field>
<Field.Label>{t('Username')}</Field.Label>
<Field.Row>
<UserAutoComplete value={username} onChange={setUsername} />
<UserAutoComplete value={username} onChange={(username: string): void => setUsername(username)} />
<Button disabled={!username} onClick={handleSave} mis='x8' primary>
{t('Add')}
</Button>
Expand Down

0 comments on commit c154709

Please sign in to comment.