Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support 2-Decimal Formatting & customizable decimal separator #192

Merged
merged 30 commits into from
Feb 11, 2018
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
dd3d16e
Closes hql287/Manta#190, Closes hql287/Manta#173
Jan 25, 2018
7e77648
Merge branch 'dev' into dev
DarkSmile92 Jan 29, 2018
1b8fd42
Preview and Invoices list
Jan 29, 2018
812f2ae
Merge branch 'dev' into dev
hql287 Feb 1, 2018
733ca44
#190 tests and other points
Feb 1, 2018
e0df73c
Merge branch 'dev' of https://github.com/DarkSmile92/Manta into dev
Feb 1, 2018
a7e196b
Removed console logs and eslint errors
Feb 1, 2018
4473f69
Use dialog instead of notification
Feb 1, 2018
3916e2f
Refactored Invoice setting component
hql287 Feb 2, 2018
4c157b0
Merge branch 'dev' into dev
hql287 Feb 2, 2018
9bc2ede
Added new definitions
hql287 Feb 2, 2018
7b8c458
Refactored Invoice settings tab
hql287 Feb 2, 2018
ac85c09
Merge branch 'dev' into dev
hql287 Feb 2, 2018
8167821
Merge branch 'dev' into dev
hql287 Feb 3, 2018
b70229d
Merge branch 'dev' into dev
hql287 Feb 4, 2018
0325b95
Reimplemented currency settings
hql287 Feb 5, 2018
ff5d8e8
Refactored InvoiceMW & Form helper
hql287 Feb 5, 2018
d7aeefe
Moved numer helper to application helpers folder
hql287 Feb 5, 2018
21db7a0
Updated Currency component in Form
hql287 Feb 5, 2018
015f2fa
Refactored Tax & Recipient Form with the shared Part component
hql287 Feb 5, 2018
a510844
Refactored components
hql287 Feb 5, 2018
5b25aab
Make sure numbers are displayed correctly in templates
hql287 Feb 5, 2018
171d18d
Send notification when saveAsDefault successfully
hql287 Feb 5, 2018
637b8d0
Updated translation
hql287 Feb 5, 2018
17d8343
Fixed tests
hql287 Feb 5, 2018
91284b0
Updated translation
hql287 Feb 5, 2018
c8b851c
Clear the form if the invoice is being editted
hql287 Feb 6, 2018
cfe6e41
Refactored validation rules, tests & added translation
hql287 Feb 7, 2018
a2de896
Updated migration for invoices
hql287 Feb 11, 2018
ae3a05d
Refactored formatNumber helper and added tests
hql287 Feb 11, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,9 @@ function setInitialValues() {
tax: false,
note: false,
},
decimalFractions: 2,
currencyPlacement: 'before',
decimalSeparator: 'dot',
},
};

Expand Down
8 changes: 8 additions & 0 deletions app/actions/__tests__/settings.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,11 @@ it('saveSettings should create SAVE_SETTINGS action', () => {
payload: settingsData,
});
});

it('notifyInvalidDecimalFractions should create UI_NOTIFICATION_NEW action', () => {
const settingsData = {};
expect(actions.notifyInvalidDecimalFractions(settingsData)).toEqual({
type: ACTION_TYPES.UI_NOTIFICATION_NEW,
payload: {message: 'Invalid decimal fractions specified! Please correct settings.', type: 'warning'},
});
});
6 changes: 6 additions & 0 deletions app/actions/settings.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,9 @@ export const saveSettings = createAction(
ACTION_TYPES.SETTINGS_SAVE,
data => data
);

// Notify user about invalid decimal fractions
export const notifyInvalidDecimalFractions = createAction(
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use dialog for validation message. I would like to user to acknowledge this before moving on.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed :)

ACTION_TYPES.UI_NOTIFICATION_NEW,
(type, message) => ({type: 'warning', message: 'Invalid decimal fractions specified! Please correct settings.'})
);
5 changes: 3 additions & 2 deletions app/components/invoices/Invoice.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ class Invoice extends PureComponent {
}

