Fakultas Ilmu Komputer UI

index.tsx 2.31 KB
Newer Older
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
import React, { FC, useState } from 'react';
import { View, StyleSheet, Dimensions } from 'react-native';
import { layoutStyles } from 'styles';
import Carousel from 'react-native-snap-carousel';
import { pages } from './pages';
import { CarouselPagination, BigButton } from 'components/core';
import { useForm } from 'hooks';
import { dietReportCommentInitialValues, fieldValidations } from './schema';
import { generateValidationSchema } from 'utils/form';
import { DietReportPage } from './components';
import { mockUserReportResponse } from '__mocks__/userReport';

const DietReportForNutritionist: FC = () => {
  const [activeSlide, setActiveSlide] = useState(0);
  const userReport = mockUserReportResponse;

  const { getTextInputProps, handleSubmit, isSubmitting } = useForm({
    initialValues: dietReportCommentInitialValues,
    validationSchema: generateValidationSchema(fieldValidations),
    onSubmit: async (values) => {
      console.log('masuk');
      console.log(values);
    },
  });

  return (
    <View style={[layoutStyles, styles.reportContainer]}>
      <View style={[styles.flexContainer]}>
        <Carousel
          data={pages.map((page, idx) => (
            <DietReportPage
              key={idx}
              content={page.pageContent(userReport, getTextInputProps)}
              pageName={page.pageName}
              getTextInputProps={getTextInputProps}
            />
          ))}
          renderItem={({ item }: any) => item}
          sliderWidth={Dimensions.get('window').width}
          itemWidth={Dimensions.get('window').width}
          onSnapToItem={setActiveSlide}
          containerCustomStyle={styles.flexContainer}
          slideStyle={styles.flexContainer}
        />
      </View>
      <CarouselPagination index={activeSlide} length={4} />
      <BigButton
        title="Submit Komentar"
        onPress={handleSubmit}
        loading={isSubmitting}
      />
    </View>
  );
};

const styles = StyleSheet.create({
  flexContainer: {
    flex: 1,
  },
  reportContainer: {
    position: 'relative',
    flex: 1,
    paddingBottom: 20,
  },
  searchContainer: {
    backgroundColor: 'white',
    borderWidth: 1,
    borderRadius: 5,
    marginBottom: 20,
    justifyContent: 'center',
    height: 58,
  },
  backgroundWhite: { backgroundColor: 'white' },
});

export default DietReportForNutritionist;