Add signup form stuff to admin
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
import * as React from "react";
|
||||
import * as shortid from "shortid";
|
||||
|
||||
export interface SignupQuestionsWidgetProps {
|
||||
value: string;
|
||||
onChange: (value: string) => void;
|
||||
required: boolean;
|
||||
disabled: boolean;
|
||||
}
|
||||
export interface SignupQuestionsWidgetState {}
|
||||
|
||||
interface Question {
|
||||
id: string;
|
||||
name: string;
|
||||
options: string[];
|
||||
}
|
||||
|
||||
class SignupQuestionsWidget extends React.Component<SignupQuestionsWidgetProps, SignupQuestionsWidgetState> {
|
||||
onValueChange = (questions: Question[]) => {
|
||||
const { onChange } = this.props;
|
||||
const newValue = JSON.stringify(questions);
|
||||
onChange(newValue);
|
||||
}
|
||||
|
||||
handleNewRowClick = (questions) => () => {
|
||||
const newQuestions = questions.concat([{
|
||||
id: shortid.generate(),
|
||||
name: `Question #${questions.length + 1}`,
|
||||
options: [],
|
||||
}]);
|
||||
|
||||
this.onValueChange(newQuestions);
|
||||
}
|
||||
|
||||
handleNameInputChange = (questions: Question[], index: number) => (event) => {
|
||||
const val = event.target.value;
|
||||
questions[index].name = val;
|
||||
this.onValueChange(questions);
|
||||
}
|
||||
|
||||
renderQuestions = (questions: Question[]) => {
|
||||
return questions.map((q, index) => (
|
||||
<div key={q.id} className="signup-questions-widget-row">
|
||||
<input type="text" value={ q.name } onChange={this.handleNameInputChange(questions, index)} />
|
||||
</div>
|
||||
));
|
||||
}
|
||||
|
||||
render() {
|
||||
const { value } = this.props;
|
||||
|
||||
const questions = JSON.parse(value) as Question[];
|
||||
|
||||
return (
|
||||
<div className="signup-questions-widget">
|
||||
<button type="button" onClick={this.handleNewRowClick(questions)}>New Row</button>
|
||||
{this.renderQuestions(questions)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default SignupQuestionsWidget;
|
||||
@@ -0,0 +1,2 @@
|
||||
import SignupQuestionsWidget from "./SignupQuestionsWidget";
|
||||
export default SignupQuestionsWidget;
|
||||
Reference in New Issue
Block a user