Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 52 additions & 54 deletions src/actions/media-file-type-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,12 @@ import {
createAction,
stopLoading,
startLoading,
showMessage,
showSuccessMessage,
authErrorHandler,
fetchResponseHandler,
fetchErrorHandler,
escapeFilterValue
} from "openstack-uicore-foundation/lib/utils/actions";
import URI from "urijs";
import history from "../history";
import { snackbarErrorHandler, snackbarSuccessHandler } from "./base-actions";
import { getAccessTokenSafely } from "../utils/methods";
import {
DEBOUNCE_WAIT,
Expand Down Expand Up @@ -87,9 +84,9 @@ export const getMediaFileTypes =
createAction(REQUEST_MEDIA_FILE_TYPES),
createAction(RECEIVE_MEDIA_FILE_TYPES),
`${window.API_BASE_URL}/api/v1/summit-media-file-types`,
authErrorHandler,
{ order, orderDir, term }
)(params)(dispatch).then(() => {
snackbarErrorHandler,
{ order, orderDir, term, perPage }
)(params)(dispatch).finally(() => {
dispatch(stopLoading());
});
};
Expand All @@ -109,9 +106,9 @@ export const getAllMediaFileTypes = () => async (dispatch) => {
createAction(REQUEST_ALL_MEDIA_FILE_TYPES),
createAction(RECEIVE_ALL_MEDIA_FILE_TYPES),
`${window.API_BASE_URL}/api/v1/summit-media-file-types`,
authErrorHandler,
snackbarErrorHandler,
{}
)(params)(dispatch).then(() => {
)(params)(dispatch).finally(() => {
dispatch(stopLoading());
});
};
Expand All @@ -129,8 +126,8 @@ export const getMediaFileType = (mediaFileTypeId) => async (dispatch) => {
null,
createAction(RECEIVE_MEDIA_FILE_TYPE),
`${window.API_BASE_URL}/api/v1/summit-media-file-types/${mediaFileTypeId}`,
authErrorHandler
)(params)(dispatch).then(() => {
snackbarErrorHandler
)(params)(dispatch).finally(() => {
dispatch(stopLoading());
});
};
Expand All @@ -139,54 +136,55 @@ export const resetMediaFileTypeForm = () => (dispatch) => {
dispatch(createAction(RESET_MEDIA_FILE_TYPE_FORM)({}));
};

