Skip to content

Commit 128ea47

Browse files
author
edificex
committed
edit reducer to fix bug resulting in duplicates ending up in the responses object for checkbox questions
Relates #148
1 parent ed7f6a2 commit 128ea47

File tree

5 files changed

+29
-12
lines changed

5 files changed

+29
-12
lines changed

netlify.toml

+6
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@
3232
status = 301
3333
force = true
3434

35+
[[redirect]]
36+
from = "https://musafespace.netlify.com/*"
37+
to = "https://www.musafespace.org.uk/:splat"
38+
status = 301
39+
force = true
40+
3541
[[redirect]]
3642
from = "https://musafespace.netlify.com/*"
3743
to = "https://www.musafespace.org.uk/:splat"

src/App/Home/Home.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const Home = () => {
2424
Together we can change this
2525
</Type5>
2626
<TypeB1 use='body1' tag='p'>
27-
This site to a safe space for everyone working in the music industry
27+
This site is a safe space for everyone working in the music industry
2828
to log instances of sexual harassment and abuse on the job.
2929
</TypeB1>
3030
<TypeExtra use='body1' tag='p'>

src/App/Report/Form/Form.js

+2
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ const Form = ({ questions, responses, updateResponses }) => {
8989
const page = parseInt(useParams().index, 10);
9090
const history = useHistory();
9191

92+
console.log(responses);
93+
9294
// get questions to be displayed on this page
9395
const pageQuestions = filterQuestions(questions, page, responses);
9496

src/App/Report/Report.js

+20-9
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,12 @@ import hardDividers from '../../model/dividers';
2121
const Report = () => {
2222
// grab React Router state to determine which components to render at Report level, and which questions/dividers to fetch
2323
const location = useLocation();
24-
// default to first person version if choice not available (i.e. user navigated directly to report)
24+
// default to first person version if choice not available (i.e. if user navigates directly to report)
2525
const choice = useMemo(
2626
() =>
2727
location.state && location.state.choice ? location.state.choice : 'first',
2828
[]
2929
);
30-
console.log('choice: ', choice);
3130

3231
// set up states
3332
const [questions, setQuestions] = useState(null);
@@ -70,30 +69,42 @@ const Report = () => {
7069
if (type === 'checkbox') {
7170
// checkboxes need special handling since they can take multiple answers
7271
if (checked && state[field]) {
73-
// if the value is an 'Other' submission but we've already collected a response not belonging to pre-set answers, replace it
74-
// for this we will first need to derive the question from which the event emanates, by searching the questions object with field
72+
console.log(
73+
`existing data checkbox branch of reducer invoked with value '${value} and trusted ${trusted}'`
74+
);
75+
// we first derive the question from which the event emanates, by searching the questions object with field
7576
let index;
7677
questions.forEach((question, i) => {
7778
if (question.question === field) index = i;
7879
});
7980
const otherSubmissions = state[field].filter(
8081
answer => !questions[index].content.includes(answer)
8182
);
82-
if (!trusted && otherSubmissions.length > 0) {
83+
// if there's response data, checkbox is checked, but response already includes this value, no change
84+
if (state[field].includes(value)) {
85+
console.log(
86+
`#1 normal existing value branch triggered for value '${value}'`
87+
);
88+
return state;
89+
// 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
90+
// 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
91+
} else if (!trusted && otherSubmissions.length > 0) {
92+
console.log(
93+
`#2 changed other submission branch triggered for value '${value}'`
94+
);
8395
const newResponses = deleteValue(state[field], otherSubmissions[0]);
8496
return {
8597
...state,
8698
[field]: [...newResponses, value],
8799
};
88-
// else if there's response data, checkbox is checked, but response already includes this value, no change
89-
} else if (state[field].includes(value)) {
90-
return state;
91100
// and else simply incorporate the new value
92-
} else
101+
} else {
102+
console.log(`#3 new value branch triggered for value '${value}'`);
93103
return {
94104
...state,
95105
[field]: [...state[field], value],
96106
};
107+
}
97108
} else if (checked) {
98109
// else if there is no response data and checkbox is being checked, it is for the first time, so incorporate given value
99110
return { ...state, [field]: [value] };

src/App/Report/Submit/Submit.js

-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ const Submit = ({ responses, updateResponses, choice, userRef }) => {
2626
return responses;
2727
};
2828

29-
// NEED TO devise a way to submit multiple responses to Airtable, rather than just concatenate into one string
30-
// OR have them arrive in separate columns in the responses tables
3129
const handleSubmit = event => {
3230
event.preventDefault();
3331
const finalResponses = {

0 commit comments

Comments
 (0)