import { Button, Dialog, DialogActions, DialogContent, DialogTitle, } from '@material-ui/core' import { SelectInput, SimpleForm, useCreate, useGetList, useNotify, } from 'react-admin' import { useMemo, useState } from 'react' import { shareUrl } from '../utils' import Typography from '@material-ui/core/Typography' export const ShareDialog = ({ open, close, onClose, ids, resource }) => { const notify = useNotify() const [format, setFormat] = useState('') const [maxBitRate, setMaxBitRate] = useState(0) const { data: formats, loading } = useGetList( 'transcoding', { page: 1, perPage: 1000, }, { field: 'name', order: 'ASC' } ) const formatOptions = useMemo( () => loading ? [] : Object.values(formats).map((f) => { return { id: f.targetFormat, name: f.targetFormat } }), [formats, loading] ) const [createShare] = useCreate( 'share', { resourceType: resource, resourceIds: ids?.join(','), format, maxBitRate, }, { onSuccess: (res) => { const url = shareUrl(res?.data?.id) close() navigator.clipboard .writeText(url) .then(() => { notify(`URL copied to clipboard: ${url}`, { type: 'info', multiLine: true, duration: 0, }) }) .catch((err) => { notify(`Error copying URL ${url} to clipboard: ${err.message}`, { type: 'warning', multiLine: true, duration: 0, }) }) }, onFailure: (error) => notify(`Error sharing media: ${error.message}`, { type: 'warning' }), } ) return ( Create a link to share your music with friends Select transcoding options: (Leave options empty for original quality) { setFormat(event.target.value) }} /> { setMaxBitRate(event.target.value) }} /> ) }