chrone: sperate client and server to different repos.

This commit is contained in:
a.bouhuolia
2021-09-21 17:13:53 +02:00
parent e011b2a82b
commit 18df5530c7
10015 changed files with 17686 additions and 97524 deletions

View File

@@ -0,0 +1,20 @@
import React from 'react';
import classNames from 'classnames';
import { CLASSES } from 'common/classes';
import CurrenciesList from './CurrenciesList';
export default function PreferencesCurrenciesPage() {
return (
<div className={classNames(
CLASSES.PREFERENCES_PAGE_INSIDE_CONTENT,
CLASSES.PREFERENCES_PAGE_INSIDE_CONTENT_CURRENCIES,
)}>
<div className={classNames(CLASSES.CARD)}>
<CurrenciesList />
</div>
</div>
)
}

View File

@@ -0,0 +1,26 @@
import React, { useCallback } from 'react';
import { Button, Intent } from '@blueprintjs/core';
import Icon from 'components/Icon';
import withDialogActions from 'containers/Dialog/withDialogActions';
import { compose } from 'utils';
import { FormattedMessage as T } from 'components';
function CurrenciesActions({ openDialog }) {
const handleClickNewCurrency = useCallback(() => {
openDialog('currency-form');
}, [openDialog]);
return (
<div class="users-actions">
<Button
icon={<Icon icon="plus" iconSize={12} />}
onClick={handleClickNewCurrency}
intent={Intent.PRIMARY}
>
<T id={'new_currency'} />
</Button>
</div>
);
}
export default compose(withDialogActions)(CurrenciesActions);

View File

@@ -0,0 +1,10 @@
import React from 'react';
import CurrencyDeleteAlert from 'containers/Alerts/Currencies/CurrencyDeleteAlert';
export default function CurrenciesAlerts() {
return (
<div>
<CurrencyDeleteAlert name={'currency-delete'} />
</div>
);
}

View File

@@ -0,0 +1,70 @@
import React, { useCallback } from 'react';
import { compose } from 'utils';
import { DataTable } from 'components';
import { useCurrenciesContext } from './CurrenciesProvider';
import TableSkeletonRows from 'components/Datatable/TableSkeletonRows';
import { ActionMenuList, useCurrenciesTableColumns } from './components';
import withDialogActions from 'containers/Dialog/withDialogActions';
import withAlertActions from 'containers/Alert/withAlertActions';
/**
* Currencies table.
*/
function CurrenciesDataTable({
// #ownProps
tableProps,
// #withDialog.
openDialog,
// #withAlertActions
openAlert,
}) {
const { currencies, isCurrenciesLoading } = useCurrenciesContext();
// Table columns.
const columns = useCurrenciesTableColumns();
// Handle Edit Currency.
const handleEditCurrency = useCallback(
(currency) => {
openDialog('currency-form', {
action: 'edit',
currency: currency,
});
},
[openDialog],
);
// Handle delete currency.
const handleDeleteCurrency = ({ currency_code }) => {
openAlert('currency-delete', { currency_code: currency_code });
};
return (
<DataTable
columns={columns}
data={currencies}
loading={isCurrenciesLoading}
progressBarLoading={isCurrenciesLoading}
TableLoadingRenderer={TableSkeletonRows}
ContextMenu={ActionMenuList}
noInitialFetch={true}
payload={{
onDeleteCurrency: handleDeleteCurrency,
onEditCurrency: handleEditCurrency,
}}
rowContextMenu={ActionMenuList}
{...tableProps}
/>
);
}
export default compose(
withDialogActions,
withAlertActions,
)(CurrenciesDataTable);

View File

@@ -0,0 +1,30 @@
import React, { useEffect } from 'react';
import { FormattedMessage as T } from 'components';
import intl from 'react-intl-universal';
import { CurrenciesProvider } from './CurrenciesProvider';
import CurrenciesDataTable from './CurrenciesDataTable';
import CurrenciesAlerts from './CurrenciesAlerts';
import withDashboardActions from 'containers/Dashboard/withDashboardActions';
import { compose } from 'utils';
function CurrenciesList({
// #withDashboardActions
changePreferencesPageTitle,
}) {
useEffect(() => {
changePreferencesPageTitle(intl.get('currencies'));
}, [changePreferencesPageTitle]);
return (
<CurrenciesProvider>
<CurrenciesDataTable />
<CurrenciesAlerts />
</CurrenciesProvider>
);
}
export default compose(withDashboardActions)(CurrenciesList);

View File

@@ -0,0 +1,25 @@
import React, { createContext, useContext } from 'react';
import { useCurrencies } from 'hooks/query';
const CurrenciesContext = createContext();
/**
* currencies provider.
*/
function CurrenciesProvider({ ...props }) {
// fetches the currencies list.
const { data: currencies, isLoading: isCurrenciesLoading } = useCurrencies();
const state = {
currencies,
isCurrenciesLoading,
};
return (
<CurrenciesContext.Provider value={state} {...props} />
);
}
const useCurrenciesContext = () => useContext(CurrenciesContext);
export { CurrenciesProvider, useCurrenciesContext };

View File

@@ -0,0 +1,85 @@
import React, { useMemo } from 'react';
import {
Menu,
Popover,
Button,
Position,
MenuItem,
Intent,
} from '@blueprintjs/core';
import intl from 'react-intl-universal';
import { Icon } from 'components';
import { safeCallback } from 'utils';
/**
* Row actions menu list.
*/
export function ActionMenuList({
row: { original },
payload: { onEditCurrency, onDeleteCurrency },
}) {
return (
<Menu>
<MenuItem
icon={<Icon icon="pen-18" />}
text={intl.get('edit_currency')}
onClick={safeCallback(onEditCurrency, original)}
/>
<MenuItem
icon={<Icon icon="trash-16" iconSize={16} />}
text={intl.get('delete_currency')}
onClick={safeCallback(onDeleteCurrency, original)}
intent={Intent.DANGER}
/>
</Menu>
);
}
/**
* Actions cell.
*/
export const ActionsCell = (props) => {
return (
<Popover
position={Position.RIGHT_BOTTOM}
content={<ActionMenuList {...props} />}
>
<Button icon={<Icon icon="more-h-16" iconSize={16} />} />
</Popover>
);
};
export function useCurrenciesTableColumns() {
return useMemo(
() => [
{
Header: intl.get('currency_name'),
accessor: 'currency_name',
width: 150,
},
{
Header: intl.get('currency_code'),
accessor: 'currency_code',
className: 'currency_code',
width: 120,
},
{
Header: 'Currency sign',
width: 120,
accessor: 'currency_sign'
},
{
id: 'actions',
Header: '',
Cell: ActionsCell,
className: 'actions',
width: 50,
disableResizing: true,
},
],
[],
);
}