Skip to content

Commit

Permalink
xchem#16 enable to remove project by logged in user
Browse files Browse the repository at this point in the history
  • Loading branch information
tibor-postek-m2ms committed Mar 26, 2020
1 parent 1d4c854 commit 274561a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
13 changes: 10 additions & 3 deletions js/components/projects/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import moment from 'moment';
import { setProjectModalOpen } from './redux/actions';
import { useDispatch, useSelector } from 'react-redux';
import { ProjectModal } from './projectModal';
import { loadListOfProjects, searchInProjects } from './redux/dispatchActions';
import { loadListOfProjects, removeProject, searchInProjects } from './redux/dispatchActions';
import { DJANGO_CONTEXT } from '../../utils/djangoContext';

const useStyles = makeStyles(theme => ({
Expand Down Expand Up @@ -50,7 +50,7 @@ export const Projects = memo(({}) => {
tags: JSON.parse(project.tags),
target: project.target.title,
createdAt: project.init_date,
author: project.author.email
author: (project.author && project.author.email) || '-'
};
});

Expand Down Expand Up @@ -143,7 +143,14 @@ export const Projects = memo(({}) => {
<TableCell align="left">{project.author}</TableCell>
<TableCell align="left">{moment(project.createdAt).format('LLL')}</TableCell>
<TableCell align="right">
<IconButton>
<IconButton
disabled={DJANGO_CONTEXT['username'] === 'NOT_LOGGED_IN'}
onClick={() =>
dispatch(removeProject(project.id)).catch(error => {
throw new Error(error);
})
}
>
<Delete />
</IconButton>
</TableCell>
Expand Down
5 changes: 5 additions & 0 deletions js/components/projects/redux/dispatchActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ export const searchInProjects = title => (dispatch, getState) => {
dispatch(setListOfProjects((response && response.data && response.data.results) || []))
);
};
export const removeProject = projectID => dispatch => {
return api({ url: `${base_url}/api/session-projects/${projectID}/`, method: METHOD.DELETE }).then(() =>
dispatch(loadListOfProjects())
);
};

export const loadSnapshotByProjectID = projectID => (dispatch, getState) => {
return api({ url: `${base_url}/api/snapshots/?session_project=${projectID}&type=INIT` }).then(response => {
Expand Down
2 changes: 1 addition & 1 deletion js/components/snapshot/modals/newSnapshotForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Typography } from '@material-ui/core';
import { useSelector } from 'react-redux';

export const NewSnapshotForm = memo(() => {
const snapshotID = useSelector(state => state.projectReducers.currentSnapshot.id);
const currentSnapshot = useSelector(state => state.projectReducers.currentSnapshot);
// TODO if exists children of existing snapshot, create branch
return <Typography variant="h3">Snapshot details</Typography>;
});

0 comments on commit 274561a

Please sign in to comment.