mirror of
https://github.com/devcode-it/openstamanager.git
synced 2025-06-05 22:09:38 +02:00
fix: Fix snackbar quando il salvataggio fallisce
This commit is contained in:
1
.idea/inspectionProfiles/Project_Default.xml
generated
1
.idea/inspectionProfiles/Project_Default.xml
generated
@@ -2,6 +2,7 @@
|
||||
<profile version="1.0">
|
||||
<option name="myName" value="Project Default" />
|
||||
<inspection_tool class="ContractViolationInspection" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||
<inspection_tool class="ES6MissingAwait" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
|
||||
<inspection_tool class="ES6UnusedImports" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||
<inspection_tool class="EditorConfigPartialOverride" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
|
||||
<inspection_tool class="Eslint" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
|
@@ -31,11 +31,13 @@ import type {
|
||||
TextAreaT,
|
||||
TextFieldT
|
||||
} from '../../typings';
|
||||
import {JSONAPI} from '../../typings';
|
||||
import {
|
||||
getFormData,
|
||||
isFormValid,
|
||||
showSnackbar
|
||||
} from '../../utils';
|
||||
import type {Select} from '../../WebComponents';
|
||||
import DataTable from '../DataTable/DataTable';
|
||||
import TableCell from '../DataTable/TableCell';
|
||||
import TableColumn from '../DataTable/TableColumn';
|
||||
@@ -43,7 +45,6 @@ import TableRow from '../DataTable/TableRow';
|
||||
import LoadingButton from '../LoadingButton';
|
||||
import Mdi from '../Mdi';
|
||||
import Page from '../Page';
|
||||
import {Select} from '../../WebComponents';
|
||||
|
||||
export type ColumnT = {
|
||||
id?: string
|
||||
@@ -388,14 +389,14 @@ export class RecordsPage extends Page {
|
||||
}
|
||||
|
||||
this.rows.put(model.getId(), model);
|
||||
loading.hide();
|
||||
m.redraw();
|
||||
await showSnackbar(__('Record salvato'), 4000);
|
||||
}
|
||||
} else {
|
||||
loading.hide();
|
||||
await showSnackbar(__('Campi non validi. Controlla i dati inseriti'));
|
||||
}
|
||||
|
||||
loading.hide();
|
||||
}
|
||||
|
||||
async setter(model: IModel, data: Collection<File | string>) {
|
||||
@@ -410,6 +411,7 @@ export class RecordsPage extends Page {
|
||||
|
||||
await this.saveFields(model, relations, data);
|
||||
|
||||
try {
|
||||
// Save relations
|
||||
for (const [relation, relatedModel] of Object.entries(relations)) {
|
||||
const response = await relatedModel.save();
|
||||
@@ -420,6 +422,12 @@ export class RecordsPage extends Page {
|
||||
|
||||
const response = await model.save();
|
||||
return response.getModelId();
|
||||
} catch (error) {
|
||||
const {errors} = (error as JSONAPI.RequestError).response.data;
|
||||
const errorMessage = errors.map((error_) => error_.detail)
|
||||
.join(';\n');
|
||||
void showSnackbar(__('Errore durante il salvataggio: :error', {error: errorMessage}), false);
|
||||
}
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/require-await
|
||||
|
@@ -13,3 +13,35 @@ export type JSXElement<T> = Omit<Partial<T>, 'children' | 'style'>
|
||||
style?: string | CSSStyleDeclaration
|
||||
};
|
||||
|
||||
export declare namespace JSONAPI {
|
||||
|
||||
export interface Trace {
|
||||
file: string;
|
||||
line: number;
|
||||
function: string;
|
||||
class: string;
|
||||
type: string;
|
||||
}
|
||||
|
||||
export interface Meta {
|
||||
exception: string;
|
||||
file: string;
|
||||
line: number;
|
||||
trace: Trace[];
|
||||
}
|
||||
|
||||
export interface Error {
|
||||
detail: string;
|
||||
meta: Meta;
|
||||
status: string;
|
||||
title: string;
|
||||
}
|
||||
|
||||
export interface RequestError {
|
||||
response: {
|
||||
data: {
|
||||
errors: JSONAPI.Error[]
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user