Skip to content

Commit

Permalink
Merge pull request #185 from BoomTech-LLC/staging
Browse files Browse the repository at this point in the history
Staging -> Main
  • Loading branch information
devboomtech authored Aug 26, 2024
2 parents 628ced6 + 79aa514 commit 3688fb6
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 11 deletions.
41 changes: 37 additions & 4 deletions src/Helpers/payment.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,53 @@ export const currencys = {
}

export const formatPrice = ({ payment, price }) => {
const { showPrices, currency, format } = payment
const { showPrices, currency, format, numberFormat } = payment

if (
showPrices &&
price !== '' &&
price !== null &&
Number(price) !== NaN &&
price > 0
)
) {
let formattedPrice

switch (numberFormat) {
case '10 000':
formattedPrice = price.toFixed(0).replace(/\B(?=(\d{3})+(?!\d))/g, ' ')
break
case '10,000':
formattedPrice = price.toFixed(0).replace(/\B(?=(\d{3})+(?!\d))/g, ',')
break
case '10.000':
formattedPrice = price.toFixed(0).replace(/\B(?=(\d{3})+(?!\d))/g, '.')
break
case '10000':
formattedPrice = price.toString().replace(/\B(?=(\d{3})+(?!\d))/g, '')
break
case '10,000.00':
formattedPrice = price.toFixed(2).replace(/\B(?=(\d{3})+(?!\d))/g, ',')
break
case '10,000.0':
formattedPrice = price.toFixed(1).replace(/\B(?=(\d{3})+(?!\d))/g, ',')
break
case '10K':
formattedPrice = (price / 1000).toFixed(0) + 'K'
break
case '10k':
formattedPrice = (price / 1000).toFixed(0) + 'k'
break
default:
formattedPrice = price.toString()
}

return (
' ' +
format.toString().replace('100', price).replace('$', currencys[currency])
format.replace('100', formattedPrice).replace('$', currencys[currency])
)
else return ''
} else {
return ''
}
}

export const getTotalPrice = ({
Expand Down
4 changes: 3 additions & 1 deletion src/Print/Print.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ const Print = ({ fields, name, description }) => {
pri.document.write(content.innerHTML)
pri.document.close()
pri.focus()
pri.print()
setTimeout(() => {
pri.print()
}, 200)
}

return (
Expand Down
51 changes: 45 additions & 6 deletions src/Print/Table.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ const Table = ({ fields }) => {
return checkbox.slice(0, -1)
}
case 'phone': {
return `${countries[values[id]?.code].dial_code} ${values[id]?.phone || ''
}`
return `${countries[values[id]?.code].dial_code} ${
values[id]?.phone || ''
}`
}
case 'time': {
return `${values[id]?.hour || ''} : ${values[id]?.minute || ''} ${values[id]?.format ? values[id].format?.value : ''
}`
return `${values[id]?.hour || ''} : ${values[id]?.minute || ''} ${
values[id]?.format ? values[id].format?.value : ''
}`
}
case 'singleChoice':
case 'scaleRating': {
Expand Down Expand Up @@ -61,6 +63,44 @@ const Table = ({ fields }) => {
}
return address
}
case 'file': {
const isImage = fileName => {
return /\.(jpg|jpeg|png|gif|webp|svg|bmp|tiff|tif|ico|heic)$/i.test(
fileName
)
}
const fileElements = []
let index = 0
for (let value in values[id]) {
const file = values[id][value]?.responce?.data

if (file) {
if (isImage(file.name && file.name)) {
fileElements.push(
<div key={`img-${index++}`}>
<img
style={{
width: '50%',
height: 'auto',
marginRight: '5px',
marginBottom: '10px'
}}
src={file?.path}
alt='Uploaded file'
/>
</div>
)
} else {
fileElements.push(
<div key={`link-${index++}`}>
<a href={file?.path}>{file?.name || file?.path}</a>
</div>
)
}
}
}
return fileElements.length ? fileElements : ''
}
default:
return values[id]
}
Expand All @@ -69,14 +109,13 @@ const Table = ({ fields }) => {
return (
<table>
<tbody>
{fields.map((field) => {
{fields.map(field => {
const { id, label, type } = field
if (
!type ||
type === 'terms' ||
type === 'map' ||
type === 'custom' ||
type === 'file' ||
type === 'just' ||
allValues.state.values[id] === undefined
)
Expand Down

0 comments on commit 3688fb6

Please sign in to comment.