| 1 | import {
|
| 2 | View,
|
| 3 | Text,
|
| 4 | StyleSheet,
|
| 5 | KeyboardAvoidingView,
|
| 6 | ScrollView,
|
| 7 | } from "react-native";
|
| 8 | import { useState } from "react";
|
| 9 | import { router } from "expo-router";
|
| 10 |
|
| 11 | import { Card } from "@/components/ui/Cards";
|
| 12 | import { 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, useMoodEntries } from "@/hooks";
|
| 18 | import { CategoryChips, CategoryOption } from "@/components/ui/CategoryChips";
|
| 19 | import { TriggerCategory } from "@/constants/triggers";
|
| 20 | import { TimePicker } from "@/components/ui/TimePicker";
|
| 21 | import { getMood } from "@/constants/moods";
|
| 22 | import { LinkRow } from "@/components/ui/LinkRow";
|
| 23 |
|
| 24 | const TRIGGER_CATEGORIES: CategoryOption<TriggerCategory>[] = [
|
| 25 | {
|
| 26 | label: "Trabalho",
|
| 27 | value: "WORK",
|
| 28 | icon: <MaterialIcons size={16} color="#60A5FA" name="work" />,
|
| 29 | },
|
| 30 | {
|
| 31 | label: "Social",
|
| 32 | value: "SOCIAL",
|
| 33 | icon: <MaterialIcons size={16} color="#AF52DE" name="diversity-1" />,
|
| 34 | },
|
| 35 | {
|
| 36 | label: "Saúde",
|
| 37 | value: "HEALTH",
|
| 38 | icon: <MaterialIcons size={16} color="#34C759" name="healing" />,
|
| 39 | },
|
| 40 | {
|
| 41 | label: "Família",
|
| 42 | value: "FAMILY",
|
| 43 | icon: <MaterialIcons size={16} color="#FF9500" name="family-restroom" />,
|
| 44 | },
|
| 45 | {
|
| 46 | label: "Outros",
|
| 47 | value: "OTHER",
|
| 48 | icon: <Ionicons size={16} color="#8E8E93" name="ellipsis-horizontal" />,
|
| 49 | },
|
| 50 | ];
|
| 51 |
|
| 52 | export default function NewTrigger() {
|
| 53 | const [moment, setMoment] = useState(new Date());
|
| 54 | const [comment, setComment] = useState("");
|
| 55 | const [category, setCategory] = useState("WORK");
|
| 56 | const createTrigger = useCreateTrigger();
|
| 57 | const [linkMood, setLinkMood] = useState(false);
|
| 58 | const { data: moodEntries, isLoading: isLoadingMood } = useMoodEntries({
|
| 59 | limit: 1,
|
| 60 | });
|
| 61 |
|
| 62 | const latestMood = moodEntries?.entries[0] ?? null;
|
| 63 | const moodDef = latestMood
|
| 64 | ? getMood(latestMood.selectedMood.toLowerCase())
|
| 65 | : null;
|
| 66 |
|
| 67 | const save = async () => {
|
| 68 | const data = {
|
| 69 | moment,
|
| 70 | comment,
|
| 71 | category,
|
| 72 | ...(linkMood && latestMood ? { moodId: latestMood.id } : null),
|
| 73 | };
|
| 74 |
|
| 75 | await createTrigger.mutateAsync(data);
|
| 76 | router.replace("/(tabs)/actions");
|
| 77 | };
|
| 78 |
|
| 79 | return (
|
| 80 | <KeyboardAvoidingView behavior="height" style={styles.keyboardView}>
|
| 81 | <ScrollView scrollEventThrottle={16}>
|
| 82 | <View style={styles.container}>
|
| 83 | <View style={styles.header}>
|
| 84 | <View style={styles.innerHeaderWrapper}>
|
| 85 | <View style={[styles.headerIcon, { backgroundColor: "#FFF7ED" }]}>
|
| 86 | <Ionicons name="flash-outline" size={20} color="#EA580C" />
|
| 87 | </View>
|
| 88 |
|
| 89 | <View style={styles.headerTitleSubtitle}>
|
| 90 | <Text style={styles.headerTitle}>Aconteceu algo?</Text>
|
| 91 | <Text style={styles.headerSubtitle}>
|
| 92 | Registre acontecimentos fora do padrão
|
| 93 | </Text>
|
| 94 | </View>
|
| 95 | </View>
|
| 96 |
|
| 97 | <Text style={styles.description}>
|
| 98 | Identificar gatilhos ajuda a entender melhor seus padrões
|
| 99 | emocionais
|
| 100 | </Text>
|
| 101 | </View>
|
| 102 |
|
| 103 | <Section>
|
| 104 | <SectionHeader title="Horário do Evento" />
|
| 105 | <TimePicker value={moment} onChange={setMoment} />
|
| 106 | </Section>
|
| 107 |
|
| 108 | <Section>
|
| 109 | <SectionHeader title="Selecionar uma categoria" />
|
| 110 | <CategoryChips
|
| 111 | options={TRIGGER_CATEGORIES}
|
| 112 | active={category}
|
| 113 | onChange={setCategory}
|
| 114 | />
|
| 115 | </Section>
|
| 116 |
|
| 117 | <Section>
|
| 118 | <SectionHeader title="Adicione detalhes" />
|
| 119 |
|
| 120 | <Card style={styles.mainCard}>
|
| 121 | <TextArea
|
| 122 | label="Comentários sobre"
|
| 123 | variant="darkGhost"
|
| 124 | onChangeText={(val) => setComment(val)}
|
| 125 | value={comment}
|
| 126 | minRows={5}
|
| 127 | maxRows={10}
|
| 128 | placeholder="Descreva o que gerou esse sentimento"
|
| 129 | />
|
| 130 | </Card>
|
| 131 | </Section>
|
| 132 |
|
| 133 | <Section>
|
| 134 | <SectionHeader title="Vincular registro" />
|
| 135 |
|
| 136 | <LinkRow
|
| 137 | icon={
|
| 138 | <View
|
| 139 | style={[styles.iconWrap, { backgroundColor: "transparent" }]}
|
| 140 | >
|
| 141 | <Text style={styles.moodIconEmoji}>
|
| 142 | {moodDef?.icon ?? "😐"}
|
| 143 | </Text>
|
| 144 | </View>
|
| 145 | }
|
| 146 | label="Humor atual"
|
| 147 | sublabel={
|
| 148 | isLoadingMood ? "..." : (moodDef?.label ?? "Nenhum registrado")
|
| 149 | }
|
| 150 | disabled={!latestMood}
|
| 151 | value={linkMood && !!latestMood}
|
| 152 | onToggle={setLinkMood}
|
| 153 | />
|
| 154 |
|
| 155 | <LinkRow
|
| 156 | icon={
|
| 157 | <MaterialIcons
|
| 158 | name="psychology"
|
| 159 | size={40}
|
| 160 | color={Colors.light.disabled}
|
| 161 | />
|
| 162 | }
|
| 163 | label="Prática"
|
| 164 | sublabel={"Nenhuma registrada"}
|
| 165 | disabled={true}
|
| 166 | value={false}
|
| 167 | onToggle={() => {
|
| 168 | console.log("When we get that");
|
| 169 | }}
|
| 170 | />
|
| 171 | </Section>
|
| 172 |
|
| 173 | <Button title="Salvar Registro" onPress={save} />
|
| 174 | </View>
|
| 175 | </ScrollView>
|
| 176 | </KeyboardAvoidingView>
|
| 177 | );
|
| 178 | }
|
| 179 |
|
| 180 | const styles = StyleSheet.create({
|
| 181 | container: {
|
| 182 | gap: 24,
|
| 183 | paddingHorizontal: Spacing.containerPadding,
|
| 184 | paddingVertical: Spacing.sectionGap,
|
| 185 | marginBottom: 50,
|
| 186 | },
|
| 187 | mainCard: {
|
| 188 | padding: Spacing.cardGap,
|
| 189 | },
|
| 190 | // Header
|
| 191 | header: {},
|
| 192 | headerIcon: {
|
| 193 | paddingVertical: 15,
|
| 194 | paddingHorizontal: 14,
|
| 195 | width: 48,
|
| 196 | borderRadius: BorderRadius.md,
|
| 197 | },
|
| 198 | innerHeaderWrapper: {
|
| 199 | flex: 1,
|
| 200 | flexDirection: "row",
|
| 201 | alignItems: "center",
|
| 202 | },
|
| 203 | headerTitleSubtitle: {
|
| 204 | marginLeft: 10,
|
| 205 | },
|
| 206 | headerTitle: {
|
| 207 | ...Typography.headlineMd,
|
| 208 | },
|
| 209 | headerSubtitle: {
|
| 210 | ...Typography.bodyMd,
|
| 211 | color: Colors.light.textSecondary,
|
| 212 | },
|
| 213 | description: {
|
| 214 | ...Typography.bodyMd,
|
| 215 | color: Colors.light.textSecondary,
|
| 216 | marginTop: 20,
|
| 217 | },
|
| 218 | keyboardView: {
|
| 219 | flex: 1,
|
| 220 | },
|
| 221 | moodIconEmoji: {
|
| 222 | fontSize: 26,
|
| 223 | },
|
| 224 | iconWrap: {
|
| 225 | width: 40,
|
| 226 | height: 40,
|
| 227 | borderRadius: 20,
|
| 228 | alignItems: "center",
|
| 229 | justifyContent: "center",
|
| 230 | marginTop: 1,
|
| 231 | },
|
| 232 | });
|