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 { CreateExpenseDto } from './dtos/Expense.dto';
import { ImportableService } from '../Import/decorators/Import.decorator';
import { ManualJournal } from '../ManualJournals/models/ManualJournal';
import { Expense } from './models/Expense.model';
@Injectable()
@ImportableService({ name: ManualJournal.name })
@ImportableService({ name: Expense.name })
export class ExpensesImportable extends Importable {
constructor(private readonly createExpenseService: CreateExpense) {
super();

View File

@@ -18,7 +18,7 @@ import { CurrencyParsingDTOs } from './_constants';
export class ImportFileDataTransformer {
constructor(
private readonly resource: ResourceService,
) {}
) { }
/**
* Parses the given sheet data before passing to the service layer.

View File

@@ -6,7 +6,7 @@ import { ContextIdFactory, ModuleRef } from '@nestjs/core';
@Injectable()
export class ImportableRegistry {
constructor(private readonly moduleRef: ModuleRef) {}
constructor(private readonly moduleRef: ModuleRef) { }
/**
* Retrieves the importable service instance of the given resource name.
* @param {string} name
@@ -15,6 +15,12 @@ export class ImportableRegistry {
public async getImportable(name: string) {
const _name = this.sanitizeResourceName(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 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 { SaleInvoicesSampleData } from '../constants';
import { ImportableService } from '@/modules/Import/decorators/Import.decorator';
import { ManualJournal } from '@/modules/ManualJournals/models/ManualJournal';
import { SaleInvoice } from '../models/SaleInvoice';
@Injectable()
@ImportableService({ name: ManualJournal.name })
@ImportableService({ name: SaleInvoice.name })
export class SaleInvoicesImportable extends Importable {
constructor(private readonly createInvoiceService: CreateSaleInvoice) {
super();

View File

@@ -107,4 +107,4 @@ const modelProviders = models.map((model) => RegisterTenancyModel(model));
imports: [...modelProviders],
exports: [...modelProviders],
})
export class TenancyModelsModule {}
export class TenancyModelsModule { }

View File

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

View File

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

View File

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