mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-21 15:20:34 +00:00
feat: roles data & delete alert.
This commit is contained in:
@@ -5,6 +5,7 @@ import { Intent, Alert } from '@blueprintjs/core';
|
|||||||
import { AppToaster } from 'components';
|
import { AppToaster } from 'components';
|
||||||
|
|
||||||
import { useDeleteRole } from 'hooks/query';
|
import { useDeleteRole } from 'hooks/query';
|
||||||
|
import { handleDeleteErrors } from '../../Preferences/Users/Roles/utils';
|
||||||
|
|
||||||
import withAlertStoreConnect from 'containers/Alert/withAlertStoreConnect';
|
import withAlertStoreConnect from 'containers/Alert/withAlertStoreConnect';
|
||||||
import withAlertActions from 'containers/Alert/withAlertActions';
|
import withAlertActions from 'containers/Alert/withAlertActions';
|
||||||
@@ -45,7 +46,9 @@ function RoleDeleteAlert({
|
|||||||
response: {
|
response: {
|
||||||
data: { errors },
|
data: { errors },
|
||||||
},
|
},
|
||||||
}) => {},
|
}) => {
|
||||||
|
handleDeleteErrors(errors);
|
||||||
|
},
|
||||||
)
|
)
|
||||||
.finally(() => {
|
.finally(() => {
|
||||||
closeAlert(name);
|
closeAlert(name);
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
import { useHistory } from 'react-router-dom';
|
||||||
import intl from 'react-intl-universal';
|
import intl from 'react-intl-universal';
|
||||||
import { Formik } from 'formik';
|
import { Formik } from 'formik';
|
||||||
import { defaultTo, sumBy, isEmpty } from 'lodash';
|
|
||||||
|
|
||||||
import 'style/pages/Preferences/Roles/Form.scss';
|
import 'style/pages/Preferences/Roles/Form.scss';
|
||||||
|
|
||||||
@@ -32,6 +32,9 @@ function RolesForm({
|
|||||||
// #withDashboardActions
|
// #withDashboardActions
|
||||||
changePreferencesPageTitle,
|
changePreferencesPageTitle,
|
||||||
}) {
|
}) {
|
||||||
|
// History context.
|
||||||
|
const history = useHistory();
|
||||||
|
|
||||||
const {
|
const {
|
||||||
isNewMode,
|
isNewMode,
|
||||||
createRolePermissionMutate,
|
createRolePermissionMutate,
|
||||||
@@ -67,6 +70,7 @@ function RolesForm({
|
|||||||
intent: Intent.SUCCESS,
|
intent: Intent.SUCCESS,
|
||||||
});
|
});
|
||||||
setSubmitting(false);
|
setSubmitting(false);
|
||||||
|
history.push('/preferences/users');
|
||||||
};
|
};
|
||||||
|
|
||||||
const onError = (errors) => {
|
const onError = (errors) => {
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
import { useParams } from 'react-router-dom';
|
||||||
import RolesForm from './RolesForm';
|
import RolesForm from './RolesForm';
|
||||||
import { RolesFormProvider } from './RolesFormProvider';
|
import { RolesFormProvider } from './RolesFormProvider';
|
||||||
|
|
||||||
@@ -6,8 +7,11 @@ import { RolesFormProvider } from './RolesFormProvider';
|
|||||||
* Roles Form page.
|
* Roles Form page.
|
||||||
*/
|
*/
|
||||||
export default function RolesFormPage() {
|
export default function RolesFormPage() {
|
||||||
|
const { id } = useParams();
|
||||||
|
const idInteger = parseInt(id, 10);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<RolesFormProvider roleId={undefined}>
|
<RolesFormProvider roleId={idInteger}>
|
||||||
<RolesForm />
|
<RolesForm />
|
||||||
</RolesFormProvider>
|
</RolesFormProvider>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -31,8 +31,6 @@ function RolesFormProvider({ roleId, ...props }) {
|
|||||||
isFetching: isPermissionsSchemaFetching,
|
isFetching: isPermissionsSchemaFetching,
|
||||||
} = usePermissionsSchema();
|
} = usePermissionsSchema();
|
||||||
|
|
||||||
// const roleId = 6;
|
|
||||||
|
|
||||||
const { data: permission, isLoading: isPermissionLoading } =
|
const { data: permission, isLoading: isPermissionLoading } =
|
||||||
useRolePermission(roleId, {
|
useRolePermission(roleId, {
|
||||||
enabled: !!roleId,
|
enabled: !!roleId,
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
import { useHistory } from 'react-router-dom';
|
||||||
|
|
||||||
import intl from 'react-intl-universal';
|
import intl from 'react-intl-universal';
|
||||||
|
|
||||||
import { DataTable } from 'components';
|
import { DataTable } from 'components';
|
||||||
@@ -6,6 +8,7 @@ import TableSkeletonRows from 'components/Datatable/TableSkeletonRows';
|
|||||||
|
|
||||||
import { useRolesTableColumns, ActionsMenu } from './components';
|
import { useRolesTableColumns, ActionsMenu } from './components';
|
||||||
import withAlertsActions from 'containers/Alert/withAlertActions';
|
import withAlertsActions from 'containers/Alert/withAlertActions';
|
||||||
|
import { useRolesContext } from './RolesListProvider';
|
||||||
|
|
||||||
import { compose } from 'utils';
|
import { compose } from 'utils';
|
||||||
|
|
||||||
@@ -16,23 +19,33 @@ function RolesDataTable({
|
|||||||
// #withAlertsActions
|
// #withAlertsActions
|
||||||
openAlert,
|
openAlert,
|
||||||
}) {
|
}) {
|
||||||
|
// History context.
|
||||||
|
const history = useHistory();
|
||||||
|
|
||||||
const columns = useRolesTableColumns();
|
const columns = useRolesTableColumns();
|
||||||
|
|
||||||
|
const { roles, isRolesFetching, isRolesLoading } = useRolesContext();
|
||||||
|
|
||||||
const handleDeleteRole = ({ id }) => {
|
const handleDeleteRole = ({ id }) => {
|
||||||
openAlert('role-delete', { roleId: id });
|
openAlert('role-delete', { roleId: id });
|
||||||
};
|
};
|
||||||
|
|
||||||
// const Data = [{ name: 'AH', description: 'Description' }];
|
const handleEditRole = ({ id }) => {
|
||||||
|
history.push(`/preferences/roles/${id}`);
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DataTable
|
<DataTable
|
||||||
columns={columns}
|
columns={columns}
|
||||||
data={[]}
|
data={roles}
|
||||||
// loading={}
|
loading={isRolesLoading}
|
||||||
// progressBarLoading={}
|
headerLoading={isRolesFetching}
|
||||||
|
progressBarLoading={isRolesFetching}
|
||||||
TableLoadingRenderer={TableSkeletonRows}
|
TableLoadingRenderer={TableSkeletonRows}
|
||||||
ContextMenu={ActionsMenu}
|
ContextMenu={ActionsMenu}
|
||||||
payload={{
|
payload={{
|
||||||
onDeleteRole: handleDeleteRole,
|
onDeleteRole: handleDeleteRole,
|
||||||
|
onEditRole: handleEditRole,
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
import { CLASSES } from 'common/classes';
|
import { CLASSES } from 'common/classes';
|
||||||
// import {} from 'hooks/query';
|
import { useRoles } from 'hooks/query';
|
||||||
|
|
||||||
const RolesListContext = React.createContext();
|
const RolesListContext = React.createContext();
|
||||||
|
|
||||||
@@ -9,8 +9,20 @@ const RolesListContext = React.createContext();
|
|||||||
* Roles list provider.
|
* Roles list provider.
|
||||||
*/
|
*/
|
||||||
function RolesListProvider({ ...props }) {
|
function RolesListProvider({ ...props }) {
|
||||||
|
|
||||||
|
// fetch roles list.
|
||||||
|
const {
|
||||||
|
data: roles,
|
||||||
|
isFetching: isRolesFetching,
|
||||||
|
isLoading: isRolesLoading,
|
||||||
|
} = useRoles();
|
||||||
|
|
||||||
// Provider state.
|
// Provider state.
|
||||||
const provider = {};
|
const provider = {
|
||||||
|
roles,
|
||||||
|
isRolesFetching,
|
||||||
|
isRolesLoading,
|
||||||
|
};
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className={classNames(
|
className={classNames(
|
||||||
|
|||||||
@@ -8,12 +8,16 @@ import { Icon, If } from 'components';
|
|||||||
/**
|
/**
|
||||||
* Context menu of roles.
|
* Context menu of roles.
|
||||||
*/
|
*/
|
||||||
export function ActionsMenu({ payload: { onDeleteRole }, row: { original } }) {
|
export function ActionsMenu({
|
||||||
|
payload: { onDeleteRole, onEditRole },
|
||||||
|
row: { original },
|
||||||
|
}) {
|
||||||
return (
|
return (
|
||||||
<Menu>
|
<Menu>
|
||||||
<MenuItem
|
<MenuItem
|
||||||
icon={<Icon icon="pen-18" />}
|
icon={<Icon icon="pen-18" />}
|
||||||
text={intl.get('roles.edit_roles')}
|
text={intl.get('roles.edit_roles')}
|
||||||
|
onClick={safeCallback(onEditRole, original)}
|
||||||
/>
|
/>
|
||||||
<MenuDivider />
|
<MenuDivider />
|
||||||
<MenuItem
|
<MenuItem
|
||||||
@@ -38,16 +42,16 @@ export function useRolesTableColumns() {
|
|||||||
Header: intl.get('roles.column.name'),
|
Header: intl.get('roles.column.name'),
|
||||||
accessor: 'name',
|
accessor: 'name',
|
||||||
className: 'name',
|
className: 'name',
|
||||||
width: '100',
|
width: '80',
|
||||||
disableSortBy: true,
|
textOverview: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 'description',
|
id: 'description',
|
||||||
Header: intl.get('roles.column.description'),
|
Header: intl.get('roles.column.description'),
|
||||||
accessor: 'description',
|
accessor: 'description',
|
||||||
className: 'description',
|
className: 'description',
|
||||||
width: '120',
|
width: '180',
|
||||||
disableSortBy: true,
|
textOverview: true,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
[],
|
[],
|
||||||
|
|||||||
@@ -5,8 +5,9 @@ import t from './types';
|
|||||||
|
|
||||||
// Common invalidate queries.
|
// Common invalidate queries.
|
||||||
const commonInvalidateQueries = (queryClient) => {
|
const commonInvalidateQueries = (queryClient) => {
|
||||||
queryClient.invalidateQueries(t.ROLES_PERMISSIONS_SCHEMA);
|
|
||||||
queryClient.invalidateQueries(t.ROLE);
|
queryClient.invalidateQueries(t.ROLE);
|
||||||
|
queryClient.invalidateQueries(t.ROLES);
|
||||||
|
queryClient.invalidateQueries(t.ROLES_PERMISSIONS_SCHEMA);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -93,3 +94,18 @@ export function useRolePermission(role_id, props, requestProps) {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve the roles.
|
||||||
|
*/
|
||||||
|
export function useRoles(props, query) {
|
||||||
|
return useRequestQuery(
|
||||||
|
[t.ROLES, query],
|
||||||
|
{ method: 'get', url: `roles`, params: query },
|
||||||
|
{
|
||||||
|
select: (res) => res.data.roles,
|
||||||
|
defaultData: [],
|
||||||
|
...props,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|||||||
@@ -1470,11 +1470,14 @@
|
|||||||
"list.create":"Create {value}",
|
"list.create":"Create {value}",
|
||||||
"roles.label":"Roles",
|
"roles.label":"Roles",
|
||||||
"roles.column.name":"Name",
|
"roles.column.name":"Name",
|
||||||
"roles.column.description":"description",
|
"roles.column.description":"Description",
|
||||||
|
"roles.column.role_name":"Role Name",
|
||||||
"roles.edit_roles":"Edit Roles",
|
"roles.edit_roles":"Edit Roles",
|
||||||
"roles.delete_roles":"Delete Roles",
|
"roles.delete_roles":"Delete Roles",
|
||||||
"roles.label.role_name":"Role Name",
|
"roles.label.role_name":"Role Name",
|
||||||
"roles.label.role_name_":"Role name",
|
"roles.label.role_name_":"Role name",
|
||||||
|
"roles.error.role_is_predefined":"Role is predefined, you cannot delete predefined roles.",
|
||||||
|
"roles.error.you_cannot_change_your_own_role":"You cannot change your own role.",
|
||||||
"sidebar.transactions_locaking":"Transactions Locaking",
|
"sidebar.transactions_locaking":"Transactions Locaking",
|
||||||
"transactions_locking.dialog.label":"Transactions locking",
|
"transactions_locking.dialog.label":"Transactions locking",
|
||||||
"roles.permission_schema.success_message":"The role has been created successfully.",
|
"roles.permission_schema.success_message":"The role has been created successfully.",
|
||||||
|
|||||||
Reference in New Issue
Block a user