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

(Mailables): Support Simultaneous Small and Large Print #925

Merged
merged 2 commits into from
Jun 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
27 changes: 22 additions & 5 deletions lib/components/admin/mailables-window.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ class SelectedMailable extends Component {
updateField(index, 'largeFormat', evt.target.checked)
}

_changeSmallFormat = (evt) => {
const { index, updateField } = this.props
updateField(index, 'smallFormat', evt.target.checked)
}

_changeQuantity = (evt) => {
const { index, updateField } = this.props
updateField(index, 'quantity', evt.target.value)
Expand All @@ -57,7 +62,8 @@ class SelectedMailable extends Component {

render() {
const { index, mailable } = this.props
const id = `largeFormat-${index}`
const largeId = `largeFormat-${index}`
const smallId = `smallFormat-${index}`
return (
<SelectedMailableContainer>
<MailableLabel mailable={mailable} />
Expand All @@ -70,15 +76,26 @@ class SelectedMailable extends Component {
type="number"
value={mailable.quantity}
/>
<div style={{ marginTop: '5px' }}>
<input
checked={mailable.smallFormat}
id={smallId}
onChange={this._changeSmallFormat}
type="checkbox"
/>
<label htmlFor={smallId} style={{ marginLeft: '5px' }}>
Small format?
</label>
</div>
{mailable.largePrint && (
<div style={{ marginTop: '5px' }}>
<input
id={id}
checked={mailable.largeFormat}
id={largeId}
onChange={this._changeLargeFormat}
type="checkbox"
value={mailable.largeFormat}
/>
<label htmlFor={id} style={{ marginLeft: '5px' }}>
<label htmlFor={largeId} style={{ marginLeft: '5px' }}>
Large format?
</label>
</div>
Expand Down Expand Up @@ -107,7 +124,7 @@ class MailablesWindow extends Component {
_addMailable = (mailable) => {
if (!this.state.mailables.find((m) => m.name === mailable.name)) {
const mailables = [...this.state.mailables]
mailables.push({ ...mailable, quantity: 1 })
mailables.push({ ...mailable, quantity: 1, smallFormat: true })
this.setState({ mailables })
}
}
Expand Down
23 changes: 16 additions & 7 deletions lib/util/mailables.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,22 @@ async function writePDF(formData, imageData, otpConfig) {

const tableData = {
headers: ['Item', 'Quantity'],
rows: mailables.map((mailable) => {
let { largeFormat, largePrint, name, quantity } = mailable
if (largePrint && largeFormat) {
name += ' (LARGE PRINT)'
}
return [name, quantity]
})
rows: mailables
.map((mailable) => {
let { largeFormat, largePrint, name, quantity, smallFormat } = mailable
const rows = []

if (smallFormat) {
rows.push([name, quantity])
}

if (largePrint && largeFormat) {
name += ' (LARGE PRINT)'
rows.push([name, quantity])
}
return rows
})
.flat()
Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpicky, but could just change the above map to flatMap

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is much cleaner thanks!

}

doc.table(tableData, {
Expand Down