mirror of
https://github.com/umami-software/umami.git
synced 2026-02-06 21:57:16 +01:00
Updated teams button.
This commit is contained in:
parent
8048bc7866
commit
44393472cf
12 changed files with 46 additions and 55 deletions
|
|
@ -2,25 +2,30 @@ import { Key } from 'react';
|
|||
import { Text, Icon, Button, Popup, Menu, Item, PopupTrigger, Flexbox } from 'react-basics';
|
||||
import classNames from 'classnames';
|
||||
import Icons from 'components/icons';
|
||||
import { useLogin, useMessages, useNavigation } from 'components/hooks';
|
||||
import { useLogin, useMessages, useTeams } from 'components/hooks';
|
||||
import styles from './TeamsButton.module.css';
|
||||
|
||||
export function TeamsButton({ teamId }: { teamId: string }) {
|
||||
export function TeamsButton({
|
||||
teamId,
|
||||
onChange,
|
||||
}: {
|
||||
teamId: string;
|
||||
onChange?: (value: string) => void;
|
||||
}) {
|
||||
const { user } = useLogin();
|
||||
const { formatMessage, labels } = useMessages();
|
||||
const { router } = useNavigation();
|
||||
const team = user?.teams?.find(({ id }) => id === teamId);
|
||||
const cloudMode = !!process.env.cloudMode;
|
||||
const { result } = useTeams(user?.id);
|
||||
const team = result?.data?.find(({ id }) => id === teamId);
|
||||
|
||||
const handleSelect = (close: () => void, id: Key) => {
|
||||
if (id !== user.id) {
|
||||
router.push(cloudMode ? `${process.env.cloudUrl}/teams/${id}` : `/teams/${id}`);
|
||||
} else {
|
||||
router.push('/');
|
||||
}
|
||||
onChange?.(id as string);
|
||||
close();
|
||||
};
|
||||
|
||||
if (!result) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<PopupTrigger>
|
||||
<Button className={styles.button} variant="quiet">
|
||||
|
|
@ -40,7 +45,7 @@ export function TeamsButton({ teamId }: { teamId: string }) {
|
|||
</Flexbox>
|
||||
</Item>
|
||||
<div className={styles.heading}>{formatMessage(labels.team)}</div>
|
||||
{user?.teams?.map(({ id, name }) => (
|
||||
{result?.data?.map(({ id, name }) => (
|
||||
<Item key={id} className={classNames({ [styles.selected]: id === teamId })}>
|
||||
<Flexbox gap={10} alignItems="center">
|
||||
<Icon>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue