import { ServiceRepository } from "~/services/services";
import { KeepServiceResource } from '~/models/keep-services';
import { dialogActions } from '~/store/dialog/dialog-actions';
-import { snackbarActions } from '~/store/snackbar/snackbar-actions';
+import {snackbarActions, SnackbarKind} from '~/store/snackbar/snackbar-actions';
+import { navigateToRootProject } from '~/store/navigation/navigation-action';
export const keepServicesActions = unionize({
SET_KEEP_SERVICES: ofType<KeepServiceResource[]>(),
- REMOVE_KEEP_SERVICE: ofType<string>(),
- RESET_KEEP_SERVICES: ofType<{}>()
+ REMOVE_KEEP_SERVICE: ofType<string>()
});
export type KeepServicesActions = UnionOf<typeof keepServicesActions>;
export const KEEP_SERVICE_REMOVE_DIALOG = 'keepServiceRemoveDialog';
export const KEEP_SERVICE_ATTRIBUTES_DIALOG = 'keepServiceAttributesDialog';
-// ToDo: access denied for loading keepService and reset data and redirect
export const loadKeepServicesPanel = () =>
async (dispatch: Dispatch<any>, getState: () => RootState, services: ServiceRepository) => {
- try {
- dispatch(setBreadcrumbs([{ label: 'Keep Services' }]));
- const response = await services.keepService.list();
- dispatch(keepServicesActions.SET_KEEP_SERVICES(response.items));
- } catch (e) {
- return;
+ const user = getState().auth.user;
+ if(user && user.isAdmin) {
+ try {
+ dispatch(setBreadcrumbs([{ label: 'Keep Services' }]));
+ const response = await services.keepService.list();
+ dispatch(keepServicesActions.SET_KEEP_SERVICES(response.items));
+ } catch (e) {
+ return;
+ }
+ } else {
+ dispatch(navigateToRootProject);
+ dispatch(snackbarActions.OPEN_SNACKBAR({ message: "You don't have permissions to view this page", hideDuration: 2000, kind: SnackbarKind.ERROR }));
}
};
-export const openKeepServiceAttributesDialog = (index: number) =>
+export const openKeepServiceAttributesDialog = (uuid: string) =>
(dispatch: Dispatch, getState: () => RootState) => {
- const keepService = getState().keepServices[index];
+ const keepService = getState().keepServices.find(it => it.uuid === uuid);
dispatch(dialogActions.OPEN_DIALOG({ id: KEEP_SERVICE_ATTRIBUTES_DIALOG, data: { keepService } }));
};
}));
};
-// ToDo: access denied for removing keepService and reset data and redirect
export const removeKeepService = (uuid: string) =>
async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
- dispatch(snackbarActions.OPEN_SNACKBAR({ message: 'Removing ...' }));
+ dispatch(snackbarActions.OPEN_SNACKBAR({ message: 'Removing ...', kind: SnackbarKind.INFO }));
try {
await services.keepService.delete(uuid);
dispatch(keepServicesActions.REMOVE_KEEP_SERVICE(uuid));
- dispatch(snackbarActions.OPEN_SNACKBAR({ message: 'Keep service has been successfully removed.', hideDuration: 2000 }));
+ dispatch(snackbarActions.OPEN_SNACKBAR({ message: 'Keep service has been successfully removed.', hideDuration: 2000, kind: SnackbarKind.SUCCESS }));
} catch (e) {
return;
}