mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-19 22:30:31 +00:00
wip
This commit is contained in:
@@ -16,7 +16,7 @@ export class BulkDeleteDto {
|
||||
|
||||
@IsOptional()
|
||||
@IsBoolean()
|
||||
@Transform(({ value }) => parseBoolean(value, false))
|
||||
@Transform(({ value, obj }) => parseBoolean(value ?? obj?.skip_undeletable, false))
|
||||
@ApiPropertyOptional({
|
||||
description: 'When true, undeletable items will be skipped and only deletable ones will be removed.',
|
||||
type: Boolean,
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { castArray, uniq } from 'lodash';
|
||||
import { PromisePool } from '@supercharge/promise-pool';
|
||||
import { DeleteCustomer } from './commands/DeleteCustomer.service';
|
||||
|
||||
@Injectable()
|
||||
export class BulkDeleteCustomersService {
|
||||
constructor(private readonly deleteCustomerService: DeleteCustomer) {}
|
||||
|
||||
public async bulkDeleteCustomers(
|
||||
customerIds: number[],
|
||||
options?: { skipUndeletable?: boolean },
|
||||
): Promise<void> {
|
||||
const { skipUndeletable = false } = options ?? {};
|
||||
const ids = uniq(castArray(customerIds));
|
||||
|
||||
const results = await PromisePool.withConcurrency(1)
|
||||
.for(ids)
|
||||
.process(async (customerId: number) => {
|
||||
try {
|
||||
await this.deleteCustomerService.deleteCustomer(customerId);
|
||||
} catch (error) {
|
||||
if (!skipUndeletable) {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (!skipUndeletable && results.errors && results.errors.length > 0) {
|
||||
throw results.errors[0].raw ?? results.errors[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,10 @@ import { CreateCustomerDto } from './dtos/CreateCustomer.dto';
|
||||
import { EditCustomerDto } from './dtos/EditCustomer.dto';
|
||||
import { CustomerResponseDto } from './dtos/CustomerResponse.dto';
|
||||
import { GetCustomersQueryDto } from './dtos/GetCustomersQuery.dto';
|
||||
import {
|
||||
BulkDeleteCustomersDto,
|
||||
ValidateBulkDeleteCustomersResponseDto,
|
||||
} from './dtos/BulkDeleteCustomers.dto';
|
||||
import { ApiCommonHeaders } from '@/common/decorators/ApiCommonHeaders';
|
||||
|
||||
@Controller('customers')
|
||||
@@ -31,7 +35,7 @@ import { ApiCommonHeaders } from '@/common/decorators/ApiCommonHeaders';
|
||||
@ApiExtraModels(CustomerResponseDto)
|
||||
@ApiCommonHeaders()
|
||||
export class CustomersController {
|
||||
constructor(private customersApplication: CustomersApplication) {}
|
||||
constructor(private customersApplication: CustomersApplication) { }
|
||||
|
||||
@Get(':id')
|
||||
@ApiOperation({ summary: 'Retrieves the customer details.' })
|
||||
@@ -109,4 +113,37 @@ export class CustomersController {
|
||||
openingBalanceDTO,
|
||||
);
|
||||
}
|
||||
|
||||
@Post('validate-bulk-delete')
|
||||
@ApiOperation({
|
||||
summary:
|
||||
'Validates which customers can be deleted and returns counts of deletable and non-deletable customers.',
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 200,
|
||||
description:
|
||||
'Validation completed. Returns counts and IDs of deletable and non-deletable customers.',
|
||||
schema: { $ref: getSchemaPath(ValidateBulkDeleteCustomersResponseDto) },
|
||||
})
|
||||
validateBulkDeleteCustomers(
|
||||
@Body() bulkDeleteDto: BulkDeleteCustomersDto,
|
||||
): Promise<ValidateBulkDeleteCustomersResponseDto> {
|
||||
return this.customersApplication.validateBulkDeleteCustomers(
|
||||
bulkDeleteDto.ids,
|
||||
);
|
||||
}
|
||||
|
||||
@Post('bulk-delete')
|
||||
@ApiOperation({ summary: 'Deletes multiple customers in bulk.' })
|
||||
@ApiResponse({
|
||||
status: 200,
|
||||
description: 'The customers have been successfully deleted.',
|
||||
})
|
||||
async bulkDeleteCustomers(
|
||||
@Body() bulkDeleteDto: BulkDeleteCustomersDto,
|
||||
): Promise<void> {
|
||||
return this.customersApplication.bulkDeleteCustomers(bulkDeleteDto.ids, {
|
||||
skipUndeletable: bulkDeleteDto.skipUndeletable ?? false,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,8 @@ import { CustomersExportable } from './CustomersExportable';
|
||||
import { CustomersImportable } from './CustomersImportable';
|
||||
import { GetCustomers } from './queries/GetCustomers.service';
|
||||
import { DynamicListModule } from '../DynamicListing/DynamicList.module';
|
||||
import { BulkDeleteCustomersService } from './BulkDeleteCustomers.service';
|
||||
import { ValidateBulkDeleteCustomersService } from './ValidateBulkDeleteCustomers.service';
|
||||
|
||||
@Module({
|
||||
imports: [TenancyDatabaseModule, DynamicListModule],
|
||||
@@ -37,6 +39,8 @@ import { DynamicListModule } from '../DynamicListing/DynamicList.module';
|
||||
CustomersExportable,
|
||||
CustomersImportable,
|
||||
GetCustomers,
|
||||
BulkDeleteCustomersService,
|
||||
ValidateBulkDeleteCustomersService,
|
||||
],
|
||||
})
|
||||
export class CustomersModule {}
|
||||
|
||||
@@ -12,6 +12,8 @@ import { CreateCustomerDto } from './dtos/CreateCustomer.dto';
|
||||
import { EditCustomerDto } from './dtos/EditCustomer.dto';
|
||||
import { GetCustomers } from './queries/GetCustomers.service';
|
||||
import { GetCustomersQueryDto } from './dtos/GetCustomersQuery.dto';
|
||||
import { BulkDeleteCustomersService } from './BulkDeleteCustomers.service';
|
||||
import { ValidateBulkDeleteCustomersService } from './ValidateBulkDeleteCustomers.service';
|
||||
|
||||
@Injectable()
|
||||
export class CustomersApplication {
|
||||
@@ -22,6 +24,8 @@ export class CustomersApplication {
|
||||
private deleteCustomerService: DeleteCustomer,
|
||||
private editOpeningBalanceService: EditOpeningBalanceCustomer,
|
||||
private getCustomersService: GetCustomers,
|
||||
private readonly bulkDeleteCustomersService: BulkDeleteCustomersService,
|
||||
private readonly validateBulkDeleteCustomersService: ValidateBulkDeleteCustomersService,
|
||||
) {}
|
||||
|
||||
/**
|
||||
@@ -83,4 +87,20 @@ export class CustomersApplication {
|
||||
public getCustomers = (filterDTO: GetCustomersQueryDto) => {
|
||||
return this.getCustomersService.getCustomersList(filterDTO);
|
||||
};
|
||||
|
||||
public bulkDeleteCustomers = (
|
||||
customerIds: number[],
|
||||
options?: { skipUndeletable?: boolean },
|
||||
) => {
|
||||
return this.bulkDeleteCustomersService.bulkDeleteCustomers(
|
||||
customerIds,
|
||||
options,
|
||||
);
|
||||
};
|
||||
|
||||
public validateBulkDeleteCustomers = (customerIds: number[]) => {
|
||||
return this.validateBulkDeleteCustomersService.validateBulkDeleteCustomers(
|
||||
customerIds,
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
import { Inject, Injectable } from '@nestjs/common';
|
||||
import { Knex } from 'knex';
|
||||
import { TENANCY_DB_CONNECTION } from '../Tenancy/TenancyDB/TenancyDB.constants';
|
||||
import { DeleteCustomer } from './commands/DeleteCustomer.service';
|
||||
import { ModelHasRelationsError } from '@/common/exceptions/ModelHasRelations.exception';
|
||||
import { ServiceError } from '@/modules/Items/ServiceError';
|
||||
|
||||
@Injectable()
|
||||
export class ValidateBulkDeleteCustomersService {
|
||||
constructor(
|
||||
private readonly deleteCustomerService: DeleteCustomer,
|
||||
@Inject(TENANCY_DB_CONNECTION)
|
||||
private readonly tenantKnex: () => Knex,
|
||||
) {}
|
||||
|
||||
public async validateBulkDeleteCustomers(customerIds: number[]): Promise<{
|
||||
deletableCount: number;
|
||||
nonDeletableCount: number;
|
||||
deletableIds: number[];
|
||||
nonDeletableIds: number[];
|
||||
}> {
|
||||
const trx = await this.tenantKnex().transaction({
|
||||
isolationLevel: 'read uncommitted',
|
||||
});
|
||||
|
||||
try {
|
||||
const deletableIds: number[] = [];
|
||||
const nonDeletableIds: number[] = [];
|
||||
|
||||
for (const customerId of customerIds) {
|
||||
try {
|
||||
await this.deleteCustomerService.deleteCustomer(customerId, trx);
|
||||
deletableIds.push(customerId);
|
||||
} catch (error) {
|
||||
if (
|
||||
error instanceof ModelHasRelationsError ||
|
||||
(error instanceof ServiceError &&
|
||||
error.errorType === 'CUSTOMER_HAS_TRANSACTIONS')
|
||||
) {
|
||||
nonDeletableIds.push(customerId);
|
||||
} else {
|
||||
nonDeletableIds.push(customerId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
await trx.rollback();
|
||||
|
||||
return {
|
||||
deletableCount: deletableIds.length,
|
||||
nonDeletableCount: nonDeletableIds.length,
|
||||
deletableIds,
|
||||
nonDeletableIds,
|
||||
};
|
||||
} catch (error) {
|
||||
await trx.rollback();
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,12 +31,13 @@ export class DeleteCustomer {
|
||||
* @param {number} customerId - Customer ID.
|
||||
* @return {Promise<void>}
|
||||
*/
|
||||
public async deleteCustomer(customerId: number): Promise<void> {
|
||||
public async deleteCustomer(
|
||||
customerId: number,
|
||||
trx?: Knex.Transaction,
|
||||
): Promise<void> {
|
||||
// Retrieve the customer or throw not found service error.
|
||||
const oldCustomer = await this.customerModel()
|
||||
.query()
|
||||
.findById(customerId)
|
||||
.throwIfNotFound();
|
||||
const query = this.customerModel().query(trx);
|
||||
const oldCustomer = await query.findById(customerId).throwIfNotFound();
|
||||
|
||||
// Triggers `onCustomerDeleting` event.
|
||||
await this.eventPublisher.emitAsync(events.customers.onDeleting, {
|
||||
@@ -45,10 +46,10 @@ export class DeleteCustomer {
|
||||
} as ICustomerDeletingPayload);
|
||||
|
||||
// Deletes the customer and associated entities under UOW transaction.
|
||||
return this.uow.withTransaction(async (trx: Knex.Transaction) => {
|
||||
return this.uow.withTransaction(async (transaction: Knex.Transaction) => {
|
||||
// Delete the customer from the storage.
|
||||
await this.customerModel()
|
||||
.query(trx)
|
||||
.query(transaction)
|
||||
.findById(customerId)
|
||||
.deleteIfNoRelations({
|
||||
type: ERRORS.CUSTOMER_HAS_TRANSACTIONS,
|
||||
@@ -58,8 +59,8 @@ export class DeleteCustomer {
|
||||
await this.eventPublisher.emitAsync(events.customers.onDeleted, {
|
||||
customerId,
|
||||
oldCustomer,
|
||||
trx,
|
||||
trx: transaction,
|
||||
} as ICustomerEventDeletedPayload);
|
||||
});
|
||||
}, trx);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
import {
|
||||
ArrayNotEmpty,
|
||||
IsArray,
|
||||
IsInt,
|
||||
IsOptional,
|
||||
IsBoolean,
|
||||
} from 'class-validator';
|
||||
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
|
||||
import { Transform } from 'class-transformer';
|
||||
import { parseBoolean } from '@/utils/parse-boolean';
|
||||
|
||||
export class BulkDeleteCustomersDto {
|
||||
@IsArray()
|
||||
@ArrayNotEmpty()
|
||||
@IsInt({ each: true })
|
||||
@ApiProperty({
|
||||
description: 'Array of customer IDs to delete',
|
||||
type: [Number],
|
||||
example: [1, 2, 3],
|
||||
})
|
||||
ids: number[];
|
||||
|
||||
@IsOptional()
|
||||
@IsBoolean()
|
||||
@Transform(({ value, obj }) => parseBoolean(value ?? obj?.skip_undeletable, false))
|
||||
@ApiPropertyOptional({
|
||||
description:
|
||||
'When true, undeletable customers will be skipped and only deletable ones removed.',
|
||||
type: Boolean,
|
||||
default: false,
|
||||
})
|
||||
skipUndeletable?: boolean;
|
||||
}
|
||||
|
||||
export class ValidateBulkDeleteCustomersResponseDto {
|
||||
@ApiProperty({
|
||||
description: 'Number of customers that can be deleted',
|
||||
example: 2,
|
||||
})
|
||||
deletableCount: number;
|
||||
|
||||
@ApiProperty({
|
||||
description: 'Number of customers that cannot be deleted',
|
||||
example: 1,
|
||||
})
|
||||
nonDeletableCount: number;
|
||||
|
||||
@ApiProperty({
|
||||
description: 'IDs of customers that can be deleted',
|
||||
type: [Number],
|
||||
example: [1, 2],
|
||||
})
|
||||
deletableIds: number[];
|
||||
|
||||
@ApiProperty({
|
||||
description: 'IDs of customers that cannot be deleted',
|
||||
type: [Number],
|
||||
example: [3],
|
||||
})
|
||||
nonDeletableIds: number[];
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import { DeleteItemService } from './DeleteItem.service';
|
||||
|
||||
@Injectable()
|
||||
export class BulkDeleteItemsService {
|
||||
constructor(private readonly deleteItemService: DeleteItemService) { }
|
||||
constructor(private readonly deleteItemService: DeleteItemService) {}
|
||||
|
||||
/**
|
||||
* Deletes multiple items.
|
||||
@@ -15,23 +15,26 @@ export class BulkDeleteItemsService {
|
||||
*/
|
||||
async bulkDeleteItems(
|
||||
itemIds: number | Array<number>,
|
||||
options?: { skipUndeletable?: boolean },
|
||||
trx?: Knex.Transaction,
|
||||
): Promise<void> {
|
||||
const { skipUndeletable = false } = options ?? {};
|
||||
const itemsIds = uniq(castArray(itemIds));
|
||||
|
||||
// Use PromisePool to delete items sequentially (concurrency: 1)
|
||||
// to avoid potential database locks and maintain transaction integrity
|
||||
const results = await PromisePool.withConcurrency(1)
|
||||
.for(itemsIds)
|
||||
.process(async (itemId: number) => {
|
||||
await this.deleteItemService.deleteItem(itemId, trx);
|
||||
try {
|
||||
await this.deleteItemService.deleteItem(itemId, trx);
|
||||
} catch (error) {
|
||||
if (!skipUndeletable) {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Check if there were any errors
|
||||
if (results.errors && results.errors.length > 0) {
|
||||
// If needed, you can throw an error here or handle errors individually
|
||||
// For now, we'll let individual errors bubble up
|
||||
throw results.errors[0].raw;
|
||||
if (!skipUndeletable && results.errors && results.errors.length > 0) {
|
||||
throw results.errors[0].raw ?? results.errors[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -374,6 +374,8 @@ export class ItemsController extends TenantController {
|
||||
async bulkDeleteItems(
|
||||
@Body() bulkDeleteDto: BulkDeleteItemsDto,
|
||||
): Promise<void> {
|
||||
return this.itemsApplication.bulkDeleteItems(bulkDeleteDto.ids);
|
||||
return this.itemsApplication.bulkDeleteItems(bulkDeleteDto.ids, {
|
||||
skipUndeletable: bulkDeleteDto.skipUndeletable ?? false,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -158,7 +158,10 @@ export class ItemsApplicationService {
|
||||
* @param {number[]} itemIds - Array of item IDs to delete
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
async bulkDeleteItems(itemIds: number[]): Promise<void> {
|
||||
return this.bulkDeleteItemsService.bulkDeleteItems(itemIds);
|
||||
async bulkDeleteItems(
|
||||
itemIds: number[],
|
||||
options?: { skipUndeletable?: boolean },
|
||||
): Promise<void> {
|
||||
return this.bulkDeleteItemsService.bulkDeleteItems(itemIds, options);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,13 @@
|
||||
import { IsArray, IsInt, ArrayNotEmpty } from 'class-validator';
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
import {
|
||||
IsArray,
|
||||
IsInt,
|
||||
ArrayNotEmpty,
|
||||
IsOptional,
|
||||
IsBoolean,
|
||||
} from 'class-validator';
|
||||
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
|
||||
import { Transform } from 'class-transformer';
|
||||
import { parseBoolean } from '@/utils/parse-boolean';
|
||||
|
||||
export class BulkDeleteItemsDto {
|
||||
@IsArray()
|
||||
@@ -11,6 +19,17 @@ export class BulkDeleteItemsDto {
|
||||
example: [1, 2, 3],
|
||||
})
|
||||
ids: number[];
|
||||
|
||||
@IsOptional()
|
||||
@IsBoolean()
|
||||
@Transform(({ value, obj }) => parseBoolean(value ?? obj?.skip_undeletable, false))
|
||||
@ApiPropertyOptional({
|
||||
description:
|
||||
'When true, undeletable items will be skipped and only deletable ones removed.',
|
||||
type: Boolean,
|
||||
default: false,
|
||||
})
|
||||
skipUndeletable?: boolean;
|
||||
}
|
||||
|
||||
export class ValidateBulkDeleteItemsResponseDto {
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { castArray, uniq } from 'lodash';
|
||||
import { PromisePool } from '@supercharge/promise-pool';
|
||||
import { DeleteVendorService } from './commands/DeleteVendor.service';
|
||||
|
||||
@Injectable()
|
||||
export class BulkDeleteVendorsService {
|
||||
constructor(private readonly deleteVendorService: DeleteVendorService) {}
|
||||
|
||||
public async bulkDeleteVendors(
|
||||
vendorIds: number[],
|
||||
options?: { skipUndeletable?: boolean },
|
||||
): Promise<void> {
|
||||
const { skipUndeletable = false } = options ?? {};
|
||||
const ids = uniq(castArray(vendorIds));
|
||||
|
||||
const results = await PromisePool.withConcurrency(1)
|
||||
.for(ids)
|
||||
.process(async (vendorId: number) => {
|
||||
try {
|
||||
await this.deleteVendorService.deleteVendor(vendorId);
|
||||
} catch (error) {
|
||||
if (!skipUndeletable) {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (!skipUndeletable && results.errors && results.errors.length > 0) {
|
||||
throw results.errors[0].raw ?? results.errors[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
import { Inject, Injectable } from '@nestjs/common';
|
||||
import { Knex } from 'knex';
|
||||
import { TENANCY_DB_CONNECTION } from '../Tenancy/TenancyDB/TenancyDB.constants';
|
||||
import { DeleteVendorService } from './commands/DeleteVendor.service';
|
||||
import { ModelHasRelationsError } from '@/common/exceptions/ModelHasRelations.exception';
|
||||
import { ServiceError } from '@/modules/Items/ServiceError';
|
||||
|
||||
@Injectable()
|
||||
export class ValidateBulkDeleteVendorsService {
|
||||
constructor(
|
||||
private readonly deleteVendorService: DeleteVendorService,
|
||||
@Inject(TENANCY_DB_CONNECTION)
|
||||
private readonly tenantKnex: () => Knex,
|
||||
) {}
|
||||
|
||||
public async validateBulkDeleteVendors(vendorIds: number[]): Promise<{
|
||||
deletableCount: number;
|
||||
nonDeletableCount: number;
|
||||
deletableIds: number[];
|
||||
nonDeletableIds: number[];
|
||||
}> {
|
||||
const trx = await this.tenantKnex().transaction({
|
||||
isolationLevel: 'read uncommitted',
|
||||
});
|
||||
|
||||
try {
|
||||
const deletableIds: number[] = [];
|
||||
const nonDeletableIds: number[] = [];
|
||||
|
||||
for (const vendorId of vendorIds) {
|
||||
try {
|
||||
await this.deleteVendorService.deleteVendor(vendorId, trx);
|
||||
deletableIds.push(vendorId);
|
||||
} catch (error) {
|
||||
if (
|
||||
error instanceof ModelHasRelationsError ||
|
||||
(error instanceof ServiceError &&
|
||||
error.errorType === 'VENDOR_HAS_TRANSACTIONS')
|
||||
) {
|
||||
nonDeletableIds.push(vendorId);
|
||||
} else {
|
||||
nonDeletableIds.push(vendorId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
await trx.rollback();
|
||||
|
||||
return {
|
||||
deletableCount: deletableIds.length,
|
||||
nonDeletableCount: nonDeletableIds.length,
|
||||
deletableIds,
|
||||
nonDeletableIds,
|
||||
};
|
||||
} catch (error) {
|
||||
await trx.rollback();
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,11 +13,20 @@ import {
|
||||
IVendorOpeningBalanceEditDTO,
|
||||
IVendorsFilter,
|
||||
} from './types/Vendors.types';
|
||||
import { ApiOperation, ApiTags } from '@nestjs/swagger';
|
||||
import {
|
||||
ApiOperation,
|
||||
ApiResponse,
|
||||
ApiTags,
|
||||
getSchemaPath,
|
||||
} from '@nestjs/swagger';
|
||||
import { CreateVendorDto } from './dtos/CreateVendor.dto';
|
||||
import { EditVendorDto } from './dtos/EditVendor.dto';
|
||||
import { GetVendorsQueryDto } from './dtos/GetVendorsQuery.dto';
|
||||
import { ApiCommonHeaders } from '@/common/decorators/ApiCommonHeaders';
|
||||
import {
|
||||
BulkDeleteVendorsDto,
|
||||
ValidateBulkDeleteVendorsResponseDto,
|
||||
} from './dtos/BulkDeleteVendors.dto';
|
||||
|
||||
@Controller('vendors')
|
||||
@ApiTags('Vendors')
|
||||
@@ -66,4 +75,37 @@ export class VendorsController {
|
||||
openingBalanceDTO,
|
||||
);
|
||||
}
|
||||
|
||||
@Post('validate-bulk-delete')
|
||||
@ApiOperation({
|
||||
summary:
|
||||
'Validates which vendors can be deleted and returns counts of deletable and non-deletable vendors.',
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 200,
|
||||
description:
|
||||
'Validation completed. Returns counts and IDs of deletable and non-deletable vendors.',
|
||||
schema: { $ref: getSchemaPath(ValidateBulkDeleteVendorsResponseDto) },
|
||||
})
|
||||
validateBulkDeleteVendors(
|
||||
@Body() bulkDeleteDto: BulkDeleteVendorsDto,
|
||||
): Promise<ValidateBulkDeleteVendorsResponseDto> {
|
||||
return this.vendorsApplication.validateBulkDeleteVendors(
|
||||
bulkDeleteDto.ids,
|
||||
);
|
||||
}
|
||||
|
||||
@Post('bulk-delete')
|
||||
@ApiOperation({ summary: 'Deletes multiple vendors in bulk.' })
|
||||
@ApiResponse({
|
||||
status: 200,
|
||||
description: 'The vendors have been successfully deleted.',
|
||||
})
|
||||
async bulkDeleteVendors(
|
||||
@Body() bulkDeleteDto: BulkDeleteVendorsDto,
|
||||
): Promise<void> {
|
||||
return this.vendorsApplication.bulkDeleteVendors(bulkDeleteDto.ids, {
|
||||
skipUndeletable: bulkDeleteDto.skipUndeletable ?? false,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,8 @@ import { GetVendorsService } from './queries/GetVendors.service';
|
||||
import { DynamicListModule } from '../DynamicListing/DynamicList.module';
|
||||
import { VendorsExportable } from './VendorsExportable';
|
||||
import { VendorsImportable } from './VendorsImportable';
|
||||
import { BulkDeleteVendorsService } from './BulkDeleteVendors.service';
|
||||
import { ValidateBulkDeleteVendorsService } from './ValidateBulkDeleteVendors.service';
|
||||
|
||||
@Module({
|
||||
imports: [TenancyDatabaseModule, DynamicListModule],
|
||||
@@ -31,6 +33,8 @@ import { VendorsImportable } from './VendorsImportable';
|
||||
VendorValidators,
|
||||
DeleteVendorService,
|
||||
VendorsApplication,
|
||||
BulkDeleteVendorsService,
|
||||
ValidateBulkDeleteVendorsService,
|
||||
TransformerInjectable,
|
||||
TenancyContext,
|
||||
VendorsExportable,
|
||||
|
||||
@@ -13,6 +13,8 @@ import { GetVendorsService } from './queries/GetVendors.service';
|
||||
import { CreateVendorDto } from './dtos/CreateVendor.dto';
|
||||
import { EditVendorDto } from './dtos/EditVendor.dto';
|
||||
import { GetVendorsQueryDto } from './dtos/GetVendorsQuery.dto';
|
||||
import { BulkDeleteVendorsService } from './BulkDeleteVendors.service';
|
||||
import { ValidateBulkDeleteVendorsService } from './ValidateBulkDeleteVendors.service';
|
||||
|
||||
@Injectable()
|
||||
export class VendorsApplication {
|
||||
@@ -23,6 +25,8 @@ export class VendorsApplication {
|
||||
private editOpeningBalanceService: EditOpeningBalanceVendorService,
|
||||
private getVendorService: GetVendorService,
|
||||
private getVendorsService: GetVendorsService,
|
||||
private readonly bulkDeleteVendorsService: BulkDeleteVendorsService,
|
||||
private readonly validateBulkDeleteVendorsService: ValidateBulkDeleteVendorsService,
|
||||
) {}
|
||||
|
||||
/**
|
||||
@@ -86,4 +90,20 @@ export class VendorsApplication {
|
||||
public getVendors(filterDTO: GetVendorsQueryDto) {
|
||||
return this.getVendorsService.getVendorsList(filterDTO);
|
||||
}
|
||||
|
||||
public bulkDeleteVendors(
|
||||
vendorIds: number[],
|
||||
options?: { skipUndeletable?: boolean },
|
||||
) {
|
||||
return this.bulkDeleteVendorsService.bulkDeleteVendors(
|
||||
vendorIds,
|
||||
options,
|
||||
);
|
||||
}
|
||||
|
||||
public validateBulkDeleteVendors(vendorIds: number[]) {
|
||||
return this.validateBulkDeleteVendorsService.validateBulkDeleteVendors(
|
||||
vendorIds,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,12 +29,10 @@ export class DeleteVendorService {
|
||||
* @param {number} vendorId
|
||||
* @return {Promise<void>}
|
||||
*/
|
||||
public async deleteVendor(vendorId: number) {
|
||||
public async deleteVendor(vendorId: number, trx?: Knex.Transaction) {
|
||||
// Retrieves the old vendor or throw not found service error.
|
||||
const oldVendor = await this.vendorModel()
|
||||
.query()
|
||||
.findById(vendorId)
|
||||
.throwIfNotFound();
|
||||
const query = this.vendorModel().query(trx);
|
||||
const oldVendor = await query.findById(vendorId).throwIfNotFound();
|
||||
|
||||
// Triggers `onVendorDeleting` event.
|
||||
await this.eventPublisher.emitAsync(events.vendors.onDeleting, {
|
||||
@@ -43,10 +41,10 @@ export class DeleteVendorService {
|
||||
} as IVendorEventDeletingPayload);
|
||||
|
||||
// Deletes vendor contact under unit-of-work.
|
||||
return this.uow.withTransaction(async (trx: Knex.Transaction) => {
|
||||
return this.uow.withTransaction(async (transaction: Knex.Transaction) => {
|
||||
// Deletes the vendor contact from the storage.
|
||||
await this.vendorModel()
|
||||
.query(trx)
|
||||
.query(transaction)
|
||||
.findById(vendorId)
|
||||
.deleteIfNoRelations({
|
||||
type: ERRORS.VENDOR_HAS_TRANSACTIONS,
|
||||
@@ -56,8 +54,8 @@ export class DeleteVendorService {
|
||||
await this.eventPublisher.emitAsync(events.vendors.onDeleted, {
|
||||
vendorId,
|
||||
oldVendor,
|
||||
trx,
|
||||
trx: transaction,
|
||||
} as IVendorEventDeletedPayload);
|
||||
});
|
||||
}, trx);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
import {
|
||||
ArrayNotEmpty,
|
||||
IsArray,
|
||||
IsInt,
|
||||
IsOptional,
|
||||
IsBoolean,
|
||||
} from 'class-validator';
|
||||
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
|
||||
import { Transform } from 'class-transformer';
|
||||
import { parseBoolean } from '@/utils/parse-boolean';
|
||||
|
||||
export class BulkDeleteVendorsDto {
|
||||
@IsArray()
|
||||
@ArrayNotEmpty()
|
||||
@IsInt({ each: true })
|
||||
@ApiProperty({
|
||||
description: 'Array of vendor IDs to delete',
|
||||
type: [Number],
|
||||
example: [1, 2, 3],
|
||||
})
|
||||
ids: number[];
|
||||
|
||||
@IsOptional()
|
||||
@IsBoolean()
|
||||
@Transform(({ value, obj }) => parseBoolean(value ?? obj?.skip_undeletable, false))
|
||||
@ApiPropertyOptional({
|
||||
description:
|
||||
'When true, undeletable vendors will be skipped and only deletable ones removed.',
|
||||
type: Boolean,
|
||||
default: false,
|
||||
})
|
||||
skipUndeletable?: boolean;
|
||||
}
|
||||
|
||||
export class ValidateBulkDeleteVendorsResponseDto {
|
||||
@ApiProperty({
|
||||
description: 'Number of vendors that can be deleted',
|
||||
example: 2,
|
||||
})
|
||||
deletableCount: number;
|
||||
|
||||
@ApiProperty({
|
||||
description: 'Number of vendors that cannot be deleted',
|
||||
example: 1,
|
||||
})
|
||||
nonDeletableCount: number;
|
||||
|
||||
@ApiProperty({
|
||||
description: 'IDs of vendors that can be deleted',
|
||||
type: [Number],
|
||||
example: [1, 2],
|
||||
})
|
||||
deletableIds: number[];
|
||||
|
||||
@ApiProperty({
|
||||
description: 'IDs of vendors that cannot be deleted',
|
||||
type: [Number],
|
||||
example: [3],
|
||||
})
|
||||
nonDeletableIds: number[];
|
||||
}
|
||||
|
||||
@@ -60,6 +60,9 @@ import VendorCreditBulkDeleteDialog from '@/containers/Dialogs/VendorCredits/Ven
|
||||
import ManualJournalBulkDeleteDialog from '@/containers/Dialogs/ManualJournals/ManualJournalBulkDeleteDialog';
|
||||
import ExpenseBulkDeleteDialog from '@/containers/Dialogs/Expenses/ExpenseBulkDeleteDialog';
|
||||
import AccountBulkDeleteDialog from '@/containers/Dialogs/Accounts/AccountBulkDeleteDialog';
|
||||
import ItemBulkDeleteDialog from '@/containers/Dialogs/Items/ItemBulkDeleteDialog';
|
||||
import CustomerBulkDeleteDialog from '@/containers/Dialogs/Customers/CustomerBulkDeleteDialog';
|
||||
import VendorBulkDeleteDialog from '@/containers/Dialogs/Vendors/VendorBulkDeleteDialog';
|
||||
|
||||
/**
|
||||
* Dialogs container.
|
||||
@@ -167,6 +170,9 @@ export default function DialogsContainer() {
|
||||
/>
|
||||
<ExpenseBulkDeleteDialog dialogName={DialogsName.ExpenseBulkDelete} />
|
||||
<AccountBulkDeleteDialog dialogName={DialogsName.AccountBulkDelete} />
|
||||
<ItemBulkDeleteDialog dialogName={DialogsName.ItemBulkDelete} />
|
||||
<CustomerBulkDeleteDialog dialogName={DialogsName.CustomerBulkDelete} />
|
||||
<VendorBulkDeleteDialog dialogName={DialogsName.VendorBulkDelete} />
|
||||
<ExportDialog dialogName={DialogsName.Export} />
|
||||
<RuleFormDialog dialogName={DialogsName.BankRuleForm} />
|
||||
<DisconnectBankAccountDialog
|
||||
|
||||
@@ -59,6 +59,9 @@ export enum DialogsName {
|
||||
ManualJournalBulkDelete = 'manual-journals-bulk-delete',
|
||||
ExpenseBulkDelete = 'expenses-bulk-delete',
|
||||
AccountBulkDelete = 'accounts-bulk-delete',
|
||||
ItemBulkDelete = 'items-bulk-delete',
|
||||
CustomerBulkDelete = 'customers-bulk-delete',
|
||||
VendorBulkDelete = 'vendors-bulk-delete',
|
||||
InvoiceMail = 'invoice-mail',
|
||||
EstimateMail = 'estimate-mail',
|
||||
ReceiptMail = 'receipt-mail',
|
||||
|
||||
@@ -1,68 +0,0 @@
|
||||
// @ts-nocheck
|
||||
import React from 'react';
|
||||
import { AppToaster, FormattedMessage as T } from '@/components';
|
||||
import intl from 'react-intl-universal';
|
||||
import { Intent, Alert } from '@blueprintjs/core';
|
||||
import { size } from 'lodash';
|
||||
|
||||
import { useBulkDeleteItems } from '@/hooks/query/items';
|
||||
import withAlertStoreConnect from '@/containers/Alert/withAlertStoreConnect';
|
||||
import withAlertActions from '@/containers/Alert/withAlertActions';
|
||||
|
||||
import { compose } from '@/utils';
|
||||
|
||||
/**
|
||||
* Item bulk delete alert.
|
||||
*/
|
||||
function ItemBulkDeleteAlert({
|
||||
name,
|
||||
|
||||
// #withAlertStoreConnect
|
||||
isOpen,
|
||||
payload: { itemsIds },
|
||||
|
||||
// #withAlertActions
|
||||
closeAlert,
|
||||
}) {
|
||||
const { mutateAsync: bulkDeleteItems, isLoading } = useBulkDeleteItems();
|
||||
|
||||
// handle cancel item bulk delete alert.
|
||||
const handleCancelBulkDelete = () => {
|
||||
closeAlert(name);
|
||||
};
|
||||
// Handle confirm items bulk delete.
|
||||
const handleConfirmBulkDelete = () => {
|
||||
bulkDeleteItems(itemsIds)
|
||||
.then(() => {
|
||||
AppToaster.show({
|
||||
message: intl.get('the_items_has_been_deleted_successfully'),
|
||||
intent: Intent.SUCCESS,
|
||||
});
|
||||
closeAlert(name);
|
||||
})
|
||||
.catch((errors) => { });
|
||||
};
|
||||
return (
|
||||
<Alert
|
||||
cancelButtonText={<T id={'cancel'} />}
|
||||
confirmButtonText={
|
||||
<T id={'delete_count'} values={{ count: size(itemsIds) }} />
|
||||
}
|
||||
icon="trash"
|
||||
intent={Intent.DANGER}
|
||||
isOpen={isOpen}
|
||||
onCancel={handleCancelBulkDelete}
|
||||
onConfirm={handleConfirmBulkDelete}
|
||||
loading={isLoading}
|
||||
>
|
||||
<p>
|
||||
<T id={'once_delete_these_items_you_will_not_able_restore_them'} />
|
||||
</p>
|
||||
</Alert>
|
||||
);
|
||||
}
|
||||
|
||||
export default compose(
|
||||
withAlertStoreConnect(),
|
||||
withAlertActions,
|
||||
)(ItemBulkDeleteAlert);
|
||||
@@ -12,7 +12,6 @@ import {
|
||||
import { useHistory } from 'react-router-dom';
|
||||
|
||||
import {
|
||||
If,
|
||||
Icon,
|
||||
Can,
|
||||
FormattedMessage as T,
|
||||
@@ -29,7 +28,6 @@ import { useDownloadExportPdf } from '@/hooks/query/FinancialReports/use-export-
|
||||
|
||||
import withCustomers from './withCustomers';
|
||||
import withCustomersActions from './withCustomersActions';
|
||||
import withAlertActions from '@/containers/Alert/withAlertActions';
|
||||
import withSettingsActions from '@/containers/Settings/withSettingsActions';
|
||||
import withSettings from '@/containers/Settings/withSettings';
|
||||
import withDialogActions from '@/containers/Dialog/withDialogActions';
|
||||
@@ -37,6 +35,8 @@ import withDialogActions from '@/containers/Dialog/withDialogActions';
|
||||
import { CustomerAction, AbilitySubject } from '@/constants/abilityOption';
|
||||
import { compose } from '@/utils';
|
||||
import { DialogsName } from '@/constants/dialogs';
|
||||
import { isEmpty } from 'lodash';
|
||||
import { useBulkDeleteCustomersDialog } from './hooks/use-bulk-delete-customers-dialog';
|
||||
|
||||
/**
|
||||
* Customers actions bar.
|
||||
@@ -50,9 +50,6 @@ function CustomerActionsBar({
|
||||
setCustomersTableState,
|
||||
accountsInactiveMode,
|
||||
|
||||
// #withAlertActions
|
||||
openAlert,
|
||||
|
||||
// #withSettings
|
||||
customersTableSize,
|
||||
|
||||
@@ -62,6 +59,9 @@ function CustomerActionsBar({
|
||||
// #withDialogActions
|
||||
openDialog,
|
||||
}) {
|
||||
const { openBulkDeleteDialog, isValidatingBulkDeleteCustomers } =
|
||||
useBulkDeleteCustomersDialog();
|
||||
|
||||
// History context.
|
||||
const history = useHistory();
|
||||
|
||||
@@ -80,7 +80,7 @@ function CustomerActionsBar({
|
||||
|
||||
// Handle Customers bulk delete button click.,
|
||||
const handleBulkDelete = () => {
|
||||
openAlert('customers-bulk-delete', { customersIds: customersSelectedRows });
|
||||
openBulkDeleteDialog(customersSelectedRows);
|
||||
};
|
||||
|
||||
const handleTabChange = (view) => {
|
||||
@@ -118,6 +118,23 @@ function CustomerActionsBar({
|
||||
downloadExportPdf({ resource: 'Customer' });
|
||||
};
|
||||
|
||||
if (!isEmpty(customersSelectedRows)) {
|
||||
return (
|
||||
<DashboardActionsBar>
|
||||
<NavbarGroup>
|
||||
<Button
|
||||
className={Classes.MINIMAL}
|
||||
icon={<Icon icon="trash-16" iconSize={16} />}
|
||||
text={<T id={'delete'} />}
|
||||
intent={Intent.DANGER}
|
||||
onClick={handleBulkDelete}
|
||||
disabled={isValidatingBulkDeleteCustomers}
|
||||
/>
|
||||
</NavbarGroup>
|
||||
</DashboardActionsBar>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<DashboardActionsBar>
|
||||
<NavbarGroup>
|
||||
@@ -129,7 +146,7 @@ function CustomerActionsBar({
|
||||
onChange={handleTabChange}
|
||||
/>
|
||||
<NavbarDivider />
|
||||
<Can I={CustomerAction.Create} a={AbilitySubject.Item}>
|
||||
<Can I={CustomerAction.Create} a={AbilitySubject.Customer}>
|
||||
<Button
|
||||
className={Classes.MINIMAL}
|
||||
icon={<Icon icon={'plus'} />}
|
||||
@@ -153,16 +170,6 @@ function CustomerActionsBar({
|
||||
/>
|
||||
</AdvancedFilterPopover>
|
||||
|
||||
<If condition={customersSelectedRows.length}>
|
||||
<Button
|
||||
className={Classes.MINIMAL}
|
||||
icon={<Icon icon="trash-16" iconSize={16} />}
|
||||
text={<T id={'delete'} />}
|
||||
intent={Intent.DANGER}
|
||||
onClick={handleBulkDelete}
|
||||
/>
|
||||
</If>
|
||||
<NavbarDivider />
|
||||
<Button
|
||||
className={Classes.MINIMAL}
|
||||
icon={<Icon icon="print-16" iconSize={16} />}
|
||||
@@ -217,6 +224,5 @@ export default compose(
|
||||
withSettings(({ customersSettings }) => ({
|
||||
customersTableSize: customersSettings?.tableSize,
|
||||
})),
|
||||
withAlertActions,
|
||||
withDialogActions,
|
||||
)(CustomerActionsBar);
|
||||
|
||||
@@ -24,13 +24,15 @@ function CustomersList({
|
||||
|
||||
// #withCustomersActions
|
||||
resetCustomersTableState,
|
||||
resetCustomersSelectedRows,
|
||||
}) {
|
||||
// Resets the accounts table state once the page unmount.
|
||||
useEffect(
|
||||
() => () => {
|
||||
resetCustomersTableState();
|
||||
resetCustomersSelectedRows();
|
||||
},
|
||||
[resetCustomersTableState],
|
||||
[resetCustomersSelectedRows, resetCustomersTableState],
|
||||
);
|
||||
|
||||
return (
|
||||
|
||||
@@ -32,6 +32,7 @@ import { DRAWERS } from '@/constants/drawers';
|
||||
function CustomersTable({
|
||||
// #withCustomersActions
|
||||
setCustomersTableState,
|
||||
setCustomersSelectedRows,
|
||||
|
||||
// #withCustomers
|
||||
customersTableState,
|
||||
@@ -78,6 +79,14 @@ function CustomersTable({
|
||||
[setCustomersTableState],
|
||||
);
|
||||
|
||||
const handleSelectedRowsChange = React.useCallback(
|
||||
(selectedFlatRows) => {
|
||||
const selectedIds = selectedFlatRows?.map((row) => row.original.id) || [];
|
||||
setCustomersSelectedRows(selectedIds);
|
||||
},
|
||||
[setCustomersSelectedRows],
|
||||
);
|
||||
|
||||
// Handles the customer delete action.
|
||||
const handleCustomerDelete = ({ id }) => {
|
||||
openAlert('customer-delete', { contactId: id });
|
||||
@@ -140,6 +149,8 @@ function CustomersTable({
|
||||
manualSortBy={true}
|
||||
manualPagination={true}
|
||||
pagesCount={pagination.pagesCount}
|
||||
onSelectedRowsChange={handleSelectedRowsChange}
|
||||
autoResetSelectedRows={false}
|
||||
autoResetSortBy={false}
|
||||
autoResetPage={false}
|
||||
TableLoadingRenderer={TableSkeletonRows}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
// @ts-nocheck
|
||||
import { DialogsName } from '@/constants/dialogs';
|
||||
import { useValidateBulkDeleteCustomers } from '@/hooks/query/customers';
|
||||
import { useBulkDeleteDialog } from '@/hooks/dialogs/useBulkDeleteDialog';
|
||||
|
||||
export const useBulkDeleteCustomersDialog = () => {
|
||||
const validateBulkDeleteMutation = useValidateBulkDeleteCustomers();
|
||||
|
||||
return useBulkDeleteDialog(
|
||||
DialogsName.CustomerBulkDelete,
|
||||
validateBulkDeleteMutation,
|
||||
);
|
||||
};
|
||||
|
||||
@@ -12,6 +12,7 @@ export default (mapState) => {
|
||||
|
||||
const mapStateToProps = (state, props) => {
|
||||
const mapped = {
|
||||
customersSelectedRows: state.customers.selectedRows,
|
||||
customersTableState: getCustomersTableState(state, props),
|
||||
customersTableStateChanged: customersTableStateChanged(state, props),
|
||||
};
|
||||
|
||||
@@ -2,12 +2,17 @@
|
||||
import { connect } from 'react-redux';
|
||||
import {
|
||||
setCustomersTableState,
|
||||
resetCustomersTableState
|
||||
resetCustomersTableState,
|
||||
setCustomersSelectedRows,
|
||||
resetCustomersSelectedRows,
|
||||
} from '@/store/customers/customers.actions';
|
||||
|
||||
export const mapDispatchToProps = (dispatch) => ({
|
||||
setCustomersTableState: (state) => dispatch(setCustomersTableState(state)),
|
||||
resetCustomersTableState: () => dispatch(resetCustomersTableState()),
|
||||
setCustomersSelectedRows: (selectedRows) =>
|
||||
dispatch(setCustomersSelectedRows(selectedRows)),
|
||||
resetCustomersSelectedRows: () => dispatch(resetCustomersSelectedRows()),
|
||||
});
|
||||
|
||||
export default connect(null, mapDispatchToProps);
|
||||
|
||||
@@ -3,7 +3,6 @@ import React from 'react';
|
||||
import { Button, Classes, Dialog, Intent } from '@blueprintjs/core';
|
||||
import { FormattedMessage as T, AppToaster } from '@/components';
|
||||
import intl from 'react-intl-universal';
|
||||
import { queryCache } from 'react-query';
|
||||
|
||||
import BulkDeleteDialogContent from '@/containers/Dialogs/components/BulkDeleteDialogContent';
|
||||
import { useBulkDeleteAccounts } from '@/hooks/query/accounts';
|
||||
@@ -45,7 +44,6 @@ function AccountBulkDeleteDialog({
|
||||
message: intl.get('the_accounts_has_been_successfully_deleted'),
|
||||
intent: Intent.SUCCESS,
|
||||
});
|
||||
queryCache.invalidateQueries('accounts-table');
|
||||
setAccountsSelectedRows([]);
|
||||
closeDialog(dialogName);
|
||||
})
|
||||
|
||||
@@ -3,7 +3,6 @@ import React from 'react';
|
||||
import { Button, Classes, Dialog, Intent } from '@blueprintjs/core';
|
||||
import { FormattedMessage as T, AppToaster } from '@/components';
|
||||
import intl from 'react-intl-universal';
|
||||
import { queryCache } from 'react-query';
|
||||
|
||||
import BulkDeleteDialogContent from '@/containers/Dialogs/components/BulkDeleteDialogContent';
|
||||
import { useBulkDeleteBills } from '@/hooks/query/bills';
|
||||
@@ -44,7 +43,6 @@ function BillBulkDeleteDialog({
|
||||
message: intl.get('the_bills_has_been_deleted_successfully'),
|
||||
intent: Intent.SUCCESS,
|
||||
});
|
||||
queryCache.invalidateQueries('bills-table');
|
||||
setBillsSelectedRows([]);
|
||||
closeDialog(dialogName);
|
||||
})
|
||||
|
||||
@@ -3,7 +3,6 @@ import React from 'react';
|
||||
import { Button, Classes, Dialog, Intent } from '@blueprintjs/core';
|
||||
import { FormattedMessage as T, AppToaster } from '@/components';
|
||||
import intl from 'react-intl-universal';
|
||||
import { queryCache } from 'react-query';
|
||||
|
||||
import BulkDeleteDialogContent from '@/containers/Dialogs/components/BulkDeleteDialogContent';
|
||||
import { useBulkDeleteCreditNotes } from '@/hooks/query/creditNote';
|
||||
@@ -45,7 +44,6 @@ function CreditNoteBulkDeleteDialog({
|
||||
message: intl.get('the_credit_notes_has_been_deleted_successfully'),
|
||||
intent: Intent.SUCCESS,
|
||||
});
|
||||
queryCache.invalidateQueries('credit-notes-table');
|
||||
setCreditNotesSelectedRows([]);
|
||||
closeDialog(dialogName);
|
||||
})
|
||||
|
||||
@@ -0,0 +1,104 @@
|
||||
// @ts-nocheck
|
||||
import React from 'react';
|
||||
import { Button, Classes, Dialog, Intent } from '@blueprintjs/core';
|
||||
import { FormattedMessage as T, AppToaster } from '@/components';
|
||||
import intl from 'react-intl-universal';
|
||||
|
||||
import BulkDeleteDialogContent from '@/containers/Dialogs/components/BulkDeleteDialogContent';
|
||||
import { useBulkDeleteCustomers } from '@/hooks/query/customers';
|
||||
import withDialogRedux from '@/components/DialogReduxConnect';
|
||||
import withDialogActions from '@/containers/Dialog/withDialogActions';
|
||||
import withCustomersActions from '@/containers/Customers/CustomersLanding/withCustomersActions';
|
||||
import { compose } from '@/utils';
|
||||
|
||||
function CustomerBulkDeleteDialog({
|
||||
dialogName,
|
||||
isOpen,
|
||||
payload: {
|
||||
ids = [],
|
||||
deletableCount = 0,
|
||||
undeletableCount = 0,
|
||||
totalSelected = ids.length,
|
||||
} = {},
|
||||
|
||||
// #withCustomersActions
|
||||
setCustomersSelectedRows,
|
||||
|
||||
// #withDialogActions
|
||||
closeDialog,
|
||||
}) {
|
||||
const { mutateAsync: bulkDeleteCustomers, isLoading } =
|
||||
useBulkDeleteCustomers();
|
||||
|
||||
const handleCancel = () => {
|
||||
closeDialog(dialogName);
|
||||
};
|
||||
|
||||
const handleConfirmBulkDelete = () => {
|
||||
bulkDeleteCustomers({
|
||||
ids,
|
||||
skipUndeletable: true,
|
||||
})
|
||||
.then(() => {
|
||||
AppToaster.show({
|
||||
message: intl.get('the_customers_has_been_deleted_successfully'),
|
||||
intent: Intent.SUCCESS,
|
||||
});
|
||||
setCustomersSelectedRows([]);
|
||||
closeDialog(dialogName);
|
||||
})
|
||||
.catch(() => {
|
||||
AppToaster.show({
|
||||
message: intl.get('something_went_wrong'),
|
||||
intent: Intent.DANGER,
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<Dialog
|
||||
title={
|
||||
<T
|
||||
id={'bulk_delete_dialog_title'}
|
||||
values={{ resourcePlural: intl.get('resource_customer_plural') }}
|
||||
/>
|
||||
}
|
||||
isOpen={isOpen}
|
||||
onClose={handleCancel}
|
||||
canEscapeKeyClose={!isLoading}
|
||||
canOutsideClickClose={!isLoading}
|
||||
>
|
||||
<BulkDeleteDialogContent
|
||||
totalSelected={totalSelected}
|
||||
deletableCount={deletableCount}
|
||||
undeletableCount={undeletableCount}
|
||||
resourceSingularLabel={intl.get('resource_customer_singular')}
|
||||
resourcePluralLabel={intl.get('resource_customer_plural')}
|
||||
/>
|
||||
|
||||
<div className={Classes.DIALOG_FOOTER}>
|
||||
<div className={Classes.DIALOG_FOOTER_ACTIONS}>
|
||||
<Button onClick={handleCancel} disabled={isLoading}>
|
||||
<T id={'cancel'} />
|
||||
</Button>
|
||||
|
||||
<Button
|
||||
intent={Intent.DANGER}
|
||||
onClick={handleConfirmBulkDelete}
|
||||
loading={isLoading}
|
||||
disabled={deletableCount === 0 || isLoading}
|
||||
>
|
||||
<T id={'delete_count'} values={{ count: deletableCount }} />
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
|
||||
export default compose(
|
||||
withDialogRedux(),
|
||||
withDialogActions,
|
||||
withCustomersActions,
|
||||
)(CustomerBulkDeleteDialog);
|
||||
|
||||
@@ -3,7 +3,6 @@ import React from 'react';
|
||||
import { Button, Classes, Dialog, Intent } from '@blueprintjs/core';
|
||||
import { FormattedMessage as T, AppToaster } from '@/components';
|
||||
import intl from 'react-intl-universal';
|
||||
import { queryCache } from 'react-query';
|
||||
|
||||
import BulkDeleteDialogContent from '@/containers/Dialogs/components/BulkDeleteDialogContent';
|
||||
import { useBulkDeleteEstimates } from '@/hooks/query/estimates';
|
||||
@@ -45,7 +44,6 @@ function EstimateBulkDeleteDialog({
|
||||
message: intl.get('the_estimates_has_been_deleted_successfully'),
|
||||
intent: Intent.SUCCESS,
|
||||
});
|
||||
queryCache.invalidateQueries('estimates-table');
|
||||
setEstimatesSelectedRows([]);
|
||||
closeDialog(dialogName);
|
||||
})
|
||||
|
||||
@@ -3,7 +3,6 @@ import React from 'react';
|
||||
import { Button, Classes, Dialog, Intent } from '@blueprintjs/core';
|
||||
import { FormattedMessage as T, AppToaster } from '@/components';
|
||||
import intl from 'react-intl-universal';
|
||||
import { queryCache } from 'react-query';
|
||||
|
||||
import BulkDeleteDialogContent from '@/containers/Dialogs/components/BulkDeleteDialogContent';
|
||||
import { useBulkDeleteExpenses } from '@/hooks/query/expenses';
|
||||
@@ -45,7 +44,6 @@ function ExpenseBulkDeleteDialog({
|
||||
message: intl.get('the_expenses_has_been_deleted_successfully'),
|
||||
intent: Intent.SUCCESS,
|
||||
});
|
||||
queryCache.invalidateQueries('expenses-table');
|
||||
setExpensesSelectedRows([]);
|
||||
closeDialog(dialogName);
|
||||
})
|
||||
|
||||
@@ -3,7 +3,6 @@ import React from 'react';
|
||||
import { FormattedMessage as T } from '@/components';
|
||||
import intl from 'react-intl-universal';
|
||||
import { Button, Classes, Dialog, Intent } from '@blueprintjs/core';
|
||||
import { queryCache } from 'react-query';
|
||||
|
||||
import withDialogRedux from '@/components/DialogReduxConnect';
|
||||
import withDialogActions from '@/containers/Dialog/withDialogActions';
|
||||
@@ -50,7 +49,6 @@ function InvoiceBulkDeleteDialog({
|
||||
message: intl.get('the_invoices_has_been_deleted_successfully'),
|
||||
intent: Intent.SUCCESS,
|
||||
});
|
||||
queryCache.invalidateQueries('invoices-table');
|
||||
resetInvoicesSelectedRows();
|
||||
closeDialog(dialogName);
|
||||
})
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
// @ts-nocheck
|
||||
import React from 'react';
|
||||
import { Button, Classes, Dialog, Intent } from '@blueprintjs/core';
|
||||
import { FormattedMessage as T, AppToaster } from '@/components';
|
||||
import intl from 'react-intl-universal';
|
||||
|
||||
import BulkDeleteDialogContent from '@/containers/Dialogs/components/BulkDeleteDialogContent';
|
||||
import { useBulkDeleteItems } from '@/hooks/query/items';
|
||||
import withDialogRedux from '@/components/DialogReduxConnect';
|
||||
import withDialogActions from '@/containers/Dialog/withDialogActions';
|
||||
import withItemsActions from '@/containers/Items/withItemsActions';
|
||||
import { compose } from '@/utils';
|
||||
|
||||
function ItemBulkDeleteDialog({
|
||||
dialogName,
|
||||
isOpen,
|
||||
payload: {
|
||||
ids = [],
|
||||
deletableCount = 0,
|
||||
undeletableCount = 0,
|
||||
totalSelected = ids.length,
|
||||
} = {},
|
||||
|
||||
// #withItemsActions
|
||||
setItemsSelectedRows,
|
||||
|
||||
// #withDialogActions
|
||||
closeDialog,
|
||||
}) {
|
||||
const { mutateAsync: bulkDeleteItems, isLoading } = useBulkDeleteItems();
|
||||
|
||||
const handleCancel = () => {
|
||||
closeDialog(dialogName);
|
||||
};
|
||||
|
||||
const handleConfirmBulkDelete = () => {
|
||||
bulkDeleteItems({
|
||||
ids,
|
||||
skipUndeletable: true,
|
||||
})
|
||||
.then(() => {
|
||||
AppToaster.show({
|
||||
message: intl.get('the_items_has_been_deleted_successfully'),
|
||||
intent: Intent.SUCCESS,
|
||||
});
|
||||
setItemsSelectedRows([]);
|
||||
closeDialog(dialogName);
|
||||
})
|
||||
.catch(() => {
|
||||
AppToaster.show({
|
||||
message: intl.get('something_went_wrong'),
|
||||
intent: Intent.DANGER,
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<Dialog
|
||||
title={
|
||||
<T
|
||||
id={'bulk_delete_dialog_title'}
|
||||
values={{ resourcePlural: intl.get('resource_item_plural') }}
|
||||
/>
|
||||
}
|
||||
isOpen={isOpen}
|
||||
onClose={handleCancel}
|
||||
canEscapeKeyClose={!isLoading}
|
||||
canOutsideClickClose={!isLoading}
|
||||
>
|
||||
<BulkDeleteDialogContent
|
||||
totalSelected={totalSelected}
|
||||
deletableCount={deletableCount}
|
||||
undeletableCount={undeletableCount}
|
||||
resourceSingularLabel={intl.get('resource_item_singular')}
|
||||
resourcePluralLabel={intl.get('resource_item_plural')}
|
||||
/>
|
||||
|
||||
<div className={Classes.DIALOG_FOOTER}>
|
||||
<div className={Classes.DIALOG_FOOTER_ACTIONS}>
|
||||
<Button onClick={handleCancel} disabled={isLoading}>
|
||||
<T id={'cancel'} />
|
||||
</Button>
|
||||
|
||||
<Button
|
||||
intent={Intent.DANGER}
|
||||
onClick={handleConfirmBulkDelete}
|
||||
loading={isLoading}
|
||||
disabled={deletableCount === 0 || isLoading}
|
||||
>
|
||||
<T id={'delete_count'} values={{ count: deletableCount }} />
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
|
||||
export default compose(
|
||||
withDialogRedux(),
|
||||
withDialogActions,
|
||||
withItemsActions,
|
||||
)(ItemBulkDeleteDialog);
|
||||
|
||||
@@ -3,7 +3,6 @@ import React from 'react';
|
||||
import { Button, Classes, Dialog, Intent } from '@blueprintjs/core';
|
||||
import { FormattedMessage as T, AppToaster } from '@/components';
|
||||
import intl from 'react-intl-universal';
|
||||
import { queryCache } from 'react-query';
|
||||
|
||||
import BulkDeleteDialogContent from '@/containers/Dialogs/components/BulkDeleteDialogContent';
|
||||
import { useBulkDeleteManualJournals } from '@/hooks/query/manualJournals';
|
||||
@@ -45,7 +44,6 @@ function ManualJournalBulkDeleteDialog({
|
||||
message: intl.get('the_journals_has_been_deleted_successfully'),
|
||||
intent: Intent.SUCCESS,
|
||||
});
|
||||
queryCache.invalidateQueries('manual-journals-table');
|
||||
setManualJournalsSelectedRows([]);
|
||||
closeDialog(dialogName);
|
||||
})
|
||||
|
||||
@@ -3,7 +3,6 @@ import React from 'react';
|
||||
import { Button, Classes, Dialog, Intent } from '@blueprintjs/core';
|
||||
import { FormattedMessage as T, AppToaster } from '@/components';
|
||||
import intl from 'react-intl-universal';
|
||||
import { queryCache } from 'react-query';
|
||||
|
||||
import BulkDeleteDialogContent from '@/containers/Dialogs/components/BulkDeleteDialogContent';
|
||||
import { useBulkDeletePaymentReceives } from '@/hooks/query/paymentReceives';
|
||||
@@ -47,7 +46,6 @@ function PaymentReceivedBulkDeleteDialog({
|
||||
),
|
||||
intent: Intent.SUCCESS,
|
||||
});
|
||||
queryCache.invalidateQueries('payments-received-table');
|
||||
setPaymentReceivesSelectedRows([]);
|
||||
closeDialog(dialogName);
|
||||
})
|
||||
|
||||
@@ -3,7 +3,6 @@ import React from 'react';
|
||||
import { Button, Classes, Dialog, Intent } from '@blueprintjs/core';
|
||||
import { FormattedMessage as T, AppToaster } from '@/components';
|
||||
import intl from 'react-intl-universal';
|
||||
import { queryCache } from 'react-query';
|
||||
|
||||
import BulkDeleteDialogContent from '@/containers/Dialogs/components/BulkDeleteDialogContent';
|
||||
import { useBulkDeleteReceipts } from '@/hooks/query/receipts';
|
||||
@@ -45,7 +44,6 @@ function ReceiptBulkDeleteDialog({
|
||||
message: intl.get('the_receipts_has_been_deleted_successfully'),
|
||||
intent: Intent.SUCCESS,
|
||||
});
|
||||
queryCache.invalidateQueries('sale-receipts-table');
|
||||
setReceiptsSelectedRows([]);
|
||||
closeDialog(dialogName);
|
||||
})
|
||||
|
||||
@@ -3,7 +3,6 @@ import React from 'react';
|
||||
import { Button, Classes, Dialog, Intent } from '@blueprintjs/core';
|
||||
import { FormattedMessage as T, AppToaster } from '@/components';
|
||||
import intl from 'react-intl-universal';
|
||||
import { queryCache } from 'react-query';
|
||||
|
||||
import BulkDeleteDialogContent from '@/containers/Dialogs/components/BulkDeleteDialogContent';
|
||||
import { useBulkDeleteVendorCredits } from '@/hooks/query/vendorCredit';
|
||||
@@ -47,7 +46,6 @@ function VendorCreditBulkDeleteDialog({
|
||||
),
|
||||
intent: Intent.SUCCESS,
|
||||
});
|
||||
queryCache.invalidateQueries('vendor-credits-table');
|
||||
setVendorsCreditNoteSelectedRows([]);
|
||||
closeDialog(dialogName);
|
||||
})
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
// @ts-nocheck
|
||||
import React from 'react';
|
||||
import { Button, Classes, Dialog, Intent } from '@blueprintjs/core';
|
||||
import { FormattedMessage as T, AppToaster } from '@/components';
|
||||
import intl from 'react-intl-universal';
|
||||
|
||||
import BulkDeleteDialogContent from '@/containers/Dialogs/components/BulkDeleteDialogContent';
|
||||
import { useBulkDeleteVendors } from '@/hooks/query/vendors';
|
||||
import withDialogRedux from '@/components/DialogReduxConnect';
|
||||
import withDialogActions from '@/containers/Dialog/withDialogActions';
|
||||
import withVendorsActions from '@/containers/Vendors/VendorsLanding/withVendorsActions';
|
||||
import { compose } from '@/utils';
|
||||
|
||||
function VendorBulkDeleteDialog({
|
||||
dialogName,
|
||||
isOpen,
|
||||
payload: {
|
||||
ids = [],
|
||||
deletableCount = 0,
|
||||
undeletableCount = 0,
|
||||
totalSelected = ids.length,
|
||||
} = {},
|
||||
|
||||
// #withVendorsActions
|
||||
setVendorsSelectedRows,
|
||||
|
||||
// #withDialogActions
|
||||
closeDialog,
|
||||
}) {
|
||||
const { mutateAsync: bulkDeleteVendors, isLoading } = useBulkDeleteVendors();
|
||||
|
||||
const handleCancel = () => {
|
||||
closeDialog(dialogName);
|
||||
};
|
||||
|
||||
const handleConfirmBulkDelete = () => {
|
||||
bulkDeleteVendors({
|
||||
ids,
|
||||
skipUndeletable: true,
|
||||
})
|
||||
.then(() => {
|
||||
AppToaster.show({
|
||||
message: intl.get('the_vendors_has_been_deleted_successfully'),
|
||||
intent: Intent.SUCCESS,
|
||||
});
|
||||
setVendorsSelectedRows([]);
|
||||
closeDialog(dialogName);
|
||||
})
|
||||
.catch(() => {
|
||||
AppToaster.show({
|
||||
message: intl.get('something_went_wrong'),
|
||||
intent: Intent.DANGER,
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<Dialog
|
||||
title={
|
||||
<T
|
||||
id={'bulk_delete_dialog_title'}
|
||||
values={{ resourcePlural: intl.get('resource_vendor_plural') }}
|
||||
/>
|
||||
}
|
||||
isOpen={isOpen}
|
||||
onClose={handleCancel}
|
||||
canEscapeKeyClose={!isLoading}
|
||||
canOutsideClickClose={!isLoading}
|
||||
>
|
||||
<BulkDeleteDialogContent
|
||||
totalSelected={totalSelected}
|
||||
deletableCount={deletableCount}
|
||||
undeletableCount={undeletableCount}
|
||||
resourceSingularLabel={intl.get('resource_vendor_singular')}
|
||||
resourcePluralLabel={intl.get('resource_vendor_plural')}
|
||||
/>
|
||||
|
||||
<div className={Classes.DIALOG_FOOTER}>
|
||||
<div className={Classes.DIALOG_FOOTER_ACTIONS}>
|
||||
<Button onClick={handleCancel} disabled={isLoading}>
|
||||
<T id={'cancel'} />
|
||||
</Button>
|
||||
|
||||
<Button
|
||||
intent={Intent.DANGER}
|
||||
onClick={handleConfirmBulkDelete}
|
||||
loading={isLoading}
|
||||
disabled={deletableCount === 0 || isLoading}
|
||||
>
|
||||
<T id={'delete_count'} values={{ count: deletableCount }} />
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
|
||||
export default compose(
|
||||
withDialogRedux(),
|
||||
withDialogActions,
|
||||
withVendorsActions,
|
||||
)(VendorBulkDeleteDialog);
|
||||
|
||||
@@ -31,7 +31,6 @@ import { useDownloadExportPdf } from '@/hooks/query/FinancialReports/use-export-
|
||||
|
||||
import withItems from './withItems';
|
||||
import withItemsActions from './withItemsActions';
|
||||
import withAlertActions from '@/containers/Alert/withAlertActions';
|
||||
import withSettings from '@/containers/Settings/withSettings';
|
||||
import withSettingsActions from '@/containers/Settings/withSettingsActions';
|
||||
import withDialogActions from '../Dialog/withDialogActions';
|
||||
@@ -39,6 +38,7 @@ import withDialogActions from '../Dialog/withDialogActions';
|
||||
import { DialogsName } from '@/constants/dialogs';
|
||||
import { compose } from '@/utils';
|
||||
import { isEmpty } from 'lodash';
|
||||
import { useBulkDeleteItemsDialog } from './hooks/use-bulk-delete-items-dialog';
|
||||
|
||||
/**
|
||||
* Items actions bar.
|
||||
@@ -52,9 +52,6 @@ function ItemsActionsBar({
|
||||
setItemsTableState,
|
||||
itemsInactiveMode,
|
||||
|
||||
// #withAlertActions
|
||||
openAlert,
|
||||
|
||||
// #withSettings
|
||||
itemsTableSize,
|
||||
|
||||
@@ -64,6 +61,9 @@ function ItemsActionsBar({
|
||||
// #withDialogActions
|
||||
openDialog,
|
||||
}) {
|
||||
const { openBulkDeleteDialog, isValidatingBulkDeleteItems } =
|
||||
useBulkDeleteItemsDialog();
|
||||
|
||||
// Items list context.
|
||||
const { itemsViews, fields } = useItemsListContext();
|
||||
|
||||
@@ -88,7 +88,7 @@ function ItemsActionsBar({
|
||||
|
||||
// Handle cancel/confirm items bulk.
|
||||
const handleBulkDelete = () => {
|
||||
openAlert('items-bulk-delete', { itemsIds: itemsSelectedRows });
|
||||
openBulkDeleteDialog(itemsSelectedRows);
|
||||
};
|
||||
|
||||
// Handle inactive switch changing.
|
||||
@@ -129,6 +129,7 @@ function ItemsActionsBar({
|
||||
text={<T id={'delete'} />}
|
||||
intent={Intent.DANGER}
|
||||
onClick={handleBulkDelete}
|
||||
disabled={isValidatingBulkDeleteItems}
|
||||
/>
|
||||
</NavbarGroup>
|
||||
</DashboardActionsBar>
|
||||
@@ -224,6 +225,5 @@ export default compose(
|
||||
itemsTableSize: itemsSettings.tableSize,
|
||||
})),
|
||||
withItemsActions,
|
||||
withAlertActions,
|
||||
withDialogActions,
|
||||
)(ItemsActionsBar);
|
||||
|
||||
@@ -13,10 +13,6 @@ const ItemActivateAlert = React.lazy(
|
||||
() => import('@/containers/Alerts/Items/ItemActivateAlert'),
|
||||
);
|
||||
|
||||
const ItemBulkDeleteAlert = React.lazy(
|
||||
() => import('@/containers/Alerts/Items/ItemBulkDeleteAlert'),
|
||||
);
|
||||
|
||||
const cancelUnlockingPartialAlert = React.lazy(
|
||||
() =>
|
||||
import(
|
||||
@@ -40,8 +36,4 @@ export default [
|
||||
name: 'item-activate',
|
||||
component: ItemActivateAlert,
|
||||
},
|
||||
{
|
||||
name: 'items-bulk-delete',
|
||||
component: ItemBulkDeleteAlert,
|
||||
},
|
||||
];
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
// @ts-nocheck
|
||||
import { DialogsName } from '@/constants/dialogs';
|
||||
import { useValidateBulkDeleteItems } from '@/hooks/query/items';
|
||||
import { useBulkDeleteDialog } from '@/hooks/dialogs/useBulkDeleteDialog';
|
||||
|
||||
export const useBulkDeleteItemsDialog = () => {
|
||||
const validateBulkDeleteMutation = useValidateBulkDeleteItems();
|
||||
|
||||
return useBulkDeleteDialog(
|
||||
DialogsName.ItemBulkDelete,
|
||||
validateBulkDeleteMutation,
|
||||
);
|
||||
};
|
||||
|
||||
@@ -11,7 +11,6 @@ import {
|
||||
} from '@blueprintjs/core';
|
||||
|
||||
import {
|
||||
If,
|
||||
Can,
|
||||
Icon,
|
||||
FormattedMessage as T,
|
||||
@@ -28,6 +27,8 @@ import { useRefreshVendors } from '@/hooks/query/vendors';
|
||||
import { useVendorsListContext } from './VendorsListProvider';
|
||||
import { useHistory } from 'react-router-dom';
|
||||
import { useDownloadExportPdf } from '@/hooks/query/FinancialReports/use-export-pdf';
|
||||
import { useBulkDeleteVendorsDialog } from './hooks/use-bulk-delete-vendors-dialog';
|
||||
import { isEmpty } from 'lodash';
|
||||
|
||||
import withVendors from './withVendors';
|
||||
import withVendorsActions from './withVendorsActions';
|
||||
@@ -43,6 +44,7 @@ import { DialogsName } from '@/constants/dialogs';
|
||||
*/
|
||||
function VendorActionsBar({
|
||||
// #withVendors
|
||||
vendorsSelectedRows = [],
|
||||
vendorsFilterConditions,
|
||||
|
||||
// #withVendorActions
|
||||
@@ -59,6 +61,9 @@ function VendorActionsBar({
|
||||
openDialog,
|
||||
}) {
|
||||
const history = useHistory();
|
||||
const { openBulkDeleteDialog, isValidatingBulkDeleteVendors } =
|
||||
useBulkDeleteVendorsDialog();
|
||||
|
||||
|
||||
// Vendors list context.
|
||||
const { vendorsViews, fields } = useVendorsListContext();
|
||||
@@ -102,6 +107,27 @@ function VendorActionsBar({
|
||||
downloadExportPdf({ resource: 'Vendor' });
|
||||
};
|
||||
|
||||
const handleBulkDelete = () => {
|
||||
openBulkDeleteDialog(vendorsSelectedRows);
|
||||
};
|
||||
|
||||
if (!isEmpty(vendorsSelectedRows)) {
|
||||
return (
|
||||
<DashboardActionsBar>
|
||||
<NavbarGroup>
|
||||
<Button
|
||||
className={Classes.MINIMAL}
|
||||
icon={<Icon icon="trash-16" iconSize={16} />}
|
||||
text={<T id={'delete'} />}
|
||||
intent={Intent.DANGER}
|
||||
onClick={handleBulkDelete}
|
||||
disabled={isValidatingBulkDeleteVendors}
|
||||
/>
|
||||
</NavbarGroup>
|
||||
</DashboardActionsBar>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<DashboardActionsBar>
|
||||
<NavbarGroup>
|
||||
@@ -111,7 +137,7 @@ function VendorActionsBar({
|
||||
onChange={handleTabChange}
|
||||
/>
|
||||
<NavbarDivider />
|
||||
<Can I={VendorActionsBar.Create} a={AbilitySubject.Vendor}>
|
||||
<Can I={VendorAction.Create} a={AbilitySubject.Vendor}>
|
||||
<Button
|
||||
className={Classes.MINIMAL}
|
||||
icon={<Icon icon={'plus'} />}
|
||||
@@ -135,15 +161,6 @@ function VendorActionsBar({
|
||||
/>
|
||||
</AdvancedFilterPopover>
|
||||
|
||||
<If condition={false}>
|
||||
<Button
|
||||
className={Classes.MINIMAL}
|
||||
icon={<Icon icon="trash-16" iconSize={16} />}
|
||||
text={<T id={'delete'} />}
|
||||
intent={Intent.DANGER}
|
||||
/>
|
||||
</If>
|
||||
<NavbarDivider />
|
||||
<Button
|
||||
className={Classes.MINIMAL}
|
||||
icon={<Icon icon="print-16" iconSize={16} />}
|
||||
@@ -191,7 +208,8 @@ function VendorActionsBar({
|
||||
export default compose(
|
||||
withVendorsActions,
|
||||
withSettingsActions,
|
||||
withVendors(({ vendorsTableState }) => ({
|
||||
withVendors(({ vendorsTableState, vendorsSelectedRows }) => ({
|
||||
vendorsSelectedRows,
|
||||
vendorsInactiveMode: vendorsTableState.inactiveMode,
|
||||
vendorsFilterConditions: vendorsTableState.filterRoles,
|
||||
})),
|
||||
|
||||
@@ -24,13 +24,15 @@ function VendorsList({
|
||||
|
||||
// #withVendorsActions
|
||||
resetVendorsTableState,
|
||||
resetVendorsSelectedRows,
|
||||
}) {
|
||||
// Resets the vendors table state once the page unmount.
|
||||
useEffect(
|
||||
() => () => {
|
||||
resetVendorsTableState();
|
||||
resetVendorsSelectedRows();
|
||||
},
|
||||
[resetVendorsTableState],
|
||||
[resetVendorsSelectedRows, resetVendorsTableState],
|
||||
);
|
||||
|
||||
return (
|
||||
|
||||
@@ -31,6 +31,7 @@ import { DRAWERS } from '@/constants/drawers';
|
||||
function VendorsTable({
|
||||
// #withVendorsActions
|
||||
setVendorsTableState,
|
||||
setVendorsSelectedRows,
|
||||
|
||||
// #withVendors
|
||||
vendorsTableState,
|
||||
@@ -118,6 +119,14 @@ function VendorsTable({
|
||||
[setVendorsTableState],
|
||||
);
|
||||
|
||||
const handleSelectedRowsChange = React.useCallback(
|
||||
(selectedFlatRows) => {
|
||||
const selectedIds = selectedFlatRows?.map((row) => row.original.id) || [];
|
||||
setVendorsSelectedRows(selectedIds);
|
||||
},
|
||||
[setVendorsSelectedRows],
|
||||
);
|
||||
|
||||
// Display empty status instead of the table.
|
||||
if (isEmptyStatus) {
|
||||
return <VendorsEmptyStatus />;
|
||||
@@ -142,6 +151,8 @@ function VendorsTable({
|
||||
pagesCount={pagination.pagesCount}
|
||||
autoResetSortBy={false}
|
||||
autoResetPage={false}
|
||||
onSelectedRowsChange={handleSelectedRowsChange}
|
||||
autoResetSelectedRows={false}
|
||||
TableLoadingRenderer={TableSkeletonRows}
|
||||
TableHeaderSkeletonRenderer={TableSkeletonHeader}
|
||||
ContextMenu={ActionsMenu}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
// @ts-nocheck
|
||||
import { DialogsName } from '@/constants/dialogs';
|
||||
import { useValidateBulkDeleteVendors } from '@/hooks/query/vendors';
|
||||
import { useBulkDeleteDialog } from '@/hooks/dialogs/useBulkDeleteDialog';
|
||||
|
||||
export const useBulkDeleteVendorsDialog = () => {
|
||||
const validateBulkDeleteMutation = useValidateBulkDeleteVendors();
|
||||
|
||||
return useBulkDeleteDialog(
|
||||
DialogsName.VendorBulkDelete,
|
||||
validateBulkDeleteMutation,
|
||||
);
|
||||
};
|
||||
|
||||
@@ -11,6 +11,7 @@ export default (mapState) => {
|
||||
|
||||
const mapStateToProps = (state, props) => {
|
||||
const mapped = {
|
||||
vendorsSelectedRows: state.vendors.selectedRows,
|
||||
vendorsTableState: getVendorsTableState(state, props),
|
||||
vendorsTableStateChanged: vendorsTableStateChanged(state, props),
|
||||
};
|
||||
|
||||
@@ -3,11 +3,16 @@ import { connect } from 'react-redux';
|
||||
import {
|
||||
setVendorsTableState,
|
||||
resetVendorsTableState,
|
||||
setVendorsSelectedRows,
|
||||
resetVendorsSelectedRows,
|
||||
} from '@/store/vendors/vendors.actions';
|
||||
|
||||
const mapDispatchToProps = (dispatch) => ({
|
||||
setVendorsTableState: (queries) => dispatch(setVendorsTableState(queries)),
|
||||
resetVendorsTableState: () => dispatch(resetVendorsTableState()),
|
||||
setVendorsSelectedRows: (selectedRows) =>
|
||||
dispatch(setVendorsSelectedRows(selectedRows)),
|
||||
resetVendorsSelectedRows: () => dispatch(resetVendorsSelectedRows()),
|
||||
});
|
||||
|
||||
export default connect(null, mapDispatchToProps);
|
||||
|
||||
@@ -16,6 +16,7 @@ export const useBulkDeleteDialog = (
|
||||
if (!ids?.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
const { deletableCount = 0, nonDeletableCount = 0 } =
|
||||
await validateBulkDelete(ids);
|
||||
|
||||
|
||||
@@ -167,7 +167,7 @@ export function useBulkDeleteAccounts(props) {
|
||||
}) =>
|
||||
apiRequest.post('accounts/bulk-delete', {
|
||||
ids,
|
||||
skipUndeletable,
|
||||
skip_undeletable: skipUndeletable,
|
||||
}),
|
||||
{
|
||||
onSuccess: () => {
|
||||
|
||||
@@ -128,7 +128,7 @@ export function useBulkDeleteCreditNotes(props) {
|
||||
}) =>
|
||||
apiRequest.post('credit-notes/bulk-delete', {
|
||||
ids,
|
||||
skipUndeletable,
|
||||
skip_undeletable: skipUndeletable,
|
||||
}),
|
||||
{
|
||||
onSuccess: () => {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// @ts-nocheck
|
||||
import { useMutation, useQueryClient } from 'react-query';
|
||||
import { useRequestQuery } from '../useQueryRequest';
|
||||
import { transformPagination } from '@/utils';
|
||||
import { transformPagination, transformToCamelCase } from '@/utils';
|
||||
import useApiRequest from '../useRequest';
|
||||
import t from './types';
|
||||
|
||||
@@ -100,6 +100,49 @@ export function useDeleteCustomer(props) {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes multiple customers in bulk.
|
||||
*/
|
||||
export function useBulkDeleteCustomers(props) {
|
||||
const queryClient = useQueryClient();
|
||||
const apiRequest = useApiRequest();
|
||||
|
||||
return useMutation(
|
||||
({
|
||||
ids,
|
||||
skipUndeletable = false,
|
||||
}: {
|
||||
ids: number[];
|
||||
skipUndeletable?: boolean;
|
||||
}) =>
|
||||
apiRequest.post('customers/bulk-delete', {
|
||||
ids,
|
||||
skip_undeletable: skipUndeletable,
|
||||
}).then((res) => transformToCamelCase(res.data)),
|
||||
{
|
||||
onSuccess: () => {
|
||||
commonInvalidateQueries(queryClient);
|
||||
},
|
||||
...props,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates which customers can be deleted in bulk.
|
||||
*/
|
||||
export function useValidateBulkDeleteCustomers(props) {
|
||||
const apiRequest = useApiRequest();
|
||||
|
||||
return useMutation(
|
||||
(ids: number[]) =>
|
||||
apiRequest.post('customers/validate-bulk-delete', { ids }).then((res) => transformToCamelCase(res.data)),
|
||||
{
|
||||
...props,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new customer.
|
||||
*/
|
||||
|
||||
@@ -141,7 +141,7 @@ export function useBulkDeleteEstimates(props) {
|
||||
}) =>
|
||||
apiRequest.post('sale-estimates/bulk-delete', {
|
||||
ids,
|
||||
skipUndeletable,
|
||||
skip_undeletable: skipUndeletable,
|
||||
}),
|
||||
{
|
||||
onSuccess: () => {
|
||||
|
||||
@@ -119,7 +119,7 @@ export function useBulkDeleteExpenses(props) {
|
||||
}) =>
|
||||
apiRequest.post('expenses/bulk-delete', {
|
||||
ids,
|
||||
skipUndeletable,
|
||||
skip_undeletable: skipUndeletable,
|
||||
}),
|
||||
{
|
||||
onSuccess: () => {
|
||||
|
||||
@@ -142,7 +142,7 @@ export function useBulkDeleteInvoices(props) {
|
||||
}) =>
|
||||
apiRequest.post('sale-invoices/bulk-delete', {
|
||||
ids,
|
||||
skipUndeletable,
|
||||
skip_undeletable: skipUndeletable,
|
||||
}),
|
||||
{
|
||||
onSuccess: () => {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// @ts-nocheck
|
||||
import { useMutation, useQueryClient } from 'react-query';
|
||||
import { transformPagination, transformResponse } from '@/utils';
|
||||
import { transformPagination, transformResponse, transformToCamelCase } from '@/utils';
|
||||
import { useRequestQuery } from '../useQueryRequest';
|
||||
import useApiRequest from '../useRequest';
|
||||
import t from './types';
|
||||
@@ -81,7 +81,17 @@ export function useBulkDeleteItems(props) {
|
||||
const apiRequest = useApiRequest();
|
||||
|
||||
return useMutation(
|
||||
(ids: number[]) => apiRequest.post('items/bulk-delete', { ids }),
|
||||
({
|
||||
ids,
|
||||
skipUndeletable = false,
|
||||
}: {
|
||||
ids: number[];
|
||||
skipUndeletable?: boolean;
|
||||
}) =>
|
||||
apiRequest.post('items/bulk-delete', {
|
||||
ids,
|
||||
skip_undeletable: skipUndeletable,
|
||||
}),
|
||||
{
|
||||
onSuccess: () => {
|
||||
// Common invalidate queries.
|
||||
@@ -92,6 +102,21 @@ export function useBulkDeleteItems(props) {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates which items can be deleted in bulk.
|
||||
*/
|
||||
export function useValidateBulkDeleteItems(props) {
|
||||
const apiRequest = useApiRequest();
|
||||
|
||||
return useMutation(
|
||||
(ids: number[]) =>
|
||||
apiRequest.post('items/validate-bulk-delete', { ids }).then((res) => transformToCamelCase(res.data)),
|
||||
{
|
||||
...props,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Activate the given item.
|
||||
*/
|
||||
|
||||
@@ -105,7 +105,7 @@ export function useBulkDeleteManualJournals(props) {
|
||||
}) =>
|
||||
apiRequest.post('manual-journals/bulk-delete', {
|
||||
ids,
|
||||
skipUndeletable,
|
||||
skip_undeletable: skipUndeletable,
|
||||
}),
|
||||
{
|
||||
onSuccess: () => {
|
||||
|
||||
@@ -167,7 +167,7 @@ export function useBulkDeletePaymentReceives(props) {
|
||||
}) =>
|
||||
apiRequest.post('payments-received/bulk-delete', {
|
||||
ids,
|
||||
skipUndeletable,
|
||||
skip_undeletable: skipUndeletable,
|
||||
}),
|
||||
{
|
||||
onSuccess: () => {
|
||||
|
||||
@@ -121,7 +121,7 @@ export function useBulkDeleteReceipts(props) {
|
||||
}) =>
|
||||
apiRequest.post('sale-receipts/bulk-delete', {
|
||||
ids,
|
||||
skipUndeletable,
|
||||
skip_undeletable: skipUndeletable,
|
||||
}),
|
||||
{
|
||||
onSuccess: () => {
|
||||
|
||||
@@ -130,7 +130,7 @@ export function useBulkDeleteVendorCredits(props) {
|
||||
}) =>
|
||||
apiRequest.post('vendor-credits/bulk-delete', {
|
||||
ids,
|
||||
skipUndeletable,
|
||||
skip_undeletable: skipUndeletable,
|
||||
}),
|
||||
{
|
||||
onSuccess: () => {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// @ts-nocheck
|
||||
import { useMutation, useQueryClient } from 'react-query';
|
||||
import t from './types';
|
||||
import { transformPagination } from '@/utils';
|
||||
import { transformPagination, transformToCamelCase } from '@/utils';
|
||||
import useApiRequest from '../useRequest';
|
||||
import { useRequestQuery } from '../useQueryRequest';
|
||||
|
||||
@@ -88,6 +88,49 @@ export function useDeleteVendor(props) {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes multiple vendors in bulk.
|
||||
*/
|
||||
export function useBulkDeleteVendors(props) {
|
||||
const queryClient = useQueryClient();
|
||||
const apiRequest = useApiRequest();
|
||||
|
||||
return useMutation(
|
||||
({
|
||||
ids,
|
||||
skipUndeletable = false,
|
||||
}: {
|
||||
ids: number[];
|
||||
skipUndeletable?: boolean;
|
||||
}) =>
|
||||
apiRequest.post('vendors/bulk-delete', {
|
||||
ids,
|
||||
skip_undeletable: skipUndeletable,
|
||||
}),
|
||||
{
|
||||
onSuccess: () => {
|
||||
commonInvalidateQueries(queryClient);
|
||||
},
|
||||
...props,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates which vendors can be deleted in bulk.
|
||||
*/
|
||||
export function useValidateBulkDeleteVendors(props) {
|
||||
const apiRequest = useApiRequest();
|
||||
|
||||
return useMutation(
|
||||
(ids: number[]) =>
|
||||
apiRequest.post('vendors/validate-bulk-delete', { ids }).then((res) => transformToCamelCase(res.data)),
|
||||
{
|
||||
...props,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new vendor.
|
||||
*/
|
||||
|
||||
@@ -512,6 +512,12 @@
|
||||
"resource_expense_plural": "Expenses",
|
||||
"resource_account_singular": "Account",
|
||||
"resource_account_plural": "Accounts",
|
||||
"resource_item_singular": "Item",
|
||||
"resource_item_plural": "Items",
|
||||
"resource_customer_singular": "Customer",
|
||||
"resource_customer_plural": "Customers",
|
||||
"resource_vendor_singular": "Vendor",
|
||||
"resource_vendor_plural": "Vendors",
|
||||
"you_could_not_delete_account_has_child_accounts": "لا يمكنك حذف حساب لديه حسابات فرعية.",
|
||||
"journal_entry": "القيد",
|
||||
"estimate": "رقم العرض",
|
||||
@@ -730,6 +736,7 @@
|
||||
"vendors_list": "قائمة الموردين",
|
||||
"the_vendor_has_been_created_successfully": "تم اضافة مورد جديد بنجاح.",
|
||||
"the_vendor_has_been_deleted_successfully": "تم حذف المورد بنجاح.",
|
||||
"the_vendors_has_been_deleted_successfully": "تم حذف الموردين بنجاح.",
|
||||
"the_item_vendor_has_been_edited_successfully": "تم تعديل المورد بنجاح.",
|
||||
"once_delete_this_vendor_you_will_able_to_restore_it": "بمجرد حذف هذا المورد ، لن تتمكن من استعادته لاحقًا. هل أنت متأكد أنك تريد حذف؟",
|
||||
"once_delete_these_vendors_you_will_not_able_restore_them": "بمجرد حذف هؤلاء الموردين ، لن تتمكن من استعادتهم لاحقًا. هل أنت متأكد أنك تريد حذفها؟",
|
||||
|
||||
@@ -557,6 +557,12 @@
|
||||
"resource_expense_plural": "Expenses",
|
||||
"resource_account_singular": "Account",
|
||||
"resource_account_plural": "Accounts",
|
||||
"resource_item_singular": "Item",
|
||||
"resource_item_plural": "Items",
|
||||
"resource_customer_singular": "Customer",
|
||||
"resource_customer_plural": "Customers",
|
||||
"resource_vendor_singular": "Vendor",
|
||||
"resource_vendor_plural": "Vendors",
|
||||
"receipts_list": "Receipts List",
|
||||
"receipts": "Receipts",
|
||||
"receipt": "Receipt #",
|
||||
@@ -720,6 +726,7 @@
|
||||
"vendors_list": "Vendors List",
|
||||
"the_vendor_has_been_created_successfully": "The vendor has been successfully created.",
|
||||
"the_vendor_has_been_deleted_successfully": "The vendor has been deleted successfully.",
|
||||
"the_vendors_has_been_deleted_successfully": "The vendors have been deleted successfully.",
|
||||
"the_item_vendor_has_been_edited_successfully": "The item vendor has been edited successfully.",
|
||||
"once_delete_this_vendor_you_will_able_to_restore_it": "Once you delete this vendor, you won't be able to restore it later. Are you sure you want to delete this vendor?",
|
||||
"once_delete_these_vendors_you_will_not_able_restore_them": "Once you delete these vendors, you won't be able to retrieve them later. Are you sure you want to delete them?",
|
||||
|
||||
@@ -512,6 +512,12 @@
|
||||
"resource_expense_plural": "Expenses",
|
||||
"resource_account_singular": "Account",
|
||||
"resource_account_plural": "Accounts",
|
||||
"resource_item_singular": "Item",
|
||||
"resource_item_plural": "Items",
|
||||
"resource_customer_singular": "Customer",
|
||||
"resource_customer_plural": "Customers",
|
||||
"resource_vendor_singular": "Vendor",
|
||||
"resource_vendor_plural": "Vendors",
|
||||
"you_could_not_delete_account_has_child_accounts": "No pudiste eliminar la cuenta que tiene cuentas secundarias.",
|
||||
"journal_entry": "Asiento de diario",
|
||||
"estimate": "Estimación #",
|
||||
@@ -725,6 +731,7 @@
|
||||
"vendors_list": "Lista de proveedores",
|
||||
"the_vendor_has_been_created_successfully": "El proveedor ha sido creado exitosamente.",
|
||||
"the_vendor_has_been_deleted_successfully": "El proveedor ha sido eliminado exitosamente.",
|
||||
"the_vendors_has_been_deleted_successfully": "Los proveedores han sido eliminados exitosamente.",
|
||||
"the_item_vendor_has_been_edited_successfully": "El proveedor del artículo ha sido editado exitosamente.",
|
||||
"once_delete_this_vendor_you_will_able_to_restore_it": "Una vez que elimines este proveedor, no podrás restaurarlo más tarde. ¿Estás seguro de que quieres eliminar este proveedor?",
|
||||
"once_delete_these_vendors_you_will_not_able_restore_them": "Una vez que elimines estos proveedores, no podrás recuperarlos más tarde. ¿Estás seguro de que quieres eliminarlos?",
|
||||
|
||||
@@ -502,6 +502,12 @@
|
||||
"resource_expense_plural": "Expenses",
|
||||
"resource_account_singular": "Account",
|
||||
"resource_account_plural": "Accounts",
|
||||
"resource_item_singular": "Item",
|
||||
"resource_item_plural": "Items",
|
||||
"resource_customer_singular": "Customer",
|
||||
"resource_customer_plural": "Customers",
|
||||
"resource_vendor_singular": "Vendor",
|
||||
"resource_vendor_plural": "Vendors",
|
||||
"journal_entry": "Journalanteckning",
|
||||
"estimate": "Uppskattning #",
|
||||
"estimate_date": "Uppskattning Datum",
|
||||
@@ -711,6 +717,7 @@
|
||||
"vendors_list": "Lista över leverantörer",
|
||||
"the_vendor_has_been_created_successfully": "Leverantören har skapats på ett framgångsrikt sätt.",
|
||||
"the_vendor_has_been_deleted_successfully": "Leverantören har tagits bort framgångsrikt.",
|
||||
"the_vendors_has_been_deleted_successfully": "Leverantörerna har raderats framgångsrikt.",
|
||||
"the_item_vendor_has_been_edited_successfully": "Artikelns leverantör har redigerats framgångsrikt.",
|
||||
"once_delete_this_vendor_you_will_able_to_restore_it": "När du har tagit bort den här leverantören kan du inte återställa den senare. Är du säker på att du vill ta bort den här leverantören?",
|
||||
"once_delete_these_vendors_you_will_not_able_restore_them": "När du har tagit bort dessa leverantörer kommer du inte att kunna hämta dem senare. Är du säker på att du vill ta bort dem?",
|
||||
|
||||
@@ -15,4 +15,17 @@ export const resetCustomersTableState = () => {
|
||||
return {
|
||||
type: t.CUSTOMERS_TABLE_STATE_RESET,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
export const setCustomersSelectedRows = (selectedRows) => {
|
||||
return {
|
||||
type: 'CUSTOMERS/SET_SELECTED_ROWS',
|
||||
payload: selectedRows,
|
||||
};
|
||||
};
|
||||
|
||||
export const resetCustomersSelectedRows = () => {
|
||||
return {
|
||||
type: 'CUSTOMERS/RESET_SELECTED_ROWS',
|
||||
};
|
||||
};
|
||||
@@ -3,6 +3,7 @@ import { createReducer } from '@reduxjs/toolkit';
|
||||
import { persistReducer } from 'redux-persist';
|
||||
import storage from 'redux-persist/lib/storage';
|
||||
import { createTableStateReducers } from '@/store/tableState.reducer';
|
||||
import t from '@/store/types';
|
||||
|
||||
// Default table query state.
|
||||
export const defaultTableQueryState = {
|
||||
@@ -16,10 +17,21 @@ export const defaultTableQueryState = {
|
||||
// initial data.
|
||||
const initialState = {
|
||||
tableState: defaultTableQueryState,
|
||||
selectedRows: [],
|
||||
};
|
||||
|
||||
const reducerInstance = createReducer(initialState, {
|
||||
...createTableStateReducers('CUSTOMERS', defaultTableQueryState),
|
||||
|
||||
['CUSTOMERS/SET_SELECTED_ROWS']: (state, action) => {
|
||||
state.selectedRows = action.payload;
|
||||
},
|
||||
|
||||
['CUSTOMERS/RESET_SELECTED_ROWS']: (state) => {
|
||||
state.selectedRows = [];
|
||||
},
|
||||
|
||||
[t.RESET]: () => initialState,
|
||||
});
|
||||
|
||||
const STORAGE_KEY = 'bigcapital:estimates';
|
||||
|
||||
@@ -12,4 +12,17 @@ export const resetVendorsTableState = () => {
|
||||
return {
|
||||
type: t.VENDORS_TABLE_STATE_RESET,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const setVendorsSelectedRows = (selectedRows) => {
|
||||
return {
|
||||
type: 'VENDORS/SET_SELECTED_ROWS',
|
||||
payload: selectedRows,
|
||||
};
|
||||
};
|
||||
|
||||
export const resetVendorsSelectedRows = () => {
|
||||
return {
|
||||
type: 'VENDORS/RESET_SELECTED_ROWS',
|
||||
};
|
||||
};
|
||||
@@ -15,6 +15,7 @@ export const defaultTableQueryState = {
|
||||
|
||||
const initialState = {
|
||||
tableState: defaultTableQueryState,
|
||||
selectedRows: [],
|
||||
};
|
||||
|
||||
const STORAGE_KEY = 'bigcapital:vendors';
|
||||
@@ -28,8 +29,17 @@ const CONFIG = {
|
||||
const reducerInstance = createReducer(initialState, {
|
||||
...createTableStateReducers('VENDORS', defaultTableQueryState),
|
||||
|
||||
['VENDORS/SET_SELECTED_ROWS']: (state, action) => {
|
||||
state.selectedRows = action.payload;
|
||||
},
|
||||
|
||||
['VENDORS/RESET_SELECTED_ROWS']: (state) => {
|
||||
state.selectedRows = [];
|
||||
},
|
||||
|
||||
[t.RESET]: () => {
|
||||
purgeStoredState(CONFIG);
|
||||
return initialState;
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user