2023-01-20 04:52:55 +01:00
|
|
|
import {
|
|
|
|
Button,
|
|
|
|
Dialog,
|
|
|
|
DialogActions,
|
|
|
|
DialogContent,
|
|
|
|
DialogTitle,
|
|
|
|
} from '@material-ui/core'
|
2023-01-22 04:14:58 +01:00
|
|
|
import { SimpleForm, TextInput, useCreate, useNotify } from 'react-admin'
|
|
|
|
import { useState } from 'react'
|
2023-01-20 04:52:55 +01:00
|
|
|
import { shareUrl } from '../utils'
|
2023-01-22 04:14:58 +01:00
|
|
|
import { useTranscodingOptions } from './useTranscodingOptions'
|
2023-01-20 04:52:55 +01:00
|
|
|
|
2023-01-22 04:14:58 +01:00
|
|
|
export const ShareDialog = ({ open, onClose, ids, resource, title }) => {
|
2023-01-20 04:52:55 +01:00
|
|
|
const notify = useNotify()
|
2023-01-22 04:04:40 +01:00
|
|
|
const [description, setDescription] = useState('')
|
2023-01-22 04:14:58 +01:00
|
|
|
const { TranscodingOptionsInput, format, maxBitRate, originalFormat } =
|
|
|
|
useTranscodingOptions()
|
2023-01-20 04:52:55 +01:00
|
|
|
const [createShare] = useCreate(
|
|
|
|
'share',
|
|
|
|
{
|
|
|
|
resourceType: resource,
|
|
|
|
resourceIds: ids?.join(','),
|
2023-01-22 04:04:40 +01:00
|
|
|
description,
|
2023-01-22 03:44:26 +01:00
|
|
|
...(!originalFormat && { format }),
|
|
|
|
...(!originalFormat && { maxBitRate }),
|
2023-01-20 04:52:55 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
onSuccess: (res) => {
|
|
|
|
const url = shareUrl(res?.data?.id)
|
2023-01-22 04:14:58 +01:00
|
|
|
onClose()
|
2023-01-20 04:52:55 +01:00
|
|
|
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 (
|
|
|
|
<Dialog
|
|
|
|
open={open}
|
|
|
|
onClose={onClose}
|
|
|
|
onBackdropClick={onClose}
|
2023-01-21 01:53:53 +01:00
|
|
|
aria-labelledby="share-dialog"
|
2023-01-20 04:52:55 +01:00
|
|
|
fullWidth={true}
|
2023-01-22 04:14:58 +01:00
|
|
|
maxWidth={'xs'}
|
2023-01-20 04:52:55 +01:00
|
|
|
>
|
2023-01-21 01:53:53 +01:00
|
|
|
<DialogTitle id="share-dialog">{title}</DialogTitle>
|
2023-01-20 04:52:55 +01:00
|
|
|
<DialogContent>
|
|
|
|
<SimpleForm toolbar={null} variant={'outlined'}>
|
2023-01-22 04:04:40 +01:00
|
|
|
<TextInput
|
|
|
|
source="description"
|
2023-01-22 04:14:58 +01:00
|
|
|
fullWidth
|
2023-01-22 04:04:40 +01:00
|
|
|
onChange={(event) => {
|
|
|
|
setDescription(event.target.value)
|
|
|
|
}}
|
|
|
|
/>
|
2023-01-22 04:14:58 +01:00
|
|
|
<TranscodingOptionsInput />
|
2023-01-20 04:52:55 +01:00
|
|
|
</SimpleForm>
|
|
|
|
</DialogContent>
|
|
|
|
<DialogActions>
|
|
|
|
<Button onClick={createShare} color="primary">
|
|
|
|
Share
|
|
|
|
</Button>
|
|
|
|
<Button onClick={onClose} color="primary">
|
|
|
|
Cancel
|
|
|
|
</Button>
|
|
|
|
</DialogActions>
|
|
|
|
</Dialog>
|
|
|
|
)
|
|
|
|
}
|