5425 - Introducing support for all Composite Fields Import (#5470)
Adding support for all Composite Fields while using the "import" functionality. This includes: - Currency - Address Edit : - Refactored a lot of types in the spreadsheet import module - Renamed a lot of functions, hooks and types that were not self-explanatory enough --------- Co-authored-by: Charles Bochet <charles@twenty.com> Co-authored-by: Félix Malfait <felix.malfait@gmail.com> Co-authored-by: Lucas Bordeau <bordeau.lucas@gmail.com>
This commit is contained in:
@ -1,35 +1,17 @@
|
||||
import {
|
||||
convertCurrencyMicrosToCurrency,
|
||||
convertCurrencyToCurrencyMicros,
|
||||
} from '~/utils/convert-currency-amount';
|
||||
|
||||
describe('convertCurrencyToCurrencyMicros', () => {
|
||||
it('should return null if currencyAmount is null', () => {
|
||||
expect(convertCurrencyToCurrencyMicros(null)).toBeNull();
|
||||
});
|
||||
|
||||
it('should throw an error if currencyAmount converted to micros is not a whole number', () => {
|
||||
expect(() => convertCurrencyToCurrencyMicros(1.023)).toThrow(
|
||||
'Cannot convert 1.023 to micros',
|
||||
);
|
||||
});
|
||||
convertCurrencyAmountToCurrencyMicros,
|
||||
convertCurrencyMicrosToCurrencyAmount,
|
||||
} from '~/utils/convertCurrencyToCurrencyMicros';
|
||||
|
||||
describe('convertCurrencyAmountToCurrencyMicros', () => {
|
||||
it('should convert currencyAmount to micros', () => {
|
||||
expect(convertCurrencyToCurrencyMicros(1)).toBe(1000000);
|
||||
expect(convertCurrencyToCurrencyMicros(1.5)).toBe(1500000);
|
||||
expect(convertCurrencyAmountToCurrencyMicros(1)).toBe(1000000);
|
||||
expect(convertCurrencyAmountToCurrencyMicros(1.5)).toBe(1500000);
|
||||
});
|
||||
});
|
||||
|
||||
describe('convertCurrencyMicrosToCurrency', () => {
|
||||
it('should return null if currencyAmountMicros is null', () => {
|
||||
expect(convertCurrencyMicrosToCurrency(null)).toBeNull();
|
||||
});
|
||||
|
||||
it('should return null if currencyAmountMicros is undefined', () => {
|
||||
expect(convertCurrencyMicrosToCurrency(undefined)).toBeNull();
|
||||
});
|
||||
|
||||
describe('convertCurrencyMicrosToCurrencyAmount', () => {
|
||||
it('should convert currency micros to currency', () => {
|
||||
expect(convertCurrencyMicrosToCurrency(24000000)).toBe(24);
|
||||
expect(convertCurrencyMicrosToCurrencyAmount(24000000)).toBe(24);
|
||||
});
|
||||
});
|
||||
|
||||
3
packages/twenty-front/src/utils/castToString.ts
Normal file
3
packages/twenty-front/src/utils/castToString.ts
Normal file
@ -0,0 +1,3 @@
|
||||
export const castToString = (value: any) => {
|
||||
return String(value ?? '');
|
||||
};
|
||||
@ -1,29 +0,0 @@
|
||||
export const convertCurrencyToCurrencyMicros = (
|
||||
currencyAmount: number | null | undefined,
|
||||
) => {
|
||||
if (currencyAmount == null) {
|
||||
return null;
|
||||
}
|
||||
const currencyAmountAsNumber = +currencyAmount;
|
||||
if (isNaN(currencyAmountAsNumber)) {
|
||||
throw new Error(`Cannot convert ${currencyAmount} to micros`);
|
||||
}
|
||||
const currencyAmountAsMicros = currencyAmountAsNumber * 1000000;
|
||||
if (currencyAmountAsMicros % 1 !== 0) {
|
||||
throw new Error(`Cannot convert ${currencyAmount} to micros`);
|
||||
}
|
||||
return currencyAmountAsMicros;
|
||||
};
|
||||
|
||||
export const convertCurrencyMicrosToCurrency = (
|
||||
currencyAmountMicros: number | null | undefined,
|
||||
) => {
|
||||
if (currencyAmountMicros == null) {
|
||||
return null;
|
||||
}
|
||||
const currencyAmountMicrosAsNumber = +currencyAmountMicros;
|
||||
if (isNaN(currencyAmountMicrosAsNumber)) {
|
||||
throw new Error(`Cannot convert ${currencyAmountMicros} to currency`);
|
||||
}
|
||||
return currencyAmountMicrosAsNumber / 1000000;
|
||||
};
|
||||
@ -0,0 +1,13 @@
|
||||
export const convertCurrencyAmountToCurrencyMicros = (
|
||||
currencyAmount: number,
|
||||
) => {
|
||||
const currencyAmountAsMicros = currencyAmount * 1000000;
|
||||
|
||||
return currencyAmountAsMicros;
|
||||
};
|
||||
|
||||
export const convertCurrencyMicrosToCurrencyAmount = (
|
||||
currencyAmountMicros: number,
|
||||
) => {
|
||||
return currencyAmountMicros / 1000000;
|
||||
};
|
||||
5
packages/twenty-front/src/utils/isValidUuid.ts
Normal file
5
packages/twenty-front/src/utils/isValidUuid.ts
Normal file
@ -0,0 +1,5 @@
|
||||
export const isValidUuid = (value: string) => {
|
||||
return /^[0-9A-F]{8}-[0-9A-F]{4}-[4][0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i.test(
|
||||
value,
|
||||
);
|
||||
};
|
||||
Reference in New Issue
Block a user