Skip to content

Commit

Permalink
Merge pull request #1021 from knod/clean-style-2
Browse files Browse the repository at this point in the history
Clean up code style, part 2 of many parts. The prompts folder. #1018
  • Loading branch information
knod committed Dec 2, 2018
2 parents 6c70739 + 7f42094 commit 8b2ce5d
Show file tree
Hide file tree
Showing 9 changed files with 161 additions and 128 deletions.
10 changes: 5 additions & 5 deletions src/components/prompts/BrowserLeaveListener.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ class BrowserLeaveListener extends React.Component {

componentDidMount() {
window.addEventListener('beforeunload', this.confirm);
}
};

componentWillUnmount() {
window.removeEventListener('beforeunload', this.confirm);
}
};

render() {
return null;
}
}
};
};

export default BrowserLeaveListener;
export { BrowserLeaveListener };
10 changes: 5 additions & 5 deletions src/components/prompts/ErrorListener.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ class ErrorListener extends React.Component {

componentDidMount() {
window.addEventListener('error', this.handleError);
}
};

componentWillUnmount() {
window.removeEventListener('error', this.handleError);
}
};

render() {
return null;
}
}
};
};

export default ErrorListener;
export { ErrorListener };
14 changes: 7 additions & 7 deletions src/components/prompts/FeedbackAnytime.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@
import React from 'react';
import { Button } from 'semantic-ui-react';

const FeedbackAnytime = function (props) {
const FeedbackAnytime = function ({ openFeedback }) {

return (
<div>
<Button
onClick={ props.openFeedback }
type='button'
color='teal'
size='medium'
id={ 'feedbackFixed' }>
onClick = { openFeedback }
type = { `button` }
color = { `teal` }
size = { `medium` }
id = { `feedbackFixed` }>
Tell Us More
</Button>
</div>
);

}; // End <FeedbackAnytime>
}; // Ends <FeedbackAnytime>


export { FeedbackAnytime };
89 changes: 49 additions & 40 deletions src/components/prompts/FeedbackForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ class AskPermission extends React.Component {
this.props.closeAskPermission();
};

submit = (evnt) => {
this.props.submit(evnt, this.state.submitType);
submit = (event) => {
this.props.submit(event, this.state.submitType);
};

setSubmitType = (evnt, inputProps) => {
setSubmitType = (event, inputProps) => {
this.setState({ submitType: inputProps.value });
};

Expand All @@ -38,7 +38,7 @@ class AskPermission extends React.Component {
const { question, submitting } = this.props;
const { submitType } = this.state;
return ([
<Modal.Content key = { `ask-permission-content` }>
<Modal.Content key={ `ask-permission-content` }>
<p>{ question }</p>

<Form.Field>
Expand All @@ -58,7 +58,7 @@ class AskPermission extends React.Component {
onChange = { this.setSubmitType } />
</Form.Field>
</Modal.Content>,
<Modal.Actions key = { `ask-permission-actions` }>
<Modal.Actions key={ `ask-permission-actions` }>
<Button
onClick ={ this.close }
disabled ={ submitting }>Cancel
Expand All @@ -81,14 +81,15 @@ class AskPermission extends React.Component {
{ (submitType === null) ? (`Send`) : (null) }
</Button>
</Modal.Actions>,
]);}
}
]);
};
}; // Ends <AskPermission>


/**
* Modal that shows the feedback form.
*/
class FeedbackPrompt extends React.Component {
class FeedbackForm extends React.Component {
constructor(props) {
super(props);

Expand Down Expand Up @@ -130,7 +131,7 @@ class FeedbackPrompt extends React.Component {
throw error;
}
});
}
};

