- implemnted functionality adding to preferred calls;

This commit is contained in:
Vitalii Kiiko
2024-11-18 16:44:28 +01:00
parent 4d14971d1f
commit 291f769840
4 changed files with 61 additions and 16 deletions

View File

@@ -39,8 +39,10 @@ const AllBandiAccordion = () => {
useEffect(() => { useEffect(() => {
storeSet.main.setAsyncRequest(); storeSet.main.setAsyncRequest();
BandoService.getBandi(getCallback, errGetCallbacks); BandoService.getBandi(getCallback, errGetCallbacks, [
}, []); ['companyId', chosenCompanyId]
]);
}, [chosenCompanyId]);
const getCallback = (data) => { const getCallback = (data) => {
if (data.status === 'SUCCESS') { if (data.status === 'SUCCESS') {

View File

@@ -5,7 +5,7 @@ import { is, isEmpty, isNil } from 'ramda';
import "quill/dist/quill.core.css"; import "quill/dist/quill.core.css";
// store // store
import { storeSet, useStore } from '../../store'; import { storeGet, storeSet, useStore } from '../../store';
// tools // tools
import getNumberWithCurrency from '../../helpers/getNumberWithCurrency'; import getNumberWithCurrency from '../../helpers/getNumberWithCurrency';
@@ -28,6 +28,7 @@ import { Message } from 'primereact/message';
import { Toast } from 'primereact/toast'; import { Toast } from 'primereact/toast';
import { Editor } from 'primereact/editor'; import { Editor } from 'primereact/editor';
import { Dialog } from 'primereact/dialog'; import { Dialog } from 'primereact/dialog';
import PreferredBandoService from '../../service/preferred-bando-service';
const BandoViewBeneficiario = () => { const BandoViewBeneficiario = () => {
const isAsyncRequest = useStore().main.isAsyncRequest(); const isAsyncRequest = useStore().main.isAsyncRequest();
@@ -246,11 +247,50 @@ const BandoViewBeneficiario = () => {
const header = renderHeader(); const header = renderHeader();
const addToFavourites = () => {
const companyId = storeGet.main.chosenCompanyId();
const bandoId = getBandoId();
const formdData = {
companyId,
callId: bandoId
}
if (data.preferredCallId && data.preferredCallId !== 0) {
PreferredBandoService.deleteFromPreferred(data.preferredCallId, removeFavCallback, errToggleFavCallback);
} else {
PreferredBandoService.addToPreferred(formdData, addFavCallback, errToggleFavCallback);
}
}
const removeFavCallback = (resp) => {
if (resp.status === 'SUCCESS') {
const newData = {
...data,
preferredCallId: null
}
setData(newData);
}
}
const addFavCallback = (resp) => {
if (resp.status === 'SUCCESS') {
const newData = {
...data,
preferredCallId: resp.data.id
}
setData(newData);
}
}
const errToggleFavCallback = (data) => {
set404FromErrorResponse(data);
}
useEffect(() => { useEffect(() => {
if (!isEmpty(chosenCompanyId) && chosenCompanyId !== 0) { if (!isEmpty(chosenCompanyId) && chosenCompanyId !== 0) {
const bandoId = getBandoId(); const bandoId = getBandoId();
storeSet.main.setAsyncRequest(); storeSet.main.setAsyncRequest();
BandoService.getBando(bandoId, getBandoCallback, errGetBandoCallback); BandoService.getBando(bandoId, getBandoCallback, errGetBandoCallback, [
['companyId', chosenCompanyId]
]);
ApplicationService.getApplications(getApplCallback, errGetApplCallback, [ ApplicationService.getApplications(getApplCallback, errGetApplCallback, [
['callId', bandoId], ['callId', bandoId],
['companyId', chosenCompanyId] ['companyId', chosenCompanyId]
@@ -445,14 +485,15 @@ const BandoViewBeneficiario = () => {
onClick={submitApplication} onClick={submitApplication}
label={submitBtnLabel()} label={submitBtnLabel()}
icon={submitBtnIcon()} iconPos="right"/> icon={submitBtnIcon()} iconPos="right"/>
{/*<Button <Button
type="button" type="button"
outlined outlined={isNil(data.preferredCallId)}
rounded rounded
disabled={true} onClick={addToFavourites}
onClick={saveToFavourites} label={isNil(data.preferredCallId)
label={__('Aggiungi a preferiti', 'gepafin')} ? __('Aggiungi a preferiti', 'gepafin')
icon="pi pi-heart" iconPos="left"/>*/} : __('Rimuovi dai preferiti', 'gepafin')}
icon="pi pi-heart" iconPos="left"/>
</div> </div>
</div> </div>

View File

@@ -33,8 +33,10 @@ const LatestBandiTable = () => {
useEffect(() => { useEffect(() => {
setLoading(true); setLoading(true);
BandoService.getBandi(getCallback, errGetCallbacks); BandoService.getBandi(getCallback, errGetCallbacks, [
}, []); ['companyId', chosenCompanyId]
]);
}, [chosenCompanyId]);
const getCallback = (data) => { const getCallback = (data) => {
if (data.status === 'SUCCESS') { if (data.status === 'SUCCESS') {

View File

@@ -4,12 +4,12 @@ const API_BASE_URL = process.env.REACT_APP_API_EXECUTION_ADDRESS;
export default class BandoService { export default class BandoService {
static getBandi = (callback, errCallback) => { static getBandi = (callback, errCallback, queryParams) => {
NetworkService.get(`${API_BASE_URL}/call`, callback, errCallback); NetworkService.get(`${API_BASE_URL}/call`, callback, errCallback, queryParams);
}; };
static getBando = (id, callback, errCallback) => { static getBando = (id, callback, errCallback, queryParams) => {
NetworkService.get(`${API_BASE_URL}/call/${id}`, callback, errCallback); NetworkService.get(`${API_BASE_URL}/call/${id}`, callback, errCallback, queryParams);
}; };
static validateBando = (id, callback, errCallback) => { static validateBando = (id, callback, errCallback) => {