Commit 0300f29f authored by Maxym Borodenko's avatar Maxym Borodenko
Browse files

MaterialSubRequest status

parent cf06550a
......@@ -2233,7 +2233,14 @@
"dispatchedTo": "Dispatched to",
"requestedAccessions": "Requested accessions",
"removeRequest": "Remove request",
"requestRemoved": "Request has been removed successfully"
"requestRemoved": "Request has been removed successfully",
"subRequest": {
"resend": "Resend",
"state": {
"0": "Not confirmed",
"1": "Confirmed"
}
}
}
}
},
......
......@@ -4,6 +4,7 @@ import {
ADMIN_RECEIVE_MATERIAL_REQUEST,
ADMIN_RECEIVE_MATERIAL_REQUEST_ACCESSIONS,
ADMIN_REMOVE_MATERIAL_REQUEST,
ADMIN_RECEIVE_MATERIAL_SUB_REQUEST,
} from 'requests/constants';
// actions
......@@ -26,6 +27,7 @@ import MaterialRequestFilter from 'model/request/MaterialRequestFilter';
const apiListRequests = createApiCaller(RequestService.list, ADMIN_APPEND_MATERIAL_REQUESTS);
const apiLoadRequest = createApiCaller(RequestService.getRequest, ADMIN_RECEIVE_MATERIAL_REQUEST);
const apiRemoveRequest = createApiCaller(RequestService.removeRequest, ADMIN_REMOVE_MATERIAL_REQUEST);
const apiRelaySubRequest = createApiCaller(RequestService.relaySubRequest, ADMIN_RECEIVE_MATERIAL_SUB_REQUEST);
const apiAccessionIdToUUID = createPureApiCaller(AccessionService.uuidFromIds);
const apiListAccessionsByUUID = createApiCaller(AccessionService.listAllByUuid, ADMIN_RECEIVE_MATERIAL_REQUEST_ACCESSIONS);
......@@ -46,6 +48,9 @@ export const recheckPidAction = (uuid: string) => (dispatch) => {
.then((request) => dispatch(loadMaterialRequest(request.uuid)));
};
export const relaySubRequest = (uuid: string) => (dispatch) => {
return dispatch(apiRelaySubRequest(uuid));
};
export const removeRequest = (uuid: string) => (dispatch) => {
return dispatch(apiRemoveRequest(uuid))
......
......@@ -8,5 +8,7 @@ export const ADMIN_RECEIVE_MATERIAL_REQUEST = 'requests/admin/RECEIVE_MATERIAL_R
export const ADMIN_REMOVE_MATERIAL_REQUEST = 'requests/admin/REMOVE_MATERIAL_REQUEST';
export const ADMIN_RECEIVE_MATERIAL_REQUEST_ACCESSIONS = 'requests/admin/RECEIVE_MATERIAL_REQUEST_ACCESSIONS';
export const ADMIN_RECEIVE_MATERIAL_SUB_REQUEST = 'requests/admin/RECEIVE_MATERIAL_SUB_REQUEST';
export const REQUEST_FILTER_FORM = 'Form/request/admin/REQUEST_FILTER_FORM';
export const REQUEST_VALIDATE_FORM = 'Form/request/admin/REQUEST_VALIDATE_FORM';
......@@ -10,10 +10,11 @@ import {
ADMIN_APPEND_MATERIAL_REQUESTS,
ADMIN_RECEIVE_MATERIAL_REQUEST,
ADMIN_RECEIVE_MATERIAL_REQUEST_ACCESSIONS, ADMIN_REMOVE_MATERIAL_REQUEST,
ADMIN_RECEIVE_MATERIAL_SUB_REQUEST,
} from 'requests/constants';
const INITIAL_STATE: {
request: ApiCall<Request>;
request: ApiCall<MaterialRequest>;
accessions: ApiCall<Accession[]>;
paged: ApiCall<FilteredPage<MaterialRequest>>;
} = {
......@@ -48,6 +49,22 @@ function adminRequests(state = INITIAL_STATE, action: IReducerAction) {
return update(state, updates);
}
case ADMIN_RECEIVE_MATERIAL_SUB_REQUEST: {
const { apiCall } = action.payload;
const receivedIndex = state.request && state.request.data && apiCall.data ? state.request.data.subrequests.findIndex((item) => item.uuid === apiCall.data.uuid) : -1;
if (receivedIndex !== -1) {
return update(state, {
request: {
data: {
subrequests: {[receivedIndex]: {$set: apiCall.data}},
},
},
});
}
return state;
}
case ADMIN_REMOVE_MATERIAL_REQUEST: {
const { apiCall } = action.payload;
......
......@@ -73,7 +73,14 @@
"dispatchedTo": "Dispatched to",
"requestedAccessions": "Requested accessions",
"removeRequest": "Remove request",
"requestRemoved": "Request has been removed successfully"
"requestRemoved": "Request has been removed successfully",
"subRequest": {
"resend": "Resend",
"state": {
"0": "Not confirmed",
"1": "Confirmed"
}
}
}
}
},
......
......@@ -2,9 +2,10 @@ import * as React from 'react';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import { translate } from 'react-i18next';
import { withStyles } from '@material-ui/core/styles';
// Actions
import { loadMaterialRequest, sendValidationEmailAction, recheckPidAction, validateRequestAction, removeRequest } from 'requests/actions/admin';
import { loadMaterialRequest, sendValidationEmailAction, recheckPidAction, validateRequestAction, removeRequest, relaySubRequest } from 'requests/actions/admin';
// Models
import MaterialRequest from 'model/request/MaterialRequest';
......@@ -24,18 +25,42 @@ import AccessionCard from 'accessions/ui/c/AccessionCard';
import ApiCall from 'model/ApiCall';
import confirm from 'utilities/confirmAlert';
import ButtonBar from 'ui/common/buttons/ButtonBar';
import Button from '@material-ui/core/Button';
const styles = (theme) => ({
/*tslint:disable*/
propertiesContainer: {
display: 'flex' as 'flex',
justifyContent: 'space-between' as 'space-between',
alignItems: 'center' as 'center',
[theme.breakpoints.down('sm')]: {
flexDirection: 'column' as 'column',
},
'& > span:last-child': {
[theme.breakpoints.down('sm')]: {
paddingTop: '0.7rem',
},
'& > button': {
marginLeft: '0.7rem',
},
}
},
/*tslint:enable*/
});
interface IDisplayPageProps extends React.ClassAttributes<any> {
t: any;
requestId: string;
requestCall: ApiCall<MaterialRequest>;
requestAccessionsCall: ApiCall<Accession[]>;
relaySubRequest: (uuid: string) => void;
error: any;
loadMaterialRequest: any;
recheckPid: any;
validateRequest: any;
removeRequest: any;
sendValidationEmail: any;
classes: any;
}
class DisplayPage extends React.Component<IDisplayPageProps, any> {
......@@ -94,9 +119,13 @@ class DisplayPage extends React.Component<IDisplayPageProps, any> {
});
}
private resendEmail = (uuid: string) => {
this.props.relaySubRequest(uuid);
}
public render() {
const {requestCall, t, requestAccessionsCall} = this.props;
const {requestCall, t, requestAccessionsCall, classes} = this.props;
if (! requestCall || requestCall.loading) {
return <Loading />;
......@@ -169,9 +198,22 @@ class DisplayPage extends React.Component<IDisplayPageProps, any> {
<Properties>
{ request.subrequests.map((sub) => (
<PropertiesItem key={ sub.uuid } title={ sub.instCode }>
<PrettyDate value={ sub.lastReminderDate } />
&rarr;
{ sub.instEmail }
<div className={ classes.propertiesContainer }>
<span>
<PrettyDate value={ sub.lastReminderDate } />
&rarr;
{ sub.instEmail }
</span>
<span>
{ t(`requests.admin.p.display.subRequest.state.${sub.state}`) }
{
sub.state === 0 &&
<Button variant="contained" onClick={ () => this.resendEmail(sub.uuid) }>
{ t('requests.admin.p.display.subRequest.resend') }
</Button>
}
</span>
</div>
</PropertiesItem>
)) }
</Properties>
......@@ -202,10 +244,11 @@ const mapStateToProps = (state, ownProps) => ({
const mapDispatchToProps = (dispatch) => bindActionCreators({
loadMaterialRequest,
removeRequest,
relaySubRequest,
recheckPid: recheckPidAction,
sendValidationEmail: sendValidationEmailAction,
validateRequest: validateRequestAction,
}, dispatch);
export default connect(mapStateToProps, mapDispatchToProps)((translate()(DisplayPage)));
export default connect(mapStateToProps, mapDispatchToProps)(withStyles(styles)(translate()(DisplayPage)));
......@@ -15,6 +15,7 @@ const URL_RECONFIRM_REQUEST = UrlTemplate.parse(`/api/v1/requests/r/{uuid}/recon
const URL_UPDATE_PID = UrlTemplate.parse(`/api/v1/requests/r/{uuid}/update-pid`);
const URL_VALIDATE_REQUEST = UrlTemplate.parse(`/api/v1/requests/r/{uuid}/validate`);
const URL_REMOVE_REQUEST = UrlTemplate.parse(`/api/v1/requests/r/{uuid}/remove`);
const URL_RELAY_SUB_REQUEST = UrlTemplate.parse(`/api/v1/requests/r/{uuid}/resend`);
const URL_VALIDATE_CLIENT_REQUEST = `/api/v1/requests/r/validate`;
const URL_LIST_INSTITUTE_REQUESTS = UrlTemplate.parse(`/api/v1/requests/{instCode}`);
const URL_GET_INSTITUTE_REQUEST = UrlTemplate.parse(`/api/v1/requests/{instCode}/r/{uuid}`);
......@@ -48,6 +49,25 @@ class RequestService {
}).then(({ data }) => data as MaterialRequest);
}
/**
* relaySubRequest at /api/v1/requests/r/{uuid}/resend
*
* @param uuid uuid
*/
public static relaySubRequest(uuid: string, xhrConfig?): Promise<MaterialSubRequest> {
const apiUrl = URL_RELAY_SUB_REQUEST.expand({ uuid });
// console.log(`Fetching from ${apiUrl}`);
const content = { /* No content in request body */ };
return axiosBackend.request({
...xhrConfig,
url: apiUrl,
method: 'POST',
...content,
}).then(({ data }) => data as MaterialSubRequest);
}
/**
* reconfirmRequest at /api/v1/requests/r/{uuid}/reconfirm
*
......
......@@ -35,6 +35,8 @@ const styles = (theme) => ({
propertiesRowLabel: {
fontSize: '1rem',
fontFamily: 'Roboto, sans-serif',
display: 'flex' as 'flex',
alignItems: 'center' as 'center',
},
propertiesValue: {
// display: 'flex' as 'flex',
......
Markdown is supported
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