re-structure to monorepo.

This commit is contained in:
a.bouhuolia
2023-02-03 01:02:31 +02:00
parent 8242ec64ba
commit 7a0a13f9d5
10400 changed files with 46966 additions and 17223 deletions

View File

@@ -0,0 +1,59 @@
// @ts-nocheck
import React from 'react';
import moment from 'moment';
import { castArray } from 'lodash';
import { transformToForm } from '@/utils';
import { useAppQueryString } from '@/hooks';
/**
* Retrieves the default cashflow sheet query.
*/
export const getDefaultCashFlowSheetQuery = () => {
return {
fromDate: moment().startOf('year').format('YYYY-MM-DD'),
toDate: moment().endOf('year').format('YYYY-MM-DD'),
basis: 'cash',
displayColumnsType: 'total',
filterByOption: 'with-transactions',
branchesIds: [],
};
};
/**
* Parses the cashflow query from browser location.
*/
const parseCashflowQuery = (query) => {
const defaultQuery = getDefaultCashFlowSheetQuery();
const transformed = {
...defaultQuery,
...transformToForm(query, defaultQuery),
};
return {
...transformed,
// Ensures the branches ids is always array.
branchesIds: castArray(transformed.branchesIds),
};
};
/**
* Retrieves the cashflow statement query.
*/
export const useCashflowStatementQuery = () => {
// Retrieves location query.
const [locationQuery, setLocationQuery] = useAppQueryString();
// Merges the default filter query with location URL query.
const query = React.useMemo(
() => parseCashflowQuery(locationQuery),
[locationQuery],
);
return {
query,
locationQuery,
setLocationQuery,
};
};