u
This commit is contained in:
@@ -220,15 +220,13 @@ class ManifestForm extends PureComponent {
|
||||
prevState.date !== this.state.date ||
|
||||
prevState.partyId !== this.state.partyId ||
|
||||
prevState.externalNumber !== this.state.externalNumber ||
|
||||
prevState.lines !== this.state.lines ||
|
||||
prevState.attachments !== this.state.attachments
|
||||
prevState.lines !== this.state.lines
|
||||
) {
|
||||
this.editAutomat.actions.update({
|
||||
date: this.state.date,
|
||||
partyId: this.state.partyId,
|
||||
externalNumber: this.state.externalNumber,
|
||||
lines: this.state.lines,
|
||||
attachments: this.state.attachments,
|
||||
});
|
||||
const { isDirty, dirtyFields, dirtyLineKeys, dirtyLineFields, dirtySummary } = this.editAutomat.state;
|
||||
if (
|
||||
@@ -809,18 +807,13 @@ class ManifestForm extends PureComponent {
|
||||
this.setState({ pdfDialogOpen: false, pdfUploading: false });
|
||||
}
|
||||
|
||||
async handleCreatePdf() {
|
||||
async handleCreatePdf(e) {
|
||||
e?.preventDefault?.();
|
||||
e?.stopPropagation?.();
|
||||
const { docId } = this.props;
|
||||
if (this.state.pdfCreating || this.state.saving) return;
|
||||
if (docId == null) return;
|
||||
|
||||
if (this.state.isDirty) {
|
||||
await this.handleSave();
|
||||
if (this.state.isDirty) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
this.setState({ pdfCreating: true });
|
||||
try {
|
||||
const res = await quoteApi.createPdf(docId);
|
||||
@@ -834,20 +827,11 @@ class ManifestForm extends PureComponent {
|
||||
);
|
||||
this.setState({ attachments });
|
||||
if (this.editAutomat) {
|
||||
this.editAutomat.actions.updateDraft({ attachments });
|
||||
this.editAutomat.actions.setAttachments?.(attachments);
|
||||
}
|
||||
}
|
||||
|
||||
enqueueSnackbar('Angebot-PDF erfolgreich erstellt.', { variant: 'success' });
|
||||
|
||||
const fileUrl =
|
||||
res.fileUrl ||
|
||||
(res.attachment?.fileId
|
||||
? `/api/quote/${docId}/file/${res.attachment.fileId}`
|
||||
: null);
|
||||
if (fileUrl) {
|
||||
window.open(fileUrl, '_blank');
|
||||
}
|
||||
} catch (err) {
|
||||
if (!this._cancelled) {
|
||||
notifyError(err);
|
||||
@@ -861,23 +845,23 @@ class ManifestForm extends PureComponent {
|
||||
|
||||
async handleAttachmentDelete(attachment) {
|
||||
if (!attachment) return;
|
||||
const targetId = attachment.id ?? attachment.fileId;
|
||||
const fileId = attachment.fileId ?? attachment.id;
|
||||
const { docId } = this.props;
|
||||
|
||||
const nextAttachments = (this.state.attachments || []).filter(
|
||||
(a) => (a.id ?? a.fileId) !== targetId && a !== attachment,
|
||||
(a) => (a.fileId ?? a.id) !== fileId && a !== attachment,
|
||||
);
|
||||
this.setState({ attachments: nextAttachments });
|
||||
|
||||
if (this.editAutomat) {
|
||||
this.editAutomat.actions.updateDraft({ attachments: nextAttachments });
|
||||
this.editAutomat.actions.setAttachments?.(nextAttachments);
|
||||
}
|
||||
|
||||
if (docId != null && targetId != null && attachment.isPersisted) {
|
||||
if (docId != null && fileId != null && attachment.isPersisted) {
|
||||
try {
|
||||
const api = apiFor(this.cfg);
|
||||
if (typeof api.deleteFile === 'function') {
|
||||
await api.deleteFile(docId, targetId);
|
||||
await api.deleteFile(docId, fileId);
|
||||
enqueueSnackbar('Anhang gelöscht.', { variant: 'success' });
|
||||
}
|
||||
} catch (err) {
|
||||
|
||||
@@ -525,6 +525,7 @@ class ManifestHeader extends PureComponent {
|
||||
)}
|
||||
{kind === 'quote' && onPdfCreate && docId != null && Boolean(number) && (
|
||||
<Button
|
||||
type="button"
|
||||
variant="outlined"
|
||||
startIcon={pdfCreating ? <CircularProgress size={16} color="inherit" /> : <PictureAsPdfIcon />}
|
||||
disabled={saving || pdfCreating}
|
||||
|
||||
Reference in New Issue
Block a user