mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-23 16:19:49 +00:00
wip
This commit is contained in:
@@ -16,7 +16,7 @@ export class BulkDeleteDto {
|
|||||||
|
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsBoolean()
|
@IsBoolean()
|
||||||
@Transform(({ value }) => parseBoolean(value, false))
|
@Transform(({ value, obj }) => parseBoolean(value ?? obj?.skip_undeletable, false))
|
||||||
@ApiPropertyOptional({
|
@ApiPropertyOptional({
|
||||||
description: 'When true, undeletable items will be skipped and only deletable ones will be removed.',
|
description: 'When true, undeletable items will be skipped and only deletable ones will be removed.',
|
||||||
type: Boolean,
|
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 { EditCustomerDto } from './dtos/EditCustomer.dto';
|
||||||
import { CustomerResponseDto } from './dtos/CustomerResponse.dto';
|
import { CustomerResponseDto } from './dtos/CustomerResponse.dto';
|
||||||
import { GetCustomersQueryDto } from './dtos/GetCustomersQuery.dto';
|
import { GetCustomersQueryDto } from './dtos/GetCustomersQuery.dto';
|
||||||
|
import {
|
||||||
|
BulkDeleteCustomersDto,
|
||||||
|
ValidateBulkDeleteCustomersResponseDto,
|
||||||
|
} from './dtos/BulkDeleteCustomers.dto';
|
||||||
import { ApiCommonHeaders } from '@/common/decorators/ApiCommonHeaders';
|
import { ApiCommonHeaders } from '@/common/decorators/ApiCommonHeaders';
|
||||||
|
|
||||||
@Controller('customers')
|
@Controller('customers')
|
||||||
@@ -31,7 +35,7 @@ import { ApiCommonHeaders } from '@/common/decorators/ApiCommonHeaders';
|
|||||||
@ApiExtraModels(CustomerResponseDto)
|
@ApiExtraModels(CustomerResponseDto)
|
||||||
@ApiCommonHeaders()
|
@ApiCommonHeaders()
|
||||||
export class CustomersController {
|
export class CustomersController {
|
||||||
constructor(private customersApplication: CustomersApplication) {}
|
constructor(private customersApplication: CustomersApplication) { }
|
||||||
|
|
||||||
@Get(':id')
|
@Get(':id')
|
||||||
@ApiOperation({ summary: 'Retrieves the customer details.' })
|
@ApiOperation({ summary: 'Retrieves the customer details.' })
|
||||||
@@ -109,4 +113,37 @@ export class CustomersController {
|
|||||||
openingBalanceDTO,
|
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 { CustomersImportable } from './CustomersImportable';
|
||||||
import { GetCustomers } from './queries/GetCustomers.service';
|
import { GetCustomers } from './queries/GetCustomers.service';
|
||||||
import { DynamicListModule } from '../DynamicListing/DynamicList.module';
|
import { DynamicListModule } from '../DynamicListing/DynamicList.module';
|
||||||
|
import { BulkDeleteCustomersService } from './BulkDeleteCustomers.service';
|
||||||
|
import { ValidateBulkDeleteCustomersService } from './ValidateBulkDeleteCustomers.service';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [TenancyDatabaseModule, DynamicListModule],
|
imports: [TenancyDatabaseModule, DynamicListModule],
|
||||||
@@ -37,6 +39,8 @@ import { DynamicListModule } from '../DynamicListing/DynamicList.module';
|
|||||||
CustomersExportable,
|
CustomersExportable,
|
||||||
CustomersImportable,
|
CustomersImportable,
|
||||||
GetCustomers,
|
GetCustomers,
|
||||||
|
BulkDeleteCustomersService,
|
||||||
|
ValidateBulkDeleteCustomersService,
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
export class CustomersModule {}
|
export class CustomersModule {}
|
||||||
|
|||||||
@@ -12,6 +12,8 @@ import { CreateCustomerDto } from './dtos/CreateCustomer.dto';
|
|||||||
import { EditCustomerDto } from './dtos/EditCustomer.dto';
|
import { EditCustomerDto } from './dtos/EditCustomer.dto';
|
||||||
import { GetCustomers } from './queries/GetCustomers.service';
|
import { GetCustomers } from './queries/GetCustomers.service';
|
||||||
import { GetCustomersQueryDto } from './dtos/GetCustomersQuery.dto';
|
import { GetCustomersQueryDto } from './dtos/GetCustomersQuery.dto';
|
||||||
|
import { BulkDeleteCustomersService } from './BulkDeleteCustomers.service';
|
||||||
|
import { ValidateBulkDeleteCustomersService } from './ValidateBulkDeleteCustomers.service';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class CustomersApplication {
|
export class CustomersApplication {
|
||||||
@@ -22,6 +24,8 @@ export class CustomersApplication {
|
|||||||
private deleteCustomerService: DeleteCustomer,
|
private deleteCustomerService: DeleteCustomer,
|
||||||
private editOpeningBalanceService: EditOpeningBalanceCustomer,
|
private editOpeningBalanceService: EditOpeningBalanceCustomer,
|
||||||
private getCustomersService: GetCustomers,
|
private getCustomersService: GetCustomers,
|
||||||
|
private readonly bulkDeleteCustomersService: BulkDeleteCustomersService,
|
||||||
|
private readonly validateBulkDeleteCustomersService: ValidateBulkDeleteCustomersService,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -83,4 +87,20 @@ export class CustomersApplication {
|
|||||||
public getCustomers = (filterDTO: GetCustomersQueryDto) => {
|
public getCustomers = (filterDTO: GetCustomersQueryDto) => {
|
||||||
return this.getCustomersService.getCustomersList(filterDTO);
|
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.
|
* @param {number} customerId - Customer ID.
|
||||||
* @return {Promise<void>}
|
* @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.
|
// Retrieve the customer or throw not found service error.
|
||||||
const oldCustomer = await this.customerModel()
|
const query = this.customerModel().query(trx);
|
||||||
.query()
|
const oldCustomer = await query.findById(customerId).throwIfNotFound();
|
||||||
.findById(customerId)
|
|
||||||
.throwIfNotFound();
|
|
||||||
|
|
||||||
// Triggers `onCustomerDeleting` event.
|
// Triggers `onCustomerDeleting` event.
|
||||||
await this.eventPublisher.emitAsync(events.customers.onDeleting, {
|
await this.eventPublisher.emitAsync(events.customers.onDeleting, {
|
||||||
@@ -45,10 +46,10 @@ export class DeleteCustomer {
|
|||||||
} as ICustomerDeletingPayload);
|
} as ICustomerDeletingPayload);
|
||||||
|
|
||||||
// Deletes the customer and associated entities under UOW transaction.
|
// 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.
|
// Delete the customer from the storage.
|
||||||
await this.customerModel()
|
await this.customerModel()
|
||||||
.query(trx)
|
.query(transaction)
|
||||||
.findById(customerId)
|
.findById(customerId)
|
||||||
.deleteIfNoRelations({
|
.deleteIfNoRelations({
|
||||||
type: ERRORS.CUSTOMER_HAS_TRANSACTIONS,
|
type: ERRORS.CUSTOMER_HAS_TRANSACTIONS,
|
||||||
@@ -58,8 +59,8 @@ export class DeleteCustomer {
|
|||||||
await this.eventPublisher.emitAsync(events.customers.onDeleted, {
|
await this.eventPublisher.emitAsync(events.customers.onDeleted, {
|
||||||
customerId,
|
customerId,
|
||||||
oldCustomer,
|
oldCustomer,
|
||||||
trx,
|
trx: transaction,
|
||||||
} as ICustomerEventDeletedPayload);
|
} 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()
|
@Injectable()
|
||||||
export class BulkDeleteItemsService {
|
export class BulkDeleteItemsService {
|
||||||
constructor(private readonly deleteItemService: DeleteItemService) { }
|
constructor(private readonly deleteItemService: DeleteItemService) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes multiple items.
|
* Deletes multiple items.
|
||||||
@@ -15,23 +15,26 @@ export class BulkDeleteItemsService {
|
|||||||
*/
|
*/
|
||||||
async bulkDeleteItems(
|
async bulkDeleteItems(
|
||||||
itemIds: number | Array<number>,
|
itemIds: number | Array<number>,
|
||||||
|
options?: { skipUndeletable?: boolean },
|
||||||
trx?: Knex.Transaction,
|
trx?: Knex.Transaction,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
|
const { skipUndeletable = false } = options ?? {};
|
||||||
const itemsIds = uniq(castArray(itemIds));
|
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)
|
const results = await PromisePool.withConcurrency(1)
|
||||||
.for(itemsIds)
|
.for(itemsIds)
|
||||||
.process(async (itemId: number) => {
|
.process(async (itemId: number) => {
|
||||||
|
try {
|
||||||
await this.deleteItemService.deleteItem(itemId, trx);
|
await this.deleteItemService.deleteItem(itemId, trx);
|
||||||
|
} catch (error) {
|
||||||
|
if (!skipUndeletable) {
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Check if there were any errors
|
if (!skipUndeletable && results.errors && results.errors.length > 0) {
|
||||||
if (results.errors && results.errors.length > 0) {
|
throw results.errors[0].raw ?? results.errors[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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -374,6 +374,8 @@ export class ItemsController extends TenantController {
|
|||||||
async bulkDeleteItems(
|
async bulkDeleteItems(
|
||||||
@Body() bulkDeleteDto: BulkDeleteItemsDto,
|
@Body() bulkDeleteDto: BulkDeleteItemsDto,
|
||||||
): Promise<void> {
|
): 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
|
* @param {number[]} itemIds - Array of item IDs to delete
|
||||||
* @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
async bulkDeleteItems(itemIds: number[]): Promise<void> {
|
async bulkDeleteItems(
|
||||||
return this.bulkDeleteItemsService.bulkDeleteItems(itemIds);
|
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 {
|
||||||
import { ApiProperty } from '@nestjs/swagger';
|
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 {
|
export class BulkDeleteItemsDto {
|
||||||
@IsArray()
|
@IsArray()
|
||||||
@@ -11,6 +19,17 @@ export class BulkDeleteItemsDto {
|
|||||||
example: [1, 2, 3],
|
example: [1, 2, 3],
|
||||||
})
|
})
|
||||||
ids: number[];
|
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 {
|
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,
|
IVendorOpeningBalanceEditDTO,
|
||||||
IVendorsFilter,
|
IVendorsFilter,
|
||||||
} from './types/Vendors.types';
|
} 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 { CreateVendorDto } from './dtos/CreateVendor.dto';
|
||||||
import { EditVendorDto } from './dtos/EditVendor.dto';
|
import { EditVendorDto } from './dtos/EditVendor.dto';
|
||||||
import { GetVendorsQueryDto } from './dtos/GetVendorsQuery.dto';
|
import { GetVendorsQueryDto } from './dtos/GetVendorsQuery.dto';
|
||||||
import { ApiCommonHeaders } from '@/common/decorators/ApiCommonHeaders';
|
import { ApiCommonHeaders } from '@/common/decorators/ApiCommonHeaders';
|
||||||
|
import {
|
||||||
|
BulkDeleteVendorsDto,
|
||||||
|
ValidateBulkDeleteVendorsResponseDto,
|
||||||
|
} from './dtos/BulkDeleteVendors.dto';
|
||||||
|
|
||||||
@Controller('vendors')
|
@Controller('vendors')
|
||||||
@ApiTags('Vendors')
|
@ApiTags('Vendors')
|
||||||
@@ -66,4 +75,37 @@ export class VendorsController {
|
|||||||
openingBalanceDTO,
|
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 { DynamicListModule } from '../DynamicListing/DynamicList.module';
|
||||||
import { VendorsExportable } from './VendorsExportable';
|
import { VendorsExportable } from './VendorsExportable';
|
||||||
import { VendorsImportable } from './VendorsImportable';
|
import { VendorsImportable } from './VendorsImportable';
|
||||||
|
import { BulkDeleteVendorsService } from './BulkDeleteVendors.service';
|
||||||
|
import { ValidateBulkDeleteVendorsService } from './ValidateBulkDeleteVendors.service';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [TenancyDatabaseModule, DynamicListModule],
|
imports: [TenancyDatabaseModule, DynamicListModule],
|
||||||
@@ -31,6 +33,8 @@ import { VendorsImportable } from './VendorsImportable';
|
|||||||
VendorValidators,
|
VendorValidators,
|
||||||
DeleteVendorService,
|
DeleteVendorService,
|
||||||
VendorsApplication,
|
VendorsApplication,
|
||||||
|
BulkDeleteVendorsService,
|
||||||
|
ValidateBulkDeleteVendorsService,
|
||||||
TransformerInjectable,
|
TransformerInjectable,
|
||||||
TenancyContext,
|
TenancyContext,
|
||||||
VendorsExportable,
|
VendorsExportable,
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ import { GetVendorsService } from './queries/GetVendors.service';
|
|||||||
import { CreateVendorDto } from './dtos/CreateVendor.dto';
|
import { CreateVendorDto } from './dtos/CreateVendor.dto';
|
||||||
import { EditVendorDto } from './dtos/EditVendor.dto';
|
import { EditVendorDto } from './dtos/EditVendor.dto';
|
||||||
import { GetVendorsQueryDto } from './dtos/GetVendorsQuery.dto';
|
import { GetVendorsQueryDto } from './dtos/GetVendorsQuery.dto';
|
||||||
|
import { BulkDeleteVendorsService } from './BulkDeleteVendors.service';
|
||||||
|
import { ValidateBulkDeleteVendorsService } from './ValidateBulkDeleteVendors.service';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class VendorsApplication {
|
export class VendorsApplication {
|
||||||
@@ -23,6 +25,8 @@ export class VendorsApplication {
|
|||||||
private editOpeningBalanceService: EditOpeningBalanceVendorService,
|
private editOpeningBalanceService: EditOpeningBalanceVendorService,
|
||||||
private getVendorService: GetVendorService,
|
private getVendorService: GetVendorService,
|
||||||
private getVendorsService: GetVendorsService,
|
private getVendorsService: GetVendorsService,
|
||||||
|
private readonly bulkDeleteVendorsService: BulkDeleteVendorsService,
|
||||||
|
private readonly validateBulkDeleteVendorsService: ValidateBulkDeleteVendorsService,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -86,4 +90,20 @@ export class VendorsApplication {
|
|||||||
public getVendors(filterDTO: GetVendorsQueryDto) {
|
public getVendors(filterDTO: GetVendorsQueryDto) {
|
||||||
return this.getVendorsService.getVendorsList(filterDTO);
|
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
|
* @param {number} vendorId
|
||||||
* @return {Promise<void>}
|
* @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.
|
// Retrieves the old vendor or throw not found service error.
|
||||||
const oldVendor = await this.vendorModel()
|
const query = this.vendorModel().query(trx);
|
||||||
.query()
|
const oldVendor = await query.findById(vendorId).throwIfNotFound();
|
||||||
.findById(vendorId)
|
|
||||||
.throwIfNotFound();
|
|
||||||
|
|
||||||
// Triggers `onVendorDeleting` event.
|
// Triggers `onVendorDeleting` event.
|
||||||
await this.eventPublisher.emitAsync(events.vendors.onDeleting, {
|
await this.eventPublisher.emitAsync(events.vendors.onDeleting, {
|
||||||
@@ -43,10 +41,10 @@ export class DeleteVendorService {
|
|||||||
} as IVendorEventDeletingPayload);
|
} as IVendorEventDeletingPayload);
|
||||||
|
|
||||||
// Deletes vendor contact under unit-of-work.
|
// 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.
|
// Deletes the vendor contact from the storage.
|
||||||
await this.vendorModel()
|
await this.vendorModel()
|
||||||
.query(trx)
|
.query(transaction)
|
||||||
.findById(vendorId)
|
.findById(vendorId)
|
||||||
.deleteIfNoRelations({
|
.deleteIfNoRelations({
|
||||||
type: ERRORS.VENDOR_HAS_TRANSACTIONS,
|
type: ERRORS.VENDOR_HAS_TRANSACTIONS,
|
||||||
@@ -56,8 +54,8 @@ export class DeleteVendorService {
|
|||||||
await this.eventPublisher.emitAsync(events.vendors.onDeleted, {
|
await this.eventPublisher.emitAsync(events.vendors.onDeleted, {
|
||||||
vendorId,
|
vendorId,
|
||||||
oldVendor,
|
oldVendor,
|
||||||
trx,
|
trx: transaction,
|
||||||
} as IVendorEventDeletedPayload);
|
} 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 ManualJournalBulkDeleteDialog from '@/containers/Dialogs/ManualJournals/ManualJournalBulkDeleteDialog';
|
||||||
import ExpenseBulkDeleteDialog from '@/containers/Dialogs/Expenses/ExpenseBulkDeleteDialog';
|
import ExpenseBulkDeleteDialog from '@/containers/Dialogs/Expenses/ExpenseBulkDeleteDialog';
|
||||||
import AccountBulkDeleteDialog from '@/containers/Dialogs/Accounts/AccountBulkDeleteDialog';
|
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.
|
* Dialogs container.
|
||||||
@@ -167,6 +170,9 @@ export default function DialogsContainer() {
|
|||||||
/>
|
/>
|
||||||
<ExpenseBulkDeleteDialog dialogName={DialogsName.ExpenseBulkDelete} />
|
<ExpenseBulkDeleteDialog dialogName={DialogsName.ExpenseBulkDelete} />
|
||||||
<AccountBulkDeleteDialog dialogName={DialogsName.AccountBulkDelete} />
|
<AccountBulkDeleteDialog dialogName={DialogsName.AccountBulkDelete} />
|
||||||
|
<ItemBulkDeleteDialog dialogName={DialogsName.ItemBulkDelete} />
|
||||||
|
<CustomerBulkDeleteDialog dialogName={DialogsName.CustomerBulkDelete} />
|
||||||
|
<VendorBulkDeleteDialog dialogName={DialogsName.VendorBulkDelete} />
|
||||||
<ExportDialog dialogName={DialogsName.Export} />
|
<ExportDialog dialogName={DialogsName.Export} />
|
||||||
<RuleFormDialog dialogName={DialogsName.BankRuleForm} />
|
<RuleFormDialog dialogName={DialogsName.BankRuleForm} />
|
||||||
<DisconnectBankAccountDialog
|
<DisconnectBankAccountDialog
|
||||||
|
|||||||
@@ -59,6 +59,9 @@ export enum DialogsName {
|
|||||||
ManualJournalBulkDelete = 'manual-journals-bulk-delete',
|
ManualJournalBulkDelete = 'manual-journals-bulk-delete',
|
||||||
ExpenseBulkDelete = 'expenses-bulk-delete',
|
ExpenseBulkDelete = 'expenses-bulk-delete',
|
||||||
AccountBulkDelete = 'accounts-bulk-delete',
|
AccountBulkDelete = 'accounts-bulk-delete',
|
||||||
|
ItemBulkDelete = 'items-bulk-delete',
|
||||||
|
CustomerBulkDelete = 'customers-bulk-delete',
|
||||||
|
VendorBulkDelete = 'vendors-bulk-delete',
|
||||||
InvoiceMail = 'invoice-mail',
|
InvoiceMail = 'invoice-mail',
|
||||||
EstimateMail = 'estimate-mail',
|
EstimateMail = 'estimate-mail',
|
||||||
ReceiptMail = 'receipt-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 { useHistory } from 'react-router-dom';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
If,
|
|
||||||
Icon,
|
Icon,
|
||||||
Can,
|
Can,
|
||||||
FormattedMessage as T,
|
FormattedMessage as T,
|
||||||
@@ -29,7 +28,6 @@ import { useDownloadExportPdf } from '@/hooks/query/FinancialReports/use-export-
|
|||||||
|
|
||||||
import withCustomers from './withCustomers';
|
import withCustomers from './withCustomers';
|
||||||
import withCustomersActions from './withCustomersActions';
|
import withCustomersActions from './withCustomersActions';
|
||||||
import withAlertActions from '@/containers/Alert/withAlertActions';
|
|
||||||
import withSettingsActions from '@/containers/Settings/withSettingsActions';
|
import withSettingsActions from '@/containers/Settings/withSettingsActions';
|
||||||
import withSettings from '@/containers/Settings/withSettings';
|
import withSettings from '@/containers/Settings/withSettings';
|
||||||
import withDialogActions from '@/containers/Dialog/withDialogActions';
|
import withDialogActions from '@/containers/Dialog/withDialogActions';
|
||||||
@@ -37,6 +35,8 @@ import withDialogActions from '@/containers/Dialog/withDialogActions';
|
|||||||
import { CustomerAction, AbilitySubject } from '@/constants/abilityOption';
|
import { CustomerAction, AbilitySubject } from '@/constants/abilityOption';
|
||||||
import { compose } from '@/utils';
|
import { compose } from '@/utils';
|
||||||
import { DialogsName } from '@/constants/dialogs';
|
import { DialogsName } from '@/constants/dialogs';
|
||||||
|
import { isEmpty } from 'lodash';
|
||||||
|
import { useBulkDeleteCustomersDialog } from './hooks/use-bulk-delete-customers-dialog';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Customers actions bar.
|
* Customers actions bar.
|
||||||
@@ -50,9 +50,6 @@ function CustomerActionsBar({
|
|||||||
setCustomersTableState,
|
setCustomersTableState,
|
||||||
accountsInactiveMode,
|
accountsInactiveMode,
|
||||||
|
|
||||||
// #withAlertActions
|
|
||||||
openAlert,
|
|
||||||
|
|
||||||
// #withSettings
|
// #withSettings
|
||||||
customersTableSize,
|
customersTableSize,
|
||||||
|
|
||||||
@@ -62,6 +59,9 @@ function CustomerActionsBar({
|
|||||||
// #withDialogActions
|
// #withDialogActions
|
||||||
openDialog,
|
openDialog,
|
||||||
}) {
|
}) {
|
||||||
|
const { openBulkDeleteDialog, isValidatingBulkDeleteCustomers } =
|
||||||
|
useBulkDeleteCustomersDialog();
|
||||||
|
|
||||||
// History context.
|
// History context.
|
||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
|
|
||||||
@@ -80,7 +80,7 @@ function CustomerActionsBar({
|
|||||||
|
|
||||||
// Handle Customers bulk delete button click.,
|
// Handle Customers bulk delete button click.,
|
||||||
const handleBulkDelete = () => {
|
const handleBulkDelete = () => {
|
||||||
openAlert('customers-bulk-delete', { customersIds: customersSelectedRows });
|
openBulkDeleteDialog(customersSelectedRows);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleTabChange = (view) => {
|
const handleTabChange = (view) => {
|
||||||
@@ -118,6 +118,23 @@ function CustomerActionsBar({
|
|||||||
downloadExportPdf({ resource: 'Customer' });
|
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 (
|
return (
|
||||||
<DashboardActionsBar>
|
<DashboardActionsBar>
|
||||||
<NavbarGroup>
|
<NavbarGroup>
|
||||||
@@ -129,7 +146,7 @@ function CustomerActionsBar({
|
|||||||
onChange={handleTabChange}
|
onChange={handleTabChange}
|
||||||
/>
|
/>
|
||||||
<NavbarDivider />
|
<NavbarDivider />
|
||||||
<Can I={CustomerAction.Create} a={AbilitySubject.Item}>
|
<Can I={CustomerAction.Create} a={AbilitySubject.Customer}>
|
||||||
<Button
|
<Button
|
||||||
className={Classes.MINIMAL}
|
className={Classes.MINIMAL}
|
||||||
icon={<Icon icon={'plus'} />}
|
icon={<Icon icon={'plus'} />}
|
||||||
@@ -153,16 +170,6 @@ function CustomerActionsBar({
|
|||||||
/>
|
/>
|
||||||
</AdvancedFilterPopover>
|
</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
|
<Button
|
||||||
className={Classes.MINIMAL}
|
className={Classes.MINIMAL}
|
||||||
icon={<Icon icon="print-16" iconSize={16} />}
|
icon={<Icon icon="print-16" iconSize={16} />}
|
||||||
@@ -217,6 +224,5 @@ export default compose(
|
|||||||
withSettings(({ customersSettings }) => ({
|
withSettings(({ customersSettings }) => ({
|
||||||
customersTableSize: customersSettings?.tableSize,
|
customersTableSize: customersSettings?.tableSize,
|
||||||
})),
|
})),
|
||||||
withAlertActions,
|
|
||||||
withDialogActions,
|
withDialogActions,
|
||||||
)(CustomerActionsBar);
|
)(CustomerActionsBar);
|
||||||
|
|||||||
@@ -24,13 +24,15 @@ function CustomersList({
|
|||||||
|
|
||||||
// #withCustomersActions
|
// #withCustomersActions
|
||||||
resetCustomersTableState,
|
resetCustomersTableState,
|
||||||
|
resetCustomersSelectedRows,
|
||||||
}) {
|
}) {
|
||||||
// Resets the accounts table state once the page unmount.
|
// Resets the accounts table state once the page unmount.
|
||||||
useEffect(
|
useEffect(
|
||||||
() => () => {
|
() => () => {
|
||||||
resetCustomersTableState();
|
resetCustomersTableState();
|
||||||
|
resetCustomersSelectedRows();
|
||||||
},
|
},
|
||||||
[resetCustomersTableState],
|
[resetCustomersSelectedRows, resetCustomersTableState],
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ import { DRAWERS } from '@/constants/drawers';
|
|||||||
function CustomersTable({
|
function CustomersTable({
|
||||||
// #withCustomersActions
|
// #withCustomersActions
|
||||||
setCustomersTableState,
|
setCustomersTableState,
|
||||||
|
setCustomersSelectedRows,
|
||||||
|
|
||||||
// #withCustomers
|
// #withCustomers
|
||||||
customersTableState,
|
customersTableState,
|
||||||
@@ -78,6 +79,14 @@ function CustomersTable({
|
|||||||
[setCustomersTableState],
|
[setCustomersTableState],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const handleSelectedRowsChange = React.useCallback(
|
||||||
|
(selectedFlatRows) => {
|
||||||
|
const selectedIds = selectedFlatRows?.map((row) => row.original.id) || [];
|
||||||
|
setCustomersSelectedRows(selectedIds);
|
||||||
|
},
|
||||||
|
[setCustomersSelectedRows],
|
||||||
|
);
|
||||||
|
|
||||||
// Handles the customer delete action.
|
// Handles the customer delete action.
|
||||||
const handleCustomerDelete = ({ id }) => {
|
const handleCustomerDelete = ({ id }) => {
|
||||||
openAlert('customer-delete', { contactId: id });
|
openAlert('customer-delete', { contactId: id });
|
||||||
@@ -140,6 +149,8 @@ function CustomersTable({
|
|||||||
manualSortBy={true}
|
manualSortBy={true}
|
||||||
manualPagination={true}
|
manualPagination={true}
|
||||||
pagesCount={pagination.pagesCount}
|
pagesCount={pagination.pagesCount}
|
||||||
|
onSelectedRowsChange={handleSelectedRowsChange}
|
||||||
|
autoResetSelectedRows={false}
|
||||||
autoResetSortBy={false}
|
autoResetSortBy={false}
|
||||||
autoResetPage={false}
|
autoResetPage={false}
|
||||||
TableLoadingRenderer={TableSkeletonRows}
|
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 mapStateToProps = (state, props) => {
|
||||||
const mapped = {
|
const mapped = {
|
||||||
|
customersSelectedRows: state.customers.selectedRows,
|
||||||
customersTableState: getCustomersTableState(state, props),
|
customersTableState: getCustomersTableState(state, props),
|
||||||
customersTableStateChanged: customersTableStateChanged(state, props),
|
customersTableStateChanged: customersTableStateChanged(state, props),
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -2,12 +2,17 @@
|
|||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
import {
|
import {
|
||||||
setCustomersTableState,
|
setCustomersTableState,
|
||||||
resetCustomersTableState
|
resetCustomersTableState,
|
||||||
|
setCustomersSelectedRows,
|
||||||
|
resetCustomersSelectedRows,
|
||||||
} from '@/store/customers/customers.actions';
|
} from '@/store/customers/customers.actions';
|
||||||
|
|
||||||
export const mapDispatchToProps = (dispatch) => ({
|
export const mapDispatchToProps = (dispatch) => ({
|
||||||
setCustomersTableState: (state) => dispatch(setCustomersTableState(state)),
|
setCustomersTableState: (state) => dispatch(setCustomersTableState(state)),
|
||||||
resetCustomersTableState: () => dispatch(resetCustomersTableState()),
|
resetCustomersTableState: () => dispatch(resetCustomersTableState()),
|
||||||
|
setCustomersSelectedRows: (selectedRows) =>
|
||||||
|
dispatch(setCustomersSelectedRows(selectedRows)),
|
||||||
|
resetCustomersSelectedRows: () => dispatch(resetCustomersSelectedRows()),
|
||||||
});
|
});
|
||||||
|
|
||||||
export default connect(null, mapDispatchToProps);
|
export default connect(null, mapDispatchToProps);
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ import React from 'react';
|
|||||||
import { Button, Classes, Dialog, Intent } from '@blueprintjs/core';
|
import { Button, Classes, Dialog, Intent } from '@blueprintjs/core';
|
||||||
import { FormattedMessage as T, AppToaster } from '@/components';
|
import { FormattedMessage as T, AppToaster } from '@/components';
|
||||||
import intl from 'react-intl-universal';
|
import intl from 'react-intl-universal';
|
||||||
import { queryCache } from 'react-query';
|
|
||||||
|
|
||||||
import BulkDeleteDialogContent from '@/containers/Dialogs/components/BulkDeleteDialogContent';
|
import BulkDeleteDialogContent from '@/containers/Dialogs/components/BulkDeleteDialogContent';
|
||||||
import { useBulkDeleteAccounts } from '@/hooks/query/accounts';
|
import { useBulkDeleteAccounts } from '@/hooks/query/accounts';
|
||||||
@@ -45,7 +44,6 @@ function AccountBulkDeleteDialog({
|
|||||||
message: intl.get('the_accounts_has_been_successfully_deleted'),
|
message: intl.get('the_accounts_has_been_successfully_deleted'),
|
||||||
intent: Intent.SUCCESS,
|
intent: Intent.SUCCESS,
|
||||||
});
|
});
|
||||||
queryCache.invalidateQueries('accounts-table');
|
|
||||||
setAccountsSelectedRows([]);
|
setAccountsSelectedRows([]);
|
||||||
closeDialog(dialogName);
|
closeDialog(dialogName);
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ import React from 'react';
|
|||||||
import { Button, Classes, Dialog, Intent } from '@blueprintjs/core';
|
import { Button, Classes, Dialog, Intent } from '@blueprintjs/core';
|
||||||
import { FormattedMessage as T, AppToaster } from '@/components';
|
import { FormattedMessage as T, AppToaster } from '@/components';
|
||||||
import intl from 'react-intl-universal';
|
import intl from 'react-intl-universal';
|
||||||
import { queryCache } from 'react-query';
|
|
||||||
|
|
||||||
import BulkDeleteDialogContent from '@/containers/Dialogs/components/BulkDeleteDialogContent';
|
import BulkDeleteDialogContent from '@/containers/Dialogs/components/BulkDeleteDialogContent';
|
||||||
import { useBulkDeleteBills } from '@/hooks/query/bills';
|
import { useBulkDeleteBills } from '@/hooks/query/bills';
|
||||||
@@ -44,7 +43,6 @@ function BillBulkDeleteDialog({
|
|||||||
message: intl.get('the_bills_has_been_deleted_successfully'),
|
message: intl.get('the_bills_has_been_deleted_successfully'),
|
||||||
intent: Intent.SUCCESS,
|
intent: Intent.SUCCESS,
|
||||||
});
|
});
|
||||||
queryCache.invalidateQueries('bills-table');
|
|
||||||
setBillsSelectedRows([]);
|
setBillsSelectedRows([]);
|
||||||
closeDialog(dialogName);
|
closeDialog(dialogName);
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ import React from 'react';
|
|||||||
import { Button, Classes, Dialog, Intent } from '@blueprintjs/core';
|
import { Button, Classes, Dialog, Intent } from '@blueprintjs/core';
|
||||||
import { FormattedMessage as T, AppToaster } from '@/components';
|
import { FormattedMessage as T, AppToaster } from '@/components';
|
||||||
import intl from 'react-intl-universal';
|
import intl from 'react-intl-universal';
|
||||||
import { queryCache } from 'react-query';
|
|
||||||
|
|
||||||
import BulkDeleteDialogContent from '@/containers/Dialogs/components/BulkDeleteDialogContent';
|
import BulkDeleteDialogContent from '@/containers/Dialogs/components/BulkDeleteDialogContent';
|
||||||
import { useBulkDeleteCreditNotes } from '@/hooks/query/creditNote';
|
import { useBulkDeleteCreditNotes } from '@/hooks/query/creditNote';
|
||||||
@@ -45,7 +44,6 @@ function CreditNoteBulkDeleteDialog({
|
|||||||
message: intl.get('the_credit_notes_has_been_deleted_successfully'),
|
message: intl.get('the_credit_notes_has_been_deleted_successfully'),
|
||||||
intent: Intent.SUCCESS,
|
intent: Intent.SUCCESS,
|
||||||
});
|
});
|
||||||
queryCache.invalidateQueries('credit-notes-table');
|
|
||||||
setCreditNotesSelectedRows([]);
|
setCreditNotesSelectedRows([]);
|
||||||
closeDialog(dialogName);
|
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 { Button, Classes, Dialog, Intent } from '@blueprintjs/core';
|
||||||
import { FormattedMessage as T, AppToaster } from '@/components';
|
import { FormattedMessage as T, AppToaster } from '@/components';
|
||||||
import intl from 'react-intl-universal';
|
import intl from 'react-intl-universal';
|
||||||
import { queryCache } from 'react-query';
|
|
||||||
|
|
||||||
import BulkDeleteDialogContent from '@/containers/Dialogs/components/BulkDeleteDialogContent';
|
import BulkDeleteDialogContent from '@/containers/Dialogs/components/BulkDeleteDialogContent';
|
||||||
import { useBulkDeleteEstimates } from '@/hooks/query/estimates';
|
import { useBulkDeleteEstimates } from '@/hooks/query/estimates';
|
||||||
@@ -45,7 +44,6 @@ function EstimateBulkDeleteDialog({
|
|||||||
message: intl.get('the_estimates_has_been_deleted_successfully'),
|
message: intl.get('the_estimates_has_been_deleted_successfully'),
|
||||||
intent: Intent.SUCCESS,
|
intent: Intent.SUCCESS,
|
||||||
});
|
});
|
||||||
queryCache.invalidateQueries('estimates-table');
|
|
||||||
setEstimatesSelectedRows([]);
|
setEstimatesSelectedRows([]);
|
||||||
closeDialog(dialogName);
|
closeDialog(dialogName);
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ import React from 'react';
|
|||||||
import { Button, Classes, Dialog, Intent } from '@blueprintjs/core';
|
import { Button, Classes, Dialog, Intent } from '@blueprintjs/core';
|
||||||
import { FormattedMessage as T, AppToaster } from '@/components';
|
import { FormattedMessage as T, AppToaster } from '@/components';
|
||||||
import intl from 'react-intl-universal';
|
import intl from 'react-intl-universal';
|
||||||
import { queryCache } from 'react-query';
|
|
||||||
|
|
||||||
import BulkDeleteDialogContent from '@/containers/Dialogs/components/BulkDeleteDialogContent';
|
import BulkDeleteDialogContent from '@/containers/Dialogs/components/BulkDeleteDialogContent';
|
||||||
import { useBulkDeleteExpenses } from '@/hooks/query/expenses';
|
import { useBulkDeleteExpenses } from '@/hooks/query/expenses';
|
||||||
@@ -45,7 +44,6 @@ function ExpenseBulkDeleteDialog({
|
|||||||
message: intl.get('the_expenses_has_been_deleted_successfully'),
|
message: intl.get('the_expenses_has_been_deleted_successfully'),
|
||||||
intent: Intent.SUCCESS,
|
intent: Intent.SUCCESS,
|
||||||
});
|
});
|
||||||
queryCache.invalidateQueries('expenses-table');
|
|
||||||
setExpensesSelectedRows([]);
|
setExpensesSelectedRows([]);
|
||||||
closeDialog(dialogName);
|
closeDialog(dialogName);
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ import React from 'react';
|
|||||||
import { FormattedMessage as T } from '@/components';
|
import { FormattedMessage as T } from '@/components';
|
||||||
import intl from 'react-intl-universal';
|
import intl from 'react-intl-universal';
|
||||||
import { Button, Classes, Dialog, Intent } from '@blueprintjs/core';
|
import { Button, Classes, Dialog, Intent } from '@blueprintjs/core';
|
||||||
import { queryCache } from 'react-query';
|
|
||||||
|
|
||||||
import withDialogRedux from '@/components/DialogReduxConnect';
|
import withDialogRedux from '@/components/DialogReduxConnect';
|
||||||
import withDialogActions from '@/containers/Dialog/withDialogActions';
|
import withDialogActions from '@/containers/Dialog/withDialogActions';
|
||||||
@@ -50,7 +49,6 @@ function InvoiceBulkDeleteDialog({
|
|||||||
message: intl.get('the_invoices_has_been_deleted_successfully'),
|
message: intl.get('the_invoices_has_been_deleted_successfully'),
|
||||||
intent: Intent.SUCCESS,
|
intent: Intent.SUCCESS,
|
||||||
});
|
});
|
||||||
queryCache.invalidateQueries('invoices-table');
|
|
||||||
resetInvoicesSelectedRows();
|
resetInvoicesSelectedRows();
|
||||||
closeDialog(dialogName);
|
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 { Button, Classes, Dialog, Intent } from '@blueprintjs/core';
|
||||||
import { FormattedMessage as T, AppToaster } from '@/components';
|
import { FormattedMessage as T, AppToaster } from '@/components';
|
||||||
import intl from 'react-intl-universal';
|
import intl from 'react-intl-universal';
|
||||||
import { queryCache } from 'react-query';
|
|
||||||
|
|
||||||
import BulkDeleteDialogContent from '@/containers/Dialogs/components/BulkDeleteDialogContent';
|
import BulkDeleteDialogContent from '@/containers/Dialogs/components/BulkDeleteDialogContent';
|
||||||
import { useBulkDeleteManualJournals } from '@/hooks/query/manualJournals';
|
import { useBulkDeleteManualJournals } from '@/hooks/query/manualJournals';
|
||||||
@@ -45,7 +44,6 @@ function ManualJournalBulkDeleteDialog({
|
|||||||
message: intl.get('the_journals_has_been_deleted_successfully'),
|
message: intl.get('the_journals_has_been_deleted_successfully'),
|
||||||
intent: Intent.SUCCESS,
|
intent: Intent.SUCCESS,
|
||||||
});
|
});
|
||||||
queryCache.invalidateQueries('manual-journals-table');
|
|
||||||
setManualJournalsSelectedRows([]);
|
setManualJournalsSelectedRows([]);
|
||||||
closeDialog(dialogName);
|
closeDialog(dialogName);
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ import React from 'react';
|
|||||||
import { Button, Classes, Dialog, Intent } from '@blueprintjs/core';
|
import { Button, Classes, Dialog, Intent } from '@blueprintjs/core';
|
||||||
import { FormattedMessage as T, AppToaster } from '@/components';
|
import { FormattedMessage as T, AppToaster } from '@/components';
|
||||||
import intl from 'react-intl-universal';
|
import intl from 'react-intl-universal';
|
||||||
import { queryCache } from 'react-query';
|
|
||||||
|
|
||||||
import BulkDeleteDialogContent from '@/containers/Dialogs/components/BulkDeleteDialogContent';
|
import BulkDeleteDialogContent from '@/containers/Dialogs/components/BulkDeleteDialogContent';
|
||||||
import { useBulkDeletePaymentReceives } from '@/hooks/query/paymentReceives';
|
import { useBulkDeletePaymentReceives } from '@/hooks/query/paymentReceives';
|
||||||
@@ -47,7 +46,6 @@ function PaymentReceivedBulkDeleteDialog({
|
|||||||
),
|
),
|
||||||
intent: Intent.SUCCESS,
|
intent: Intent.SUCCESS,
|
||||||
});
|
});
|
||||||
queryCache.invalidateQueries('payments-received-table');
|
|
||||||
setPaymentReceivesSelectedRows([]);
|
setPaymentReceivesSelectedRows([]);
|
||||||
closeDialog(dialogName);
|
closeDialog(dialogName);
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ import React from 'react';
|
|||||||
import { Button, Classes, Dialog, Intent } from '@blueprintjs/core';
|
import { Button, Classes, Dialog, Intent } from '@blueprintjs/core';
|
||||||
import { FormattedMessage as T, AppToaster } from '@/components';
|
import { FormattedMessage as T, AppToaster } from '@/components';
|
||||||
import intl from 'react-intl-universal';
|
import intl from 'react-intl-universal';
|
||||||
import { queryCache } from 'react-query';
|
|
||||||
|
|
||||||
import BulkDeleteDialogContent from '@/containers/Dialogs/components/BulkDeleteDialogContent';
|
import BulkDeleteDialogContent from '@/containers/Dialogs/components/BulkDeleteDialogContent';
|
||||||
import { useBulkDeleteReceipts } from '@/hooks/query/receipts';
|
import { useBulkDeleteReceipts } from '@/hooks/query/receipts';
|
||||||
@@ -45,7 +44,6 @@ function ReceiptBulkDeleteDialog({
|
|||||||
message: intl.get('the_receipts_has_been_deleted_successfully'),
|
message: intl.get('the_receipts_has_been_deleted_successfully'),
|
||||||
intent: Intent.SUCCESS,
|
intent: Intent.SUCCESS,
|
||||||
});
|
});
|
||||||
queryCache.invalidateQueries('sale-receipts-table');
|
|
||||||
setReceiptsSelectedRows([]);
|
setReceiptsSelectedRows([]);
|
||||||
closeDialog(dialogName);
|
closeDialog(dialogName);
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ import React from 'react';
|
|||||||
import { Button, Classes, Dialog, Intent } from '@blueprintjs/core';
|
import { Button, Classes, Dialog, Intent } from '@blueprintjs/core';
|
||||||
import { FormattedMessage as T, AppToaster } from '@/components';
|
import { FormattedMessage as T, AppToaster } from '@/components';
|
||||||
import intl from 'react-intl-universal';
|
import intl from 'react-intl-universal';
|
||||||
import { queryCache } from 'react-query';
|
|
||||||
|
|
||||||
import BulkDeleteDialogContent from '@/containers/Dialogs/components/BulkDeleteDialogContent';
|
import BulkDeleteDialogContent from '@/containers/Dialogs/components/BulkDeleteDialogContent';
|
||||||
import { useBulkDeleteVendorCredits } from '@/hooks/query/vendorCredit';
|
import { useBulkDeleteVendorCredits } from '@/hooks/query/vendorCredit';
|
||||||
@@ -47,7 +46,6 @@ function VendorCreditBulkDeleteDialog({
|
|||||||
),
|
),
|
||||||
intent: Intent.SUCCESS,
|
intent: Intent.SUCCESS,
|
||||||
});
|
});
|
||||||
queryCache.invalidateQueries('vendor-credits-table');
|
|
||||||
setVendorsCreditNoteSelectedRows([]);
|
setVendorsCreditNoteSelectedRows([]);
|
||||||
closeDialog(dialogName);
|
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 withItems from './withItems';
|
||||||
import withItemsActions from './withItemsActions';
|
import withItemsActions from './withItemsActions';
|
||||||
import withAlertActions from '@/containers/Alert/withAlertActions';
|
|
||||||
import withSettings from '@/containers/Settings/withSettings';
|
import withSettings from '@/containers/Settings/withSettings';
|
||||||
import withSettingsActions from '@/containers/Settings/withSettingsActions';
|
import withSettingsActions from '@/containers/Settings/withSettingsActions';
|
||||||
import withDialogActions from '../Dialog/withDialogActions';
|
import withDialogActions from '../Dialog/withDialogActions';
|
||||||
@@ -39,6 +38,7 @@ import withDialogActions from '../Dialog/withDialogActions';
|
|||||||
import { DialogsName } from '@/constants/dialogs';
|
import { DialogsName } from '@/constants/dialogs';
|
||||||
import { compose } from '@/utils';
|
import { compose } from '@/utils';
|
||||||
import { isEmpty } from 'lodash';
|
import { isEmpty } from 'lodash';
|
||||||
|
import { useBulkDeleteItemsDialog } from './hooks/use-bulk-delete-items-dialog';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Items actions bar.
|
* Items actions bar.
|
||||||
@@ -52,9 +52,6 @@ function ItemsActionsBar({
|
|||||||
setItemsTableState,
|
setItemsTableState,
|
||||||
itemsInactiveMode,
|
itemsInactiveMode,
|
||||||
|
|
||||||
// #withAlertActions
|
|
||||||
openAlert,
|
|
||||||
|
|
||||||
// #withSettings
|
// #withSettings
|
||||||
itemsTableSize,
|
itemsTableSize,
|
||||||
|
|
||||||
@@ -64,6 +61,9 @@ function ItemsActionsBar({
|
|||||||
// #withDialogActions
|
// #withDialogActions
|
||||||
openDialog,
|
openDialog,
|
||||||
}) {
|
}) {
|
||||||
|
const { openBulkDeleteDialog, isValidatingBulkDeleteItems } =
|
||||||
|
useBulkDeleteItemsDialog();
|
||||||
|
|
||||||
// Items list context.
|
// Items list context.
|
||||||
const { itemsViews, fields } = useItemsListContext();
|
const { itemsViews, fields } = useItemsListContext();
|
||||||
|
|
||||||
@@ -88,7 +88,7 @@ function ItemsActionsBar({
|
|||||||
|
|
||||||
// Handle cancel/confirm items bulk.
|
// Handle cancel/confirm items bulk.
|
||||||
const handleBulkDelete = () => {
|
const handleBulkDelete = () => {
|
||||||
openAlert('items-bulk-delete', { itemsIds: itemsSelectedRows });
|
openBulkDeleteDialog(itemsSelectedRows);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Handle inactive switch changing.
|
// Handle inactive switch changing.
|
||||||
@@ -129,6 +129,7 @@ function ItemsActionsBar({
|
|||||||
text={<T id={'delete'} />}
|
text={<T id={'delete'} />}
|
||||||
intent={Intent.DANGER}
|
intent={Intent.DANGER}
|
||||||
onClick={handleBulkDelete}
|
onClick={handleBulkDelete}
|
||||||
|
disabled={isValidatingBulkDeleteItems}
|
||||||
/>
|
/>
|
||||||
</NavbarGroup>
|
</NavbarGroup>
|
||||||
</DashboardActionsBar>
|
</DashboardActionsBar>
|
||||||
@@ -224,6 +225,5 @@ export default compose(
|
|||||||
itemsTableSize: itemsSettings.tableSize,
|
itemsTableSize: itemsSettings.tableSize,
|
||||||
})),
|
})),
|
||||||
withItemsActions,
|
withItemsActions,
|
||||||
withAlertActions,
|
|
||||||
withDialogActions,
|
withDialogActions,
|
||||||
)(ItemsActionsBar);
|
)(ItemsActionsBar);
|
||||||
|
|||||||
@@ -13,10 +13,6 @@ const ItemActivateAlert = React.lazy(
|
|||||||
() => import('@/containers/Alerts/Items/ItemActivateAlert'),
|
() => import('@/containers/Alerts/Items/ItemActivateAlert'),
|
||||||
);
|
);
|
||||||
|
|
||||||
const ItemBulkDeleteAlert = React.lazy(
|
|
||||||
() => import('@/containers/Alerts/Items/ItemBulkDeleteAlert'),
|
|
||||||
);
|
|
||||||
|
|
||||||
const cancelUnlockingPartialAlert = React.lazy(
|
const cancelUnlockingPartialAlert = React.lazy(
|
||||||
() =>
|
() =>
|
||||||
import(
|
import(
|
||||||
@@ -40,8 +36,4 @@ export default [
|
|||||||
name: 'item-activate',
|
name: 'item-activate',
|
||||||
component: ItemActivateAlert,
|
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';
|
} from '@blueprintjs/core';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
If,
|
|
||||||
Can,
|
Can,
|
||||||
Icon,
|
Icon,
|
||||||
FormattedMessage as T,
|
FormattedMessage as T,
|
||||||
@@ -28,6 +27,8 @@ import { useRefreshVendors } from '@/hooks/query/vendors';
|
|||||||
import { useVendorsListContext } from './VendorsListProvider';
|
import { useVendorsListContext } from './VendorsListProvider';
|
||||||
import { useHistory } from 'react-router-dom';
|
import { useHistory } from 'react-router-dom';
|
||||||
import { useDownloadExportPdf } from '@/hooks/query/FinancialReports/use-export-pdf';
|
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 withVendors from './withVendors';
|
||||||
import withVendorsActions from './withVendorsActions';
|
import withVendorsActions from './withVendorsActions';
|
||||||
@@ -43,6 +44,7 @@ import { DialogsName } from '@/constants/dialogs';
|
|||||||
*/
|
*/
|
||||||
function VendorActionsBar({
|
function VendorActionsBar({
|
||||||
// #withVendors
|
// #withVendors
|
||||||
|
vendorsSelectedRows = [],
|
||||||
vendorsFilterConditions,
|
vendorsFilterConditions,
|
||||||
|
|
||||||
// #withVendorActions
|
// #withVendorActions
|
||||||
@@ -59,6 +61,9 @@ function VendorActionsBar({
|
|||||||
openDialog,
|
openDialog,
|
||||||
}) {
|
}) {
|
||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
|
const { openBulkDeleteDialog, isValidatingBulkDeleteVendors } =
|
||||||
|
useBulkDeleteVendorsDialog();
|
||||||
|
|
||||||
|
|
||||||
// Vendors list context.
|
// Vendors list context.
|
||||||
const { vendorsViews, fields } = useVendorsListContext();
|
const { vendorsViews, fields } = useVendorsListContext();
|
||||||
@@ -102,6 +107,27 @@ function VendorActionsBar({
|
|||||||
downloadExportPdf({ resource: 'Vendor' });
|
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 (
|
return (
|
||||||
<DashboardActionsBar>
|
<DashboardActionsBar>
|
||||||
<NavbarGroup>
|
<NavbarGroup>
|
||||||
@@ -111,7 +137,7 @@ function VendorActionsBar({
|
|||||||
onChange={handleTabChange}
|
onChange={handleTabChange}
|
||||||
/>
|
/>
|
||||||
<NavbarDivider />
|
<NavbarDivider />
|
||||||
<Can I={VendorActionsBar.Create} a={AbilitySubject.Vendor}>
|
<Can I={VendorAction.Create} a={AbilitySubject.Vendor}>
|
||||||
<Button
|
<Button
|
||||||
className={Classes.MINIMAL}
|
className={Classes.MINIMAL}
|
||||||
icon={<Icon icon={'plus'} />}
|
icon={<Icon icon={'plus'} />}
|
||||||
@@ -135,15 +161,6 @@ function VendorActionsBar({
|
|||||||
/>
|
/>
|
||||||
</AdvancedFilterPopover>
|
</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
|
<Button
|
||||||
className={Classes.MINIMAL}
|
className={Classes.MINIMAL}
|
||||||
icon={<Icon icon="print-16" iconSize={16} />}
|
icon={<Icon icon="print-16" iconSize={16} />}
|
||||||
@@ -191,7 +208,8 @@ function VendorActionsBar({
|
|||||||
export default compose(
|
export default compose(
|
||||||
withVendorsActions,
|
withVendorsActions,
|
||||||
withSettingsActions,
|
withSettingsActions,
|
||||||
withVendors(({ vendorsTableState }) => ({
|
withVendors(({ vendorsTableState, vendorsSelectedRows }) => ({
|
||||||
|
vendorsSelectedRows,
|
||||||
vendorsInactiveMode: vendorsTableState.inactiveMode,
|
vendorsInactiveMode: vendorsTableState.inactiveMode,
|
||||||
vendorsFilterConditions: vendorsTableState.filterRoles,
|
vendorsFilterConditions: vendorsTableState.filterRoles,
|
||||||
})),
|
})),
|
||||||
|
|||||||
@@ -24,13 +24,15 @@ function VendorsList({
|
|||||||
|
|
||||||
// #withVendorsActions
|
// #withVendorsActions
|
||||||
resetVendorsTableState,
|
resetVendorsTableState,
|
||||||
|
resetVendorsSelectedRows,
|
||||||
}) {
|
}) {
|
||||||
// Resets the vendors table state once the page unmount.
|
// Resets the vendors table state once the page unmount.
|
||||||
useEffect(
|
useEffect(
|
||||||
() => () => {
|
() => () => {
|
||||||
resetVendorsTableState();
|
resetVendorsTableState();
|
||||||
|
resetVendorsSelectedRows();
|
||||||
},
|
},
|
||||||
[resetVendorsTableState],
|
[resetVendorsSelectedRows, resetVendorsTableState],
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ import { DRAWERS } from '@/constants/drawers';
|
|||||||
function VendorsTable({
|
function VendorsTable({
|
||||||
// #withVendorsActions
|
// #withVendorsActions
|
||||||
setVendorsTableState,
|
setVendorsTableState,
|
||||||
|
setVendorsSelectedRows,
|
||||||
|
|
||||||
// #withVendors
|
// #withVendors
|
||||||
vendorsTableState,
|
vendorsTableState,
|
||||||
@@ -118,6 +119,14 @@ function VendorsTable({
|
|||||||
[setVendorsTableState],
|
[setVendorsTableState],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const handleSelectedRowsChange = React.useCallback(
|
||||||
|
(selectedFlatRows) => {
|
||||||
|
const selectedIds = selectedFlatRows?.map((row) => row.original.id) || [];
|
||||||
|
setVendorsSelectedRows(selectedIds);
|
||||||
|
},
|
||||||
|
[setVendorsSelectedRows],
|
||||||
|
);
|
||||||
|
|
||||||
// Display empty status instead of the table.
|
// Display empty status instead of the table.
|
||||||
if (isEmptyStatus) {
|
if (isEmptyStatus) {
|
||||||
return <VendorsEmptyStatus />;
|
return <VendorsEmptyStatus />;
|
||||||
@@ -142,6 +151,8 @@ function VendorsTable({
|
|||||||
pagesCount={pagination.pagesCount}
|
pagesCount={pagination.pagesCount}
|
||||||
autoResetSortBy={false}
|
autoResetSortBy={false}
|
||||||
autoResetPage={false}
|
autoResetPage={false}
|
||||||
|
onSelectedRowsChange={handleSelectedRowsChange}
|
||||||
|
autoResetSelectedRows={false}
|
||||||
TableLoadingRenderer={TableSkeletonRows}
|
TableLoadingRenderer={TableSkeletonRows}
|
||||||
TableHeaderSkeletonRenderer={TableSkeletonHeader}
|
TableHeaderSkeletonRenderer={TableSkeletonHeader}
|
||||||
ContextMenu={ActionsMenu}
|
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 mapStateToProps = (state, props) => {
|
||||||
const mapped = {
|
const mapped = {
|
||||||
|
vendorsSelectedRows: state.vendors.selectedRows,
|
||||||
vendorsTableState: getVendorsTableState(state, props),
|
vendorsTableState: getVendorsTableState(state, props),
|
||||||
vendorsTableStateChanged: vendorsTableStateChanged(state, props),
|
vendorsTableStateChanged: vendorsTableStateChanged(state, props),
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -3,11 +3,16 @@ import { connect } from 'react-redux';
|
|||||||
import {
|
import {
|
||||||
setVendorsTableState,
|
setVendorsTableState,
|
||||||
resetVendorsTableState,
|
resetVendorsTableState,
|
||||||
|
setVendorsSelectedRows,
|
||||||
|
resetVendorsSelectedRows,
|
||||||
} from '@/store/vendors/vendors.actions';
|
} from '@/store/vendors/vendors.actions';
|
||||||
|
|
||||||
const mapDispatchToProps = (dispatch) => ({
|
const mapDispatchToProps = (dispatch) => ({
|
||||||
setVendorsTableState: (queries) => dispatch(setVendorsTableState(queries)),
|
setVendorsTableState: (queries) => dispatch(setVendorsTableState(queries)),
|
||||||
resetVendorsTableState: () => dispatch(resetVendorsTableState()),
|
resetVendorsTableState: () => dispatch(resetVendorsTableState()),
|
||||||
|
setVendorsSelectedRows: (selectedRows) =>
|
||||||
|
dispatch(setVendorsSelectedRows(selectedRows)),
|
||||||
|
resetVendorsSelectedRows: () => dispatch(resetVendorsSelectedRows()),
|
||||||
});
|
});
|
||||||
|
|
||||||
export default connect(null, mapDispatchToProps);
|
export default connect(null, mapDispatchToProps);
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ export const useBulkDeleteDialog = (
|
|||||||
if (!ids?.length) {
|
if (!ids?.length) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const { deletableCount = 0, nonDeletableCount = 0 } =
|
const { deletableCount = 0, nonDeletableCount = 0 } =
|
||||||
await validateBulkDelete(ids);
|
await validateBulkDelete(ids);
|
||||||
|
|
||||||
|
|||||||
@@ -167,7 +167,7 @@ export function useBulkDeleteAccounts(props) {
|
|||||||
}) =>
|
}) =>
|
||||||
apiRequest.post('accounts/bulk-delete', {
|
apiRequest.post('accounts/bulk-delete', {
|
||||||
ids,
|
ids,
|
||||||
skipUndeletable,
|
skip_undeletable: skipUndeletable,
|
||||||
}),
|
}),
|
||||||
{
|
{
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
|
|||||||
@@ -128,7 +128,7 @@ export function useBulkDeleteCreditNotes(props) {
|
|||||||
}) =>
|
}) =>
|
||||||
apiRequest.post('credit-notes/bulk-delete', {
|
apiRequest.post('credit-notes/bulk-delete', {
|
||||||
ids,
|
ids,
|
||||||
skipUndeletable,
|
skip_undeletable: skipUndeletable,
|
||||||
}),
|
}),
|
||||||
{
|
{
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
// @ts-nocheck
|
// @ts-nocheck
|
||||||
import { useMutation, useQueryClient } from 'react-query';
|
import { useMutation, useQueryClient } from 'react-query';
|
||||||
import { useRequestQuery } from '../useQueryRequest';
|
import { useRequestQuery } from '../useQueryRequest';
|
||||||
import { transformPagination } from '@/utils';
|
import { transformPagination, transformToCamelCase } from '@/utils';
|
||||||
import useApiRequest from '../useRequest';
|
import useApiRequest from '../useRequest';
|
||||||
import t from './types';
|
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.
|
* Creates a new customer.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -141,7 +141,7 @@ export function useBulkDeleteEstimates(props) {
|
|||||||
}) =>
|
}) =>
|
||||||
apiRequest.post('sale-estimates/bulk-delete', {
|
apiRequest.post('sale-estimates/bulk-delete', {
|
||||||
ids,
|
ids,
|
||||||
skipUndeletable,
|
skip_undeletable: skipUndeletable,
|
||||||
}),
|
}),
|
||||||
{
|
{
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
|
|||||||
@@ -119,7 +119,7 @@ export function useBulkDeleteExpenses(props) {
|
|||||||
}) =>
|
}) =>
|
||||||
apiRequest.post('expenses/bulk-delete', {
|
apiRequest.post('expenses/bulk-delete', {
|
||||||
ids,
|
ids,
|
||||||
skipUndeletable,
|
skip_undeletable: skipUndeletable,
|
||||||
}),
|
}),
|
||||||
{
|
{
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
|
|||||||
@@ -142,7 +142,7 @@ export function useBulkDeleteInvoices(props) {
|
|||||||
}) =>
|
}) =>
|
||||||
apiRequest.post('sale-invoices/bulk-delete', {
|
apiRequest.post('sale-invoices/bulk-delete', {
|
||||||
ids,
|
ids,
|
||||||
skipUndeletable,
|
skip_undeletable: skipUndeletable,
|
||||||
}),
|
}),
|
||||||
{
|
{
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
// @ts-nocheck
|
// @ts-nocheck
|
||||||
import { useMutation, useQueryClient } from 'react-query';
|
import { useMutation, useQueryClient } from 'react-query';
|
||||||
import { transformPagination, transformResponse } from '@/utils';
|
import { transformPagination, transformResponse, transformToCamelCase } from '@/utils';
|
||||||
import { useRequestQuery } from '../useQueryRequest';
|
import { useRequestQuery } from '../useQueryRequest';
|
||||||
import useApiRequest from '../useRequest';
|
import useApiRequest from '../useRequest';
|
||||||
import t from './types';
|
import t from './types';
|
||||||
@@ -81,7 +81,17 @@ export function useBulkDeleteItems(props) {
|
|||||||
const apiRequest = useApiRequest();
|
const apiRequest = useApiRequest();
|
||||||
|
|
||||||
return useMutation(
|
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: () => {
|
onSuccess: () => {
|
||||||
// Common invalidate queries.
|
// 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.
|
* Activate the given item.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -105,7 +105,7 @@ export function useBulkDeleteManualJournals(props) {
|
|||||||
}) =>
|
}) =>
|
||||||
apiRequest.post('manual-journals/bulk-delete', {
|
apiRequest.post('manual-journals/bulk-delete', {
|
||||||
ids,
|
ids,
|
||||||
skipUndeletable,
|
skip_undeletable: skipUndeletable,
|
||||||
}),
|
}),
|
||||||
{
|
{
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
|
|||||||
@@ -167,7 +167,7 @@ export function useBulkDeletePaymentReceives(props) {
|
|||||||
}) =>
|
}) =>
|
||||||
apiRequest.post('payments-received/bulk-delete', {
|
apiRequest.post('payments-received/bulk-delete', {
|
||||||
ids,
|
ids,
|
||||||
skipUndeletable,
|
skip_undeletable: skipUndeletable,
|
||||||
}),
|
}),
|
||||||
{
|
{
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
|
|||||||
@@ -121,7 +121,7 @@ export function useBulkDeleteReceipts(props) {
|
|||||||
}) =>
|
}) =>
|
||||||
apiRequest.post('sale-receipts/bulk-delete', {
|
apiRequest.post('sale-receipts/bulk-delete', {
|
||||||
ids,
|
ids,
|
||||||
skipUndeletable,
|
skip_undeletable: skipUndeletable,
|
||||||
}),
|
}),
|
||||||
{
|
{
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
|
|||||||
@@ -130,7 +130,7 @@ export function useBulkDeleteVendorCredits(props) {
|
|||||||
}) =>
|
}) =>
|
||||||
apiRequest.post('vendor-credits/bulk-delete', {
|
apiRequest.post('vendor-credits/bulk-delete', {
|
||||||
ids,
|
ids,
|
||||||
skipUndeletable,
|
skip_undeletable: skipUndeletable,
|
||||||
}),
|
}),
|
||||||
{
|
{
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
// @ts-nocheck
|
// @ts-nocheck
|
||||||
import { useMutation, useQueryClient } from 'react-query';
|
import { useMutation, useQueryClient } from 'react-query';
|
||||||
import t from './types';
|
import t from './types';
|
||||||
import { transformPagination } from '@/utils';
|
import { transformPagination, transformToCamelCase } from '@/utils';
|
||||||
import useApiRequest from '../useRequest';
|
import useApiRequest from '../useRequest';
|
||||||
import { useRequestQuery } from '../useQueryRequest';
|
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.
|
* Creates a new vendor.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -512,6 +512,12 @@
|
|||||||
"resource_expense_plural": "Expenses",
|
"resource_expense_plural": "Expenses",
|
||||||
"resource_account_singular": "Account",
|
"resource_account_singular": "Account",
|
||||||
"resource_account_plural": "Accounts",
|
"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": "لا يمكنك حذف حساب لديه حسابات فرعية.",
|
"you_could_not_delete_account_has_child_accounts": "لا يمكنك حذف حساب لديه حسابات فرعية.",
|
||||||
"journal_entry": "القيد",
|
"journal_entry": "القيد",
|
||||||
"estimate": "رقم العرض",
|
"estimate": "رقم العرض",
|
||||||
@@ -730,6 +736,7 @@
|
|||||||
"vendors_list": "قائمة الموردين",
|
"vendors_list": "قائمة الموردين",
|
||||||
"the_vendor_has_been_created_successfully": "تم اضافة مورد جديد بنجاح.",
|
"the_vendor_has_been_created_successfully": "تم اضافة مورد جديد بنجاح.",
|
||||||
"the_vendor_has_been_deleted_successfully": "تم حذف المورد بنجاح.",
|
"the_vendor_has_been_deleted_successfully": "تم حذف المورد بنجاح.",
|
||||||
|
"the_vendors_has_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_delete_this_vendor_you_will_able_to_restore_it": "بمجرد حذف هذا المورد ، لن تتمكن من استعادته لاحقًا. هل أنت متأكد أنك تريد حذف؟",
|
||||||
"once_delete_these_vendors_you_will_not_able_restore_them": "بمجرد حذف هؤلاء الموردين ، لن تتمكن من استعادتهم لاحقًا. هل أنت متأكد أنك تريد حذفها؟",
|
"once_delete_these_vendors_you_will_not_able_restore_them": "بمجرد حذف هؤلاء الموردين ، لن تتمكن من استعادتهم لاحقًا. هل أنت متأكد أنك تريد حذفها؟",
|
||||||
|
|||||||
@@ -557,6 +557,12 @@
|
|||||||
"resource_expense_plural": "Expenses",
|
"resource_expense_plural": "Expenses",
|
||||||
"resource_account_singular": "Account",
|
"resource_account_singular": "Account",
|
||||||
"resource_account_plural": "Accounts",
|
"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_list": "Receipts List",
|
||||||
"receipts": "Receipts",
|
"receipts": "Receipts",
|
||||||
"receipt": "Receipt #",
|
"receipt": "Receipt #",
|
||||||
@@ -720,6 +726,7 @@
|
|||||||
"vendors_list": "Vendors List",
|
"vendors_list": "Vendors List",
|
||||||
"the_vendor_has_been_created_successfully": "The vendor has been successfully created.",
|
"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_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.",
|
"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_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?",
|
"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_expense_plural": "Expenses",
|
||||||
"resource_account_singular": "Account",
|
"resource_account_singular": "Account",
|
||||||
"resource_account_plural": "Accounts",
|
"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.",
|
"you_could_not_delete_account_has_child_accounts": "No pudiste eliminar la cuenta que tiene cuentas secundarias.",
|
||||||
"journal_entry": "Asiento de diario",
|
"journal_entry": "Asiento de diario",
|
||||||
"estimate": "Estimación #",
|
"estimate": "Estimación #",
|
||||||
@@ -725,6 +731,7 @@
|
|||||||
"vendors_list": "Lista de proveedores",
|
"vendors_list": "Lista de proveedores",
|
||||||
"the_vendor_has_been_created_successfully": "El proveedor ha sido creado exitosamente.",
|
"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_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.",
|
"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_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?",
|
"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_expense_plural": "Expenses",
|
||||||
"resource_account_singular": "Account",
|
"resource_account_singular": "Account",
|
||||||
"resource_account_plural": "Accounts",
|
"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",
|
"journal_entry": "Journalanteckning",
|
||||||
"estimate": "Uppskattning #",
|
"estimate": "Uppskattning #",
|
||||||
"estimate_date": "Uppskattning Datum",
|
"estimate_date": "Uppskattning Datum",
|
||||||
@@ -711,6 +717,7 @@
|
|||||||
"vendors_list": "Lista över leverantörer",
|
"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_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_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.",
|
"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_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?",
|
"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 {
|
return {
|
||||||
type: t.CUSTOMERS_TABLE_STATE_RESET,
|
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 { persistReducer } from 'redux-persist';
|
||||||
import storage from 'redux-persist/lib/storage';
|
import storage from 'redux-persist/lib/storage';
|
||||||
import { createTableStateReducers } from '@/store/tableState.reducer';
|
import { createTableStateReducers } from '@/store/tableState.reducer';
|
||||||
|
import t from '@/store/types';
|
||||||
|
|
||||||
// Default table query state.
|
// Default table query state.
|
||||||
export const defaultTableQueryState = {
|
export const defaultTableQueryState = {
|
||||||
@@ -16,10 +17,21 @@ export const defaultTableQueryState = {
|
|||||||
// initial data.
|
// initial data.
|
||||||
const initialState = {
|
const initialState = {
|
||||||
tableState: defaultTableQueryState,
|
tableState: defaultTableQueryState,
|
||||||
|
selectedRows: [],
|
||||||
};
|
};
|
||||||
|
|
||||||
const reducerInstance = createReducer(initialState, {
|
const reducerInstance = createReducer(initialState, {
|
||||||
...createTableStateReducers('CUSTOMERS', defaultTableQueryState),
|
...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';
|
const STORAGE_KEY = 'bigcapital:estimates';
|
||||||
|
|||||||
@@ -13,3 +13,16 @@ export const resetVendorsTableState = () => {
|
|||||||
type: t.VENDORS_TABLE_STATE_RESET,
|
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 = {
|
const initialState = {
|
||||||
tableState: defaultTableQueryState,
|
tableState: defaultTableQueryState,
|
||||||
|
selectedRows: [],
|
||||||
};
|
};
|
||||||
|
|
||||||
const STORAGE_KEY = 'bigcapital:vendors';
|
const STORAGE_KEY = 'bigcapital:vendors';
|
||||||
@@ -28,8 +29,17 @@ const CONFIG = {
|
|||||||
const reducerInstance = createReducer(initialState, {
|
const reducerInstance = createReducer(initialState, {
|
||||||
...createTableStateReducers('VENDORS', defaultTableQueryState),
|
...createTableStateReducers('VENDORS', defaultTableQueryState),
|
||||||
|
|
||||||
|
['VENDORS/SET_SELECTED_ROWS']: (state, action) => {
|
||||||
|
state.selectedRows = action.payload;
|
||||||
|
},
|
||||||
|
|
||||||
|
['VENDORS/RESET_SELECTED_ROWS']: (state) => {
|
||||||
|
state.selectedRows = [];
|
||||||
|
},
|
||||||
|
|
||||||
[t.RESET]: () => {
|
[t.RESET]: () => {
|
||||||
purgeStoredState(CONFIG);
|
purgeStoredState(CONFIG);
|
||||||
|
return initialState;
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user