eletrotupi / tcc/ frontend/app/triggers/new.tsx3c48957da540557e7d3a844d97efd318222a1371
4.4 KB | 163 lines Raw
1
import {
2
  View,
3
  Text,
4
  StyleSheet,
5
  KeyboardAvoidingView,
6
  ScrollView,
7
} from "react-native";
8
import { useEffect, useState } from "react";
9
import { router } from "expo-router";
10

11
import { Card } from "@/components/ui/Cards";
12
import { Input, TextArea } from "@/components/ui/Input";
13
import { Button } from "@/components/ui/Button";
14
import { Section, SectionHeader } from "@/components/ui/Sections";
15
import { Spacing, Typography, Colors, BorderRadius } from "@/constants/theme";
16
import { Ionicons, MaterialIcons } from "@expo/vector-icons";
17
import { useCreateTrigger } from "@/hooks";
18
import { CategoryChips, CategoryOption } from "@/components/ui/CategoryChips";
19
import { TriggerCategory } from "@/constants/triggers";
20

21
const TRIGGER_CATEGORIES: CategoryOption<TriggerCategory>[] = [
22
  {
23
    label: "Trabalho",
24
    value: "WORK",
25
    icon: <Ionicons size={16} color="#60A5FA" name="briefcase" />,
26
  },
27
  {
28
    label: "Social",
29
    value: "SOCIAL",
30
    icon: <MaterialIcons size={16} color="#AF52DE" name="diversity-1" />,
31
  },
32
  {
33
    label: "Saúde",
34
    value: "HEALTH",
35
    icon: <MaterialIcons size={16} color="#34C759" name="healing" />,
36
  },
37
  {
38
    label: "Família",
39
    value: "FAMILY",
40
    icon: <MaterialIcons size={16} color="#FF9500" name="family-restroom" />,
41
  },
42
  {
43
    label: "Outros",
44
    value: "OTHER",
45
    icon: <Ionicons size={16} color="#8E8E93" name="ellipsis-horizontal" />,
46
  },
47
];
48

49
export default function NewTrigger() {
50
  const [moment, setMoment] = useState(new Date());
51
  const [comment, setComment] = useState("");
52
  const [category, setCategory] = useState("WORK");
53
  const createTrigger = useCreateTrigger();
54

55
  const save = async () => {
56
    const data = {
57
      moment,
58
      comment,
59
      category,
60
    };
61

62
    await createTrigger.mutateAsync(data);
63
    router.replace("/(tabs)/actions");
64
  };
65

66
  return (
67
    <KeyboardAvoidingView behavior="height" style={styles.keyboardView}>
68
      <ScrollView scrollEventThrottle={16}>
69
        <View style={styles.container}>
70
          <View style={styles.header}>
71
            <View style={styles.innerHeaderWrapper}>
72
              <View style={[styles.headerIcon, { backgroundColor: "#FFF7ED" }]}>
73
                <Ionicons name="flash-outline" size={20} color="#EA580C" />
74
              </View>
75

76
              <View style={styles.headerTitleSubtitle}>
77
                <Text style={styles.headerTitle}>Aconteceu algo?</Text>
78
                <Text style={styles.headerSubtitle}>
79
                  Registre acontecimentos fora do padrão
80
                </Text>
81
              </View>
82
            </View>
83

84
            <Text style={styles.description}>
85
              Identificar gatilhos ajuda a entender melhor seus padrões
86
              emocionais
87
            </Text>
88
          </View>
89

90
          <Section>
91
            <SectionHeader title="Selecionar uma categoria" />
92
            <CategoryChips
93
              options={TRIGGER_CATEGORIES}
94
              active={category}
95
              onChange={setCategory}
96
            />
97
          </Section>
98

99
          <Section>
100
            <SectionHeader title="Adicione detalhes" />
101

102
            <Card style={styles.mainCard}>
103
              <TextArea
104
                label="Comentários sobre"
105
                variant="darkGhost"
106
                onChangeText={(val) => setComment(val)}
107
                value={comment}
108
                minRows={5}
109
                maxRows={10}
110
                placeholder="Descreva o que gerou esse sentimento"
111
              />
112
            </Card>
113
          </Section>
114

115
          <Button title="Salvar Registro" onPress={save} />
116
        </View>
117
      </ScrollView>
118
    </KeyboardAvoidingView>
119
  );
120
}
121

122
const styles = StyleSheet.create({
123
  container: {
124
    gap: 24,
125
    paddingHorizontal: Spacing.containerPadding,
126
    paddingVertical: Spacing.sectionGap,
127
    marginBottom: 50,
128
  },
129
  mainCard: {
130
    padding: Spacing.cardGap,
131
  },
132
  // Header
133
  header: {},
134
  headerIcon: {
135
    paddingVertical: 15,
136
    paddingHorizontal: 14,
137
    width: 48,
138
    borderRadius: BorderRadius.md,
139
  },
140
  innerHeaderWrapper: {
141
    flex: 1,
142
    flexDirection: "row",
143
    alignItems: "center",
144
  },
145
  headerTitleSubtitle: {
146
    marginLeft: 10,
147
  },
148
  headerTitle: {
149
    ...Typography.headlineMd,
150
  },
151
  headerSubtitle: {
152
    ...Typography.bodyMd,
153
    color: Colors.light.textSecondary,
154
  },
155
  description: {
156
    ...Typography.bodyMd,
157
    color: Colors.light.textSecondary,
158
    marginTop: 20,
159
  },
160
  keyboardView: {
161
    flex: 1,
162
  },
163
});