mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 13:20:31 +00:00
fix(InviteUsers): fix invite users bugs.
This commit is contained in:
@@ -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,
|
||||
},
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user