Skip to content

Commit

Permalink
refinements, formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
scoxen1 committed May 2, 2024
1 parent 09852be commit 166130d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
4 changes: 2 additions & 2 deletions frontend/src/components/eCommerce/CartItem.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useState, useEffect, Fragment } from 'react'
import { Form, Col, Card } from 'react-bootstrap'
import { validateCartItem_Quantity } from '../../utils/CartUtil';
import { generateLogMessageString } from '../../utils/UtilityService';
import { formatCurrency, generateLogMessageString } from '../../utils/UtilityService';
import _icon from '../img/icon-cesmii-white.png'
import '../styles/Modal.scss';

Expand Down Expand Up @@ -145,7 +145,7 @@ function CartItem(props) {
</Col>
}
<Col className='d-flex'>
<Form.Label className='ml-auto'>${price.amount}</Form.Label>
<Form.Label className='ml-auto pr-2'>{formatCurrency(price.amount)}</Form.Label>
</Col>
</Form.Row>
</Form.Group>
Expand Down
14 changes: 7 additions & 7 deletions frontend/src/components/eCommerce/CartPreview.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { useState, Fragment, useEffect } from 'react'
import { Form } from 'react-bootstrap'

import { useLoadingContext } from '../../components/contexts/LoadingContext';
import { generateLogMessageString } from '../../utils/UtilityService';
import { formatCurrency, generateLogMessageString } from '../../utils/UtilityService';
import { removeCartItem, updateCart } from '../../utils/CartUtil';
import CartItem from './CartItem';

Expand Down Expand Up @@ -124,20 +124,20 @@ function CartPreview() {
<>
{credits != null &&
<>
<div className="row m-0 pt-1 mt-1 border-bottom font-weight-bold">
<div className="row m-0 py-1 mt-1 border-bottom">
<div className="col-8">
Sub-Total
</div>
<div className="col-4 text-right">
${subTotal}
<span className="pr-2" >{formatCurrency(subTotal)}</span>
</div>
</div>
<div className="row m-0 pt-1 mt-1 border-bottom font-weight-bold">
<div className="row m-0 py-1 mt-1 border-bottom">
<div className="col-8">
Credits Applied
</div>
<div className="col-4 text-right">
${credits}
<span className="pr-2" >{formatCurrency(credits)}</span>
</div>
</div>
</>
Expand All @@ -147,7 +147,7 @@ function CartPreview() {
Total
</div>
<div className="col-4 text-right">
${total}
<span className="pr-2" >{formatCurrency(total)}</span>
</div>
</div>
</>
Expand All @@ -163,7 +163,7 @@ function CartPreview() {

return (
<div className="text-center border-top mt-3 pt-2">
<p>Your organization has <b>${loadingProps.user.credit} {loadingProps.user.credit === 1? 'credit' : 'credits' }</b> available to apply to this purchase.</p>
<p>Your organization has <b>{formatCurrency(loadingProps.user.credit)} {loadingProps.user.credit === 1? 'credit' : 'credits' }</b> available to apply to this purchase.</p>
<Form.Group>
<Form.Check className="align-self-end" type="checkbox" id="useCredits" label="Use credits for this purchase?"
checked={_useCredits} onChange={onChangeChecked} />
Expand Down
5 changes: 5 additions & 0 deletions frontend/src/utils/UtilityService.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,11 @@ export function formatItemPublishDate(item) {
return formatDate(item.publishDate);
}

export function formatCurrency(val) {
if (val == null || val === '') return null;
var usd = new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD' });
return usd.format(val);
}

// From ProfileDesigner\frontend\src\views\shared\ProfileEntity.js:
//Dates will come in two formats:
Expand Down

0 comments on commit 166130d

Please sign in to comment.