import React from 'react'; import {SelectField, Option} from 'react-mdl-selectfield'; import I18n from 'coral-framework/modules/i18n/i18n'; import translations from '../../translations.json'; import styles from './Configure.css'; import {Textfield, Checkbox} from 'react-mdl'; import {Card, Icon, Spinner} from 'coral-ui'; const TIMESTAMPS = { weeks: 60 * 60 * 24 * 7, days: 60 * 60 * 24, hours: 60 * 60 }; const updateCharCountEnable = (updateSettings, charCountChecked) => () => { const charCountEnable = !charCountChecked; updateSettings({charCountEnable}); }; const updateCharCount = (updateSettings, settingsError) => (event) => { const charCount = event.target.value; if (charCount.match(/[^0-9]/) || charCount.length === 0) { settingsError('charCount', true); } else { settingsError('charCount', false); } updateSettings({charCount: charCount}); }; const updateModeration = (updateSettings, mod) => () => { const moderation = mod === 'PRE' ? 'POST' : 'PRE'; updateSettings({moderation}); }; const updateEmailConfirmation = (updateSettings, verify) => () => { updateSettings({requireEmailConfirmation: !verify}); }; const updateInfoBoxEnable = (updateSettings, infoBox) => () => { const infoBoxEnable = !infoBox; updateSettings({infoBoxEnable}); }; const updateInfoBoxContent = (updateSettings) => (event) => { const infoBoxContent = event.target.value; updateSettings({infoBoxContent}); }; const updateClosedMessage = (updateSettings) => (event) => { const closedMessage = event.target.value; updateSettings({closedMessage}); }; const updateCustomCssUrl = (updateSettings) => (event) => { console.log('updateCustomCssUrl', event.target.value); const customCssUrl = event.target.value; updateSettings({customCssUrl}); }; // If we are changing the measure we need to recalculate using the old amount // Same thing if we are just changing the amount const updateClosedTimeout = (updateSettings, ts, isMeasure) => (event) => { if (isMeasure) { const amount = getTimeoutAmount(ts); const closedTimeout = amount * TIMESTAMPS[event]; updateSettings({closedTimeout}); } else { const val = event.target.value; const measure = getTimeoutMeasure(ts); const closedTimeout = val * TIMESTAMPS[measure]; updateSettings({closedTimeout}); } }; const CommentSettings = ({fetchingSettings, title, updateSettings, settingsError, settings, errors}) => { if (fetchingSettings) { return Loading settings...; } // just putting this here for shorthand below const on = styles.enabledSetting; const off = styles.disabledSetting; return (

{title}

{lang.t('configure.enable-pre-moderation')}

{lang.t('configure.enable-pre-moderation-text')}

{lang.t('configure.require-email-verification')}

{lang.t('configure.require-email-verification-text')}

{lang.t('configure.comment-count-header')}

{lang.t('configure.comment-count-text-pre')} {lang.t('configure.comment-count-text-post')} { errors.charCount &&
{lang.t('configure.comment-count-error')}
}

{lang.t('configure.include-comment-stream')}

{lang.t('configure.include-comment-stream-desc')}

{lang.t('configure.closed-comments-desc')}
{lang.t('configure.close-after')}
{lang.t('configure.custom-css-url')}

{lang.t('configure.custom-css-url-desc')}


); }; export default CommentSettings; // To see if we are talking about weeks, days or hours // We talk the remainder of the division and see if it's 0 const getTimeoutMeasure = ts => { if (ts % TIMESTAMPS['weeks'] === 0) { return 'weeks'; } else if (ts % TIMESTAMPS['days'] === 0) { return 'days'; } else if (ts % TIMESTAMPS['hours'] === 0) { return 'hours'; } }; // Dividing the amount by it's measure (hours, days, weeks) we // obtain the amount of time const getTimeoutAmount = ts => ts / TIMESTAMPS[getTimeoutMeasure(ts)]; const lang = new I18n(translations);