+
+ const dialog = getDialog<SharingDialogData>(getState().dialog, SHARING_DIALOG_NAME);
+ if (dialog && dialog.data.refresh) {
+ dialog.data.refresh();
+ }
+};
+
+export interface SharingDialogData {
+ resourceUuid: string;
+ refresh: () => void;
+}
+
+export const createSharingToken = async (dispatch: Dispatch, getState: () => RootState, { apiClientAuthorizationService }: ServiceRepository) => {
+ const dialog = getDialog<SharingDialogData>(getState().dialog, SHARING_DIALOG_NAME);
+ if (dialog) {
+ const resourceUuid = dialog.data.resourceUuid;
+ if (extractUuidObjectType(resourceUuid) === ResourceObjectType.COLLECTION) {
+ dispatch(progressIndicatorActions.START_WORKING(SHARING_DIALOG_NAME));
+ try {
+ const sharingToken = await apiClientAuthorizationService.createCollectionSharingToken(resourceUuid);
+ dispatch(resourcesActions.SET_RESOURCES([sharingToken]));
+ dispatch(snackbarActions.OPEN_SNACKBAR({
+ message: 'Sharing URL created',
+ hideDuration: 2000,
+ kind: SnackbarKind.SUCCESS,
+ }));
+ } catch (e) {
+ dispatch(snackbarActions.OPEN_SNACKBAR({
+ message: 'Failed to create sharing URL',
+ hideDuration: 2000,
+ kind: SnackbarKind.ERROR,
+ }));
+ } finally {
+ dispatch(progressIndicatorActions.STOP_WORKING(SHARING_DIALOG_NAME));
+ }
+ }
+ }
+};
+
+export const deleteSharingToken = (uuid: string) => async (dispatch: Dispatch, getState: () => RootState, { apiClientAuthorizationService }: ServiceRepository) => {
+ dispatch(progressIndicatorActions.START_WORKING(SHARING_DIALOG_NAME));
+ try {
+ await apiClientAuthorizationService.delete(uuid);
+ dispatch(resourcesActions.DELETE_RESOURCES([uuid]));
+ dispatch(snackbarActions.OPEN_SNACKBAR({
+ message: 'Sharing URL removed',
+ hideDuration: 2000,
+ kind: SnackbarKind.SUCCESS,
+ }));
+ } catch (e) {
+ dispatch(snackbarActions.OPEN_SNACKBAR({
+ message: 'Failed to remove sharing URL',
+ hideDuration: 2000,
+ kind: SnackbarKind.ERROR,
+ }));
+ } finally {
+ dispatch(progressIndicatorActions.STOP_WORKING(SHARING_DIALOG_NAME));
+ }