mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-20 06:40:31 +00:00
feat: Preferences issue.
This commit is contained in:
@@ -8,7 +8,7 @@ import PreferencesSidebar from 'components/Preferences/PreferencesSidebar';
|
|||||||
|
|
||||||
export default function() {
|
export default function() {
|
||||||
return (
|
return (
|
||||||
<div className="dashboard dashboard--preferences">
|
<div className="dashboard">
|
||||||
<Switch>
|
<Switch>
|
||||||
<Route path="/dashboard/preferences">
|
<Route path="/dashboard/preferences">
|
||||||
<Sidebar />
|
<Sidebar />
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import PreferencesContentRoute from 'components/Preferences/PreferencesContentRo
|
|||||||
|
|
||||||
export default function() {
|
export default function() {
|
||||||
return (
|
return (
|
||||||
<div className="dashboard-content" id="dashboard">
|
<div className="dashboard-content dashboard-content--preferences">
|
||||||
<PreferencesTopbar pageTitle={"asdad"}/>
|
<PreferencesTopbar pageTitle={"asdad"}/>
|
||||||
|
|
||||||
<div class="dashboard__preferences-content">
|
<div class="dashboard__preferences-content">
|
||||||
|
|||||||
@@ -3,15 +3,13 @@ import { Route, Switch, useRouteMatch } from 'react-router-dom';
|
|||||||
import preferencesRoutes from 'routes/preferences'
|
import preferencesRoutes from 'routes/preferences'
|
||||||
|
|
||||||
export default function DashboardContentRoute() {
|
export default function DashboardContentRoute() {
|
||||||
const { path } = useRouteMatch();
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Route pathname="/dashboard/preferences">
|
<Route pathname="/dashboard/preferences">
|
||||||
<Switch>
|
<Switch>
|
||||||
{ preferencesRoutes.map((route, index) => (
|
{ preferencesRoutes.map((route, index) => (
|
||||||
<Route
|
<Route
|
||||||
key={index}
|
key={index}
|
||||||
path={`${path}/${route.path}`}
|
path={`${route.path}`}
|
||||||
exact={route.exact}
|
exact={route.exact}
|
||||||
component={route.component}
|
component={route.component}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -18,13 +18,15 @@ export default function PreferencesSidebar() {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div class="preferences__sidebar">
|
<div class="preferences__sidebar">
|
||||||
<div class="preferences__sidebar-head">
|
<div class="preferences__sidebar-wrapper">
|
||||||
<h2>Preferences</h2>
|
<div class="preferences__sidebar-head">
|
||||||
</div>
|
<h2>Preferences</h2>
|
||||||
|
</div>
|
||||||
|
|
||||||
<Menu className="preferences__sidebar-menu">
|
<Menu className="preferences__sidebar-menu">
|
||||||
{ items }
|
{ items }
|
||||||
</Menu>
|
</Menu>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import React, {useState, useEffect} from 'react';
|
import React, {useState, useEffect, useCallback, useMemo} from 'react';
|
||||||
import {Formik, useFormik, ErrorMessage} from "formik";
|
import {Formik, useFormik, ErrorMessage} from "formik";
|
||||||
import {useIntl} from 'react-intl';
|
import {useIntl} from 'react-intl';
|
||||||
import {
|
import {
|
||||||
@@ -34,12 +34,13 @@ function ViewForm({
|
|||||||
const [draggedColumns, setDraggedColumn] = useState([]);
|
const [draggedColumns, setDraggedColumn] = useState([]);
|
||||||
const [availableColumns, setAvailableColumns] = useState(columns);
|
const [availableColumns, setAvailableColumns] = useState(columns);
|
||||||
|
|
||||||
const defaultViewRole = {
|
const defaultViewRole = useMemo(() => ({
|
||||||
field_key: '',
|
field_key: '',
|
||||||
comparator: 'AND',
|
comparator: 'AND',
|
||||||
value: '',
|
value: '',
|
||||||
index: 1,
|
index: 1,
|
||||||
};
|
}), []);
|
||||||
|
|
||||||
const validationSchema = Yup.object().shape({
|
const validationSchema = Yup.object().shape({
|
||||||
resource_name: Yup.string().required(),
|
resource_name: Yup.string().required(),
|
||||||
name: Yup.string().required(),
|
name: Yup.string().required(),
|
||||||
@@ -86,7 +87,6 @@ function ViewForm({
|
|||||||
],
|
],
|
||||||
},
|
},
|
||||||
onSubmit: (values) => {
|
onSubmit: (values) => {
|
||||||
|
|
||||||
if (viewForm && viewForm.id) {
|
if (viewForm && viewForm.id) {
|
||||||
editView(viewForm.id, values).then((response) => {
|
editView(viewForm.id, values).then((response) => {
|
||||||
|
|
||||||
@@ -100,10 +100,11 @@ function ViewForm({
|
|||||||
});
|
});
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
formik.setFieldValue('columns', draggedColumns.map((column, index) => ({
|
formik.setFieldValue('columns',
|
||||||
|
draggedColumns.map((column, index) => ({
|
||||||
index, key: column.key,
|
index, key: column.key,
|
||||||
})));
|
})));
|
||||||
}, [draggedColumns]);
|
}, [draggedColumns, formik]);
|
||||||
|
|
||||||
const conditionalsItems = [
|
const conditionalsItems = [
|
||||||
{ value: 'and', label: 'AND' },
|
{ value: 'and', label: 'AND' },
|
||||||
@@ -123,16 +124,16 @@ function ViewForm({
|
|||||||
];
|
];
|
||||||
|
|
||||||
// Resource fields.
|
// Resource fields.
|
||||||
const resourceFields = [
|
const resourceFields = useMemo(() => ([
|
||||||
{value: '', label: 'Select a field'},
|
{value: '', label: 'Select a field'},
|
||||||
...fields.map((field) => ({ value: field.key, label: field.labelName, })),
|
...fields.map((field) => ({ value: field.key, label: field.labelName, })),
|
||||||
];
|
]), []);
|
||||||
// Account item of select accounts field.
|
// Account item of select accounts field.
|
||||||
const selectItem = (item, { handleClick, modifiers, query }) => {
|
const selectItem = (item, { handleClick, modifiers, query }) => {
|
||||||
return (<MenuItem text={item.label} key={item.key} onClick={handleClick} />)
|
return (<MenuItem text={item.label} key={item.key} onClick={handleClick} />)
|
||||||
};
|
};
|
||||||
// Handle click new condition button.
|
// Handle click new condition button.
|
||||||
const onClickNewRole = () => {
|
const onClickNewRole = useCallback(() => {
|
||||||
formik.setFieldValue('roles', [
|
formik.setFieldValue('roles', [
|
||||||
...formik.values.roles,
|
...formik.values.roles,
|
||||||
{
|
{
|
||||||
@@ -140,9 +141,10 @@ function ViewForm({
|
|||||||
index: formik.values.roles.length + 1,
|
index: formik.values.roles.length + 1,
|
||||||
}
|
}
|
||||||
]);
|
]);
|
||||||
};
|
}, [formik, defaultViewRole]);
|
||||||
|
|
||||||
// Handle click remove view role button.
|
// Handle click remove view role button.
|
||||||
const onClickRemoveRole = (viewRole, index) => () => {
|
const onClickRemoveRole = useCallback((viewRole, index) => () => {
|
||||||
const viewRoles = [...formik.values.roles];
|
const viewRoles = [...formik.values.roles];
|
||||||
viewRoles.splice(index, 1);
|
viewRoles.splice(index, 1);
|
||||||
viewRoles.map((role, i) => {
|
viewRoles.map((role, i) => {
|
||||||
@@ -150,9 +152,12 @@ function ViewForm({
|
|||||||
return role;
|
return role;
|
||||||
});
|
});
|
||||||
formik.setFieldValue('roles', viewRoles);
|
formik.setFieldValue('roles', viewRoles);
|
||||||
};
|
}, [formik]);
|
||||||
|
|
||||||
|
const onClickDeleteView = useCallback(() => {
|
||||||
|
onDelete && onDelete(viewForm);
|
||||||
|
}, [onDelete, viewForm]);
|
||||||
|
|
||||||
const onClickDeleteView = () => { onDelete(viewForm); };
|
|
||||||
return (
|
return (
|
||||||
<div class="view-form">
|
<div class="view-form">
|
||||||
<form onSubmit={formik.handleSubmit}>
|
<form onSubmit={formik.handleSubmit}>
|
||||||
|
|||||||
@@ -1,30 +1,22 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { useFormik } from 'formik';
|
import { useFormik } from 'formik';
|
||||||
import * as Yup from 'yup';
|
import * as Yup from 'yup';
|
||||||
import {connect} from 'react-redux';
|
|
||||||
import {
|
import {
|
||||||
Button,
|
Button,
|
||||||
FormGroup,
|
FormGroup,
|
||||||
InputGroup,
|
InputGroup,
|
||||||
Intent,
|
Intent,
|
||||||
} from "@blueprintjs/core";
|
} from "@blueprintjs/core";
|
||||||
import { useAsync } from 'react-use';
|
|
||||||
import {optionsMapToArray} from 'utils';
|
import {optionsMapToArray} from 'utils';
|
||||||
import AppToaster from 'components/AppToaster';
|
|
||||||
import {
|
|
||||||
savePreferences,
|
|
||||||
fetchPreferences,
|
|
||||||
} from 'store/preferences/preferences.actions';
|
|
||||||
|
|
||||||
function GeneralPreferences({ savePreferences, fetchPreferences }) {
|
function GeneralPreferences({
|
||||||
|
|
||||||
|
}) {
|
||||||
const validationSchema = Yup.object().shape({
|
const validationSchema = Yup.object().shape({
|
||||||
organization_name: Yup.string().required(),
|
organization_name: Yup.string().required(),
|
||||||
organization_industry: Yup.string().required(),
|
organization_industry: Yup.string().required(),
|
||||||
});
|
});
|
||||||
|
|
||||||
const asyncHook = useAsync(async () => {
|
|
||||||
await fetchPreferences();
|
|
||||||
});
|
|
||||||
const formik = useFormik({
|
const formik = useFormik({
|
||||||
enableReinitialize: true,
|
enableReinitialize: true,
|
||||||
initialValues: {
|
initialValues: {
|
||||||
@@ -35,13 +27,6 @@ function GeneralPreferences({ savePreferences, fetchPreferences }) {
|
|||||||
return {...option, group: 'general'};
|
return {...option, group: 'general'};
|
||||||
});
|
});
|
||||||
|
|
||||||
savePreferences(options).then((response) => {
|
|
||||||
AppToaster.show({
|
|
||||||
message: 'preferences_have_been_updated',
|
|
||||||
});
|
|
||||||
}).catch(error => {
|
|
||||||
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -80,9 +65,4 @@ function GeneralPreferences({ savePreferences, fetchPreferences }) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
const mapDispatchToProps = (dispatch) => ({
|
export default GeneralPreferences;
|
||||||
savePreferences: (options) => dispatch(savePreferences({ options })),
|
|
||||||
fetchPreferences: (keys) => dispatch(fetchPreferences())
|
|
||||||
});
|
|
||||||
|
|
||||||
export default connect(null, mapDispatchToProps)(GeneralPreferences);
|
|
||||||
@@ -1,5 +1,8 @@
|
|||||||
|
|
||||||
|
|
||||||
|
.dashboard-content--preferences{
|
||||||
|
margin-left: 430px;
|
||||||
|
}
|
||||||
|
|
||||||
.preferences{
|
.preferences{
|
||||||
&__inside-content--tabable{
|
&__inside-content--tabable{
|
||||||
@@ -8,7 +11,6 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
&__inside-content{
|
&__inside-content{
|
||||||
|
|
||||||
.#{$ns}-tab-list{
|
.#{$ns}-tab-list{
|
||||||
border-bottom: 1px solid #E5E5E5;
|
border-bottom: 1px solid #E5E5E5;
|
||||||
padding-left: 15px;
|
padding-left: 15px;
|
||||||
@@ -22,9 +24,16 @@
|
|||||||
|
|
||||||
.preferences__sidebar{
|
.preferences__sidebar{
|
||||||
background: #fdfdfd;
|
background: #fdfdfd;
|
||||||
|
position: fixed;
|
||||||
|
left: 220px;
|
||||||
min-width: 210px;
|
min-width: 210px;
|
||||||
max-width: 210px;
|
max-width: 210px;
|
||||||
|
height: 100%;
|
||||||
|
|
||||||
|
.sidebar-wrapper{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
&-head{
|
&-head{
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
|
|||||||
Reference in New Issue
Block a user