Merge pull request #48 from Kitzanos/resend
'Resend emails' functionality
This commit is contained in:
@@ -413,6 +413,10 @@
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.appPageSection__actions:empty {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.appPageSection__tableActions {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
|
||||
@@ -262,4 +262,9 @@ export const classificationType = [
|
||||
'name': 'GENERICO',
|
||||
'idTipoprotocollo': 3
|
||||
}
|
||||
];
|
||||
];
|
||||
|
||||
export const resendEmailLabelsByType = {
|
||||
APPLICATION_AMENDMENT_REQUESTED: 'Invia email (nuovo soccorso)',
|
||||
APPLICATION_AMENDMENT_REMINDER: 'Invia email (sollecito)'
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
import React, { useRef, useState } from 'react';
|
||||
import { pathOr } from 'ramda';
|
||||
|
||||
// tools
|
||||
import set404FromErrorResponse from '../../../../helpers/set404FromErrorResponse';
|
||||
|
||||
// api
|
||||
import EmailService from '../../../../service/email-service';
|
||||
|
||||
import { Toast } from 'primereact/toast';
|
||||
import { Button } from 'primereact/button';
|
||||
|
||||
import { resendEmailLabelsByType } from '../../../../configData';
|
||||
|
||||
const SoccorsoResendEmails = ({ emailsData = [], setDataEmailsSoccorso }) => {
|
||||
const [isResendingRequest, setIsResendingRequest] = useState(false);
|
||||
const toast = useRef(null);
|
||||
const filtered = emailsData.filter(o => !o.isEmailSend);
|
||||
|
||||
const resendEmail = (data) => {
|
||||
setIsResendingRequest(true);
|
||||
|
||||
EmailService.emailResend(
|
||||
data.userActionId,
|
||||
(resp) => resendingCallback(resp, data.userActionId),
|
||||
errResendingCallback
|
||||
);
|
||||
}
|
||||
|
||||
const resendingCallback = (resp, id) => {
|
||||
if (resp.status === 'SUCCESS') {
|
||||
if (toast.current && resp.message) {
|
||||
toast.current.show({
|
||||
severity: 'success',
|
||||
summary: '',
|
||||
detail: resp.message
|
||||
});
|
||||
}
|
||||
setTimeout(() => {
|
||||
if (setDataEmailsSoccorso) {
|
||||
const newEmailSendResponse = emailsData.map((o) => {
|
||||
if (o.userActionId === id) {
|
||||
o.isEmailSend = true;
|
||||
}
|
||||
return o;
|
||||
});
|
||||
setDataEmailsSoccorso(newEmailSendResponse);
|
||||
}
|
||||
setIsResendingRequest(false);
|
||||
}, 1500);
|
||||
}
|
||||
}
|
||||
|
||||
const errResendingCallback = (resp) => {
|
||||
if (toast.current && resp.message) {
|
||||
toast.current.show({
|
||||
severity: 'error',
|
||||
summary: '',
|
||||
detail: resp.message
|
||||
});
|
||||
}
|
||||
set404FromErrorResponse(resp);
|
||||
setIsResendingRequest(false);
|
||||
}
|
||||
|
||||
return(
|
||||
filtered.length > 0 ? <>
|
||||
<Toast ref={toast}/>
|
||||
{filtered
|
||||
.map(o => <Button
|
||||
severity="warning"
|
||||
type="button"
|
||||
disabled={isResendingRequest}
|
||||
onClick={() => resendEmail(o)}
|
||||
label={pathOr('Re-inivia email', ['emailScenario'], resendEmailLabelsByType)}
|
||||
icon="pi pi-send" iconPos="right"/>)}
|
||||
</> : null
|
||||
)
|
||||
}
|
||||
|
||||
export default SoccorsoResendEmails;
|
||||
@@ -1,7 +1,7 @@
|
||||
import React, { useState, useEffect, useRef, useMemo } from 'react';
|
||||
import React, { useState, useEffect, useRef, useMemo, useCallback } from 'react';
|
||||
import { __ } from '@wordpress/i18n';
|
||||
import { useNavigate, useParams } from 'react-router-dom';
|
||||
import { is, isEmpty } from 'ramda';
|
||||
import { is, isEmpty, isNil, pathOr } from 'ramda';
|
||||
import { wrap } from 'object-path-immutable';
|
||||
import { klona } from 'klona';
|
||||
import { useForm } from 'react-hook-form';
|
||||
@@ -28,6 +28,7 @@ import FormField from '../../components/FormField';
|
||||
import { Editor } from 'primereact/editor';
|
||||
import { InputNumber } from 'primereact/inputnumber';
|
||||
import SoccorsoComunications from './components/SoccorsoComunications';
|
||||
import SoccorsoResendEmails from './components/SoccorsoResendEmails';
|
||||
|
||||
|
||||
const SoccorsoEditPreInstructor = () => {
|
||||
@@ -43,6 +44,7 @@ const SoccorsoEditPreInstructor = () => {
|
||||
const [internalNote, setInternalNote] = useState('');
|
||||
const toast = useRef(null);
|
||||
const [formInitialData, setFormInitialData] = useState({});
|
||||
const emailSendResponse = pathOr([], ['emailSendResponse'], data);
|
||||
const {
|
||||
control,
|
||||
handleSubmit,
|
||||
@@ -346,6 +348,11 @@ const SoccorsoEditPreInstructor = () => {
|
||||
setIsLoadingReminding(false);
|
||||
}
|
||||
|
||||
const updateEmailSendResponses = useCallback((newEmailData) => {
|
||||
const newData = wrap(data).set(['emailSendResponse'], newEmailData).value();
|
||||
setData(newData);
|
||||
}, [data]);
|
||||
|
||||
useEffect(() => {
|
||||
if (formInitialData) {
|
||||
Object.keys(formInitialData).map(k => setValue(k, formInitialData[k]));
|
||||
@@ -506,7 +513,8 @@ const SoccorsoEditPreInstructor = () => {
|
||||
<Button
|
||||
type="button"
|
||||
onClick={sendReminder}
|
||||
disabled={isLoadingReminding || ['CLOSE', 'EXPIRED'].includes(data.status)}
|
||||
disabled={isLoadingReminding || ['CLOSE', 'EXPIRED'].includes(data.status)
|
||||
|| (!isNil(emailSendResponse) && !isEmpty(emailSendResponse))}
|
||||
outlined
|
||||
label={__('Invia Sollecito', 'gepafin')}
|
||||
icon="pi pi-send"
|
||||
@@ -532,6 +540,11 @@ const SoccorsoEditPreInstructor = () => {
|
||||
label={__('Chiudi Soccorso Istruttorio', 'gepafin')}
|
||||
icon="pi pi-times" iconPos="right"/>
|
||||
</div>
|
||||
<div className="appPageSection__actions">
|
||||
<SoccorsoResendEmails
|
||||
emailsData={emailSendResponse}
|
||||
setDataEmailsSoccorso={updateEmailSendResponses}/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
@@ -22,6 +22,7 @@ import ProperBandoLabel from '../../../../components/ProperBandoLabel';
|
||||
import { Dropdown } from 'primereact/dropdown';
|
||||
import { Tag } from 'primereact/tag';
|
||||
import { Calendar } from 'primereact/calendar';
|
||||
import SoccorsoResendEmails from '../../../SoccorsoEditPreInstructor/components/SoccorsoResendEmails';
|
||||
|
||||
const SoccorsiPreInstructorTableAsync = ({ userId = null }) => {
|
||||
const [localAsyncRequest, setLocalAsyncRequest] = useState(false);
|
||||
@@ -94,10 +95,25 @@ const SoccorsiPreInstructorTableAsync = ({ userId = null }) => {
|
||||
});
|
||||
};
|
||||
|
||||
const updateRowData = useCallback((id, updateResponse) => {
|
||||
const newItems = items.map((o) => {
|
||||
if (o.id === id) {
|
||||
o.emailSendResponse = updateResponse;
|
||||
}
|
||||
return o;
|
||||
})
|
||||
setItems(newItems);
|
||||
}, [items]);
|
||||
|
||||
const actionsBodyTemplate = (rowData) => {
|
||||
return <Link to={`/domande/${rowData.applicationId}/soccorso/${rowData.id}`}>
|
||||
<Button severity="info" label={__('Dettagli', 'gepafin')} size="small"/>
|
||||
</Link>
|
||||
return <div className="appPageSection__tableActions lessGap">
|
||||
<Link to={`/domande/${rowData.applicationId}/soccorso/${rowData.id}`}>
|
||||
<Button severity="info" label={__('Dettagli', 'gepafin')} size="small"/>
|
||||
</Link>
|
||||
<SoccorsoResendEmails
|
||||
emailsData={rowData.emailSendResponse}
|
||||
setDataEmailsSoccorso={(updateResponse) => updateRowData(rowData.id, updateResponse)}/>
|
||||
</div>
|
||||
}
|
||||
|
||||
const statusBodyTemplate = (rowData) => {
|
||||
|
||||
13
src/service/email-service.js
Normal file
13
src/service/email-service.js
Normal file
@@ -0,0 +1,13 @@
|
||||
import { NetworkService } from './network-service';
|
||||
|
||||
const API_BASE_URL = process.env.REACT_APP_API_EXECUTION_ADDRESS;
|
||||
|
||||
export default class EmailService {
|
||||
|
||||
static emailResend = (id, callback, errCallback) => {
|
||||
NetworkService.post(`${API_BASE_URL}/email/resend`, {}, callback, errCallback, [
|
||||
['userActionId', id]
|
||||
]);
|
||||
};
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user