-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPicker.js
83 lines (76 loc) · 2.12 KB
/
Picker.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
//
// Picker.js
// RNSurvey
//
// Created by Rogier van der Sluijs on 23/03/2019.
// Copyright © 2019 Rogier van der Sluijs. All rights reserved.
//
// React
import React from 'react';
import { View } from 'react-native';
// Third-party
import PropTypes from 'prop-types';
// Components
import BasicQuestion from '../Basic/Basic';
// Layout
import styles from './styles';
/**
* This component chooses which question component it needs to draw, based on
* the type of question. This enables theming, specialized layouts (such as
* maps) and fallback mechanisms based on the status of such a specialized
* question component.
* @param {int} questionIndex Index of the question.
* @param {Object} questionnaire Questionnaire.
* @param {Object} answers Answers.
* @param {Object} actions Actions.
*/
const QuestionPicker = ({
questionIndex,
questionnaire,
answers,
actions,
}) => {
const { type } = questionnaire.questions[questionIndex];
return (
<View style={styles.container}>
{[1, 2, 3, 4, 5, 6, 7].includes(type)
&& (
<BasicQuestion
questionIndex={questionIndex}
questionnaire={questionnaire}
answers={answers}
actions={actions}
/>
)
}
</View>
);
};
// Props
QuestionPicker.propTypes = {
questionIndex: PropTypes.number.isRequired,
questionnaire: PropTypes.shape({
questionnaire_id: PropTypes.number.isRequired,
questions: PropTypes.arrayOf(
PropTypes.shape({
type: PropTypes.number.isRequired,
title: PropTypes.string.isRequired,
description: PropTypes.string.isRequired,
obligatory: PropTypes.bool.isRequired,
}),
).isRequired,
}).isRequired,
answers: PropTypes.arrayOf(
PropTypes.shape({
questionId: PropTypes.number.isRequired,
value: PropTypes.number,
timestamp: PropTypes.string.isRequired,
}),
).isRequired,
actions: PropTypes.shape({
setAnswer: PropTypes.func.isRequired,
toggleAnswer: PropTypes.func.isRequired,
clearQuestion: PropTypes.func.isRequired,
}).isRequired,
};
export default QuestionPicker;