From 128ea47a33c7d37fc76153f4fb81548aaa99298c Mon Sep 17 00:00:00 2001 From: edificex Date: Thu, 2 Apr 2020 10:46:07 +0100 Subject: [PATCH] edit reducer to fix bug resulting in duplicates ending up in the responses object for checkbox questions Relates #148 --- netlify.toml | 6 ++++++ src/App/Home/Home.js | 2 +- src/App/Report/Form/Form.js | 2 ++ src/App/Report/Report.js | 29 ++++++++++++++++++++--------- src/App/Report/Submit/Submit.js | 2 -- 5 files changed, 29 insertions(+), 12 deletions(-) diff --git a/netlify.toml b/netlify.toml index e31f927..8c5b831 100644 --- a/netlify.toml +++ b/netlify.toml @@ -32,6 +32,12 @@ status = 301 force = true +[[redirect]] + from = "https://musafespace.netlify.com/*" + to = "https://www.musafespace.org.uk/:splat" + status = 301 + force = true + [[redirect]] from = "https://musafespace.netlify.com/*" to = "https://www.musafespace.org.uk/:splat" diff --git a/src/App/Home/Home.js b/src/App/Home/Home.js index 0ef800b..680e85f 100644 --- a/src/App/Home/Home.js +++ b/src/App/Home/Home.js @@ -24,7 +24,7 @@ const Home = () => { Together we can change this - This site to a safe space for everyone working in the music industry + This site is a safe space for everyone working in the music industry to log instances of sexual harassment and abuse on the job. diff --git a/src/App/Report/Form/Form.js b/src/App/Report/Form/Form.js index eb8df39..cc8e1da 100644 --- a/src/App/Report/Form/Form.js +++ b/src/App/Report/Form/Form.js @@ -89,6 +89,8 @@ const Form = ({ questions, responses, updateResponses }) => { const page = parseInt(useParams().index, 10); const history = useHistory(); + console.log(responses); + // get questions to be displayed on this page const pageQuestions = filterQuestions(questions, page, responses); diff --git a/src/App/Report/Report.js b/src/App/Report/Report.js index 1377bb8..55eb4b6 100644 --- a/src/App/Report/Report.js +++ b/src/App/Report/Report.js @@ -21,13 +21,12 @@ import hardDividers from '../../model/dividers'; const Report = () => { // grab React Router state to determine which components to render at Report level, and which questions/dividers to fetch const location = useLocation(); - // default to first person version if choice not available (i.e. user navigated directly to report) + // default to first person version if choice not available (i.e. if user navigates directly to report) const choice = useMemo( () => location.state && location.state.choice ? location.state.choice : 'first', [] ); - console.log('choice: ', choice); // set up states const [questions, setQuestions] = useState(null); @@ -70,8 +69,10 @@ const Report = () => { if (type === 'checkbox') { // checkboxes need special handling since they can take multiple answers if (checked && state[field]) { - // if the value is an 'Other' submission but we've already collected a response not belonging to pre-set answers, replace it - // for this we will first need to derive the question from which the event emanates, by searching the questions object with field + console.log( + `existing data checkbox branch of reducer invoked with value '${value} and trusted ${trusted}'` + ); + // we first derive the question from which the event emanates, by searching the questions object with field let index; questions.forEach((question, i) => { if (question.question === field) index = i; @@ -79,21 +80,31 @@ const Report = () => { const otherSubmissions = state[field].filter( answer => !questions[index].content.includes(answer) ); - if (!trusted && otherSubmissions.length > 0) { + // if there's response data, checkbox is checked, but response already includes this value, no change + if (state[field].includes(value)) { + console.log( + `#1 normal existing value branch triggered for value '${value}'` + ); + return state; + // else if the value is an 'Other' submission but we've already collected an 'Other' response (i.e. one not belonging to pre-set answers), replace it + // NB. the re-selection of checkboxes on returning to a page are not trusted events, but those relating to non-'Other' options are caught by previous branch + } else if (!trusted && otherSubmissions.length > 0) { + console.log( + `#2 changed other submission branch triggered for value '${value}'` + ); const newResponses = deleteValue(state[field], otherSubmissions[0]); return { ...state, [field]: [...newResponses, value], }; - // else if there's response data, checkbox is checked, but response already includes this value, no change - } else if (state[field].includes(value)) { - return state; // and else simply incorporate the new value - } else + } else { + console.log(`#3 new value branch triggered for value '${value}'`); return { ...state, [field]: [...state[field], value], }; + } } else if (checked) { // else if there is no response data and checkbox is being checked, it is for the first time, so incorporate given value return { ...state, [field]: [value] }; diff --git a/src/App/Report/Submit/Submit.js b/src/App/Report/Submit/Submit.js index 626ce27..a08b267 100644 --- a/src/App/Report/Submit/Submit.js +++ b/src/App/Report/Submit/Submit.js @@ -26,8 +26,6 @@ const Submit = ({ responses, updateResponses, choice, userRef }) => { return responses; }; - // NEED TO devise a way to submit multiple responses to Airtable, rather than just concatenate into one string - // OR have them arrive in separate columns in the responses tables const handleSubmit = event => { event.preventDefault(); const finalResponses = {