-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(entities): adds delete / restore for document
- Loading branch information
1 parent
3a1e06d
commit a694a3e
Showing
6 changed files
with
397 additions
and
287 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import fetch from 'isomorphic-fetch'; | ||
import { deleteDocumentUrl } from '../../conf/apiRoutes'; | ||
import { checkAndGetStatus } from '../utils'; | ||
|
||
export const DELETE_DOCUMENT = 'DELETE_DOCUMENT'; | ||
export const DELETE_DOCUMENT_SUCCESS = 'DELETE_DOCUMENT_SUCCESS'; | ||
export const DELETE_DOCUMENT_PERMANENT_SUCCESS = | ||
'DELETE_DOCUMENT_PERMANENT_SUCCESS'; | ||
export const DELETE_DOCUMENT_FAILURE = 'DELETE_DOCUMENT_FAILURE'; | ||
|
||
const deleteDocumentAction = () => ({ | ||
type: DELETE_DOCUMENT | ||
}); | ||
|
||
const deleteDocumentSuccess = (data, isPermanent) => ({ | ||
type: isPermanent | ||
? DELETE_DOCUMENT_PERMANENT_SUCCESS | ||
: DELETE_DOCUMENT_SUCCESS, | ||
data | ||
}); | ||
|
||
const deleteDocumentFailure = error => ({ | ||
type: DELETE_DOCUMENT_FAILURE, | ||
error | ||
}); | ||
|
||
export const deleteDocument = | ||
({ id, entityId, isPermanent }) => | ||
(dispatch, getState) => { | ||
dispatch(deleteDocumentAction()); | ||
|
||
const requestOptions = { | ||
method: 'DELETE', | ||
headers: getState().login.authorizationHeader | ||
}; | ||
|
||
return fetch( | ||
deleteDocumentUrl(id, { entityId, isPermanent }), | ||
requestOptions | ||
) | ||
.then(checkAndGetStatus) | ||
.then(response => response.json()) | ||
.then(data => dispatch(deleteDocumentSuccess(data, isPermanent))) | ||
.catch(error => { | ||
dispatch(deleteDocumentFailure(error)); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import fetch from 'isomorphic-fetch'; | ||
import { restoreDocumentUrl } from '../../conf/apiRoutes'; | ||
import { checkAndGetStatus } from '../utils'; | ||
|
||
export const RESTORE_DOCUMENT = 'RESTORE_DOCUMENT'; | ||
export const RESTORE_DOCUMENT_SUCCESS = 'RESTORE_DOCUMENT_SUCCESS'; | ||
export const RESTORE_DOCUMENT_FAILURE = 'RESTORE_DOCUMENT_FAILURE'; | ||
|
||
const restoreDocumentAction = () => ({ | ||
type: RESTORE_DOCUMENT | ||
}); | ||
|
||
const restoreDocumentSuccess = data => ({ | ||
type: RESTORE_DOCUMENT_SUCCESS, | ||
data | ||
}); | ||
|
||
const restoreDocumentFailure = error => ({ | ||
type: RESTORE_DOCUMENT_FAILURE, | ||
error | ||
}); | ||
|
||
export const restoreDocument = | ||
({ id }) => | ||
(dispatch, getState) => { | ||
dispatch(restoreDocumentAction()); | ||
|
||
const requestOptions = { | ||
method: 'POST', | ||
headers: getState().login.authorizationHeader | ||
}; | ||
|
||
return fetch(restoreDocumentUrl(id), requestOptions) | ||
.then(checkAndGetStatus) | ||
.then(response => response.json()) | ||
.then(data => dispatch(restoreDocumentSuccess(data))) | ||
.catch(errorMessage => { | ||
dispatch(restoreDocumentFailure(errorMessage)); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.