From e0d9a56a2993dafc8855fbeb25f6572a0d8cd735 Mon Sep 17 00:00:00 2001 From: Ahmed Bouhuolia Date: Thu, 12 Feb 2026 20:06:49 +0200 Subject: [PATCH] fix: tax rates API and UI improvements - Add @ToNumber() decorator to rate field for proper validation - Fix getTaxRates to return { data: taxRates } response - Fix useTaxRate URL typo and response handling - Fix activate/inactivate endpoint methods and paths - Apply TEXT_MUTED class to description and compound tax - Add dark mode support for rate number display --- .../modules/TaxRates/TaxRate.application.ts | 7 ++++--- .../modules/TaxRates/TaxRate.controller.ts | 11 +++++++--- .../src/modules/TaxRates/dtos/TaxRate.dto.ts | 2 ++ .../containers/TaxRates/containers/_utils.tsx | 20 ++++++++----------- .../TaxRateDetailsContentDetails.tsx | 6 +++++- packages/webapp/src/hooks/query/taxRates.ts | 8 ++++---- 6 files changed, 31 insertions(+), 23 deletions(-) diff --git a/packages/server/src/modules/TaxRates/TaxRate.application.ts b/packages/server/src/modules/TaxRates/TaxRate.application.ts index 2159c7d33..8847dcbe7 100644 --- a/packages/server/src/modules/TaxRates/TaxRate.application.ts +++ b/packages/server/src/modules/TaxRates/TaxRate.application.ts @@ -62,10 +62,11 @@ export class TaxRatesApplication { /** * Retrieves the tax rates list. - * @returns {Promise} + * @returns {Promise<{ data: ITaxRate[] }>} */ - public getTaxRates() { - return this.getTaxRatesService.getTaxRates(); + public async getTaxRates() { + const taxRates = await this.getTaxRatesService.getTaxRates(); + return { data: taxRates }; } /** diff --git a/packages/server/src/modules/TaxRates/TaxRate.controller.ts b/packages/server/src/modules/TaxRates/TaxRate.controller.ts index 476ac4e32..43a2cf63a 100644 --- a/packages/server/src/modules/TaxRates/TaxRate.controller.ts +++ b/packages/server/src/modules/TaxRates/TaxRate.controller.ts @@ -85,9 +85,14 @@ export class TaxRatesController { status: 200, description: 'The tax rates have been successfully retrieved.', schema: { - type: 'array', - items: { - $ref: getSchemaPath(TaxRateResponseDto), + type: 'object', + properties: { + data: { + type: 'array', + items: { + $ref: getSchemaPath(TaxRateResponseDto), + }, + }, }, }, }) diff --git a/packages/server/src/modules/TaxRates/dtos/TaxRate.dto.ts b/packages/server/src/modules/TaxRates/dtos/TaxRate.dto.ts index 678e81c94..7bbca6105 100644 --- a/packages/server/src/modules/TaxRates/dtos/TaxRate.dto.ts +++ b/packages/server/src/modules/TaxRates/dtos/TaxRate.dto.ts @@ -1,3 +1,4 @@ +import { ToNumber } from '@/common/decorators/Validators'; import { ApiProperty } from '@nestjs/swagger'; import { Transform } from 'class-transformer'; import { @@ -30,6 +31,7 @@ export class CommandTaxRateDto { */ @IsNumber() @IsNotEmpty() + @ToNumber() @ApiProperty({ description: 'The rate of the tax rate.', example: 10, diff --git a/packages/webapp/src/containers/TaxRates/containers/_utils.tsx b/packages/webapp/src/containers/TaxRates/containers/_utils.tsx index 29fe64649..fb752e5bf 100644 --- a/packages/webapp/src/containers/TaxRates/containers/_utils.tsx +++ b/packages/webapp/src/containers/TaxRates/containers/_utils.tsx @@ -1,8 +1,8 @@ // @ts-nocheck import React from 'react'; -import { Intent, Tag } from '@blueprintjs/core'; +import { Intent, Tag, Classes } from '@blueprintjs/core'; import { Align } from '@/constants'; -import styled from 'styled-components'; +import clsx from 'classnames'; const codeAccessor = (taxRate) => { return ( @@ -28,13 +28,17 @@ const nameAccessor = (taxRate) => { return ( <> {taxRate.name} - {!!taxRate.is_compound && (Compound tax)} + {!!taxRate.is_compound && ( + (Compound tax) + )} ); }; const DescriptionAccessor = (taxRate) => { - return {taxRate.description}; + return ( + {taxRate.description} + ); }; /** @@ -72,11 +76,3 @@ export const useTaxRatesTableColumns = () => { ]; }; -const CompoundText = styled('span')` - color: #738091; - margin-left: 5px; -`; - -const DescriptionText = styled('span')` - color: #5f6b7c; -`; diff --git a/packages/webapp/src/containers/TaxRates/drawers/TaxRateDetailsDrawer/TaxRateDetailsContentDetails.tsx b/packages/webapp/src/containers/TaxRates/drawers/TaxRateDetailsDrawer/TaxRateDetailsContentDetails.tsx index e145ddaef..ac6e9dd69 100644 --- a/packages/webapp/src/containers/TaxRates/drawers/TaxRateDetailsDrawer/TaxRateDetailsContentDetails.tsx +++ b/packages/webapp/src/containers/TaxRates/drawers/TaxRateDetailsDrawer/TaxRateDetailsContentDetails.tsx @@ -74,9 +74,13 @@ const TaxRateHeader = styled(`div`)` const TaxRateAmount = styled('div')` line-height: 1; font-size: 30px; - color: #565b71; font-weight: 600; display: inline-block; + color: var(--x-color-amount-text, #565b71); + + .bp4-dark & { + color: rgba(255, 255, 255, 0.9); + } `; const TaxRateActiveTag = styled(Tag)` diff --git a/packages/webapp/src/hooks/query/taxRates.ts b/packages/webapp/src/hooks/query/taxRates.ts index a026d4387..add6f7928 100644 --- a/packages/webapp/src/hooks/query/taxRates.ts +++ b/packages/webapp/src/hooks/query/taxRates.ts @@ -37,10 +37,10 @@ export function useTaxRate(taxRateId: string, props) { [QUERY_TYPES.TAX_RATES, taxRateId], { method: 'get', - url: `tax-rates/${taxRateId}}`, + url: `tax-rates/${taxRateId}`, }, { - select: (res) => res.data.data, + select: (res) => res.data, ...props, }, ); @@ -106,7 +106,7 @@ export function useActivateTaxRate(props) { const queryClient = useQueryClient(); const apiRequest = useApiRequest(); - return useMutation((id) => apiRequest.post(`tax-rates/${id}/active`), { + return useMutation((id) => apiRequest.put(`tax-rates/${id}/activate`), { onSuccess: (res, id) => { commonInvalidateQueries(queryClient); queryClient.invalidateQueries([QUERY_TYPES.TAX_RATES, id]); @@ -122,7 +122,7 @@ export function useInactivateTaxRate(props) { const queryClient = useQueryClient(); const apiRequest = useApiRequest(); - return useMutation((id) => apiRequest.post(`tax-rates/${id}/inactive`), { + return useMutation((id) => apiRequest.put(`tax-rates/${id}/inactivate`), { onSuccess: (res, id) => { commonInvalidateQueries(queryClient); queryClient.invalidateQueries([QUERY_TYPES.TAX_RATES, id]);