snooze vor expired, contracts, display snoozed contracts if an item is missing, un snooze implemented, fixed invoice upload bug
This commit is contained in:
@@ -216,12 +216,7 @@ function InvoiceModal({
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
const createMutation = useMutation({
|
||||
mutationFn: async () => {
|
||||
// Validierung: Dokument ist Pflicht, außer bei NOT_AVAILABLE
|
||||
if (formData.invoiceType !== 'NOT_AVAILABLE' && !selectedFile) {
|
||||
throw new Error('Bitte laden Sie ein Dokument hoch');
|
||||
}
|
||||
|
||||
mutationFn: async (file: File) => {
|
||||
// 1. Invoice erstellen
|
||||
const result = await invoiceApi.addInvoice(ecdId, {
|
||||
invoiceDate: formData.invoiceDate,
|
||||
@@ -229,9 +224,9 @@ function InvoiceModal({
|
||||
notes: formData.notes || undefined,
|
||||
});
|
||||
|
||||
// 2. Upload file if selected
|
||||
if (selectedFile && result.data?.id) {
|
||||
await invoiceApi.uploadDocument(result.data.id, selectedFile);
|
||||
// 2. Upload file
|
||||
if (result.data?.id) {
|
||||
await invoiceApi.uploadDocument(result.data.id, file);
|
||||
}
|
||||
|
||||
return result;
|
||||
@@ -245,13 +240,26 @@ function InvoiceModal({
|
||||
},
|
||||
});
|
||||
|
||||
const updateMutation = useMutation({
|
||||
const createWithoutFileMutation = useMutation({
|
||||
mutationFn: async () => {
|
||||
// Validierung: Dokument ist Pflicht, außer bei NOT_AVAILABLE
|
||||
if (formData.invoiceType !== 'NOT_AVAILABLE' && !invoice?.documentPath && !selectedFile) {
|
||||
throw new Error('Bitte laden Sie ein Dokument hoch');
|
||||
}
|
||||
// Für NOT_AVAILABLE Typ - kein Dokument erforderlich
|
||||
return await invoiceApi.addInvoice(ecdId, {
|
||||
invoiceDate: formData.invoiceDate,
|
||||
invoiceType: formData.invoiceType,
|
||||
notes: formData.notes || undefined,
|
||||
});
|
||||
},
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['contract', contractId.toString()] });
|
||||
onClose();
|
||||
},
|
||||
onError: (err: Error) => {
|
||||
setError(err.message);
|
||||
},
|
||||
});
|
||||
|
||||
const updateMutation = useMutation({
|
||||
mutationFn: async (file: File | null) => {
|
||||
// 1. Invoice aktualisieren
|
||||
const result = await invoiceApi.updateInvoice(ecdId, invoice!.id, {
|
||||
invoiceDate: formData.invoiceDate,
|
||||
@@ -259,9 +267,9 @@ function InvoiceModal({
|
||||
notes: formData.notes || undefined,
|
||||
});
|
||||
|
||||
// 2. Upload file if selected
|
||||
if (selectedFile) {
|
||||
await invoiceApi.uploadDocument(invoice!.id, selectedFile);
|
||||
// 2. Upload file if provided
|
||||
if (file) {
|
||||
await invoiceApi.uploadDocument(invoice!.id, file);
|
||||
}
|
||||
|
||||
return result;
|
||||
@@ -280,9 +288,22 @@ function InvoiceModal({
|
||||
setError(null);
|
||||
|
||||
if (isEditing) {
|
||||
updateMutation.mutate();
|
||||
// Edit-Modus: Dokument ist Pflicht, außer bei NOT_AVAILABLE oder wenn schon vorhanden
|
||||
if (formData.invoiceType !== 'NOT_AVAILABLE' && !invoice?.documentPath && !selectedFile) {
|
||||
setError('Bitte laden Sie ein Dokument hoch');
|
||||
return;
|
||||
}
|
||||
updateMutation.mutate(selectedFile);
|
||||
} else {
|
||||
createMutation.mutate();
|
||||
// Add-Modus: Dokument ist Pflicht, außer bei NOT_AVAILABLE
|
||||
if (formData.invoiceType === 'NOT_AVAILABLE') {
|
||||
createWithoutFileMutation.mutate();
|
||||
} else if (!selectedFile) {
|
||||
setError('Bitte laden Sie ein Dokument hoch');
|
||||
return;
|
||||
} else {
|
||||
createMutation.mutate(selectedFile);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -302,7 +323,7 @@ function InvoiceModal({
|
||||
}
|
||||
};
|
||||
|
||||
const isPending = createMutation.isPending || updateMutation.isPending;
|
||||
const isPending = createMutation.isPending || createWithoutFileMutation.isPending || updateMutation.isPending;
|
||||
|
||||
return (
|
||||
<Modal isOpen={isOpen} onClose={onClose} title={isEditing ? 'Rechnung bearbeiten' : 'Rechnung hinzufügen'}>
|
||||
|
||||
Reference in New Issue
Block a user