-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix loading active surveys was triggered on component creation and no…
…t before modal display
- Loading branch information
Showing
3 changed files
with
103 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,95 +1,60 @@ | ||
import React, { Component, PropTypes } from "react" | ||
import React, { PropTypes } from "react" | ||
import { translate } from "react-i18next" | ||
import * as api from "../../api" | ||
import { ConfirmationModal } from "../ui" | ||
import { config } from "../../config" | ||
|
||
export class ProviderModal extends Component { | ||
constructor(props) { | ||
super(props) | ||
this.state = { | ||
loading: false, | ||
surveys: [], | ||
} | ||
} | ||
|
||
componentDidMount() { | ||
const { provider, index } = this.props | ||
const { baseUrl } = config[provider][index] | ||
this.setState({ | ||
loading: true, | ||
surveys: [], | ||
}) | ||
api.fetchActiveSurveys(provider, baseUrl) | ||
.then((response) => { | ||
const surveys = response || [] | ||
this.setState({ | ||
loading: false, | ||
surveys, | ||
}) | ||
}) | ||
.catch(() => { | ||
this.setState({ | ||
loading: false, | ||
surveys: [], | ||
}) | ||
}) | ||
} | ||
|
||
render() { | ||
const { | ||
t, | ||
provider, | ||
index, | ||
friendlyName, | ||
multiple, | ||
onConfirm, | ||
} = this.props | ||
|
||
const { loading, surveys } = this.state | ||
|
||
let name = `${provider[0].toUpperCase()}${provider.slice(1)}` | ||
if (multiple) name = `${name} (${friendlyName})` | ||
|
||
return ( | ||
<ConfirmationModal | ||
modalId={`${provider}Modal-${index}`} | ||
header={t("Turn off {{name}}", { name })} | ||
confirmationText={t("Yes")} | ||
onConfirm={onConfirm} | ||
style={{ maxWidth: "600px" }} | ||
showCancel | ||
> | ||
<div> | ||
<p>{t("Do you want to delete the channels provided by {{name}}?", { name })}</p> | ||
|
||
<div className="provider-surveys"> | ||
{loading ? <span>{t("Loading surveys...")}</span> : | ||
surveys.length == 0 ? <span>{t("No active surveys")}</span> : | ||
<div> | ||
<span>{t("Active surveys")}</span> | ||
<ul> | ||
{surveys.map((survey) => ( | ||
<li key={`survey-${survey.id}`}> | ||
<span>{survey.name}</span> | ||
</li> | ||
))} | ||
</ul> | ||
</div>} | ||
</div> | ||
export const ProviderModal = ({ | ||
t, | ||
provider, | ||
index, | ||
friendlyName, | ||
multiple, | ||
onConfirm, | ||
loading, | ||
surveys, | ||
}) => { | ||
let name = `${provider[0].toUpperCase()}${provider.slice(1)}` | ||
if (multiple) name = `${name} (${friendlyName})` | ||
|
||
return ( | ||
<ConfirmationModal | ||
modalId={`${provider}Modal-${index}`} | ||
header={t("Turn off {{name}}", { name })} | ||
confirmationText={t("Yes")} | ||
onConfirm={onConfirm} | ||
style={{ maxWidth: "600px" }} | ||
showCancel | ||
> | ||
<div> | ||
<p>{t("Do you want to delete the channels provided by {{name}}?", { name })}</p> | ||
|
||
<div className="provider-surveys"> | ||
{loading ? <span>{t("Searching active surveys...")}</span> : | ||
surveys.length == 0 ? <span>{t("No active surveys")}</span> : | ||
<div> | ||
<span>{t("Active surveys")}</span> | ||
<ul> | ||
{surveys.map((survey) => ( | ||
<li key={`survey-${survey.id}`}> | ||
<span>{survey.name}</span> | ||
</li> | ||
))} | ||
</ul> | ||
</div>} | ||
</div> | ||
</ConfirmationModal> | ||
) | ||
} | ||
</div> | ||
</ConfirmationModal> | ||
) | ||
} | ||
|
||
ProviderModal.propTypes = { | ||
t: PropTypes.func, | ||
provider: PropTypes.any, | ||
provider: PropTypes.string, | ||
index: PropTypes.number, | ||
friendlyName: PropTypes.string, | ||
multiple: PropTypes.bool, | ||
onConfirm: PropTypes.func, | ||
loading: PropTypes.bool, | ||
surveys: PropTypes.any | ||
} | ||
|
||
export default translate()(ProviderModal) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters