@@ -2,35 +2,57 @@ import Button from '@material-ui/core/Button';
22import Dialog from '@material-ui/core/Dialog' ;
33import DialogActions from '@material-ui/core/DialogActions' ;
44import DialogTitle from '@material-ui/core/DialogTitle' ;
5+ import Divider from '@material-ui/core/Divider' ;
6+ import { compose } from 'redux' ;
57
6- import { storage as api } from '@vidispine/vdt-api' ;
8+ import * as formActions from '../../formactions/storage' ;
9+ import withFormActions from '../../hoc/withFormActions' ;
10+ import withUI from '../../hoc/withUI' ;
11+ import DialogContent from '../ui/DialogContent' ;
712
8- export default function StorageRemove ( { closeModal, isOpen, storageId, history, openSnackBar } ) {
9- const onRemove = ( ) => {
10- api
11- . removeStorage ( { storageId } )
12- . then ( ( ) => {
13- const messageContent = `Storage ${ storageId } Removed` ;
14- openSnackBar ( { messageContent } ) ;
15- history . push ( '/storage/' ) ;
16- closeModal ( ) ;
17- } )
18- . catch ( ( ) => {
19- const messageContent = 'Error Removing Storage' ;
20- openSnackBar ( { messageContent, messageColor : 'secondary' } ) ;
21- } ) ;
13+ import StorageRemoveForm from './StorageRemoveForm' ;
14+
15+ const STORAGE_REMOVE_FORM = 'STORAGE_REMOVE_FORM' ;
16+
17+ function StorageRemove ( { open, onClose, onSuccess, onFail, openSnackBar, submitForm, storageId } ) {
18+ const onSubmitSuccess = ( response , dispatch , props ) => {
19+ const messageContent = 'Storage Deleted' ;
20+ openSnackBar ( { messageContent } ) ;
21+ if ( onSuccess ) {
22+ onSuccess ( response , dispatch , props ) ;
23+ }
24+ onClose ( ) ;
25+ } ;
26+ const onSubmitFail = ( error , dispatch , props ) => {
27+ const messageContent = 'Error Deleting Storage' ;
28+ openSnackBar ( { messageContent, messageColor : 'secondary' } ) ;
29+ if ( onFail ) {
30+ onFail ( error , dispatch , props ) ;
31+ }
2232 } ;
2333 return (
24- < Dialog open = { isOpen } onClose = { closeModal } fullWidth maxWidth = { false } >
25- < DialogTitle > { `Remove Storage "${ storageId } "?` } </ DialogTitle >
34+ < Dialog open = { open } onClose = { onClose } fullWidth maxWidth = { false } >
35+ < DialogTitle > { `Delete Storage ${ storageId } ` } </ DialogTitle >
36+ < DialogContent >
37+ < StorageRemoveForm
38+ form = { STORAGE_REMOVE_FORM }
39+ onSubmit = { formActions . onRemove }
40+ onSubmitSuccess = { onSubmitSuccess }
41+ onSubmitFail = { onSubmitFail }
42+ storageId = { storageId }
43+ />
44+ </ DialogContent >
45+ < Divider />
2646 < DialogActions >
27- < Button onClick = { closeModal } color = "primary" >
28- Cancel
47+ < Button size = "small" onClick = { onClose } >
48+ Close
2949 </ Button >
30- < Button variant = "text" onClick = { onRemove } color = "secondary" autoFocus >
31- Remove
50+ < Button size = "small" color = "secondary" onClick = { ( ) => submitForm ( STORAGE_REMOVE_FORM ) } >
51+ Delete
3252 </ Button >
3353 </ DialogActions >
3454 </ Dialog >
3555 ) ;
3656}
57+
58+ export default compose ( withUI , withFormActions ) ( StorageRemove ) ;
0 commit comments