Verified Commit 5f1a54c3 authored by Florent Chehab's avatar Florent Chehab
Browse files

fix(front): restored pending moderation

* can now moderate again
* display pending moderation data correctly

Closes  #183
parent d2e97741
......@@ -42,6 +42,14 @@ class Editor extends React.Component {
props.subscribeToModuleWrapper(this);
}
componentDidMount() {
const { saveOnMount } = this.props;
// handle moderation request
if (saveOnMount) {
this.performSave(this.parseRawModelData(this.props.rawModelData));
}
}
/**
* Function that extracts the modelData from the raw one.
*
......@@ -234,7 +242,7 @@ Editor.propTypes = {
lastUpdateTimeInModel: PropTypes.string,
hasPendingModeration: PropTypes.bool,
saveData: PropTypes.func.isRequired,
saveOnMount: PropTypes.bool.isRequired, // should we save the data on editor mount (useful when trying to moderate)
Form: PropTypes.func.isRequired, // Components with the fields
formLevelErrors: PropTypes.array,
license: PropTypes.string,
......
......@@ -14,6 +14,7 @@ import withNetworkWrapper, {
NetWrapParam
} from "../../hoc/withNetworkWrapper";
import { useApiInvalidateAll } from "../../hooks/wrappers/api";
import useOnComponentUnMount from "../../hooks/useOnComponentUnMount";
const useStyles = makeStyles(theme => ({
editButton: {
......@@ -71,7 +72,6 @@ function PendingModeration({
api,
modelInfo,
pendingModeration,
moderatePendingModeration,
editFromPendingModeration,
renderTitle,
renderCore,
......@@ -79,9 +79,9 @@ function PendingModeration({
}) {
const resetData = useApiInvalidateAll("pendingModerationObj");
useEffect(() => {
return () => resetData();
}, []);
useOnComponentUnMount(() => {
resetData();
});
// keep the component up to date
useEffect(() => {
......@@ -89,14 +89,15 @@ function PendingModeration({
}, [modelInfo]);
const pendingModelData = useMemo(() => {
const pending = pendingModeration[0];
return {
...pendingModeration.new_object,
id: pendingModeration.object_id
...pending.new_object,
id: pending.object_id
};
}, [pendingModeration]);
const moderate = useCallback(() => {
moderatePendingModeration(pendingModelData);
editFromPendingModeration(pendingModelData, true); // open editor and auto save
}, [pendingModelData]);
const editFromPending = useCallback(() => {
......@@ -127,9 +128,8 @@ PendingModeration.propTypes = {
id: PropTypes.number.isRequired
}).isRequired,
editFromPendingModeration: PropTypes.func.isRequired,
moderatePendingModeration: PropTypes.func.isRequired,
userCanModerate: PropTypes.bool.isRequired,
pendingModeration: PropTypes.object.isRequired,
pendingModeration: PropTypes.array.isRequired,
renderTitle: PropTypes.func.isRequired,
renderCore: PropTypes.func.isRequired,
api: getApiPropTypes("pendingModeration").isRequired
......
......@@ -105,8 +105,6 @@ function ModuleWrapper({
id: rawModelData.id
}}
editFromPendingModeration={openEditorTmp}
// TODO Repare pending moderation validation
moderatePendingModeration={() => {}}
userCanModerate={rawModelData.obj_info.user_can_moderate}
/>
);
......
......@@ -13,7 +13,7 @@ import useEditorState from "./wrappers/useEditorState";
*/
function useEditor(formInfo, onClose = () => {}) {
// Returns a callback that opens an editor correctly configured
return useCallback(modelData => {
return useCallback((modelData, saveOnMount = false) => {
const { route, license, Form, formLevelErrors } = formInfo;
const InternalEditor = React.memo(() => {
......@@ -33,6 +33,7 @@ function useEditor(formInfo, onClose = () => {}) {
rawModelData={modelData}
// state api related
saveData={saveData}
saveOnMount={saveOnMount}
clearSaveError={clearSaveError}
savingHasError={savingHasError}
lastUpdateTimeInModel={lastUpdateTimeInModel}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment