Refactor forms UI
This commit is contained in:
parent
276942ab91
commit
0a2d2d66be
|
@ -10,11 +10,14 @@ import * as cs from "./constants"
|
||||||
class Forms extends React.PureComponent {
|
class Forms extends React.PureComponent {
|
||||||
state = {
|
state = {
|
||||||
lists: [],
|
lists: [],
|
||||||
selected: []
|
selected: [],
|
||||||
|
selectedUUIDs: [],
|
||||||
|
indeterminate: false,
|
||||||
|
checkAll: false
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
this.props.pageTitle("Forms")
|
this.props.pageTitle("Subscription forms")
|
||||||
this.props
|
this.props
|
||||||
.modelRequest(cs.ModelLists, cs.Routes.GetLists, cs.MethodGet, {
|
.modelRequest(cs.ModelLists, cs.Routes.GetLists, cs.MethodGet, {
|
||||||
per_page: "all"
|
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) {
|
handleSelection(sel) {
|
||||||
let out = []
|
let out = []
|
||||||
sel.forEach(s => {
|
sel.forEach(s => {
|
||||||
|
@ -35,56 +48,86 @@ class Forms extends React.PureComponent {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
console.log(out)
|
this.setState({
|
||||||
this.setState({ selected: out })
|
selected: out,
|
||||||
|
selectedUUIDs: sel,
|
||||||
|
indeterminate: sel.length > 0 && sel.length < this.state.lists.length,
|
||||||
|
checkAll: sel.length === this.state.lists.length
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<section className="content list-form">
|
<section className="content list-form">
|
||||||
<h1>Forms</h1>
|
<h1>Subscription forms</h1>
|
||||||
<Row>
|
<hr />
|
||||||
<Col span={8}>
|
<Row gutter={[16, 40]}>
|
||||||
|
<Col span={24} md={8}>
|
||||||
|
<h2>Lists</h2>
|
||||||
|
<Checkbox
|
||||||
|
indeterminate={this.state.indeterminate}
|
||||||
|
onChange={this.handleSelectAll}
|
||||||
|
checked={this.state.checkAll}
|
||||||
|
>
|
||||||
|
Select all
|
||||||
|
</Checkbox>
|
||||||
|
<hr />
|
||||||
<Checkbox.Group
|
<Checkbox.Group
|
||||||
className="lists"
|
className="lists"
|
||||||
options={this.state.lists.map(l => {
|
options={this.state.lists.map(l => {
|
||||||
return { label: l.name, value: l.uuid }
|
return { label: l.name, value: l.uuid }
|
||||||
})}
|
})}
|
||||||
defaultValue={[]}
|
onChange={sel => this.handleSelection(sel)}
|
||||||
onChange={(sel) => this.handleSelection(sel)}
|
value={this.state.selectedUUIDs}
|
||||||
/>
|
/>
|
||||||
</Col>
|
</Col>
|
||||||
<Col span={16}>
|
<Col span={24} md={16}>
|
||||||
<h1>Form HTML</h1>
|
<h2>Form HTML</h2>
|
||||||
<p>Use the following HTML to show a subscription form on an external webpage.</p>
|
|
||||||
<p>
|
<p>
|
||||||
The form should have the <code><strong>email</strong></code> field and one or more{" "}
|
Use the following HTML to show a subscription form on an external
|
||||||
<code><strong>l</strong></code> (list UUID) fields. The <code><strong>name</strong></code> field is optional.
|
webpage.
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
The form should have the{" "}
|
||||||
|
<code>
|
||||||
|
<strong>email</strong>
|
||||||
|
</code>{" "}
|
||||||
|
field and one or more{" "}
|
||||||
|
<code>
|
||||||
|
<strong>l</strong>
|
||||||
|
</code>{" "}
|
||||||
|
(list UUID) fields. The{" "}
|
||||||
|
<code>
|
||||||
|
<strong>name</strong>
|
||||||
|
</code>{" "}
|
||||||
|
field is optional.
|
||||||
</p>
|
</p>
|
||||||
<pre className="html">
|
<pre className="html">
|
||||||
|
{`<form method="post" action="${
|
||||||
{`<form method="post" action="${window.CONFIG.rootURL}/subscription/form" class="listmonk-subscription">
|
window.CONFIG.rootURL
|
||||||
|
}/subscription/form" class="listmonk-form">
|
||||||
<div>
|
<div>
|
||||||
<h3>Subscribe</h3>
|
<h3>Subscribe</h3>
|
||||||
<p><input type="text" name="email" value="" placeholder="E-mail" /></p>
|
<p><input type="text" name="email" placeholder="E-mail" /></p>
|
||||||
<p><input type="text" name="name" value="" placeholder="Name (optional)" /></p>`}
|
<p><input type="text" name="name" placeholder="Name (optional)" /></p>`}
|
||||||
{(() => {
|
{(() => {
|
||||||
let out = [];
|
let out = []
|
||||||
this.state.selected.forEach(l => {
|
this.state.selected.forEach(l => {
|
||||||
out.push(`
|
out.push(`
|
||||||
<p>
|
<p>
|
||||||
<input type="checkbox" name="l" value="${l.uuid}" id="${l.uuid.substr(0,5)}" />
|
<input type="checkbox" name="l" value="${
|
||||||
|
l.uuid
|
||||||
|
}" id="${l.uuid.substr(0, 5)}" />
|
||||||
<label for="${l.uuid.substr(0, 5)}">${l.name}</label>
|
<label for="${l.uuid.substr(0, 5)}">${l.name}</label>
|
||||||
</p>`);
|
</p>`)
|
||||||
});
|
})
|
||||||
return out;
|
return out
|
||||||
})()}
|
})()}
|
||||||
{`
|
{`
|
||||||
<p><input type="submit" value="Subscribe" /></p>
|
<p><input type="submit" value="Subscribe" /></p>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
`}
|
`}
|
||||||
|
|
||||||
</pre>
|
</pre>
|
||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
|
|
Loading…
Reference in New Issue