eletrotupi / tcc/ frontend/app/triggers/new.tsxee13593e49f8dd33700f17862fb841e7660653ce
4.6 KB | 169 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
import { TimePicker } from "@/components/ui/TimePicker";
21

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

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

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

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

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

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

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

91
          <Section>
92
            <SectionHeader title="Horário do Evento" />
93
            <TimePicker value={moment} onChange={setMoment} />
94
          </Section>
95

96
          <Section>
97
            <SectionHeader title="Selecionar uma categoria" />
98
            <CategoryChips
99
              options={TRIGGER_CATEGORIES}
100
              active={category}
101
              onChange={setCategory}
102
            />
103
          </Section>
104

105
          <Section>
106
            <SectionHeader title="Adicione detalhes" />
107

108
            <Card style={styles.mainCard}>
109
              <TextArea
110
                label="Comentários sobre"
111
                variant="darkGhost"
112
                onChangeText={(val) => setComment(val)}
113
                value={comment}
114
                minRows={5}
115
                maxRows={10}
116
                placeholder="Descreva o que gerou esse sentimento"
117
              />
118
            </Card>
119
          </Section>
120

121
          <Button title="Salvar Registro" onPress={save} />
122
        </View>
123
      </ScrollView>
124
    </KeyboardAvoidingView>
125
  );
126
}
127

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