export const saveMediaFileType =
(entity, noAlert = false) =>
async (dispatch) => {
const accessToken = await getAccessTokenSafely();
export const saveMediaFileType = (entity) => async (dispatch) => {
Comment thread
tomrndom marked this conversation as resolved.
Comment thread
tomrndom marked this conversation as resolved.
const accessToken = await getAccessTokenSafely();

dispatch(startLoading());
dispatch(startLoading());

const normalizedEntity = normalizeEntity(entity);
const params = { access_token: accessToken };

if (entity.id) {
putRequest(
createAction(UPDATE_MEDIA_FILE_TYPE),
createAction(MEDIA_FILE_TYPE_UPDATED),
`${window.API_BASE_URL}/api/v1/summit-media-file-types/${entity.id}`,
normalizedEntity,
authErrorHandler,
entity
)(params)(dispatch).then(() => {
if (!noAlert)
dispatch(showSuccessMessage(T.translate("media_file_type.saved")));
else dispatch(stopLoading());
});
} else {
const success_message = {
title: T.translate("general.done"),
html: T.translate("media_file_type.created"),
type: "success"
};

postRequest(
createAction(UPDATE_MEDIA_FILE_TYPE),
createAction(MEDIA_FILE_TYPE_ADDED),
`${window.API_BASE_URL}/api/v1/summit-media-file-types`,
normalizedEntity,
authErrorHandler,
entity
)(params)(dispatch).then((payload) => {
const normalizedEntity = normalizeEntity(entity);
const params = { access_token: accessToken };

if (entity.id) {
return putRequest(
createAction(UPDATE_MEDIA_FILE_TYPE),
createAction(MEDIA_FILE_TYPE_UPDATED),
`${window.API_BASE_URL}/api/v1/summit-media-file-types/${entity.id}`,
normalizedEntity,
snackbarErrorHandler,
entity
)(params)(dispatch)
.then(() => {
dispatch(
showMessage(success_message, () => {
history.push(`/app/media-file-types/${payload.response.id}`);
snackbarSuccessHandler({
title: T.translate("general.success"),
html: T.translate("media_file_type.saved")
})
);
});
}
};
})
.finally(() => dispatch(stopLoading()));
}

return postRequest(
createAction(UPDATE_MEDIA_FILE_TYPE),
createAction(MEDIA_FILE_TYPE_ADDED),
`${window.API_BASE_URL}/api/v1/summit-media-file-types`,
normalizedEntity,
snackbarErrorHandler,
entity
)(params)(dispatch)
.then(() => {
dispatch(
snackbarSuccessHandler({
title: T.translate("general.success"),
html: T.translate("media_file_type.created")
})
);
})
.finally(() => dispatch(stopLoading()));
};

export const deleteMediaFileType = (mediaFileTypeId) => async (dispatch) => {
Comment thread
tomrndom marked this conversation as resolved.
Comment thread
tomrndom marked this conversation as resolved.
dispatch(startLoading());
const accessToken = await getAccessTokenSafely();

const params = {
Expand All @@ -198,8 +196,8 @@ export const deleteMediaFileType = (mediaFileTypeId) => async (dispatch) => {
createAction(MEDIA_FILE_TYPE_DELETED)({ mediaFileTypeId }),
`${window.API_BASE_URL}/api/v1/summit-media-file-types/${mediaFileTypeId}`,
null,
authErrorHandler
)(params)(dispatch).then(() => {
snackbarErrorHandler
)(params)(dispatch).finally(() => {
dispatch(stopLoading());
});
};
Expand Down
2 changes: 1 addition & 1 deletion src/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -3415,7 +3415,7 @@
"description": "Description",
"allowed_extensions_input": "Allowed Extensions (comma separated: PDF,DOC,etc)",
"allowed_extensions": "Allowed Extensions",
"delete_warning": "Are you sure you want to delete media file type ",
"delete_warning": "Are you sure you want to delete media file type {name}?",
"saved": "Media File Type saved successfully.",
"created": "Media File Type created successfully.",
"placeholders": {
Expand Down
53 changes: 15 additions & 38 deletions src/layouts/media-file-type-layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
* */

import React from "react";
import { Switch, Route, Redirect } from "react-router-dom";
Expand All @@ -18,43 +18,20 @@ import { connect } from "react-redux";
import { Breadcrumb } from "react-breadcrumbs";
import Restrict from "../routes/restrict";
import MediaFileTypeListPage from "../pages/media_file_types/media-file-type-list-page";
import EditMediaFileTypePage from "../pages/media_file_types/edit-media-file-type-page";

class MediaFileTypeLayout extends React.Component {
render() {
const { match } = this.props;

return (
<div>
<Breadcrumb
data={{
title: T.translate("media_file_type.media_file_types"),
pathname: match.url
}}
/>

<Switch>
<Route
exact
strict
path={match.url}
component={MediaFileTypeListPage}
/>
<Route
strict
exact
path={`${match.url}/new`}
component={EditMediaFileTypePage}
/>
<Route
path={`${match.url}/:media_file_type_id(\\d+)`}
component={EditMediaFileTypePage}
/>
<Redirect to={`/app/media-file-types`} />
</Switch>
</div>
);
}
}
const MediaFileTypeLayout = ({ match }) => (
<div>
<Breadcrumb
data={{
title: T.translate("media_file_type.media_file_types"),
pathname: match.url
}}
/>
<Switch>
<Route exact strict path={match.url} component={MediaFileTypeListPage} />
<Redirect to="/app/media-file-types" />
</Switch>
</div>
);

export default Restrict(connect(null, {})(MediaFileTypeLayout), "admin-access");
Loading
Loading