Fakultas Ilmu Komputer UI

index.tsx 1.93 KB
Newer Older
1
import React, { FC } from 'react';
2
import { StyleSheet, View } from 'react-native';
3
4
5
6
7
8
9
10
11
import { TextField, CheckboxGroup, RadioButtonGroup } from 'components/form';

import {
  dietReportTextFields,
  dietReportSelectFields,
} from 'constants/weeklyReport';
import { ReportProps } from '../../types';
import { layoutStyles } from 'styles';

12
13
const Report4: FC<ReportProps> = ({ getTextInputProps, getFormFieldProps }) => (
  <View style={layoutStyles}>
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
    {dietReportSelectFields.dietReportPage4
      .filter((item) => item.checkbox)
      .map((props, i) => {
        const textFieldProps = getTextInputProps(`${props.name}_other`);
        return (
          <View key={`report4-checkbox${i}`} style={styles.spacing}>
            <CheckboxGroup
              {...props}
              choices={props.choiceList.map((label: string, id: number) => ({
                label,
                value: id + 1,
              }))}
              {...getFormFieldProps(props.name)}
              hasOtherChoice
              otherValue={textFieldProps.value}
              setOtherValue={textFieldProps.onChangeText}
              required
            />
          </View>
        );
      })}
    {dietReportSelectFields.dietReportPage4
      .filter((item) => !item.checkbox)
      .map((props, i) => (
        <View key={`report4-select${i}`} style={styles.spacing}>
          <RadioButtonGroup
            {...props}
            choices={props.choiceList.map((label: string, id: number) => ({
              label,
              value: id + 1,
            }))}
            {...getFormFieldProps(props.name)}
            required
          />
        </View>
      ))}
    {dietReportTextFields.dietReportPage4.map((props, i) => (
      <TextField
        {...props}
        {...getTextInputProps(props.name)}
        key={`report4-textfield${i}`}
      />
    ))}
57
  </View>
58
59
60
61
62
63
64
65
66
);

export const styles = StyleSheet.create({
  spacing: {
    marginBottom: 24,
  },
});

export default Report4;