Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/origin/#470' into allfunctionality
Browse files Browse the repository at this point in the history
  • Loading branch information
boriskovar-m2ms committed Mar 29, 2021
2 parents f75cc65 + 07fdbbc commit 14351d5
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 20 deletions.
44 changes: 44 additions & 0 deletions js/components/header/discourseErrorModal.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import React, { memo } from 'react';
import Modal from '../common/Modal';
import { Grid, Typography, Button } from '@material-ui/core';
import { useDispatch } from 'react-redux';
import { setOpenDiscourseErrorModal } from '../../reducers/api/actions';

export const DiscourseErrorModal = memo(({ openModal }) => {
const dispatch = useDispatch();

const closeModal = () => {
dispatch(setOpenDiscourseErrorModal(false));
};

return (
<Modal
open={openModal}
onClose={() => {
closeModal();
}}
>
<Grid container direction="column">
<Grid item>
<Typography variant="h3">DISCOURSE ERROR!</Typography>
</Grid>
<Grid item>
<Typography variant="body1">
Most likely there already is topic with same name as is this project name.
</Typography>
</Grid>
</Grid>
<Grid container justify="flex-end">
{' '}
<Button
color="primary"
onClick={() => {
closeModal();
}}
>
Close
</Button>
</Grid>
</Modal>
);
});
28 changes: 20 additions & 8 deletions js/components/header/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ import { DJANGO_CONTEXT } from '../../utils/djangoContext';
// import { useDisableUserInteraction } from '../helpers/useEnableUserInteracion';
import { useHistory } from 'react-router-dom';
import { IssueReport } from '../userFeedback/issueReport';
import { IdeaReport } from '../userFeedback/ideaReport';
import { FundersModal } from '../funders/fundersModal';
import { TrackingModal } from '../tracking/trackingModal';
// eslint-disable-next-line import/extensions
Expand All @@ -50,6 +49,8 @@ import { useSelector, useDispatch } from 'react-redux';
import { setCurrentTargetLink } from '../target/redux/actions';
import { generateDiscourseTargetURL, getExistingPost } from '../../utils/discourse';
import { setCurrentProjectDiscourseLink } from '../projects/redux/actions';
import { DiscourseErrorModal } from './discourseErrorModal';
import { setOpenDiscourseErrorModal } from '../../reducers/api/actions';

const useStyles = makeStyles(theme => ({
padding: {
Expand Down Expand Up @@ -113,6 +114,8 @@ export default memo(
const targetDiscourseLink = useSelector(state => state.targetReducers.currentTargetLink);
const projectDiscourseLink = useSelector(state => state.projectReducers.currentProjectDiscourseLink);

const openDiscourseError = useSelector(state => state.apiReducers.open_discourse_error_modal);

const discourseAvailable = isDiscourseAvailable();
const targetDiscourseVisible = targetDiscourseLink && discourseAvailable;
const projectDiscourseVisible = discourseAvailable && projectDiscourseLink;
Expand All @@ -128,7 +131,10 @@ export default memo(
dispatch(setCurrentTargetLink(url));
}
})
.catch(err => console.log(err));
.catch(err => {
console.log(err);
dispatch(setOpenDiscourseErrorModal(true));
});
}
}, [targetDiscourseLinks, targetId, dispatch, targetName]);

