fix: bugs sprint

This commit is contained in:
Ahmed Bouhuolia
2025-12-18 13:48:12 +02:00
parent 17651e0768
commit 636d206b0e
9 changed files with 86 additions and 71 deletions

View File

@@ -5,10 +5,10 @@ import { ExpensesSampleData } from './constants';
import { CreateExpense } from './commands/CreateExpense.service'; import { CreateExpense } from './commands/CreateExpense.service';
import { CreateExpenseDto } from './dtos/Expense.dto'; import { CreateExpenseDto } from './dtos/Expense.dto';
import { ImportableService } from '../Import/decorators/Import.decorator'; import { ImportableService } from '../Import/decorators/Import.decorator';
import { ManualJournal } from '../ManualJournals/models/ManualJournal'; import { Expense } from './models/Expense.model';
@Injectable() @Injectable()
@ImportableService({ name: ManualJournal.name }) @ImportableService({ name: Expense.name })
export class ExpensesImportable extends Importable { export class ExpensesImportable extends Importable {
constructor(private readonly createExpenseService: CreateExpense) { constructor(private readonly createExpenseService: CreateExpense) {
super(); super();

View File

@@ -15,6 +15,12 @@ export class ImportableRegistry {
public async getImportable(name: string) { public async getImportable(name: string) {
const _name = this.sanitizeResourceName(name); const _name = this.sanitizeResourceName(name);
const importable = getImportableService(_name); const importable = getImportableService(_name);
if (!importable) {
throw new Error(
`No importable service found for resource "${_name}". Make sure the resource has an @ImportableService decorator registered.`,
);
}
const contextId = ContextIdFactory.create(); const contextId = ContextIdFactory.create();
const importableInstance = await this.moduleRef.resolve(importable, contextId, { const importableInstance = await this.moduleRef.resolve(importable, contextId, {

View File

@@ -5,10 +5,10 @@ import { Importable } from '@/modules/Import/Importable';
import { CreateSaleInvoiceDto } from '../dtos/SaleInvoice.dto'; import { CreateSaleInvoiceDto } from '../dtos/SaleInvoice.dto';
import { SaleInvoicesSampleData } from '../constants'; import { SaleInvoicesSampleData } from '../constants';
import { ImportableService } from '@/modules/Import/decorators/Import.decorator'; import { ImportableService } from '@/modules/Import/decorators/Import.decorator';
import { ManualJournal } from '@/modules/ManualJournals/models/ManualJournal'; import { SaleInvoice } from '../models/SaleInvoice';
@Injectable() @Injectable()
@ImportableService({ name: ManualJournal.name }) @ImportableService({ name: SaleInvoice.name })
export class SaleInvoicesImportable extends Importable { export class SaleInvoicesImportable extends Importable {
constructor(private readonly createInvoiceService: CreateSaleInvoice) { constructor(private readonly createInvoiceService: CreateSaleInvoice) {
super(); super();

View File

@@ -102,6 +102,7 @@ function AccountsSuggestFieldRoot({
return ( return (
<FSuggest <FSuggest
items={filteredAccounts} items={filteredAccounts}
itemPredicate={filterAccountsPredicater}
onCreateItemSelect={handleCreateItemSelect} onCreateItemSelect={handleCreateItemSelect}
valueAccessor="id" valueAccessor="id"
textAccessor="name" textAccessor="name"

View File

@@ -48,7 +48,7 @@ function ExpenseForm({
createExpenseMutate, createExpenseMutate,
expense, expense,
expenseId, expenseId,
submitPayload, submitPayloadRef,
} = useExpenseFormContext(); } = useExpenseFormContext();
const isNewMode = !expenseId; const isNewMode = !expenseId;
@@ -86,9 +86,12 @@ function ExpenseForm({
return; return;
} }
// Get submit payload from ref for synchronous access
const currentSubmitPayload = submitPayloadRef?.current || {};
const form = { const form = {
...transformFormValuesToRequest(values), ...transformFormValuesToRequest(values),
publish: submitPayload.publish, publish: currentSubmitPayload.publish,
}; };
// Handle request success. // Handle request success.
const handleSuccess = (response) => { const handleSuccess = (response) => {
@@ -103,10 +106,10 @@ function ExpenseForm({
}); });
setSubmitting(false); setSubmitting(false);
if (submitPayload.redirect) { if (currentSubmitPayload.redirect) {
history.push('/expenses'); history.push('/expenses');
} }
if (submitPayload.resetForm) { if (currentSubmitPayload.resetForm) {
resetForm(); resetForm();
} }
}; };

View File

@@ -59,8 +59,13 @@ function ExpenseFormPageProvider({ query, expenseId, ...props }) {
const { mutateAsync: createExpenseMutate } = useCreateExpense(); const { mutateAsync: createExpenseMutate } = useCreateExpense();
const { mutateAsync: editExpenseMutate } = useEditExpense(); const { mutateAsync: editExpenseMutate } = useEditExpense();
// Submit form payload. // Submit form payload - using ref for synchronous access.
const [submitPayload, setSubmitPayload] = React.useState({}); const submitPayloadRef = React.useRef({});
// Setter to update the ref.
const setSubmitPayload = React.useCallback((payload) => {
submitPayloadRef.current = payload;
}, []);
// Detarmines whether the form in new mode. // Detarmines whether the form in new mode.
const isNewMode = !expenseId; const isNewMode = !expenseId;
@@ -69,7 +74,7 @@ function ExpenseFormPageProvider({ query, expenseId, ...props }) {
const provider = { const provider = {
isNewMode, isNewMode,
expenseId, expenseId,
submitPayload, submitPayloadRef, // Expose ref for synchronous access
currencies, currencies,
customers, customers,