mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-19 14:20:31 +00:00
feat(webapp): invoice tax rate
This commit is contained in:
22
packages/webapp/src/hooks/query/taxRates.ts
Normal file
22
packages/webapp/src/hooks/query/taxRates.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
// @ts-nocheck
|
||||
import { useRequestQuery } from '../useQueryRequest';
|
||||
import QUERY_TYPES from './types';
|
||||
|
||||
/**
|
||||
* Retrieves tax rates.
|
||||
* @param {number} customerId - Customer id.
|
||||
*/
|
||||
export function useTaxRates(props) {
|
||||
return useRequestQuery(
|
||||
[QUERY_TYPES.TAX_RATES],
|
||||
{
|
||||
method: 'get',
|
||||
url: `tax-rates`,
|
||||
},
|
||||
{
|
||||
select: (res) => res.data.data,
|
||||
defaultData: [],
|
||||
...props,
|
||||
},
|
||||
);
|
||||
}
|
||||
@@ -224,6 +224,10 @@ const ORGANIZATION = {
|
||||
ORGANIZATION_MUTATE_BASE_CURRENCY_ABILITIES: 'ORGANIZATION_MUTATE_BASE_CURRENCY_ABILITIES',
|
||||
};
|
||||
|
||||
export const TAX_RATES = {
|
||||
TAX_RATES: 'TAX_RATES',
|
||||
}
|
||||
|
||||
export default {
|
||||
...Authentication,
|
||||
...ACCOUNTS,
|
||||
@@ -257,4 +261,5 @@ export default {
|
||||
...BRANCHES,
|
||||
...DASHBOARD,
|
||||
...ORGANIZATION,
|
||||
...TAX_RATES
|
||||
};
|
||||
|
||||
36
packages/webapp/src/hooks/useUncontrolled.ts
Normal file
36
packages/webapp/src/hooks/useUncontrolled.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import React, { useState } from 'react';
|
||||
|
||||
interface UseUncontrolledInput<T> {
|
||||
/** Value for controlled state */
|
||||
value?: T;
|
||||
|
||||
/** Initial value for uncontrolled state */
|
||||
initialValue?: T;
|
||||
|
||||
/** Final value for uncontrolled state when value and initialValue are not provided */
|
||||
finalValue?: T;
|
||||
|
||||
/** Controlled state onChange handler */
|
||||
onChange?(value: T): void;
|
||||
}
|
||||
|
||||
export function useUncontrolled<T>({
|
||||
value,
|
||||
initialValue,
|
||||
finalValue,
|
||||
onChange = () => {},
|
||||
}: UseUncontrolledInput<T>) {
|
||||
const [uncontrolledValue, setUncontrolledValue] = useState(
|
||||
initialValue !== undefined ? initialValue : finalValue,
|
||||
);
|
||||
|
||||
const handleUncontrolledChange = (val: T) => {
|
||||
setUncontrolledValue(val);
|
||||
onChange?.(val);
|
||||
};
|
||||
|
||||
if (value !== undefined) {
|
||||
return [value as T, onChange, true];
|
||||
}
|
||||
return [uncontrolledValue as T, handleUncontrolledChange, false];
|
||||
}
|
||||
Reference in New Issue
Block a user