mirror of
https://github.com/kremalicious/umami.git
synced 2024-11-15 17:55:08 +01:00
28 lines
767 B
JavaScript
28 lines
767 B
JavaScript
import { Dropdown, Item } from 'react-basics';
|
|
import useApi from 'hooks/useApi';
|
|
import useMessages from 'hooks/useMessages';
|
|
|
|
export default function WebsiteSelect({ websiteId, onSelect }) {
|
|
const { formatMessage, labels } = useMessages();
|
|
const { get, useQuery } = useApi();
|
|
const { data } = useQuery(['websites:me'], () => get('/me/websites'));
|
|
|
|
const renderValue = value => {
|
|
return data?.find(({ id }) => id === value)?.name;
|
|
};
|
|
|
|
return (
|
|
<Dropdown
|
|
items={data}
|
|
value={websiteId}
|
|
renderValue={renderValue}
|
|
onChange={onSelect}
|
|
alignment="end"
|
|
placeholder={formatMessage(labels.selectWebsite)}
|
|
style={{ width: 200 }}
|
|
>
|
|
{({ id, name }) => <Item key={id}>{name}</Item>}
|
|
</Dropdown>
|
|
);
|
|
}
|