close = (event) => {
// Reset state for next time it's opened
Expand All @@ -151,12 +152,12 @@ class FeedbackPrompt extends React.Component {
this.setState({ ready: false });
};

submit = (evnt, type) => {
submit = (event, type) => {
this.setState({ submitting: true });

let data = this.state.formData;
if (type === `withData`) {
data = Object.assign({ clientData: this.props.data }, this.state.formData);
data = Object.assign({ clientData: this.props.data }, data);
}

this.sendDataToSpreadsheet(data)
Expand Down Expand Up @@ -184,56 +185,62 @@ class FeedbackPrompt extends React.Component {
// focus styles to win
return (
<Modal
mountNode = { document.getElementById(`App`) }
size='large'
open={ isOpen }
onClose={ this.close }
closeOnDimmerClick={ false }
closeOnEscape={ false }
mountNode = { document.getElementById(`App`) }
size = { `large` }
open = { isOpen }
onClose = { this.close }
closeOnDimmerClick = { false }
closeOnEscape = { false }
closeIcon>

<Modal.Header>Tell Us More</Modal.Header>

<Modal.Content scrolling>
<Form>
<Form.Input
autoFocus
{ ...inputProps('currentSnap') }
label={ <span>If the <strong>current</strong> SNAP amount was wrong, what's the right amount?</span> } />
{ ...inputProps(`currentSnap`) }
label = { <span>If the <strong>current</strong> SNAP amount was wrong, what's the right amount?</span> } />
<Form.Input
{ ...inputProps('futureSnap') }
label={ <span>If the <strong>future</strong> SNAP amount was wrong, what's the right amount?</span> } />
{ ...inputProps(`futureSnap`) }
label = { <span>If the <strong>future</strong> SNAP amount was wrong, what's the right amount?</span> } />
<Form.Input
{ ...inputProps('futureS8') }
label={ <span>If the <strong>future</strong> Section 8 amount was wrong, what's the right amount?</span> } />
{ ...inputProps(`futureS8`) }
label = { <span>If the <strong>future</strong> Section 8 amount was wrong, what's the right amount?</span> } />
<Form.TextArea
{ ...inputProps('otherCircumstances') }
label={ 'What else could be going on that could affect your benefit amount? ' +
'For example, are you a veteran? Are you a full-time student?' } />
{ ...inputProps(`otherCircumstances`) }
label = { `What else could be going on that could affect your benefit amount? ` +
`For example, are you a veteran? Are you a full-time student?` } />
<Form.TextArea
{ ...inputProps('bugReport') }
label={ 'If there was a bug or error, describe the bug and what you were trying to do when the bug happened.' } />
{ ...inputProps(`bugReport`) }
label = { `If there was a bug or error, describe the bug and what you were trying to do when the bug happened.` } />
<Form.TextArea
{ ...inputProps('comments') }
label={ 'Do you have any other comments?' } />
{ ...inputProps(`comments`) }
label = { `Do you have any other comments?` } />
</Form>

<Message
hidden={ !submissionFailed }
hidden = { !submissionFailed }
error>
Error submitting data, please try again or <a href="mailto:[email protected]">email us</a>.
</Message>
</Modal.Content>

<Modal.Actions>
<Button
onClick={ this.close }
disabled={ submitting }>Cancel
onClick = { this.close }
disabled = { submitting }>
Cancel
</Button>
<Button
onClick={ this.onReady }
color='teal'>Ready
onClick = { this.onReady }
color = { `teal` }>
Ready
</Button>
</Modal.Actions>

<Modal
mountNode = { document.getElementById(`App`) }
mountNode = { document.getElementById(`App`) }
size = { `large` }
open = { ready }
onClose = { this.closeAskPermission }
Expand All @@ -248,9 +255,11 @@ class FeedbackPrompt extends React.Component {
</Modal>
</Modal>
);
}
};
};
}; // Ends <FeedbackForm>


export default FeedbackPrompt;
export { AskPermission };
export {
FeedbackForm,
AskPermission,
};
29 changes: 17 additions & 12 deletions src/components/prompts/FeedbackPrompt.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import React from 'react';
import { Button, Modal } from 'semantic-ui-react';
import {
Button,
Modal,
} from 'semantic-ui-react';

/**
* Called with result of user interaction with on leave modal.
Expand All @@ -26,6 +29,7 @@ class FeedbackPrompt extends React.Component {
event.preventDefault();
this.props.callback(true);
};

stay = (event) => {
event.preventDefault();
this.props.callback(false);
Expand All @@ -49,32 +53,33 @@ class FeedbackPrompt extends React.Component {
}

// Otherwise, set up the prompt
let realLeave = leaveText || 'Leave',
let realLeave = leaveText || `Leave`,
realStay = stayText || `Cancel`,
realMessage = message;
if (message === 'default') {
if (message === `default`) {
realMessage = `Clicking "${realLeave}" will erase the information you have put into the form. Do you want to tell us something about the app first? That information could help us. You will still be able to come back and click "${realLeave}" afterwards.`;
}

return (
<Modal
mountNode = { document.getElementById(`App`) }
open={ open }>
open = { open }>
<Modal.Header>{header || `Do you want to tell us more before you click "${realLeave}"?`}</Modal.Header>
<Modal.Content>
<p> {realMessage} </p>
<p>{ realMessage }</p>
</Modal.Content>
<Modal.Actions>
<Button onClick={ this.stay }>{realStay}</Button>
<Button onClick={ this.leave }>{realLeave}</Button>
<Button onClick={ this.stay }>{ realStay }</Button>
<Button onClick={ this.leave }>{ realLeave }</Button>
<Button
onClick={ openFeedback }
primary>Tell Us More
onClick = { openFeedback }
primary>
Tell Us More
</Button>
</Modal.Actions>
</Modal>
);
}
}
};
}; // Ends <FeedbackPrompt>

export default FeedbackPrompt;
export { FeedbackPrompt };
Loading

0 comments on commit 8b2ce5d

Please sign in to comment.