From 2816d388a59459ea73c4405f099343a16ad93a8b Mon Sep 17 00:00:00 2001 From: Vitalii Kiiko Date: Tue, 3 Dec 2024 11:47:53 +0100 Subject: [PATCH] - saving progress; --- .env | 3 +- package.json | 3 +- src/components/ErrorBoundary/index.js | 41 +++++++++++++ src/components/ProtectedRoute/index.js | 3 +- src/pages/AddCompany/index.js | 56 +++++++++++++---- src/pages/Applications/index.js | 3 +- src/pages/BandiBeneficiario/index.js | 3 +- src/pages/DashboardBeneficiario/index.js | 5 +- src/service/network-service.js | 76 +++++++++++++++++++----- 9 files changed, 159 insertions(+), 34 deletions(-) create mode 100644 src/components/ErrorBoundary/index.js diff --git a/.env b/.env index 9ef0c84..ef5dcea 100644 --- a/.env +++ b/.env @@ -4,4 +4,5 @@ REACT_APP_API_ADDRESS=https://api-dev-gepafin.memento.credit REACT_APP_LOGO_FILENAME=gepafin-logo.svg REACT_APP_FAVICON_FILENAME=gepafin-favicon.ico REACT_APP_HUB_ID=p4lk3bcx1RStqTaIVVbXs -REACT_APP_EVALUATION_FLOW_ID=1 \ No newline at end of file +REACT_APP_EVALUATION_FLOW_ID=1 +REACT_APP_LOCAL_DEVELOPMENT=1 \ No newline at end of file diff --git a/package.json b/package.json index eb4ec21..e58a0a4 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,8 @@ "@date-fns/tz": "1.1.2", "@emailjs/browser": "^4.4.1", "@emotion/styled": "11.13.0", - "@number-flow/react": "0.2.0", + "@number-flow/react": "0.4.2", + "@sentry/browser": "^8.42.0", "@tanstack/react-table": "^8.20.5", "@wordpress/i18n": "5.8.0", "@wordpress/react-i18n": "4.8.0", diff --git a/src/components/ErrorBoundary/index.js b/src/components/ErrorBoundary/index.js new file mode 100644 index 0000000..4ac790c --- /dev/null +++ b/src/components/ErrorBoundary/index.js @@ -0,0 +1,41 @@ +import React, { Component } from 'react'; +import * as Sentry from '@sentry/browser'; + +const LOCAL_DEVELOPMENT = process.env.REACT_APP_LOCAL_DEVELOPMENT; + +class ErrorBoundary extends Component { + constructor(props) { + super(props); + + this.state = { + builderError: false + }; + } + + static getDerivedStateFromError(error) { + try { + if (LOCAL_DEVELOPMENT !== '1') { + Sentry.init({ + dsn: "https://e7b2134f7d816f663bb83e51b106a694@o4508381921738752.ingest.de.sentry.io/4508381935501392", + environment: process.env.NODE_ENV || "development" + }); + + Sentry.captureException(error); + } + } catch (err) { + console.log('err') + console.log(err); + } + return { builderError: true }; + } + + render() { + if (this.state.builderError) { + return
Error
; + } + + return this.props.children; + } +} + +export default ErrorBoundary; \ No newline at end of file diff --git a/src/components/ProtectedRoute/index.js b/src/components/ProtectedRoute/index.js index f50b3f8..a5620f8 100644 --- a/src/components/ProtectedRoute/index.js +++ b/src/components/ProtectedRoute/index.js @@ -3,6 +3,7 @@ import { Navigate, Outlet } from 'react-router-dom'; // tools import AuthenticationService from '../../service/authentication-service'; +import ErrorBoundary from '../ErrorBoundary'; const ProtectedRoute = () => { @@ -22,7 +23,7 @@ const ProtectedRoute = () => { return (); }*/ - return ; + return ; } export default ProtectedRoute; \ No newline at end of file diff --git a/src/pages/AddCompany/index.js b/src/pages/AddCompany/index.js index 4a81ad2..8f30a74 100644 --- a/src/pages/AddCompany/index.js +++ b/src/pages/AddCompany/index.js @@ -35,12 +35,14 @@ const AddCompany = () => { handleSubmit, formState: { errors }, setValue, - watch + watch, + getValues } = useForm({ defaultValues: {}, mode: 'onChange' }); const isPiva = watch('vatNumber'); + //const isPiva = watch('vatNumber'); const setEmptyValues = () => { const formData = { @@ -138,6 +140,11 @@ const AddCompany = () => { storeSet.main.unsetAsyncRequest(); } + const shouldDisableFiscalCode = () => { + const formData = getValues(); + return !formData.type || formData.type && formData.type === 'giuridica'; + } + useEffect(() => { setInputPiva(isPiva); }, [isPiva]); @@ -145,7 +152,7 @@ const AddCompany = () => { useEffect(() => { checkVatNumber(debouncedPivaValue); }, [debouncedPivaValue]) - +console.log('APP_EVALUATION_FLOW_ID', APP_EVALUATION_FLOW_ID) return (
@@ -176,6 +183,23 @@ const AddCompany = () => { />
+ {APP_EVALUATION_FLOW_ID === '2' + ?
+ +
: null} +
{ config={{ required: __('È obbligatorio', 'gepafin') }} /> - + {APP_EVALUATION_FLOW_ID === '1' + ? + : }
diff --git a/src/pages/Applications/index.js b/src/pages/Applications/index.js index 08b1012..ad3393f 100644 --- a/src/pages/Applications/index.js +++ b/src/pages/Applications/index.js @@ -5,6 +5,7 @@ import { useNavigate } from 'react-router-dom'; // components import MyLatestSubmissionsTable from '../DashboardBeneficiario/components/MyLatestSubmissionsTable'; import { Button } from 'primereact/button'; +import ErrorBoundary from '../../components/ErrorBoundary'; const Applications = () => { const navigate = useNavigate(); @@ -22,7 +23,7 @@ const Applications = () => {
- +
diff --git a/src/pages/BandiBeneficiario/index.js b/src/pages/BandiBeneficiario/index.js index be925d3..5a191be 100644 --- a/src/pages/BandiBeneficiario/index.js +++ b/src/pages/BandiBeneficiario/index.js @@ -8,6 +8,7 @@ import { useStore } from '../../store'; // components import AllBandiAccordion from './components/AllBandiAccordion'; +import ErrorBoundary from '../../components/ErrorBoundary'; const BandiBeneficiario = () => { const chosenCompanyId = useStore().main.chosenCompanyId(); @@ -34,7 +35,7 @@ const BandiBeneficiario = () => { : null}
- +
) diff --git a/src/pages/DashboardBeneficiario/index.js b/src/pages/DashboardBeneficiario/index.js index 66ac510..cc12f6e 100644 --- a/src/pages/DashboardBeneficiario/index.js +++ b/src/pages/DashboardBeneficiario/index.js @@ -14,6 +14,7 @@ import DashboardService from '../../service/dashboard-service'; import LatestBandiTable from './components/LatestBandiTable'; import MyLatestSubmissionsTable from './components/MyLatestSubmissionsTable'; import { Button } from 'primereact/button'; +import ErrorBoundary from '../../components/ErrorBoundary'; const DashboardBeneficiario = () => { const navigate = useNavigate(); @@ -85,7 +86,7 @@ const DashboardBeneficiario = () => {

{__('Domande in lavorazione', 'gepafin')}

- +
@@ -105,7 +106,7 @@ const DashboardBeneficiario = () => {

{__('Bandi disponibili', 'gepafin')}

- +
diff --git a/src/service/network-service.js b/src/service/network-service.js index 98464cb..fa0ef72 100644 --- a/src/service/network-service.js +++ b/src/service/network-service.js @@ -1,9 +1,36 @@ import { storeGet } from '../store'; +import * as Sentry from "@sentry/browser"; + +const LOCAL_DEVELOPMENT = process.env.REACT_APP_LOCAL_DEVELOPMENT; export class NetworkService { static TOKEN_KEY static REFRESH_TOKEN_KEY + static logApiError = (endpoint, status = 0, resp) => { + try { + if ([500].includes(status)) { + if (LOCAL_DEVELOPMENT !== '1') { + Sentry.init({ + dsn: "https://e7b2134f7d816f663bb83e51b106a694@o4508381921738752.ingest.de.sentry.io/4508381935501392", + environment: process.env.NODE_ENV || "development" + }); + + const error = new Error(`Status ${status}`); + Sentry.captureException(`Error in endpoint: ${endpoint}`, { + level: 'error', + extra: { + originalError: error, + details: resp + } + }); + } + } + } catch (err) { + console.log(err); + } + } + static postEmptyResponse = (url, body, callback, errorCallback) => { fetch(url, { method: 'POST', @@ -77,10 +104,12 @@ export class NetworkService { return { response: await response.json(), status: status } }) .then(data => { - if (data.status >= 400 && data.status <= 599) + if (data.status >= 400 && data.status <= 599) { errorCallback(data.response) - else + this.logApiError(url, data.status, data.response); + } else { callback(data.response) + } }) .catch(err => errorCallback(err)); }; @@ -118,10 +147,12 @@ export class NetworkService { return { response: await response.json(), status: status } }) .then(data => { - if (data.status >= 400 && data.status <= 599) + if (data.status >= 400 && data.status <= 599) { errorCallback(data.response) - else + this.logApiError(url, data.status, data.response); + } else { callback(data.response) + } }) .catch(err => errorCallback(err)); }; @@ -159,10 +190,12 @@ export class NetworkService { return { response: await response.blob(), status: status } }) .then(data => { - if (data.status >= 400 && data.status <= 599) + if (data.status >= 400 && data.status <= 599) { errorCallback(data.response) - else + this.logApiError(url, data.status, data.response); + } else { callback(data.response) + } }) .catch(err => errorCallback(err)); }; @@ -198,10 +231,12 @@ export class NetworkService { return { response: await response.json(), status: status } }) .then(data => { - if (data.status >= 400 && data.status <= 599) + if (data.status >= 400 && data.status <= 599) { errorCallback(data.response) - else + this.logApiError(url, data.status, data.response); + } else { callback(data.response) + } }) .catch(err => errorCallback(err)); }; @@ -261,10 +296,12 @@ export class NetworkService { return { response: await response.json(), status: status } }) .then(data => { - if (data.status >= 400 && data.status <= 599) + if (data.status >= 400 && data.status <= 599) { errorCallback(data.response) - else + this.logApiError(url, data.status, data.response); + } else { callback(data.response) + } }) .catch(err => errorCallback(err)); }; @@ -381,12 +418,15 @@ export class NetworkService { }) .then(data => { if (data.status >= 400 && data.status <= 599) { - errorCallback(data.response) + errorCallback(data.response); + this.logApiError(url, data.status, data.response); } else { callback(data.response) } }) - .catch(err => errorCallback(err)); + .catch(err => { + errorCallback(err) + }); }; @@ -422,10 +462,12 @@ export class NetworkService { return { response: await response.blob(), status: status } }) .then(data => { - if (data.status >= 400 && data.status <= 599) + if (data.status >= 400 && data.status <= 599) { errorCallback(data.response) - else + this.logApiError(url, data.status, data.response); + } else { callback(data.response) + } }) .catch(err => errorCallback(err)); }; @@ -504,10 +546,12 @@ export class NetworkService { return { response: await response.json(), status: status } }) .then(data => { - if (data.status >= 400 && data.status <= 599) + if (data.status >= 400 && data.status <= 599) { errorCallback(data.response) - else + this.logApiError(url, data.status, data.response); + } else { callback(data.response) + } }) .catch(err => errorCallback(err));