Skip to content

Commit

Permalink
Merge pull request #693 from bigcapitalhq/fix-display-country-name
Browse files Browse the repository at this point in the history
fix: Display country name
  • Loading branch information
abouolia authored Oct 6, 2024
2 parents 75ec315 + df9d277 commit 1846480
Show file tree
Hide file tree
Showing 15 changed files with 659 additions and 65 deletions.
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,8 @@
"hooks": {
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
}
},
"dependencies": {
"tsup": "^8.3.0"
}
}
1 change: 1 addition & 0 deletions packages/bigcapital-utils/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/dist
22 changes: 22 additions & 0 deletions packages/bigcapital-utils/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "@bigcapital/utils",
"version": "1.0.0",
"description": "",
"main": "./dist/index.js",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"exports": {
".": {
"require": "./dist/index.js",
"import": "./dist/index.mjs"
}
},
"scripts": {
"build:cjs": "tsup src/index.ts --format cjs --dts --sourcemap",
"build:esm": "tsup src/index.ts --format esm --dts --sourcemap",
"build": "npm run build:cjs && npm run build:esm",
"dev": "npm run build -- --watch"
},
"author": "",
"license": "ISC"
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,4 @@
interface Country {
name: string;
native: string;
phone: number[];
continent: string;
continents?: string[];
capital: string;
currency: string[];
languages: string[];
}
import { Country } from './types';

export const Countries: Record<string, Country> = {
AD: {
Expand Down
20 changes: 20 additions & 0 deletions packages/bigcapital-utils/src/countries/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Countries } from './constant';
import { Country, Maybe } from './types';

export const getAllCountries = () => {
return Object.keys(Countries).map((countryCode) => {
return {
...Countries[countryCode],
countryCode,
};
});
};

export const findByIsoCountryCode = (
isoCode: string
): Maybe<Country & { countryCode: string }> => {
const _isoCode = isoCode?.toUpperCase();
const country = Countries[_isoCode];

return country ? { ...country, countryCode: isoCode } : null;
};
12 changes: 12 additions & 0 deletions packages/bigcapital-utils/src/countries/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export interface Country {
name: string;
native: string;
phone: number[];
continent: string;
continents?: string[];
capital: string;
currency: string[];
languages: string[];
}

export type Maybe<T> = T | null;
3 changes: 3 additions & 0 deletions packages/bigcapital-utils/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './countries';

export const test = () => {};
17 changes: 17 additions & 0 deletions packages/bigcapital-utils/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"compilerOptions": {
"target": "ES6", // Equivalent to ES6 output
"module": "ESNext", // CommonJS for Node.js compatibility
"outDir": "dist", // Output directory for compiled files
"declaration": true, // Generates .d.ts files (same as dts: true)
"declarationDir": "dist", // Specifies where to output declaration files
"sourceMap": true, // Generate sourcemaps
"esModuleInterop": true, // Enables interop between CommonJS and ESModules
"strict": true, // Enables strict type-checking options
"moduleResolution": "node", // Resolve modules using Node.js-style resolution
"skipLibCheck": true, // Skip type checking of declaration files
"forceConsistentCasingInFileNames": true // Enforces consistent casing in import paths
},
"include": ["src/**/*"], // Includes all TypeScript files in the src directory
"exclude": ["node_modules"] // Excludes node_modules from being compiled
}
1 change: 1 addition & 0 deletions packages/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"dependencies": {
"@aws-sdk/client-s3": "^3.576.0",
"@aws-sdk/s3-request-presigner": "^3.583.0",
"@bigcapital/utils": "*",
"@casl/ability": "^5.4.3",
"@hapi/boom": "^7.4.3",
"@lemonsqueezy/lemonsqueezy.js": "^2.2.0",
Expand Down
5 changes: 4 additions & 1 deletion packages/server/src/system/models/TenantMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
organizationAddressTextFormat,
} from '@/utils/address-text-format';
import BaseModel from 'models/Model';
import { findByIsoCountryCode } from '@bigcapital/utils';
import { getUploadedObjectUri } from '../../services/Attachments/utils';

export default class TenantMetadata extends BaseModel {
Expand Down Expand Up @@ -70,6 +71,8 @@ export default class TenantMetadata extends BaseModel {
* @returns {string}
*/
public get addressTextFormatted() {
const addressCountry = findByIsoCountryCode(this.location);

return organizationAddressTextFormat(defaultOrganizationAddressFormat, {
organizationName: this.name,
address1: this.address?.address1,
Expand All @@ -78,7 +81,7 @@ export default class TenantMetadata extends BaseModel {
city: this.address?.city,
postalCode: this.address?.postalCode,
phone: this.address?.phone,
country: 'United State',
country: addressCountry?.name ?? '',
});
}
}
1 change: 1 addition & 0 deletions packages/webapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "0.10.2",
"private": true,
"dependencies": {
"@bigcapital/utils": "*",
"@blueprintjs-formik/core": "^0.3.6",
"@blueprintjs-formik/datetime": "^0.3.7",
"@blueprintjs-formik/select": "^0.3.5",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Button, FormGroup, Intent } from '@blueprintjs/core';
import { TimezonePicker } from '@blueprintjs/timezone';
import { ErrorMessage, FastField } from 'formik';
import { useHistory } from 'react-router-dom';
import { getAllCountries } from '@bigcapital/utils';

import {
FieldRequiredHint,
Expand All @@ -23,7 +24,6 @@ import { getAllCurrenciesOptions } from '@/constants/currencies';
import { getFiscalYear } from '@/constants/fiscalYearOptions';
import { getLanguages } from '@/constants/languagesOptions';
import { useGeneralFormContext } from './GeneralFormProvider';
import { getAllCountries } from '@/utils/countries';

import { shouldBaseCurrencyUpdate } from './utils';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { FastField, Form, ErrorMessage } from 'formik';
import { Button, Intent, FormGroup, Classes } from '@blueprintjs/core';
import classNames from 'classnames';
import { TimezonePicker } from '@blueprintjs/timezone';
import { getAllCountries } from '@bigcapital/utils';
import {
FFormGroup,
FInputGroup,
Expand All @@ -17,7 +18,6 @@ import { inputIntent } from '@/utils';
import { getFiscalYear } from '@/constants/fiscalYearOptions';
import { getLanguages } from '@/constants/languagesOptions';
import { getAllCurrenciesOptions } from '@/constants/currencies';
import { getAllCountries } from '@/utils/countries';

const countries = getAllCountries();

Expand Down
10 changes: 0 additions & 10 deletions packages/webapp/src/utils/countries.tsx

This file was deleted.

Loading

0 comments on commit 1846480

Please sign in to comment.