Expand All @@ -137,12 +143,17 @@ export default memo(
if (targetDiscourseLinks && targetDiscourseLinks[currentProject.projectID]) {
dispatch(setCurrentProjectDiscourseLink(targetDiscourseLinks[currentProject.projectID]));
} else if (currentProject.title && targetName) {
getExistingPost(currentProject.title).then(response => {
const url = response.data['Post url'];
if (url) {
dispatch(setCurrentProjectDiscourseLink(url));
}
});
getExistingPost(currentProject.title)
.then(response => {
const url = response.data['Post url'];
if (url) {
dispatch(setCurrentProjectDiscourseLink(url));
}
})
.catch(err => {
console.log(err);
dispatch(setOpenDiscourseErrorModal(true));
});
}
}
}, [currentProject, targetDiscourseLinks, dispatch, targetName]);
Expand Down Expand Up @@ -362,6 +373,7 @@ export default memo(
</AppBar>
<FundersModal openModal={openFunders} onModalClose={() => setOpenFunders(false)} />
<TrackingModal openModal={openTrackingModal} onModalClose={() => setOpenTrackingModal(false)} />
<DiscourseErrorModal openModal={openDiscourseError} />
<Drawer
anchor="left"
open={openMenu}
Expand Down
18 changes: 12 additions & 6 deletions js/components/projects/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { ProjectModal } from './projectModal';
import { loadListOfAllProjects, removeProject, searchInProjects } from './redux/dispatchActions';
import { DJANGO_CONTEXT } from '../../utils/djangoContext';
import { isDiscourseAvailable, getExistingPost } from '../../utils/discourse';
import { setOpenDiscourseErrorModal } from '../../reducers/api/actions';

const useStyles = makeStyles(theme => ({
table: {
Expand Down Expand Up @@ -79,12 +80,17 @@ export const Projects = memo(({}) => {
if (isDiscourseAvailable()) {
listOfProjects.slice(page * rowsPerPage, page * rowsPerPage + rowsPerPage).forEach(project => {
if (!projectDiscourseLinks.hasOwnProperty(project.id)) {
getExistingPost(project.name).then(response => {
if (response.data['Post url']) {
projectDiscourseLinks[project.id] = response.data['Post url'];
dispatch(setProjectDiscourseLinks(projectDiscourseLinks));
}
});
getExistingPost(project.name)
.then(response => {
if (response.data['Post url']) {
projectDiscourseLinks[project.id] = response.data['Post url'];
dispatch(setProjectDiscourseLinks(projectDiscourseLinks));
}
})
.catch(err => {
console.log(err);
dispatch(setOpenDiscourseErrorModal(true));
});
}
});
}
Expand Down
12 changes: 9 additions & 3 deletions js/components/projects/redux/dispatchActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { DJANGO_CONTEXT } from '../../../utils/djangoContext';
import { sendInitTrackingActionByProjectId } from '../../../reducers/tracking/dispatchActions';
import { resetTrackingState } from '../../../reducers/tracking/actions';
import { createProjectPost } from '../../../utils/discourse';
import { setOpenDiscourseErrorModal } from '../../../reducers/api/actions';

import moment from 'moment';
import { resetNglTrackingState } from '../../../reducers/nglTracking/dispatchActions';
Expand Down Expand Up @@ -278,9 +279,14 @@ export const createProjectFromSnapshotDialog = data => dispatch => {
};

export const createProjectDiscoursePost = (projectName, targetName, msg, tags) => (dispatch, getState) => {
return createProjectPost(projectName, targetName, msg, tags).then(response => {
dispatch(setCurrentProjectDiscourseLink(response.data['Post url']));
});
return createProjectPost(projectName, targetName, msg, tags)
.then(response => {
dispatch(setCurrentProjectDiscourseLink(response.data['Post url']));
})
.catch(err => {
console.log(err);
dispatch(setOpenDiscourseErrorModal(true));
});
};

export const createProject = ({ title, description, target, author, tags }) => dispatch => {
Expand Down
2 changes: 2 additions & 0 deletions js/components/target/targetList.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { Link } from 'react-router-dom';
import { URLS } from '../routes/constants';
import { isDiscourseAvailable, generateDiscourseTargetURL } from '../../utils/discourse';
import { setTargetDiscourseLinks } from './redux/actions';
import { setOpenDiscourseErrorModal } from '../../reducers/api/actions';

export const TargetList = memo(() => {
const dispatch = useDispatch();
Expand All @@ -28,6 +29,7 @@ export const TargetList = memo(() => {
})
.catch(err => {
console.log(err);
dispatch(setOpenDiscourseErrorModal(true));
});
}
});
Expand Down
4 changes: 4 additions & 0 deletions js/reducers/api/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
*/
import { constants } from './constants';

export const setOpenDiscourseErrorModal = open => {
return { type: constants.SET_OPEN_DISCOURSE_ERROR_MODAL, payload: open };
};

export const setTargetIdList = function(input_json) {
return {
type: constants.SET_TARGET_ID_LIST,
Expand Down
9 changes: 7 additions & 2 deletions js/reducers/api/apiReducers.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ export const INITIAL_STATE = {
sessionTitle: undefined,
user_id: undefined,
direct_access: {},
direct_access_processed: false
direct_access_processed: false,
open_discourse_error_modal: false
};

export const RESET_TARGET_STATE = {
Expand Down Expand Up @@ -70,12 +71,16 @@ export const RESET_TARGET_STATE = {
sessionIdList: [],
sessionTitle: undefined,
user_id: undefined,
direct_access: {}
direct_access: {},
open_discourse_error_modal: false
// direct_access_processed: false
};

export default function apiReducers(state = INITIAL_STATE, action = {}) {
switch (action.type) {
case constants.SET_OPEN_DISCOURSE_ERROR_MODAL:
return Object.assign({}, state, { open_discourse_error_modal: action.payload });

case constants.SET_TARGET_ID_LIST:
return Object.assign({}, state, {
target_id_list: action.target_id_list
Expand Down
3 changes: 2 additions & 1 deletion js/reducers/api/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,6 @@ export const constants = {
RELOAD_API_STATE: prefix + 'RELOAD_API_STATE',
RESET_TARGET_STATE: prefix + 'RESET_TARGET_STATE',
SET_DIRECT_ACCESS: prefix + 'SET_DIRECT_ACCESS',
SET_DIRECT_ACCESS_PROCESSED: prefix + 'SET_DIRECT_ACCESS_PROCESSED'
SET_DIRECT_ACCESS_PROCESSED: prefix + 'SET_DIRECT_ACCESS_PROCESSED',
SET_OPEN_DISCOURSE_ERROR_MODAL: prefix + 'SET_OPEN_DISCOURSE_ERROR_MODAL'
};

0 comments on commit 14351d5

Please sign in to comment.