diff --git a/frontend/src/Forms.js b/frontend/src/Forms.js index 94354f3..c070c25 100644 --- a/frontend/src/Forms.js +++ b/frontend/src/Forms.js @@ -10,11 +10,14 @@ import * as cs from "./constants" class Forms extends React.PureComponent { state = { lists: [], - selected: [] + selected: [], + selectedUUIDs: [], + indeterminate: false, + checkAll: false } componentDidMount() { - this.props.pageTitle("Forms") + this.props.pageTitle("Subscription forms") this.props .modelRequest(cs.ModelLists, cs.Routes.GetLists, cs.MethodGet, { per_page: "all" @@ -24,6 +27,16 @@ class Forms extends React.PureComponent { }) } + handleSelectAll = e => { + const uuids = this.state.lists.map(l => l.uuid) + this.setState({ + selectedUUIDs: e.target.checked ? uuids : [], + indeterminate: false, + checkAll: e.target.checked + }) + this.handleSelection(e.target.checked ? uuids : []) + } + handleSelection(sel) { let out = [] sel.forEach(s => { @@ -35,56 +48,86 @@ class Forms extends React.PureComponent { } }) - console.log(out) - this.setState({ selected: out }) + this.setState({ + selected: out, + selectedUUIDs: sel, + indeterminate: sel.length > 0 && sel.length < this.state.lists.length, + checkAll: sel.length === this.state.lists.length + }) } render() { return (
-

Forms

- - +

Subscription forms

+
+ + +

Lists

+ + Select all + +
{ return { label: l.name, value: l.uuid } })} - defaultValue={[]} - onChange={(sel) => this.handleSelection(sel)} + onChange={sel => this.handleSelection(sel)} + value={this.state.selectedUUIDs} /> - -

Form HTML

-

Use the following HTML to show a subscription form on an external webpage.

-

- The form should have the email field and one or more{" "} - l (list UUID) fields. The name field is optional. -

+ +

Form HTML

+

+ Use the following HTML to show a subscription form on an external + webpage. +

+

+ The form should have the{" "} + + email + {" "} + field and one or more{" "} + + l + {" "} + (list UUID) fields. The{" "} + + name + {" "} + field is optional. +

-
-{`
+ {`

Subscribe

-

-

`} -{(() => { - let out = []; - this.state.selected.forEach(l => { - out.push(` +

+

`} + {(() => { + let out = [] + this.state.selected.forEach(l => { + out.push(`

- - -

`); - }); - return out; -})()} -{` + + +

`) + }) + return out + })()} + {`

`} -