Skip to content

Commit

Permalink
concept | retired/unretired
Browse files Browse the repository at this point in the history
  • Loading branch information
snyaggarwal committed Jan 11, 2021
1 parent d24d8c5 commit 51dcb47
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 8 deletions.
68 changes: 62 additions & 6 deletions src/components/concepts/ConceptHomeHeader.jsx
@@ -1,7 +1,10 @@
import React from 'react';
import alertifyjs from 'alertifyjs';
import { Tooltip, ButtonGroup, Button } from '@material-ui/core';
import { Edit as EditIcon, Delete as DeleteIcon } from '@material-ui/icons';
import { Edit as EditIcon, Delete as DeleteIcon, RestoreFromTrash as RestoreIcon } from '@material-ui/icons';
import { get } from 'lodash';
import { currentUserHasAccess } from '../../common/utils';
import APIService from '../../services/APIService';
import OwnerButton from '../common/OwnerButton';
import SourceButton from '../common/SourceButton';
import ConceptButton from '../common/ConceptButton';
Expand All @@ -18,6 +21,51 @@ const ConceptHomeHeader = ({
const isRetired = concept.retired;
const hasAccess = currentUserHasAccess();
const [conceptForm, setConceptForm] = React.useState(false);
const onRetire = () => {
const prompt = alertifyjs.prompt()
prompt.setContent('<form id="retireForm"> <p>Retire Reason</p> <textarea required id="comment" style="width: 100%;"></textarea> </form>')
prompt.set('onok', () => {
document.getElementById('retireForm').reportValidity();
const comment = document.getElementById('comment').value
if(!comment)
return false
retire(comment)
})
prompt.set('title', 'Retire Concept')
prompt.show()
}
const onUnretire = () => {
const prompt = alertifyjs
.prompt()
prompt.setContent('<form id="retireForm"> <p>Unretire Reason</p> <textarea required id="comment" style="width: 100%;"></textarea> </form>')
.set('onok', () => {
document.getElementById('retireForm').reportValidity();
const comment = document.getElementById('comment').value
if(!comment)
return false
unretire(comment)
})
.set('title', 'Unretire Concept')
.show()
}

const retire = comment => {
APIService.new().overrideURL(versionedObjectURL).delete({comment: comment}).then(response => {
if(get(response, 'status') === 204)
alertifyjs.success('Concept Retired', 1, () => window.location.reload())
else
alertifyjs.error('Something bad happened!')
})
}

const unretire = comment => {
APIService.new().overrideURL(versionedObjectURL).appendToUrl('reactivate/').put({comment: comment}).then(response => {
if(get(response, 'status') === 204)
alertifyjs.success('Concept UnRetired', 1, () => window.location.reload())
else
alertifyjs.error('Something bad happened!')
})
}

return (
<header className='home-header col-md-12'>
Expand Down Expand Up @@ -47,11 +95,19 @@ const ConceptHomeHeader = ({
<EditIcon fontSize='inherit' />
</Button>
</Tooltip>
<Tooltip title='Retire Concept'>
<Button>
<DeleteIcon fontSize='inherit' />
</Button>
</Tooltip>
{
isRetired ?
<Tooltip title='Un-Retire Concept'>
<Button onClick={onUnretire}>
<RestoreIcon fontSize='inherit' />
</Button>
</Tooltip> :
<Tooltip title='Retire Concept'>
<Button onClick={onRetire}>
<DeleteIcon fontSize='inherit' />
</Button>
</Tooltip>
}
</ButtonGroup>
</span>
}
Expand Down
4 changes: 2 additions & 2 deletions src/services/APIService.js
Expand Up @@ -65,8 +65,8 @@ class APIService {
return this.sendRequest('PUT', data, token, headers, query);
}

delete(token, headers = {}, query) {
return this.sendRequest('DELETE', null, token, headers, query);
delete(data, token, headers = {}, query) {
return this.sendRequest('DELETE', data, token, headers, query);
}

sendRequest(method, data, token, headers, query) {
Expand Down

0 comments on commit 51dcb47

Please sign in to comment.