umami/components/input/WebsiteSelect.js

30 lines
790 B
JavaScript
Raw Normal View History

2023-02-15 11:27:18 +01:00
import { Dropdown, Item } from 'react-basics';
import useApi from 'hooks/useApi';
2023-03-22 22:05:55 +01:00
import useMessages from 'hooks/useMessages';
2023-02-15 11:27:18 +01:00
2023-04-21 17:00:42 +02:00
export function WebsiteSelect({ websiteId, onSelect }) {
2023-03-22 22:05:55 +01:00
const { formatMessage, labels } = useMessages();
2023-02-15 11:27:18 +01:00
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 }}
>
2023-02-24 11:41:02 +01:00
{({ id, name }) => <Item key={id}>{name}</Item>}
2023-02-15 11:27:18 +01:00
</Dropdown>
);
}
2023-04-21 17:00:42 +02:00
export default WebsiteSelect;