Fakultas Ilmu Komputer UI

index.tsx 2 KB
Newer Older
Wulan Mantiri's avatar
Wulan Mantiri committed
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 } from 'react';
import { useNavigation } from '@react-navigation/native';
import { View } from 'react-native';
import { Button, Text } from 'react-native-elements';

import { styles } from './styles';
import { Props } from './types';

const StepByStepForm: FC<Props> = ({
  title,
  pages,
  currentPage,
  defaultValues,
  finishRedirectRoute,
}) => {
  const navigation = useNavigation();

  const getButton = (i: number, route: string) => {
    let buttonLabel;
    if (i < currentPage) {
      buttonLabel = 'Ubah';
    } else if (i === currentPage) {
      buttonLabel = 'Lanjut';
    }
    return buttonLabel ? (
      <Button
        title={buttonLabel}
        onPress={() => navigation.navigate(route, defaultValues)}
        buttonStyle={styles.button}
        titleStyle={styles.buttonTitle}
      />
    ) : null;
  };

  return (
    <View style={styles.container}>
      <View style={styles.titleContainer}>
        <Text style={styles.title}>{title}</Text>
      </View>
      <View style={styles.pageContainer}>
        {pages.map((page, i) => (
          <View style={styles.page} key={i}>
            <Text
              style={[
                styles.number,
                currentPage < i ? styles.notfilled : styles.filled,
              ]}>
              {i + 1}
            </Text>
            <Text
              style={[
                styles.md,
                currentPage < i ? styles.notfilled : styles.filled,
              ]}>
              {page.name}
            </Text>
            <View style={styles.buttonContainer}>
              {getButton(i, page.route)}
            </View>
          </View>
        ))}
      </View>
      <View style={styles.titleContainer}>
        <Button
          title="Selesai"
          onPress={() => navigation.navigate(finishRedirectRoute)}
          buttonStyle={styles.finishButton}
          titleStyle={styles.buttonTitle}
          disabled={currentPage !== pages.length}
        />
      </View>
    </View>
  );
};

export default StepByStepForm;