- added re-admit btn and functionality;
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
import React, { useRef, useState } from 'react';
|
||||
import { __ } from '@wordpress/i18n';
|
||||
|
||||
// tools
|
||||
import set404FromErrorResponse from '../../../../helpers/set404FromErrorResponse';
|
||||
|
||||
// api
|
||||
import ApplicationService from '../../../../service/application-service';
|
||||
|
||||
// store
|
||||
import { useStoreValue } from '../../../../store';
|
||||
|
||||
import { Toast } from 'primereact/toast';
|
||||
import { Button } from 'primereact/button';
|
||||
|
||||
const EvaluationReAdmit = ({ id, status }) => {
|
||||
const [isSendingRequest, setIsSendingRequest] = useState(false);
|
||||
const toast = useRef(null);
|
||||
const role = useStoreValue('getRole');
|
||||
|
||||
const doReAdmit = () => {
|
||||
setIsSendingRequest(true);
|
||||
|
||||
ApplicationService.reAdmitApplication(id, reAdmitCallback, errReAdmitCallback);
|
||||
}
|
||||
|
||||
const reAdmitCallback = (resp) => {
|
||||
if (resp.status === 'SUCCESS') {
|
||||
if (toast.current && resp.message) {
|
||||
toast.current.show({
|
||||
severity: 'success',
|
||||
summary: '',
|
||||
detail: resp.message
|
||||
});
|
||||
}
|
||||
window.location.reload();
|
||||
}
|
||||
setIsSendingRequest(false);
|
||||
}
|
||||
|
||||
const errReAdmitCallback = (resp) => {
|
||||
if (toast.current && resp.message) {
|
||||
toast.current.show({
|
||||
severity: resp.status === 'SUCCESS' ? 'info' : 'error',
|
||||
summary: '',
|
||||
detail: resp.message
|
||||
});
|
||||
}
|
||||
set404FromErrorResponse(resp);
|
||||
setIsSendingRequest(false);
|
||||
}
|
||||
|
||||
return (
|
||||
['ROLE_SUPER_ADMIN', 'ROLE_INSTRUCTOR_MANAGER'].includes(role) && ['REJECTED'].includes(status)
|
||||
? <>
|
||||
<Toast ref={toast}/>
|
||||
<Button
|
||||
type="button"
|
||||
disabled={isSendingRequest}
|
||||
severity="warning"
|
||||
onClick={doReAdmit}
|
||||
label={__('Riammetti', 'gepafin')}
|
||||
icon="pi pi-arrow-circle-up" iconPos="right"/>
|
||||
</> : null
|
||||
)
|
||||
}
|
||||
|
||||
export default EvaluationReAdmit;
|
||||
Reference in New Issue
Block a user