mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-15 20:30:33 +00:00
Merge branch 'master' of https://github.com/abouolia/Bigcapital
This commit is contained in:
@@ -115,7 +115,7 @@ export function NormalCell({ cell: { value } }) {
|
||||
export function BalanceCell({ cell }) {
|
||||
const account = cell.row.original;
|
||||
|
||||
return account.amount ? (
|
||||
return account.amount !== null ? (
|
||||
<span>
|
||||
<Money amount={account.amount} currency={'USD'} />
|
||||
</span>
|
||||
|
||||
@@ -45,7 +45,13 @@ function CurrencyDeleteAlert({
|
||||
});
|
||||
closeAlert(name);
|
||||
})
|
||||
.catch(() => {
|
||||
.catch(({ response: { data: { errors } } }) => {
|
||||
if (errors.find(e => e.type === 'CANNOT_DELETE_BASE_CURRENCY')) {
|
||||
AppToaster.show({
|
||||
intent: Intent.DANGER,
|
||||
message: 'Cannot delete the base currency.'
|
||||
});
|
||||
}
|
||||
closeAlert(name);
|
||||
});
|
||||
};
|
||||
|
||||
@@ -1,6 +1,69 @@
|
||||
import React from 'react';
|
||||
import { FormattedMessage as T, useIntl } from 'react-intl';
|
||||
import { Alert, Intent } from '@blueprintjs/core';
|
||||
import { AppToaster } from 'components';
|
||||
import { useActivateUser } from 'hooks/query';
|
||||
|
||||
import withAlertStoreConnect from 'containers/Alert/withAlertStoreConnect';
|
||||
import withAlertActions from 'containers/Alert/withAlertActions';
|
||||
|
||||
import { compose } from 'utils';
|
||||
|
||||
function UserActivateAlert() {
|
||||
|
||||
}
|
||||
/**
|
||||
* User inactivate alert.
|
||||
*/
|
||||
function UserActivateAlert({
|
||||
// #ownProps
|
||||
name,
|
||||
|
||||
// #withAlertStoreConnect
|
||||
isOpen,
|
||||
payload: { userId },
|
||||
|
||||
// #withAlertActions
|
||||
closeAlert,
|
||||
}) {
|
||||
const { formatMessage } = useIntl();
|
||||
|
||||
const { mutateAsync: userActivateMutate } = useActivateUser();
|
||||
|
||||
const handleConfirmActivate = () => {
|
||||
userActivateMutate(userId)
|
||||
.then(() => {
|
||||
AppToaster.show({
|
||||
message: formatMessage({
|
||||
id: 'the_user_has_been_activated_successfully',
|
||||
}),
|
||||
intent: Intent.SUCCESS,
|
||||
});
|
||||
closeAlert(name);
|
||||
})
|
||||
.catch((error) => {
|
||||
closeAlert(name);
|
||||
});
|
||||
};
|
||||
|
||||
const handleCancel = () => {
|
||||
closeAlert(name);
|
||||
};
|
||||
|
||||
return (
|
||||
<Alert
|
||||
cancelButtonText={<T id={'cancel'} />}
|
||||
confirmButtonText={<T id={'activate'} />}
|
||||
intent={Intent.WARNING}
|
||||
isOpen={isOpen}
|
||||
onCancel={handleCancel}
|
||||
onConfirm={handleConfirmActivate}
|
||||
>
|
||||
<p>
|
||||
<T id={'are_sure_to_activate_this_account'} />
|
||||
</p>
|
||||
</Alert>
|
||||
);
|
||||
}
|
||||
|
||||
export default compose(
|
||||
withAlertStoreConnect(),
|
||||
withAlertActions,
|
||||
)(UserActivateAlert);
|
||||
|
||||
@@ -40,6 +40,7 @@ function UserDeleteAlert({
|
||||
}),
|
||||
intent: Intent.SUCCESS,
|
||||
});
|
||||
closeAlert(name);
|
||||
})
|
||||
.catch(({ response: { data: { errors } } }) => {
|
||||
if (errors.find(e => e.type === 'CANNOT_DELETE_LAST_USER')) {
|
||||
|
||||
@@ -36,9 +36,16 @@ function UserInactivateAlert({
|
||||
}),
|
||||
intent: Intent.SUCCESS,
|
||||
});
|
||||
closeAlert(name);
|
||||
})
|
||||
.catch((error) => {
|
||||
|
||||
.catch(({ response: { data: { errors } } }) => {
|
||||
if (errors.find(e => e.type === 'CANNOT.TOGGLE.ACTIVATE.AUTHORIZED.USER')) {
|
||||
AppToaster.show({
|
||||
message: 'You could not activate/inactivate the same authorized user.',
|
||||
intent: Intent.DANGER,
|
||||
});
|
||||
}
|
||||
closeAlert(name);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
import React, { useMemo, useCallback } from 'react';
|
||||
import React, { useMemo } from 'react';
|
||||
import { Intent } from '@blueprintjs/core';
|
||||
import { Formik } from 'formik';
|
||||
import { FormattedMessage as T, useIntl } from 'react-intl';
|
||||
import { AppToaster } from 'components';
|
||||
import { pick } from 'lodash';
|
||||
import CurrencyFormContent from './CurrencyFormContent';
|
||||
|
||||
import { useCurrencyFormContext } from './CurrencyFormProvider';
|
||||
@@ -18,6 +17,7 @@ import { compose, transformToForm } from 'utils';
|
||||
const defaultInitialValues = {
|
||||
currency_name: '',
|
||||
currency_code: '',
|
||||
currency_sign: '',
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -59,7 +59,7 @@ function CurrencyForm({
|
||||
const afterSubmit = () => {
|
||||
closeDialog(dialogName);
|
||||
};
|
||||
|
||||
// Handle the request success.
|
||||
const onSuccess = ({ response }) => {
|
||||
AppToaster.show({
|
||||
message: formatMessage({
|
||||
@@ -71,9 +71,14 @@ function CurrencyForm({
|
||||
});
|
||||
afterSubmit(response);
|
||||
};
|
||||
|
||||
// Handle the response error.
|
||||
const onError = (errors) => {
|
||||
const onError = ({ response: { data: { errors } } }) => {
|
||||
if (errors.find(e => e.type === 'CURRENCY_CODE_EXISTS')) {
|
||||
AppToaster.show({
|
||||
message: 'The given currency code is already exists.',
|
||||
intent: Intent.DANGER,
|
||||
});
|
||||
}
|
||||
setSubmitting(false);
|
||||
};
|
||||
if (isEditMode) {
|
||||
|
||||
@@ -10,6 +10,7 @@ const Schema = Yup.object().shape({
|
||||
.max(4)
|
||||
.required()
|
||||
.label(formatMessage({ id: 'currency_code_' })),
|
||||
currency_sign: Yup.string().required(),
|
||||
});
|
||||
|
||||
export const CreateCurrencyFormSchema = Schema;
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import React from 'react';
|
||||
import { CurrencyFormProvider } from './CurrencyFormProvider';
|
||||
import { pick } from 'lodash';
|
||||
|
||||
import CurrencyForm from './CurrencyForm';
|
||||
import withCurrencyDetail from 'containers/Currencies/withCurrencyDetail';
|
||||
|
||||
@@ -1,24 +1,47 @@
|
||||
import React from 'react';
|
||||
import {
|
||||
Classes,
|
||||
FormGroup,
|
||||
InputGroup,
|
||||
} from '@blueprintjs/core';
|
||||
import { Classes, FormGroup, InputGroup } from '@blueprintjs/core';
|
||||
import { FastField } from 'formik';
|
||||
import { FormattedMessage as T } from 'react-intl';
|
||||
import {
|
||||
ErrorMessage,
|
||||
FieldRequiredHint,
|
||||
} from 'components';
|
||||
|
||||
import { useCurrencyFormContext } from './CurrencyFormProvider';
|
||||
import { ErrorMessage, FieldRequiredHint, ListSelect } from 'components';
|
||||
|
||||
import { useAutofocus } from 'hooks';
|
||||
import { inputIntent } from 'utils';
|
||||
import { inputIntent, currenciesOptions } from 'utils';
|
||||
|
||||
/**
|
||||
* Currency form fields.
|
||||
*/
|
||||
export default function CurrencyFormFields() {
|
||||
const currencyNameFieldRef = useAutofocus();
|
||||
|
||||
|
||||
const { isEditMode } = useCurrencyFormContext();
|
||||
|
||||
return (
|
||||
<div className={Classes.DIALOG_BODY}>
|
||||
<FastField name={'currency_code'}>
|
||||
{({
|
||||
form: { setFieldValue },
|
||||
field: { value },
|
||||
meta: { error, touched },
|
||||
}) => (
|
||||
<FormGroup label={'Currency code'}>
|
||||
<ListSelect
|
||||
items={currenciesOptions}
|
||||
selectedItemProp={'currency_code'}
|
||||
selectedItem={value}
|
||||
textProp={'formatted_name'}
|
||||
defaultText={'Select currency code'}
|
||||
onItemSelect={(currency) => {
|
||||
setFieldValue('currency_code', currency.currency_code);
|
||||
setFieldValue('currency_name', currency.name);
|
||||
setFieldValue('currency_sign', currency.symbol);
|
||||
}}
|
||||
disabled={isEditMode}
|
||||
/>
|
||||
</FormGroup>
|
||||
)}
|
||||
</FastField>
|
||||
{/* ----------- Currency name ----------- */}
|
||||
<FastField name={'currency_name'}>
|
||||
{({ field, field: { value }, meta: { error, touched } }) => (
|
||||
@@ -38,15 +61,14 @@ export default function CurrencyFormFields() {
|
||||
)}
|
||||
</FastField>
|
||||
{/* ----------- Currency Code ----------- */}
|
||||
<FastField name={'currency_code'}>
|
||||
<FastField name={'currency_sign'}>
|
||||
{({ field, field: { value }, meta: { error, touched } }) => (
|
||||
<FormGroup
|
||||
label={<T id={'currency_code'} />}
|
||||
label={<T id={'currency_sign'} />}
|
||||
labelInfo={<FieldRequiredHint />}
|
||||
className={'form-group--currency-code'}
|
||||
className={'form-group--currency-sign'}
|
||||
intent={inputIntent({ error, touched })}
|
||||
helperText={<ErrorMessage name="currency_code" />}
|
||||
// inline={true}
|
||||
helperText={<ErrorMessage name="currency_sign" />}
|
||||
>
|
||||
<InputGroup {...field} />
|
||||
</FormGroup>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import React, { createContext } from 'react';
|
||||
import { useCurrencies, useEditCurrency, useCreateCurrency } from 'hooks/query';
|
||||
import { useEditCurrency, useCreateCurrency } from 'hooks/query';
|
||||
import { DialogContent } from 'components';
|
||||
|
||||
const CurrencyFormContext = createContext();
|
||||
@@ -7,27 +7,22 @@ const CurrencyFormContext = createContext();
|
||||
/**
|
||||
* Currency Form page provider.
|
||||
*/
|
||||
|
||||
function CurrencyFormProvider({ isEditMode, currency, dialogName, ...props }) {
|
||||
// Create and edit item currency mutations.
|
||||
const { mutateAsync: createCurrencyMutate } = useCreateCurrency();
|
||||
const { mutateAsync: editCurrencyMutate } = useEditCurrency();
|
||||
|
||||
// fetch Currencies list.
|
||||
const { data: currencies, isLoading: isCurrenciesLoading } = useCurrencies();
|
||||
|
||||
// Provider state.
|
||||
const provider = {
|
||||
createCurrencyMutate,
|
||||
editCurrencyMutate,
|
||||
dialogName,
|
||||
currency,
|
||||
isCurrenciesLoading,
|
||||
isEditMode,
|
||||
};
|
||||
|
||||
return (
|
||||
<DialogContent isLoading={isCurrenciesLoading} name={'currency-form'}>
|
||||
<DialogContent name={'currency-form'}>
|
||||
<CurrencyFormContext.Provider value={provider} {...props} />
|
||||
</DialogContent>
|
||||
);
|
||||
|
||||
@@ -52,6 +52,7 @@ function CurrenciesDataTable({
|
||||
loading={isCurrenciesLoading}
|
||||
progressBarLoading={isCurrenciesLoading}
|
||||
TableLoadingRenderer={TableSkeletonRows}
|
||||
ContextMenu={ActionMenuList}
|
||||
noInitialFetch={true}
|
||||
payload={{
|
||||
onDeleteCurrency: handleDeleteCurrency,
|
||||
|
||||
@@ -69,6 +69,7 @@ export function useCurrenciesTableColumns() {
|
||||
{
|
||||
Header: 'Currency sign',
|
||||
width: 120,
|
||||
accessor: 'currency_sign'
|
||||
},
|
||||
{
|
||||
id: 'actions',
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
import React from 'react';
|
||||
import UserDeleteAlert from 'containers/Alerts/Users/UserDeleteAlert';
|
||||
import UserInactivateAlert from 'containers/Alerts/Users/UserInactivateAlert';
|
||||
// import UserActivateAlert from 'containers/Alerts/UserActivateAlert';
|
||||
import UserActivateAlert from 'containers/Alerts/Users/UserActivateAlert';
|
||||
|
||||
export default function UsersAlerts() {
|
||||
return (
|
||||
<>
|
||||
<UserDeleteAlert name={'user-delete'} />
|
||||
<UserInactivateAlert name={'user-inactivate'} />
|
||||
{/* <UserActivateAlert name={'user-activate'} /> */}
|
||||
<UserActivateAlert name={'user-activate'} />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@ import React, { useCallback } from 'react';
|
||||
|
||||
import { compose } from 'utils';
|
||||
import { DataTable } from 'components';
|
||||
import { useResendInvitation } from 'hooks/query';
|
||||
import AppToaster from 'components/AppToaster';
|
||||
|
||||
import TableSkeletonRows from 'components/Datatable/TableSkeletonRows';
|
||||
|
||||
@@ -10,6 +12,7 @@ import withAlertActions from 'containers/Alert/withAlertActions';
|
||||
|
||||
import { ActionsMenu, useUsersListColumns } from './components';
|
||||
import { useUsersListContext } from './UsersProvider';
|
||||
import { Intent } from '@blueprintjs/core';
|
||||
|
||||
/**
|
||||
* Users datatable.
|
||||
@@ -49,6 +52,26 @@ function UsersDataTable({
|
||||
},
|
||||
[openAlert]
|
||||
);
|
||||
|
||||
const { mutateAsync: resendInviation } = useResendInvitation();
|
||||
|
||||
const handleResendInvitation = useCallback(
|
||||
(user) => {
|
||||
resendInviation(user.id).then(() => {
|
||||
AppToaster.show({
|
||||
message: 'User invitation has been re-sent to the user.',
|
||||
intent: Intent.SUCCESS
|
||||
});
|
||||
}).catch(({ response: { data: { errors } } }) => {
|
||||
if (errors.find(e => e.type === 'USER_RECENTLY_INVITED')) {
|
||||
AppToaster.show({
|
||||
message: 'This person was recently invited. No need to invite them again just yet.',
|
||||
intent: Intent.DANGER
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
)
|
||||
// Users list columns.
|
||||
const columns = useUsersListColumns();
|
||||
|
||||
@@ -67,9 +90,10 @@ function UsersDataTable({
|
||||
ContextMenu={ActionsMenu}
|
||||
payload={{
|
||||
onEdit: handleEditUserAction,
|
||||
onActivate: handleInactivateUser,
|
||||
onInactivate: handleActivateuser,
|
||||
onDelete: handleDeleteUser
|
||||
onActivate: handleActivateuser,
|
||||
onInactivate: handleInactivateUser,
|
||||
onDelete: handleDeleteUser,
|
||||
onResendInvitation: handleResendInvitation
|
||||
}}
|
||||
/>
|
||||
);
|
||||
|
||||
@@ -25,12 +25,7 @@ function AvatarCell(row) {
|
||||
*/
|
||||
export function ActionsMenu({
|
||||
row: { original },
|
||||
payload: {
|
||||
onEdit,
|
||||
onInactivate,
|
||||
onActivate,
|
||||
onDelete
|
||||
}
|
||||
payload: { onEdit, onInactivate, onActivate, onDelete, onResendInvitation },
|
||||
}) {
|
||||
const { formatMessage } = useIntl();
|
||||
|
||||
@@ -44,9 +39,26 @@ export function ActionsMenu({
|
||||
/>
|
||||
<MenuDivider />
|
||||
|
||||
{original.active ? (
|
||||
<MenuItem
|
||||
text={formatMessage({ id: 'inactivate_user' })}
|
||||
onClick={safeCallback(onInactivate, original)}
|
||||
icon={<Icon icon="pause-16" iconSize={16} />}
|
||||
/>
|
||||
) : (
|
||||
<MenuItem
|
||||
text={formatMessage({ id: 'activate_user' })}
|
||||
onClick={safeCallback(onActivate, original)}
|
||||
icon={<Icon icon="play-16" iconSize={16} />}
|
||||
/>
|
||||
)}
|
||||
</If>
|
||||
|
||||
<If condition={!original.invite_accepted_at}>
|
||||
<MenuItem
|
||||
text={formatMessage({ id: 'inactivate_user' })}
|
||||
onClick={safeCallback(onInactivate, original)}
|
||||
text={'Resend invitation'}
|
||||
onClick={safeCallback(onResendInvitation, original)}
|
||||
icon={<Icon icon="send" iconSize={16} />}
|
||||
/>
|
||||
</If>
|
||||
|
||||
@@ -64,7 +76,7 @@ export function ActionsMenu({
|
||||
* Status accessor.
|
||||
*/
|
||||
function StatusAccessor(user) {
|
||||
return !user.invite_accepted_at ? (
|
||||
return !user.is_invite_accepted ? (
|
||||
<Tag minimal={true}>
|
||||
<T id={'inviting'} />
|
||||
</Tag>
|
||||
@@ -93,6 +105,10 @@ function ActionsCell(props) {
|
||||
);
|
||||
}
|
||||
|
||||
function FullNameAccessor(user) {
|
||||
return user.is_invite_accepted ? user.full_name : user.email;
|
||||
}
|
||||
|
||||
export const useUsersListColumns = () => {
|
||||
const { formatMessage } = useIntl();
|
||||
|
||||
@@ -107,7 +123,7 @@ export const useUsersListColumns = () => {
|
||||
{
|
||||
id: 'full_name',
|
||||
Header: formatMessage({ id: 'full_name' }),
|
||||
accessor: 'full_name',
|
||||
accessor: FullNameAccessor,
|
||||
width: 150,
|
||||
},
|
||||
{
|
||||
|
||||
@@ -27,4 +27,14 @@ export const useInviteMetaByToken = (token, props) => {
|
||||
...props
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
export const useResendInvitation = (props) => {
|
||||
const apiRequest = useApiRequest();
|
||||
|
||||
return useMutation(
|
||||
(userId) => apiRequest.post(`invite/resend/${userId}`),
|
||||
props
|
||||
)
|
||||
}
|
||||
@@ -47,10 +47,30 @@ export function useInactivateUser(props) {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation(
|
||||
([id, values]) => apiRequest.post(`users/${id}/inactivate`, values),
|
||||
(userId) => apiRequest.put(`users/${userId}/inactivate`),
|
||||
{
|
||||
onSuccess: (res, [id, values]) => {
|
||||
queryClient.invalidateQueries([t.USER, id]);
|
||||
onSuccess: (res, userId) => {
|
||||
queryClient.invalidateQueries([t.USER, userId]);
|
||||
|
||||
// Common invalidate queries.
|
||||
commonInvalidateQueries(queryClient);
|
||||
},
|
||||
...props,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
export function useActivateUser(props) {
|
||||
const apiRequest = useApiRequest();
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation(
|
||||
(userId) => apiRequest.put(`users/${userId}/activate`),
|
||||
{
|
||||
onSuccess: (res, userId) => {
|
||||
queryClient.invalidateQueries([t.USER, userId]);
|
||||
|
||||
// Common invalidate queries.
|
||||
commonInvalidateQueries(queryClient);
|
||||
|
||||
@@ -318,6 +318,7 @@ export default {
|
||||
edit_user: 'Edit User',
|
||||
edit_invite: 'Edit Invite',
|
||||
inactivate_user: 'Inactivate User',
|
||||
activate_user: 'Activate User',
|
||||
delete_user: 'Delete User',
|
||||
full_name: 'Full Name',
|
||||
the_user_has_been_inactivated_successfully:
|
||||
@@ -1033,4 +1034,6 @@ export default {
|
||||
'This customer cannot be deleted as it is associated with transactions.',
|
||||
this_vendor_cannot_be_deleted_as_it_is_associated_with_transactions:
|
||||
'This vendor cannot be deleted as it is associated with transactions.',
|
||||
|
||||
currency_sign: 'Currency sign',
|
||||
};
|
||||
|
||||
@@ -14,11 +14,11 @@
|
||||
}
|
||||
.plan-radio,
|
||||
.period-radio{
|
||||
background: transparent;
|
||||
background: #fff;
|
||||
border-color: #bbcad4;
|
||||
|
||||
&.is-selected{
|
||||
background: #f1f3fb;
|
||||
background: #fff;
|
||||
border-color: #0269ff
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,4 +12,10 @@
|
||||
height: 170px;
|
||||
}
|
||||
}
|
||||
|
||||
.bp3-dialog-footer{
|
||||
.bp3-button{
|
||||
min-width: 75px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import moment from 'moment';
|
||||
import _, { castArray } from 'lodash';
|
||||
import Currencies from 'js-money/lib/currency';
|
||||
|
||||
import { Intent } from '@blueprintjs/core';
|
||||
import Currency from 'js-money/lib/currency';
|
||||
import accounting from 'accounting';
|
||||
@@ -620,3 +622,17 @@ export const updateTableRow = (rowIndex, columnId, value) => (old) => {
|
||||
export const transformGeneralSettings = (data) => {
|
||||
return _.mapKeys(data, (value, key) => _.snakeCase(key));
|
||||
};
|
||||
|
||||
const getCurrenciesOptions = () => {
|
||||
return Object.keys(Currencies).map((currencyCode) => {
|
||||
const currency = Currencies[currencyCode];
|
||||
|
||||
return {
|
||||
...currency,
|
||||
currency_code: currencyCode,
|
||||
formatted_name: `${currencyCode} - ${currency.name}`,
|
||||
};
|
||||
})
|
||||
}
|
||||
|
||||
export const currenciesOptions = getCurrenciesOptions();
|
||||
Reference in New Issue
Block a user