X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/3f809e0be2a712d1e576f1b2acf4aff73e0f16b0..546052817ac18623f5389914a3077e8cc6a3d4f4:/src/views-components/sharing-dialog/sharing-dialog.tsx

diff --git a/src/views-components/sharing-dialog/sharing-dialog.tsx b/src/views-components/sharing-dialog/sharing-dialog.tsx
index b6c956e3..b295f6d1 100644
--- a/src/views-components/sharing-dialog/sharing-dialog.tsx
+++ b/src/views-components/sharing-dialog/sharing-dialog.tsx
@@ -6,35 +6,48 @@ import { compose, Dispatch } from 'redux';
 import { connect } from 'react-redux';
 
 import * as React from 'react';
-import { connectSharingDialog } from '~/store/sharing-dialog/sharing-dialog-actions';
+import { connectSharingDialog, saveSharingDialogChanges, connectSharingDialogProgress, sendSharingInvitations } from '~/store/sharing-dialog/sharing-dialog-actions';
 import { WithDialogProps } from '~/store/dialog/with-dialog';
 import { RootState } from '~/store/store';
 
 import SharingDialogComponent, { SharingDialogDataProps, SharingDialogActionProps } from './sharing-dialog-component';
 import { SharingDialogContent } from './sharing-dialog-content';
 import { connectAdvancedViewSwitch, AdvancedViewSwitchInjectedProps } from './advanced-view-switch';
-import { isDirty } from 'redux-form';
+import { hasChanges } from '~/store/sharing-dialog/sharing-dialog-types';
+import { WithProgressStateProps } from '~/store/progress-indicator/with-progress';
 
-const mapStateToProps = (state: RootState, { advancedViewOpen, ...props }: WithDialogProps<string> & AdvancedViewSwitchInjectedProps): SharingDialogDataProps => ({
+type Props = WithDialogProps<string> & AdvancedViewSwitchInjectedProps & WithProgressStateProps;
+
+const mapStateToProps = (state: RootState, { advancedViewOpen, working, ...props }: Props): SharingDialogDataProps => ({
     ...props,
-    saveEnabled: isDirty('SHARING_PUBLIC_ACCESS_FORM')(state) ||
-        isDirty('SHARING_MANAGEMENT_FORM')(state) ||
-        isDirty('SHARING_INVITATION_FORM')(state),
+    saveEnabled: hasChanges(state),
+    loading: working,
     advancedEnabled: !advancedViewOpen,
     children: <SharingDialogContent {...{ advancedViewOpen }} />,
 });
 
-const mapDispatchToProps = (_: Dispatch, { toggleAdvancedView, ...props }: WithDialogProps<string> & AdvancedViewSwitchInjectedProps): SharingDialogActionProps => ({
+const mapDispatchToProps = (dispatch: Dispatch, { toggleAdvancedView, advancedViewOpen, ...props }: Props): SharingDialogActionProps => ({
     ...props,
     onClose: props.closeDialog,
-    onExited: toggleAdvancedView,
-    onSave: () => { console.log('save'); },
+    onExited: () => {
+        if (advancedViewOpen) {
+            toggleAdvancedView();
+        }
+    },
+    onSave: () => {
+        if (advancedViewOpen) {
+            dispatch<any>(saveSharingDialogChanges);
+        } else {
+            dispatch<any>(sendSharingInvitations);
+        }
+    },
     onAdvanced: toggleAdvancedView,
 });
 
 export const SharingDialog = compose(
     connectAdvancedViewSwitch,
     connectSharingDialog,
+    connectSharingDialogProgress,
     connect(mapStateToProps, mapDispatchToProps)
 )(SharingDialogComponent);
 
