Skip to content

Commit

Permalink
[PPANTT-42] fix: Error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
svariant committed Aug 2, 2024
1 parent 06340d9 commit fbe9ad2
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ import { rewriteLinks } from './utils/onetrust-utils';
import tosJson from './data/tos.json';
import privacyJson from './data/privacy.json';
import StationMaintenancesPage from './pages/stationMaintenances/list/StationMaintenancesPage';
import { StationMaintenanceAddEditDetail } from './pages/stationMaintenances/addEditDetail/StationMaintenanceAddEditDetail';
import StationMaintenanceAddEditDetail from './pages/stationMaintenances/addEditDetail/StationMaintenanceAddEditDetail';

const SecuredRoutes = withLogin(
withFeatureFlags(
Expand Down
5 changes: 4 additions & 1 deletion src/locale/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -1633,6 +1633,7 @@
"title": "Configurazione",
"subtitle": "Cerca il codice stazione utilizzando la barra di ricerca.",
"search": "Cerca stazione",
"errorGetStations": "E' stato riscontrato un errore durante il recupero delle stazioni",
"hoursSection": {
"title": "Quando sarà in manutenzione?",
"subtitle": "Timezone: Rome, Italy (GMT +2:00)",
Expand All @@ -1641,7 +1642,9 @@
"toHours": "Alle ore",
"ofDay": "Del giorno",
"error": "L’orario di inizio non può essere successivo a quello di fine",
"errorMinDate": "La manuntenzione deve iniziare dopo 72 ore dalla data odierna"
"errorMinDate": "La manutenzione deve iniziare dopo 72 ore dalla data odierna",
"errorGeneric": "E' stato riscontrato un errore durante la creazione o aggiornamento della manutenzione",
"errorConflict": "E' gia presente una manutenzione con questo intervallo temporale"
},
"standInSection": {
"title": "Le posizioni debitorie sono pagabili in Stand In?",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,7 @@ import {
StationMaintenanceActionType,
StationMaintenanceState,
} from '../../../model/StationMaintenance';
import {
datesAreOnSameDay,
removeDateZoneInfoGMT2,
} from '../../../utils/common-utils';
import { datesAreOnSameDay, removeDateZoneInfoGMT2 } from '../../../utils/common-utils';
import { useAppSelector, useAppSelectorWithRedirect } from '../../../redux/hooks';
import { partiesSelectors } from '../../../redux/slices/partiesSlice';
import { getStations } from '../../../services/stationService';
Expand Down Expand Up @@ -140,7 +137,7 @@ const alertTypes = {

const minDateFromToday = add(new Date(), { days: 3 }).toString();
// eslint-disable-next-line complexity, sonarjs/cognitive-complexity
export function StationMaintenanceAddEditDetail() {
export default function StationMaintenanceAddEditDetail() {
const { t } = useTranslation();
const history = useHistory();
const addError = useErrorDispatcher();
Expand Down Expand Up @@ -282,15 +279,23 @@ export function StationMaintenanceAddEditDetail() {
history.push(ROUTES.STATION_MAINTENANCES_LIST);
})
.catch((reason) => {
if (extractProblemJson(reason)?.response?.status === 502) {
const problem = extractProblemJson(reason);
let errorDesc = t(`${componentPath}.configuration.hoursSection.errorGeneric`);

if (problem?.response?.status === 502 && problem?.status !== 409) {
setErrorDate(t(`${componentPath}.configuration.hoursSection.errorMinDate`));
} else {
if (problem?.status === 409) {
errorDesc = t(`${componentPath}.configuration.hoursSection.errorConflict`);
}
addError({
id: 'ACTION_ON_MAINTENANCE_ERROR',
blocking: false,
error: reason,
techDescription: `An error occurred while creating or updating the maintenance`,
toNotify: true,
displayableDescription: errorDesc,
component: 'Toast',
});
}
})
Expand Down Expand Up @@ -330,6 +335,8 @@ export function StationMaintenanceAddEditDetail() {
error: reason,
techDescription: `An error occurred while retrieving stations`,
toNotify: true,
displayableDescription: t(`${componentPath}.configuration.errorGetStations`),
component: 'Toast'
});
setStationList([]);
})
Expand Down Expand Up @@ -435,7 +442,7 @@ export function StationMaintenanceAddEditDetail() {
/>

{alert && (
<Alert severity={alert.severity as AlertColor}>
<Alert severity={alert.severity as AlertColor} data-testid={`alert-${alert.severity}`}>
<Box display="flex" alignItems="center">
<Typography variant="body1" width="85%">
{t(alert.description)}
Expand Down Expand Up @@ -626,7 +633,7 @@ export function StationMaintenanceAddEditDetail() {
color="primary"
variant="contained"
type="submit"
data-testid="open-modal-button-test"
data-testid="confirm-button-test"
>
{t('general.confirm')}
</Button>
Expand Down

0 comments on commit fbe9ad2

Please sign in to comment.