Compare commits
13 Commits
date-forma
...
fix-gettin
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f92acbcbe0 | ||
|
|
c986585cd9 | ||
|
|
250f0a30ef | ||
|
|
84b5e1adc1 | ||
|
|
2ab28370db | ||
|
|
a88a525326 | ||
|
|
fce8e2c5a4 | ||
|
|
095608266c | ||
|
|
0ec8aaa330 | ||
|
|
9fcb3ef77d | ||
|
|
dc61c57daf | ||
|
|
af284f3f6d | ||
|
|
c9fe6d9b37 |
@@ -2,6 +2,7 @@ import moment from 'moment';
|
||||
import * as R from 'ramda';
|
||||
import { includes, isFunction, isObject, isUndefined, omit } from 'lodash';
|
||||
import { formatNumber, sortObjectKeysAlphabetically } from 'utils';
|
||||
import { EXPORT_DTE_FORMAT } from '@/services/Export/constants';
|
||||
|
||||
export class Transformer {
|
||||
public context: any;
|
||||
@@ -156,22 +157,34 @@ export class Transformer {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param date
|
||||
* @returns
|
||||
* Format date.
|
||||
* @param {} date
|
||||
* @param {string} format -
|
||||
* @returns {}
|
||||
*/
|
||||
protected formatDate(date) {
|
||||
return date ? moment(date).format(this.dateFormat) : '';
|
||||
protected formatDate(date, format?: string) {
|
||||
// Use the export date format if the async operation is in exporting,
|
||||
// otherwise use the given or default format.
|
||||
const _format = this.context.exportAls.isExport
|
||||
? EXPORT_DTE_FORMAT
|
||||
: format || this.dateFormat;
|
||||
|
||||
return date ? moment(date).format(_format) : '';
|
||||
}
|
||||
|
||||
protected formatDateFromNow(date){
|
||||
/**
|
||||
*
|
||||
* @param date
|
||||
* @returns {}
|
||||
*/
|
||||
protected formatDateFromNow(date) {
|
||||
return date ? moment(date).fromNow(true) : '';
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param number
|
||||
* @returns
|
||||
* @returns {}
|
||||
*/
|
||||
protected formatNumber(number, props?) {
|
||||
return formatNumber(number, { money: false, ...props });
|
||||
@@ -181,7 +194,7 @@ export class Transformer {
|
||||
*
|
||||
* @param money
|
||||
* @param options
|
||||
* @returns
|
||||
* @returns {}
|
||||
*/
|
||||
protected formatMoney(money, options?) {
|
||||
return formatNumber(money, {
|
||||
|
||||
@@ -3,12 +3,17 @@ import { isNull } from 'lodash';
|
||||
import HasTenancyService from '@/services/Tenancy/TenancyService';
|
||||
import { TenantMetadata } from '@/system/models';
|
||||
import { Transformer } from './Transformer';
|
||||
import { ImportAls } from '@/services/Import/ImportALS';
|
||||
import { ExportAls } from '@/services/Export/ExportAls';
|
||||
|
||||
@Service()
|
||||
export class TransformerInjectable {
|
||||
@Inject()
|
||||
private tenancy: HasTenancyService;
|
||||
|
||||
@Inject()
|
||||
private exportAls: ExportAls;
|
||||
|
||||
/**
|
||||
* Retrieves the application context of all tenant transformers.
|
||||
* @param {number} tenantId
|
||||
@@ -17,10 +22,12 @@ export class TransformerInjectable {
|
||||
async getApplicationContext(tenantId: number) {
|
||||
const i18n = this.tenancy.i18n(tenantId);
|
||||
const organization = await TenantMetadata.query().findOne({ tenantId });
|
||||
const exportAls = this.exportAls;
|
||||
|
||||
return {
|
||||
organization,
|
||||
i18n,
|
||||
exportAls,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -95,6 +95,11 @@ export default {
|
||||
},
|
||||
},
|
||||
columns: {
|
||||
customerType: {
|
||||
name: 'Customer Type',
|
||||
type: 'text',
|
||||
accessor: 'formattedCustomerType',
|
||||
},
|
||||
firstName: {
|
||||
name: 'vendor.field.first_name',
|
||||
type: 'text',
|
||||
@@ -135,116 +140,117 @@ export default {
|
||||
openingBalance: {
|
||||
name: 'vendor.field.opening_balance',
|
||||
type: 'number',
|
||||
printable: false
|
||||
printable: false,
|
||||
},
|
||||
openingBalanceAt: {
|
||||
name: 'vendor.field.opening_balance_at',
|
||||
type: 'date',
|
||||
printable: false
|
||||
printable: false,
|
||||
accessor: 'formattedOpeningBalanceAt'
|
||||
},
|
||||
currencyCode: {
|
||||
name: 'vendor.field.currency',
|
||||
type: 'text',
|
||||
printable: false
|
||||
printable: false,
|
||||
},
|
||||
status: {
|
||||
name: 'vendor.field.status',
|
||||
printable: false
|
||||
printable: false,
|
||||
},
|
||||
note: {
|
||||
name: 'vendor.field.note',
|
||||
printable: false
|
||||
printable: false,
|
||||
},
|
||||
// Billing Address
|
||||
billingAddress1: {
|
||||
name: 'Billing Address 1',
|
||||
column: 'billing_address1',
|
||||
type: 'text',
|
||||
printable: false
|
||||
printable: false,
|
||||
},
|
||||
billingAddress2: {
|
||||
name: 'Billing Address 2',
|
||||
column: 'billing_address2',
|
||||
type: 'text',
|
||||
printable: false
|
||||
printable: false,
|
||||
},
|
||||
billingAddressCity: {
|
||||
name: 'Billing Address City',
|
||||
column: 'billing_address_city',
|
||||
type: 'text',
|
||||
printable: false
|
||||
printable: false,
|
||||
},
|
||||
billingAddressCountry: {
|
||||
name: 'Billing Address Country',
|
||||
column: 'billing_address_country',
|
||||
type: 'text',
|
||||
printable: false
|
||||
printable: false,
|
||||
},
|
||||
billingAddressPostcode: {
|
||||
name: 'Billing Address Postcode',
|
||||
column: 'billing_address_postcode',
|
||||
type: 'text',
|
||||
printable: false
|
||||
printable: false,
|
||||
},
|
||||
billingAddressState: {
|
||||
name: 'Billing Address State',
|
||||
column: 'billing_address_state',
|
||||
type: 'text',
|
||||
printable: false
|
||||
printable: false,
|
||||
},
|
||||
billingAddressPhone: {
|
||||
name: 'Billing Address Phone',
|
||||
column: 'billing_address_phone',
|
||||
type: 'text',
|
||||
printable: false
|
||||
printable: false,
|
||||
},
|
||||
// Shipping Address
|
||||
shippingAddress1: {
|
||||
name: 'Shipping Address 1',
|
||||
column: 'shipping_address1',
|
||||
type: 'text',
|
||||
printable: false
|
||||
printable: false,
|
||||
},
|
||||
shippingAddress2: {
|
||||
name: 'Shipping Address 2',
|
||||
column: 'shipping_address2',
|
||||
type: 'text',
|
||||
printable: false
|
||||
printable: false,
|
||||
},
|
||||
shippingAddressCity: {
|
||||
name: 'Shipping Address City',
|
||||
column: 'shipping_address_city',
|
||||
type: 'text',
|
||||
printable: false
|
||||
printable: false,
|
||||
},
|
||||
shippingAddressCountry: {
|
||||
name: 'Shipping Address Country',
|
||||
column: 'shipping_address_country',
|
||||
type: 'text',
|
||||
printable: false
|
||||
printable: false,
|
||||
},
|
||||
shippingAddressPostcode: {
|
||||
name: 'Shipping Address Postcode',
|
||||
column: 'shipping_address_postcode',
|
||||
type: 'text',
|
||||
printable: false
|
||||
printable: false,
|
||||
},
|
||||
shippingAddressPhone: {
|
||||
name: 'Shipping Address Phone',
|
||||
column: 'shipping_address_phone',
|
||||
type: 'text',
|
||||
printable: false
|
||||
printable: false,
|
||||
},
|
||||
shippingAddressState: {
|
||||
name: 'Shipping Address State',
|
||||
column: 'shipping_address_state',
|
||||
type: 'text',
|
||||
printable: false
|
||||
printable: false,
|
||||
},
|
||||
createdAt: {
|
||||
name: 'vendor.field.created_at',
|
||||
type: 'date',
|
||||
printable: false
|
||||
printable: false,
|
||||
},
|
||||
},
|
||||
fields2: {
|
||||
|
||||
48
packages/server/src/services/Export/ExportAls.ts
Normal file
48
packages/server/src/services/Export/ExportAls.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
import { Service } from 'typedi';
|
||||
import { AsyncLocalStorage } from 'async_hooks';
|
||||
|
||||
@Service()
|
||||
export class ExportAls {
|
||||
private als: AsyncLocalStorage<Map<string, any>>;
|
||||
|
||||
constructor() {
|
||||
this.als = new AsyncLocalStorage();
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs a callback function within the context of a new AsyncLocalStorage store.
|
||||
* @param callback The function to be executed within the AsyncLocalStorage context.
|
||||
* @returns The result of the callback function.
|
||||
*/
|
||||
public run<T>(callback: () => T): T {
|
||||
return this.als.run<T>(new Map(), () => {
|
||||
this.markAsExport();
|
||||
|
||||
return callback();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the current AsyncLocalStorage store.
|
||||
* @returns The current store or undefined if not in a valid context.
|
||||
*/
|
||||
public getStore(): Map<string, any> | undefined {
|
||||
return this.als.getStore();
|
||||
}
|
||||
|
||||
/**
|
||||
* Marks the current context as an export operation.
|
||||
* @param flag Boolean flag to set or unset the export status. Defaults to true.
|
||||
*/
|
||||
public markAsExport(flag: boolean = true): void {
|
||||
const store = this.getStore();
|
||||
store?.set('isExport', flag);
|
||||
}
|
||||
/**
|
||||
* Checks if the current context is an export operation.
|
||||
* @returns {boolean} True if the context is an export operation, false otherwise.
|
||||
*/
|
||||
public get isExport(): boolean {
|
||||
return !!this.getStore()?.get('isExport');
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,7 @@ import { Errors, ExportFormat } from './common';
|
||||
import { IModelMeta, IModelMetaColumn } from '@/interfaces';
|
||||
import { flatDataCollections, getDataAccessor } from './utils';
|
||||
import { ExportPdf } from './ExportPdf';
|
||||
import { ExportAls } from './ExportAls';
|
||||
|
||||
@Service()
|
||||
export class ExportResourceService {
|
||||
@@ -22,13 +23,33 @@ export class ExportResourceService {
|
||||
@Inject()
|
||||
private exportPdf: ExportPdf;
|
||||
|
||||
@Inject()
|
||||
private exportAls: ExportAls;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {number} tenantId
|
||||
* @param {string} resourceName
|
||||
* @param {ExportFormat} format
|
||||
* @returns
|
||||
*/
|
||||
public async export(
|
||||
tenantId: number,
|
||||
resourceName: string,
|
||||
format: ExportFormat = ExportFormat.Csv
|
||||
) {
|
||||
return this.exportAls.run(() =>
|
||||
this.exportAlsRun(tenantId, resourceName, format)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Exports the given resource data through csv, xlsx or pdf.
|
||||
* @param {number} tenantId - Tenant id.
|
||||
* @param {string} resourceName - Resource name.
|
||||
* @param {ExportFormat} format - File format.
|
||||
*/
|
||||
public async export(
|
||||
public async exportAlsRun(
|
||||
tenantId: number,
|
||||
resourceName: string,
|
||||
format: ExportFormat = ExportFormat.Csv
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
export const EXPORT_SIZE_LIMIT = 9999999;
|
||||
export const EXPORT_SIZE_LIMIT = 9999999;
|
||||
export const EXPORT_DTE_FORMAT = 'YYYY-MM-DD';
|
||||
|
||||
@@ -8,6 +8,7 @@ export class ImportAls {
|
||||
constructor() {
|
||||
this.als = new AsyncLocalStorage();
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs a callback function within the context of a new AsyncLocalStorage store.
|
||||
* @param callback The function to be executed within the AsyncLocalStorage context.
|
||||
@@ -82,7 +83,7 @@ export class ImportAls {
|
||||
* Checks if the current context is an import operation.
|
||||
* @returns {boolean} True if the context is an import operation, false otherwise.
|
||||
*/
|
||||
public isImport(): boolean {
|
||||
public get isImport(): boolean {
|
||||
return !!this.getStore()?.get('isImport');
|
||||
}
|
||||
|
||||
@@ -90,7 +91,7 @@ export class ImportAls {
|
||||
* Checks if the current context is an import commit operation.
|
||||
* @returns {boolean} True if the context is an import commit operation, false otherwise.
|
||||
*/
|
||||
public isImportCommit(): boolean {
|
||||
public get isImportCommit(): boolean {
|
||||
return !!this.getStore()?.get('isImportCommit');
|
||||
}
|
||||
|
||||
@@ -98,7 +99,7 @@ export class ImportAls {
|
||||
* Checks if the current context is an import preview operation.
|
||||
* @returns {boolean} True if the context is an import preview operation, false otherwise.
|
||||
*/
|
||||
public isImportPreview(): boolean {
|
||||
public get isImportPreview(): boolean {
|
||||
return !!this.getStore()?.get('isImportPreview');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import XLSX from 'xlsx';
|
||||
import bluebird from 'bluebird';
|
||||
import * as R from 'ramda';
|
||||
import { Inject, Service } from 'typedi';
|
||||
@@ -27,23 +26,7 @@ export class ImportFileCommon {
|
||||
|
||||
@Inject()
|
||||
private resource: ResourceService;
|
||||
|
||||
/**
|
||||
* Maps the columns of the imported data based on the provided mapping attributes.
|
||||
* @param {Record<string, any>[]} body - The array of data objects to map.
|
||||
* @param {ImportMappingAttr[]} map - The mapping attributes.
|
||||
* @returns {Record<string, any>[]} - The mapped data objects.
|
||||
*/
|
||||
public parseXlsxSheet(buffer: Buffer): Record<string, unknown>[] {
|
||||
const workbook = XLSX.read(buffer, { type: 'buffer', raw: true });
|
||||
|
||||
const firstSheetName = workbook.SheetNames[0];
|
||||
const worksheet = workbook.Sheets[firstSheetName];
|
||||
|
||||
return XLSX.utils.sheet_to_json(worksheet, {});
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Imports the given parsed data to the resource storage through registered importable service.
|
||||
* @param {number} tenantId -
|
||||
|
||||
@@ -2,18 +2,14 @@ import { Inject, Service } from 'typedi';
|
||||
import { chain } from 'lodash';
|
||||
import { Knex } from 'knex';
|
||||
import { ServiceError } from '@/exceptions';
|
||||
import {
|
||||
ERRORS,
|
||||
getSheetColumns,
|
||||
getUnmappedSheetColumns,
|
||||
readImportFile,
|
||||
} from './_utils';
|
||||
import { ERRORS, getUnmappedSheetColumns, readImportFile } from './_utils';
|
||||
import { ImportFileCommon } from './ImportFileCommon';
|
||||
import { ImportFileDataTransformer } from './ImportFileDataTransformer';
|
||||
import ResourceService from '../Resource/ResourceService';
|
||||
import UnitOfWork from '../UnitOfWork';
|
||||
import { ImportFilePreviewPOJO } from './interfaces';
|
||||
import { Import } from '@/system/models';
|
||||
import { parseSheetData } from './sheet_utils';
|
||||
|
||||
@Service()
|
||||
export class ImportFileProcess {
|
||||
@@ -49,10 +45,10 @@ export class ImportFileProcess {
|
||||
if (!importFile.isMapped) {
|
||||
throw new ServiceError(ERRORS.IMPORT_FILE_NOT_MAPPED);
|
||||
}
|
||||
// Read the imported file.
|
||||
// Read the imported file and parse the given buffer to get columns
|
||||
// and sheet data in json format.
|
||||
const buffer = await readImportFile(importFile.filename);
|
||||
const sheetData = this.importCommon.parseXlsxSheet(buffer);
|
||||
const header = getSheetColumns(sheetData);
|
||||
const [sheetData, sheetColumns] = parseSheetData(buffer);
|
||||
|
||||
const resource = importFile.resource;
|
||||
const resourceFields = this.resource.getResourceFields2(tenantId, resource);
|
||||
@@ -87,7 +83,7 @@ export class ImportFileProcess {
|
||||
.flatten()
|
||||
.value();
|
||||
|
||||
const unmappedColumns = getUnmappedSheetColumns(header, mapping);
|
||||
const unmappedColumns = getUnmappedSheetColumns(sheetColumns, mapping);
|
||||
const totalCount = allData.length;
|
||||
|
||||
const createdCount = successedImport.length;
|
||||
|
||||
@@ -11,6 +11,7 @@ import { ImportFileCommon } from './ImportFileCommon';
|
||||
import { ImportFileDataValidator } from './ImportFileDataValidator';
|
||||
import { ImportFileUploadPOJO } from './interfaces';
|
||||
import { Import } from '@/system/models';
|
||||
import { parseSheetData } from './sheet_utils';
|
||||
|
||||
@Service()
|
||||
export class ImportFileUploadService {
|
||||
@@ -77,14 +78,12 @@ export class ImportFileUploadService {
|
||||
const buffer = await readImportFile(filename);
|
||||
|
||||
// Parse the buffer file to array data.
|
||||
const sheetData = this.importFileCommon.parseXlsxSheet(buffer);
|
||||
const [sheetData, sheetColumns] = parseSheetData(buffer);
|
||||
const coumnsStringified = JSON.stringify(sheetColumns);
|
||||
|
||||
// Throws service error if the sheet data is empty.
|
||||
validateSheetEmpty(sheetData);
|
||||
|
||||
const sheetColumns = this.importFileCommon.parseSheetColumns(sheetData);
|
||||
const coumnsStringified = JSON.stringify(sheetColumns);
|
||||
|
||||
try {
|
||||
// Validates the params Yup schema.
|
||||
await this.importFileCommon.validateParamsSchema(resource, params);
|
||||
|
||||
56
packages/server/src/services/Import/sheet_utils.ts
Normal file
56
packages/server/src/services/Import/sheet_utils.ts
Normal file
@@ -0,0 +1,56 @@
|
||||
import XLSX from 'xlsx';
|
||||
import { first } from 'lodash';
|
||||
|
||||
/**
|
||||
* Parses the given sheet buffer to worksheet.
|
||||
* @param {Buffer} buffer
|
||||
* @returns {XLSX.WorkSheet}
|
||||
*/
|
||||
export function parseFirstSheet(buffer: Buffer): XLSX.WorkSheet {
|
||||
const workbook = XLSX.read(buffer, { type: 'buffer', raw: true });
|
||||
|
||||
const firstSheetName = workbook.SheetNames[0];
|
||||
const worksheet = workbook.Sheets[firstSheetName];
|
||||
|
||||
return worksheet;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts the given worksheet to columns.
|
||||
* @param {XLSX.WorkSheet} worksheet
|
||||
* @returns {Array<string>}
|
||||
*/
|
||||
export function extractSheetColumns(worksheet: XLSX.WorkSheet): Array<string> {
|
||||
// By default, sheet_to_json scans the first row and uses the values as headers.
|
||||
// With the header: 1 option, the function exports an array of arrays of values.
|
||||
const sheetCells = XLSX.utils.sheet_to_json(worksheet, { header: 1 });
|
||||
const sheetCols = first(sheetCells) as Array<string>;
|
||||
|
||||
return sheetCols.filter((col) => col);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the given worksheet to json values. the keys are columns labels.
|
||||
* @param {XLSX.WorkSheet} worksheet
|
||||
* @returns {Array<Record<string, string>>}
|
||||
*/
|
||||
export function parseSheetToJson(
|
||||
worksheet: XLSX.WorkSheet
|
||||
): Array<Record<string, string>> {
|
||||
return XLSX.utils.sheet_to_json(worksheet, {});
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the given sheet buffer then retrieves the sheet data and columns.
|
||||
* @param {Buffer} buffer
|
||||
*/
|
||||
export function parseSheetData(
|
||||
buffer: Buffer
|
||||
): [Array<Record<string, string>>, string[]] {
|
||||
const worksheet = parseFirstSheet(buffer);
|
||||
|
||||
const columns = extractSheetColumns(worksheet);
|
||||
const data = parseSheetToJson(worksheet);
|
||||
|
||||
return [data, columns];
|
||||
}
|
||||
@@ -92,7 +92,7 @@ export default class InventorySubscriber {
|
||||
inventoryTransactions,
|
||||
trx,
|
||||
}: IInventoryTransactionsCreatedPayload) => {
|
||||
const inImportPreviewScope = this.importAls.isImportPreview();
|
||||
const inImportPreviewScope = this.importAls.isImportPreview;
|
||||
|
||||
// Avoid running the cost items job if the async process is in import preview.
|
||||
if (inImportPreviewScope) return;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
// @ts-nocheck
|
||||
import { lazy, Suspense } from 'react';
|
||||
import { Router, Switch, Route } from 'react-router';
|
||||
import { createBrowserHistory } from 'history';
|
||||
import { QueryClientProvider, QueryClient } from 'react-query';
|
||||
@@ -11,25 +12,26 @@ import 'moment/locale/es-us';
|
||||
import AppIntlLoader from './AppIntlLoader';
|
||||
import { EnsureAuthenticated } from '@/components/Guards/EnsureAuthenticated';
|
||||
import GlobalErrors from '@/containers/GlobalErrors/GlobalErrors';
|
||||
import DashboardPrivatePages from '@/components/Dashboard/PrivatePages';
|
||||
import { Authentication } from '@/containers/Authentication/Authentication';
|
||||
|
||||
import LazyLoader from '@/components/LazyLoader';
|
||||
import { SplashScreen, DashboardThemeProvider } from '../components';
|
||||
import { queryConfig } from '../hooks/query/base';
|
||||
import { EnsureUserEmailVerified } from './Guards/EnsureUserEmailVerified';
|
||||
import { EnsureAuthNotAuthenticated } from './Guards/EnsureAuthNotAuthenticated';
|
||||
import { EnsureUserEmailNotVerified } from './Guards/EnsureUserEmailNotVerified';
|
||||
|
||||
const EmailConfirmation = LazyLoader({
|
||||
loader: () => import('@/containers/Authentication/EmailConfirmation'),
|
||||
});
|
||||
const RegisterVerify = LazyLoader({
|
||||
loader: () => import('@/containers/Authentication/RegisterVerify'),
|
||||
});
|
||||
const OneClickDemoPage = LazyLoader({
|
||||
loader: () => import('@/containers/OneClickDemo/OneClickDemoPage'),
|
||||
});
|
||||
const DashboardPrivatePages = lazy(
|
||||
() => import('@/components/Dashboard/PrivatePages'),
|
||||
);
|
||||
const AuthenticationPage = lazy(
|
||||
() => import('@/containers/Authentication/AuthenticationPage'),
|
||||
);
|
||||
const EmailConfirmation = lazy(
|
||||
() => import('@/containers/Authentication/EmailConfirmation'),
|
||||
);
|
||||
const RegisterVerify = lazy(
|
||||
() => import('@/containers/Authentication/RegisterVerify'),
|
||||
);
|
||||
const OneClickDemoPage = lazy(
|
||||
() => import('@/containers/OneClickDemo/OneClickDemoPage'),
|
||||
);
|
||||
|
||||
/**
|
||||
* App inner.
|
||||
@@ -38,36 +40,27 @@ function AppInsider({ history }) {
|
||||
return (
|
||||
<div className="App">
|
||||
<DashboardThemeProvider>
|
||||
<Router history={history}>
|
||||
<Switch>
|
||||
<Route path={'/one_click_demo'} children={<OneClickDemoPage />} />
|
||||
<Route path={'/auth/register/verify'}>
|
||||
<EnsureAuthenticated>
|
||||
<EnsureUserEmailNotVerified>
|
||||
<RegisterVerify />
|
||||
</EnsureUserEmailNotVerified>
|
||||
</EnsureAuthenticated>
|
||||
</Route>
|
||||
<Suspense fallback={'Loading...'}>
|
||||
<Router history={history}>
|
||||
<Switch>
|
||||
<Route path={'/one_click_demo'} children={<OneClickDemoPage />} />
|
||||
<Route path={'/auth/register/verify'}>
|
||||
<EnsureAuthenticated>
|
||||
<EnsureUserEmailNotVerified>
|
||||
<RegisterVerify />
|
||||
</EnsureUserEmailNotVerified>
|
||||
</EnsureAuthenticated>
|
||||
</Route>
|
||||
|
||||
<Route path={'/auth/email_confirmation'}>
|
||||
<EmailConfirmation />
|
||||
</Route>
|
||||
|
||||
<Route path={'/auth'}>
|
||||
<EnsureAuthNotAuthenticated>
|
||||
<Authentication />
|
||||
</EnsureAuthNotAuthenticated>
|
||||
</Route>
|
||||
|
||||
<Route path={'/'}>
|
||||
<EnsureAuthenticated>
|
||||
<EnsureUserEmailVerified>
|
||||
<DashboardPrivatePages />
|
||||
</EnsureUserEmailVerified>
|
||||
</EnsureAuthenticated>
|
||||
</Route>
|
||||
</Switch>
|
||||
</Router>
|
||||
<Route
|
||||
path={'/auth/email_confirmation'}
|
||||
children={<EmailConfirmation />}
|
||||
/>
|
||||
<Route path={'/auth'} children={<AuthenticationPage />} />
|
||||
<Route path={'/'} children={<DashboardPrivatePages />} />
|
||||
</Switch>
|
||||
</Router>
|
||||
</Suspense>
|
||||
|
||||
<GlobalErrors />
|
||||
</DashboardThemeProvider>
|
||||
|
||||
@@ -1,35 +1,37 @@
|
||||
// @ts-nocheck
|
||||
import React from 'react';
|
||||
import React, { lazy } from 'react';
|
||||
import { Switch, Route } from 'react-router';
|
||||
|
||||
import Dashboard from '@/components/Dashboard/Dashboard';
|
||||
import SetupWizardPage from '@/containers/Setup/WizardSetupPage';
|
||||
|
||||
import EnsureOrganizationIsReady from '../Guards/EnsureOrganizationIsReady';
|
||||
import EnsureOrganizationIsNotReady from '../Guards/EnsureOrganizationIsNotReady';
|
||||
import { PrivatePagesProvider } from './PrivatePagesProvider';
|
||||
import EnsureOrganizationIsReady from '../Guards/EnsureOrganizationIsReady';
|
||||
import { EnsureAuthenticated } from '../Guards/EnsureAuthenticated';
|
||||
import { EnsureUserEmailVerified } from '../Guards/EnsureUserEmailVerified';
|
||||
|
||||
import '@/style/pages/Dashboard/Dashboard.scss';
|
||||
|
||||
const SetupWizardPage = lazy(
|
||||
() => import('@/containers/Setup/WizardSetupPage'),
|
||||
);
|
||||
/**
|
||||
* Dashboard inner private pages.
|
||||
*/
|
||||
export default function DashboardPrivatePages() {
|
||||
return (
|
||||
<PrivatePagesProvider>
|
||||
<Switch>
|
||||
<Route path={'/setup'}>
|
||||
<EnsureOrganizationIsNotReady>
|
||||
<SetupWizardPage />
|
||||
</EnsureOrganizationIsNotReady>
|
||||
</Route>
|
||||
|
||||
<Route path="/">
|
||||
<EnsureOrganizationIsReady>
|
||||
<Dashboard />
|
||||
</EnsureOrganizationIsReady>
|
||||
</Route>
|
||||
</Switch>
|
||||
</PrivatePagesProvider>
|
||||
<EnsureAuthenticated>
|
||||
<EnsureUserEmailVerified>
|
||||
<PrivatePagesProvider>
|
||||
<Switch>
|
||||
<Route path={'/setup'} children={<SetupWizardPage />} />
|
||||
<Route path="/">
|
||||
<EnsureOrganizationIsReady>
|
||||
<Dashboard />
|
||||
</EnsureOrganizationIsReady>
|
||||
</Route>
|
||||
</Switch>
|
||||
</PrivatePagesProvider>
|
||||
</EnsureUserEmailVerified>
|
||||
</EnsureAuthenticated>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
// @ts-nocheck
|
||||
import * as React from 'react';
|
||||
import * as Loadable from 'react-loadable';
|
||||
|
||||
const Loader = (config) =>
|
||||
Loadable({
|
||||
loading: (props) => {
|
||||
if (props.error) {
|
||||
/* tslint:disable */
|
||||
console.error(`======= DefaultLoader Error =======`);
|
||||
console.error(props.error);
|
||||
console.error(`======= DefaultLoader Error =======`);
|
||||
/* tslint:enable */
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
},
|
||||
delay: 250,
|
||||
...config
|
||||
});
|
||||
|
||||
export default Loader;
|
||||
@@ -1,21 +1,33 @@
|
||||
// @ts-nocheck
|
||||
import React from 'react';
|
||||
import React, { Suspense } from 'react';
|
||||
import { Route, Switch } from 'react-router-dom';
|
||||
import preferencesRoutes from '@/routes/preferences';
|
||||
import { getPreferenceRoutes } from '@/routes/preferences';
|
||||
import { Spinner } from '@blueprintjs/core';
|
||||
import { Box } from '../Layout';
|
||||
|
||||
export default function DashboardContentRoute() {
|
||||
const preferencesRoutes = getPreferenceRoutes();
|
||||
|
||||
return (
|
||||
<Route pathname="/preferences">
|
||||
<Switch>
|
||||
{preferencesRoutes.map((route, index) => (
|
||||
<Route
|
||||
key={index}
|
||||
path={`${route.path}`}
|
||||
exact={route.exact}
|
||||
component={route.component}
|
||||
/>
|
||||
))}
|
||||
</Switch>
|
||||
<Suspense
|
||||
fallback={
|
||||
<Box style={{ padding: 20 }}>
|
||||
<Spinner size={20} />
|
||||
</Box>
|
||||
}
|
||||
>
|
||||
<Switch>
|
||||
{preferencesRoutes.map((route, index) => (
|
||||
<Route
|
||||
key={index}
|
||||
path={`${route.path}`}
|
||||
exact={route.exact}
|
||||
component={route.component}
|
||||
/>
|
||||
))}
|
||||
</Switch>
|
||||
</Suspense>
|
||||
</Route>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2,10 +2,12 @@
|
||||
import { Route, Switch, useLocation } from 'react-router-dom';
|
||||
import BodyClassName from 'react-body-classname';
|
||||
import styled from 'styled-components';
|
||||
import { Suspense } from 'react';
|
||||
import { TransitionGroup, CSSTransition } from 'react-transition-group';
|
||||
import { Spinner } from '@blueprintjs/core';
|
||||
|
||||
import authenticationRoutes from '@/routes/authentication';
|
||||
import { Icon, FormattedMessage as T } from '@/components';
|
||||
import { Box, Icon, FormattedMessage as T } from '@/components';
|
||||
import { AuthMetaBootProvider } from './AuthMetaBoot';
|
||||
|
||||
import '@/style/pages/Authentication/Auth.scss';
|
||||
@@ -20,7 +22,15 @@ export function Authentication() {
|
||||
</AuthLogo>
|
||||
|
||||
<AuthMetaBootProvider>
|
||||
<AuthenticationRoutes />
|
||||
<Suspense
|
||||
fallback={
|
||||
<Box style={{ marginTop: '5rem' }}>
|
||||
<Spinner size={30} />
|
||||
</Box>
|
||||
}
|
||||
>
|
||||
<AuthenticationRoutes />
|
||||
</Suspense>
|
||||
</AuthMetaBootProvider>
|
||||
</AuthInsider>
|
||||
</AuthPage>
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
import { EnsureAuthNotAuthenticated } from "@/components/Guards/EnsureAuthNotAuthenticated";
|
||||
import { Authentication } from "./Authentication";
|
||||
|
||||
export default function AuthenticationPage() {
|
||||
return (
|
||||
<EnsureAuthNotAuthenticated>
|
||||
<Authentication />
|
||||
</EnsureAuthNotAuthenticated>
|
||||
);
|
||||
}
|
||||
@@ -73,8 +73,9 @@ export function OneClickDemoPageContent() {
|
||||
)}
|
||||
{running && (
|
||||
<Text className={style.waitingText}>
|
||||
We're preparing temporary environment for trial, It typically
|
||||
take few seconds. Do not close or refresh the page.
|
||||
We're preparing the temporary environment for trial. It
|
||||
typically takes a few seconds. Do not close or refresh the
|
||||
page.
|
||||
</Text>
|
||||
)}
|
||||
</Stack>
|
||||
|
||||
@@ -2,14 +2,17 @@
|
||||
import React from 'react';
|
||||
import SetupRightSection from './SetupRightSection';
|
||||
import SetupLeftSection from './SetupLeftSection';
|
||||
import EnsureOrganizationIsNotReady from '@/components/Guards/EnsureOrganizationIsNotReady';
|
||||
|
||||
import '@/style/pages/Setup/SetupPage.scss';
|
||||
|
||||
export default function WizardSetupPage() {
|
||||
return (
|
||||
<div class="setup-page">
|
||||
<SetupLeftSection />
|
||||
<SetupRightSection />
|
||||
</div>
|
||||
<EnsureOrganizationIsNotReady>
|
||||
<div class="setup-page">
|
||||
<SetupLeftSection />
|
||||
<SetupRightSection />
|
||||
</div>
|
||||
</EnsureOrganizationIsNotReady>
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,43 +1,35 @@
|
||||
// @ts-nocheck
|
||||
import LazyLoader from '@/components/LazyLoader';
|
||||
import { lazy } from 'react';
|
||||
|
||||
const BASE_URL = '/auth';
|
||||
|
||||
export default [
|
||||
{
|
||||
path: `${BASE_URL}/login`,
|
||||
component: LazyLoader({
|
||||
loader: () => import('@/containers/Authentication/Login'),
|
||||
}),
|
||||
component: lazy(() => import('@/containers/Authentication/Login')),
|
||||
},
|
||||
{
|
||||
path: `${BASE_URL}/send_reset_password`,
|
||||
component: LazyLoader({
|
||||
loader: () => import('@/containers/Authentication/SendResetPassword'),
|
||||
}),
|
||||
component: lazy(
|
||||
() => import('@/containers/Authentication/SendResetPassword'),
|
||||
),
|
||||
},
|
||||
{
|
||||
path: `${BASE_URL}/reset_password/:token`,
|
||||
component: LazyLoader({
|
||||
loader: () => import('@/containers/Authentication/ResetPassword'),
|
||||
}),
|
||||
component: lazy(() => import('@/containers/Authentication/ResetPassword')),
|
||||
},
|
||||
{
|
||||
path: `${BASE_URL}/invite/:token/accept`,
|
||||
component: LazyLoader({
|
||||
loader: () => import('@/containers/Authentication/InviteAccept'),
|
||||
}),
|
||||
component: lazy(() => import('@/containers/Authentication/InviteAccept')),
|
||||
},
|
||||
{
|
||||
path: `${BASE_URL}/register/email_confirmation`,
|
||||
component: LazyLoader({
|
||||
loader: () => import('@/containers/Authentication/EmailConfirmation'),
|
||||
}),
|
||||
component: lazy(
|
||||
() => import('@/containers/Authentication/EmailConfirmation'),
|
||||
),
|
||||
},
|
||||
{
|
||||
path: `${BASE_URL}/register`,
|
||||
component: LazyLoader({
|
||||
loader: () => import('@/containers/Authentication/Register'),
|
||||
}),
|
||||
component: lazy(() => import('@/containers/Authentication/Register')),
|
||||
},
|
||||
];
|
||||
|
||||
@@ -1,88 +1,96 @@
|
||||
// @ts-nocheck
|
||||
import { lazy } from 'react';
|
||||
import General from '@/containers/Preferences/General/General';
|
||||
import Users from '../containers/Preferences/Users/Users';
|
||||
import Roles from '../containers/Preferences/Users/Roles/RolesForm/RolesFormPage';
|
||||
import Accountant from '@/containers/Preferences/Accountant/Accountant';
|
||||
import Currencies from '@/containers/Preferences/Currencies/Currencies';
|
||||
import Item from '@/containers/Preferences/Item';
|
||||
// import SMSIntegration from '../containers/Preferences/SMSIntegration';
|
||||
import DefaultRoute from '../containers/Preferences/DefaultRoute';
|
||||
import Warehouses from '../containers/Preferences/Warehouses';
|
||||
import Branches from '../containers/Preferences/Branches';
|
||||
import Invoices from '../containers/Preferences/Invoices/PreferencesInvoices';
|
||||
import { PreferencesCreditNotes } from '../containers/Preferences/CreditNotes/PreferencesCreditNotes';
|
||||
import { PreferencesEstimates } from '@/containers/Preferences/Estimates/PreferencesEstimates';
|
||||
import { PreferencesReceipts } from '@/containers/Preferences/Receipts/PreferencesReceipts';
|
||||
|
||||
import BillingPage from '@/containers/Subscriptions/BillingPage';
|
||||
|
||||
const BASE_URL = '/preferences';
|
||||
|
||||
export default [
|
||||
export const getPreferenceRoutes = () => [
|
||||
{
|
||||
path: `${BASE_URL}/general`,
|
||||
component: General,
|
||||
component: lazy(() => import('@/containers/Preferences/General/General')),
|
||||
exact: true,
|
||||
},
|
||||
{
|
||||
path: `${BASE_URL}/users`,
|
||||
component: Users,
|
||||
component: lazy(() => import('../containers/Preferences/Users/Users')),
|
||||
exact: true,
|
||||
},
|
||||
{
|
||||
path: `${BASE_URL}/invoices`,
|
||||
component: Invoices,
|
||||
component: lazy(
|
||||
() => import('../containers/Preferences/Invoices/PreferencesInvoices'),
|
||||
),
|
||||
exact: true,
|
||||
},
|
||||
{
|
||||
path: `${BASE_URL}/credit-notes`,
|
||||
component: PreferencesCreditNotes,
|
||||
component: lazy(() =>
|
||||
import(
|
||||
'../containers/Preferences/CreditNotes/PreferencesCreditNotes'
|
||||
).then((module) => ({ default: module.PreferencesCreditNotes })),
|
||||
),
|
||||
exact: true,
|
||||
},
|
||||
{
|
||||
path: `${BASE_URL}/estimates`,
|
||||
component: PreferencesEstimates,
|
||||
component: lazy(() =>
|
||||
import('@/containers/Preferences/Estimates/PreferencesEstimates').then(
|
||||
(module) => ({ default: module.PreferencesEstimates }),
|
||||
),
|
||||
),
|
||||
exact: true,
|
||||
},
|
||||
{
|
||||
path: `${BASE_URL}/receipts`,
|
||||
component: PreferencesReceipts,
|
||||
component: lazy(() =>
|
||||
import('@/containers/Preferences/Receipts/PreferencesReceipts').then(
|
||||
(module) => ({ default: module.PreferencesReceipts }),
|
||||
),
|
||||
),
|
||||
exact: true,
|
||||
},
|
||||
{
|
||||
path: `${BASE_URL}/roles`,
|
||||
component: Roles,
|
||||
component: lazy(
|
||||
() =>
|
||||
import('../containers/Preferences/Users/Roles/RolesForm/RolesFormPage'),
|
||||
),
|
||||
exact: true,
|
||||
},
|
||||
{
|
||||
path: `${BASE_URL}/roles/:id`,
|
||||
component: Roles,
|
||||
component: lazy(
|
||||
() =>
|
||||
import('../containers/Preferences/Users/Roles/RolesForm/RolesFormPage'),
|
||||
),
|
||||
exact: true,
|
||||
},
|
||||
{
|
||||
path: `${BASE_URL}/currencies`,
|
||||
component: Currencies,
|
||||
component: lazy(
|
||||
() => import('@/containers/Preferences/Currencies/Currencies'),
|
||||
),
|
||||
exact: true,
|
||||
},
|
||||
{
|
||||
path: `${BASE_URL}/warehouses`,
|
||||
component: Warehouses,
|
||||
component: lazy(() => import('../containers/Preferences/Warehouses')),
|
||||
exact: true,
|
||||
},
|
||||
{
|
||||
path: `${BASE_URL}/branches`,
|
||||
component: Branches,
|
||||
component: lazy(() => import('../containers/Preferences/Branches')),
|
||||
exact: true,
|
||||
},
|
||||
{
|
||||
path: `${BASE_URL}/accountant`,
|
||||
component: Accountant,
|
||||
component: lazy(
|
||||
() => import('@/containers/Preferences/Accountant/Accountant'),
|
||||
),
|
||||
exact: true,
|
||||
},
|
||||
{
|
||||
path: `${BASE_URL}/items`,
|
||||
component: Item,
|
||||
component: lazy(() => import('@/containers/Preferences/Item')),
|
||||
exact: true,
|
||||
},
|
||||
// {
|
||||
@@ -92,12 +100,12 @@ export default [
|
||||
// },
|
||||
{
|
||||
path: `${BASE_URL}/billing`,
|
||||
component: BillingPage,
|
||||
component: lazy(() => import('@/containers/Subscriptions/BillingPage')),
|
||||
exact: true,
|
||||
},
|
||||
{
|
||||
path: `${BASE_URL}/`,
|
||||
component: DefaultRoute,
|
||||
component: lazy(() => import('../containers/Preferences/DefaultRoute')),
|
||||
exact: true,
|
||||
},
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user