render() {
const { invoice, setInvoiceStatus, dateFormat } = this.props;
const { invoice, setInvoiceStatus, dateFormat, currencyPlacement } = this.props;
const { recipient, status } = invoice;
const statusActions = [
{
Expand All @@ -224,6 +224,7 @@ class Invoice extends PureComponent {
action: () => setInvoiceStatus(invoice._id, 'cancelled'),
},
];
const currencyBefore = currencyPlacement === 'before';
return (
<div className="col-lg-6">
<Wrapper>
Expand Down Expand Up @@ -254,7 +255,7 @@ class Invoice extends PureComponent {
<Field>
<label>Total Value</label>
<p>
{invoice.currency.code} {formatNumber(invoice.grandTotal)}
{currencyBefore ? invoice.currency.code : ''} {formatNumber(invoice.grandTotal)} {currencyBefore ? '' : invoice.currency.code}
</p>
</Field>
</Row>
Expand Down
8 changes: 8 additions & 0 deletions app/components/invoices/__tests__/Invoice.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const editInvoice = jest.fn();
const deleteInvoice = jest.fn();
const setInvoiceStatus = jest.fn();
const dateFormat = 'MM/DD/YY';
const currencyPlacement = 'before';

// Tests
describe('Renders correctly to the DOM', () => {
Expand All @@ -48,6 +49,7 @@ describe('Renders correctly to the DOM', () => {
deleteInvoice={deleteInvoice}
setInvoiceStatus={setInvoiceStatus}
dateFormat={dateFormat}
currencyPlacement={currencyPlacement}
/>
);
});
Expand All @@ -60,6 +62,7 @@ describe('Renders correctly to the DOM', () => {
deleteInvoice={deleteInvoice}
setInvoiceStatus={setInvoiceStatus}
dateFormat={dateFormat}
currencyPlacement={currencyPlacement}
/>
);
expect(mountWrapper.prop('invoice')).toEqual(invoice);
Expand Down Expand Up @@ -97,6 +100,7 @@ describe('Renders correctly to the DOM', () => {
deleteInvoice={deleteInvoice}
setInvoiceStatus={setInvoiceStatus}
dateFormat={dateFormat}
currencyPlacement={currencyPlacement}
/>
);
expect(
Expand All @@ -118,6 +122,7 @@ describe('Renders correctly to the DOM', () => {
deleteInvoice={deleteInvoice}
setInvoiceStatus={setInvoiceStatus}
dateFormat={dateFormat}
currencyPlacement={currencyPlacement}
/>
);
expect(
Expand All @@ -137,6 +142,7 @@ describe('Renders correctly to the DOM', () => {
deleteInvoice={deleteInvoice}
setInvoiceStatus={setInvoiceStatus}
dateFormat={dateFormat}
currencyPlacement={currencyPlacement}
/>
);
expect(
Expand Down Expand Up @@ -166,6 +172,7 @@ describe('Renders correctly to the DOM', () => {
deleteInvoice={deleteInvoice}
setInvoiceStatus={setInvoiceStatus}
dateFormat={dateFormat}
currencyPlacement={currencyPlacement}
/>
)
.toJSON();
Expand All @@ -185,6 +192,7 @@ describe('handle clicks correctly', () => {
deleteInvoice={deleteInvoice}
setInvoiceStatus={setInvoiceStatus}
dateFormat={dateFormat}
currencyPlacement={currencyPlacement}
/>
);
viewBtn = wrapper
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ exports[`Renders correctly to the DOM matches snapshot 1`] = `
<p>
USD

3,843
3,843.00


</p>
</div>
</div>
Expand Down
61 changes: 61 additions & 0 deletions app/components/settings/Invoice.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,34 @@ class Invoice extends Component {
}

handleInputChange(event) {
const { setSavable } = this.props;
const target = event.target;
const value = target.type === 'checkbox' ? target.checked : target.value;
const name = target.name;

const canSave = this.canSave(name, value);
setSavable(canSave);
if (!canSave) {
// Notifi
console.log('Cant save');
}

this.setState({ [name]: value }, () => {
this.props.updateSettings('invoice', this.state);
});
}

canSave(ctrlName, value) {
let valid = true;
if (ctrlName === 'decimalFractions' && Number(value) < 0){
valid = false;
const { invalidFractionMsg } = this.props;
invalidFractionMsg();
}

return valid;
}

handleTaxChange(event) {
const target = event.target;
const name = target.name;
Expand Down Expand Up @@ -143,6 +163,9 @@ class Invoice extends Component {
tax,
required_fields,
dateFormat,
decimalFractions,
currencyPlacement,
decimalSeparator,
} = this.state;
return (
<div>
Expand Down Expand Up @@ -334,6 +357,44 @@ class Invoice extends Component {
</div>
</Field>
</Row>
<Row>
<Field>
<label className="itemLabel">Decimal Fractions</label>
<input
className="form-control"
name="decimalFractions"
type="number"
value={decimalFractions}
onChange={this.handleInputChange}
/>
</Field>
<Field>
<label className="itemLabel">Currency Sign placement</label>
<select
name="currencyPlacement"
value={currencyPlacement}
onChange={this.handleInputChange}
>
<option value="before">Before amount</option>
<option value="after">After amount</option>
</select>
</Field>
</Row>
<Row>
<Field>
<label className="itemLabel">Decimal Separator</label>
<select
name="decimalSeparator"
value={decimalSeparator}
onChange={this.handleInputChange}
>
<option value="dot">Dot (.)</option>
<option value="comma">Comma (,)</option>
</select>
</Field>
{/* To prevent stretching the first field. Use for next paramter in future and remove comment afterwards */}
<Field />
</Row>
</Section>
</div>
);
Expand Down
6 changes: 4 additions & 2 deletions app/containers/Invoices.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import * as Actions from '../actions/invoices';

// Selectors
import { getInvoices } from '../reducers/InvoicesReducer';
import { getDateFormat } from '../reducers/SettingsReducer';
import { getDateFormat, getCurrencyPlacement } from '../reducers/SettingsReducer';

// Components
import Invoice from '../components/invoices/Invoice';
Expand Down Expand Up @@ -80,7 +80,7 @@ class Invoices extends PureComponent {

// Render
render() {
const { invoices, dateFormat } = this.props;
const { invoices, dateFormat, currencyPlacement } = this.props;
const invoicesComponent = invoices.map((invoice, index) => (
<Invoice
key={invoice._id}
Expand All @@ -89,6 +89,7 @@ class Invoices extends PureComponent {
setInvoiceStatus={this.setInvoiceStatus}
index={index}
dateFormat={dateFormat}
currencyPlacement={currencyPlacement}
invoice={invoice}
/>
));
Expand Down Expand Up @@ -119,6 +120,7 @@ Invoices.propTypes = {
const mapStateToProps = state => ({
invoices: getInvoices(state),
dateFormat: getDateFormat(state),
currencyPlacement: getCurrencyPlacement(state),
});

export default compose(connect(mapStateToProps), _withFadeInAnimation)(
Expand Down
18 changes: 12 additions & 6 deletions app/containers/Settings.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ import _withFadeInAnimation from '../components/shared/hoc/_withFadeInAnimation'
class Settings extends Component {
constructor(props) {
super(props);
this.state = { visibleTab: 1 };
this.state = { visibleTab: 1, canSave: true };
this.saveSettingsState = this.saveSettingsState.bind(this);
this.setSavable = this.setSavable.bind(this);
}

// Check if settings have been saved
Expand All @@ -55,15 +56,20 @@ class Settings extends Component {
this.setState({ visibleTab: tabNum });
}

// controls if save button appears
setSavable(settingsValid) {
this.setState({canSave: settingsValid});
}

// Render Main Content
renderSettingsContent() {
const { profile, general, invoice } = this.props.currentSettings;
const { updateSettings } = this.props.boundActionCreators;
const { updateSettings, notifyInvalidDecimalFractions } = this.props.boundActionCreators;
return (
<PageWrapper>
<PageHeader>
<PageHeaderTitle>Settings</PageHeaderTitle>
{!this.settingsSaved() && (
{!this.settingsSaved() && this.state.canSave && (
<PageHeaderActions>
<Button primary onClick={this.saveSettingsState}>
Save
Expand Down Expand Up @@ -97,13 +103,13 @@ class Settings extends Component {
</Tabs>
<TabContent>
{this.state.visibleTab === 1 && (
<Profile profile={profile} updateSettings={updateSettings} />
<Profile profile={profile} updateSettings={updateSettings} setSavable={this.setSavable} />
)}
{this.state.visibleTab === 2 && (
<Invoice invoice={invoice} updateSettings={updateSettings} />
<Invoice invoice={invoice} updateSettings={updateSettings} setSavable={this.setSavable} invalidFractionMsg={notifyInvalidDecimalFractions} />
)}
{this.state.visibleTab === 3 && (
<General general={general} updateSettings={updateSettings} />
<General general={general} updateSettings={updateSettings} setSavable={this.setSavable} />
)}
</TabContent>
</PageContent>
Expand Down
12 changes: 12 additions & 0 deletions app/helpers/__tests__/form.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ describe('getInvoiceData', () => {
tax: false,
note: false,
},
decimalFractions: 2,
currencyPlacement: 'before',
decimalSeparator: 'dot',
},
savedSettings: {
tax: {},
Expand All @@ -76,6 +79,9 @@ describe('getInvoiceData', () => {
tax: false,
note: false,
},
decimalFractions: 2,
currencyPlacement: 'before',
decimalSeparator: 'dot',
},
};
});
Expand Down Expand Up @@ -277,6 +283,9 @@ describe('validateFormData', () => {
tax: true,
note: true,
},
decimalFractions: 2,
currencyPlacement: 'before',
decimalSeparator: 'dot',
},
savedSettings: {
tax: {
Expand All @@ -292,6 +301,9 @@ describe('validateFormData', () => {
tax: true,
note: true,
},
decimalFractions: 2,
currencyPlacement: 'before',
decimalSeparator: 'dot',
},
};
});
Expand Down
Loading