Skip to content

Commit daf091a

Browse files
authored
Fixing issue when a date picker question is skipped (#162)
* Fixing issue when a date picker question is skipped The issue was due to the lack of a null/undefined check. Also removed the hack and used the date-fns library already present to format the datetime * Version bump
1 parent 4c5be81 commit daf091a

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@code4ro/taskforce-fe-components",
3-
"version": "1.0.14",
3+
"version": "1.0.15",
44
"private": false,
55
"dependencies": {
66
"bulma": "^0.8.0",

src/components/form/form.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import StaticText from "./staticText";
88
import InputQuestion from "./inputQuestion";
99
import MultipleChoice from "./multipleChoice";
1010
import { DatePicker } from "./datePicker";
11+
import format from "date-fns/format";
1112

1213
const FIRST_NODE = 1;
1314

@@ -44,21 +45,20 @@ export const Form = ({ data, evaluateForm, onFinishingForm }) => {
4445
return {};
4546
}
4647

47-
let answer = formState[id];
48+
const rawAnswer = formState[id];
4849

50+
let answer = rawAnswer;
4951
if (question.type === "SINGLE_CHOICE") {
50-
answer = String(answer);
52+
answer = String(rawAnswer);
5153
}
5254

5355
if (
5456
question.type === "DATE_PICKER" ||
5557
question.type === "DATE_TIME_PICKER"
5658
) {
57-
//little hack as seen here
58-
// https://stackoverflow.com/questions/10830357/javascript-toisostring-ignores-timezone-offset
59-
// to get around the fact that toISOString always returns on UTC
60-
const tzoffset = answer.getTimezoneOffset() * 60000; //offset in milliseconds
61-
answer = new Date(answer - tzoffset).toISOString().slice(0, -1);
59+
answer = rawAnswer
60+
? format(rawAnswer, "yyyy-MM-dd'T'HH:mm")
61+
: rawAnswer;
6262
}
6363

6464
return {

src/components/form/form.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,12 +287,12 @@ describe("Form", () => {
287287
{
288288
id: 1,
289289
questionText: "De la ce data ai inceput sa ai simptome?",
290-
answer: "2020-05-20T00:00:00.000"
290+
answer: "2020-05-20T00:00"
291291
},
292292
{
293293
id: 2,
294294
questionText: "La ce data si ora ai iesit afara?",
295-
answer: "2020-05-20T11:10:00.000"
295+
answer: "2020-05-20T11:10"
296296
}
297297
]);
298298
});

0 commit comments

Comments
 (0)