| 1 | import {
|
| 2 | View,
|
| 3 | StyleSheet,
|
| 4 | KeyboardAvoidingView,
|
| 5 | ScrollView,
|
| 6 | } from "react-native";
|
| 7 | import { Text } from "@/components/ui/Text";
|
| 8 | import { useState } from "react";
|
| 9 | import { router } from "expo-router";
|
| 10 |
|
| 11 | import { Card } from "@/components/ui/Cards";
|
| 12 | import { Input } from "@/components/ui/Input";
|
| 13 | import { Button } from "@/components/ui/Button";
|
| 14 | import { Section, SectionHeader } from "@/components/ui/Sections";
|
| 15 | import { CategoryChips, CategoryOption } from "@/components/ui/CategoryChips";
|
| 16 | import { Spacing, Typography, Colors, Shadows } from "@/constants/theme";
|
| 17 | import { Ionicons } from "@expo/vector-icons";
|
| 18 | import { useCreateCareAction } from "@/hooks";
|
| 19 | import { ActivityType } from "@/lib/api";
|
| 20 |
|
| 21 | const ACTIVITY_TYPES: CategoryOption<ActivityType>[] = [
|
| 22 | { label: 'Caminhada', value: 'WALK', icon: <Ionicons name="walk-outline" size={16} color={Colors.light.tint} /> },
|
| 23 | { label: 'Yoga', value: 'YOGA', icon: <Ionicons name="body-outline" size={16} color={Colors.light.tint} /> },
|
| 24 | { label: 'Academia', value: 'GYM', icon: <Ionicons name="barbell-outline" size={16} color={Colors.light.tint} /> },
|
| 25 | { label: 'Meditação', value: 'MEDITATION', icon: <Ionicons name="leaf-outline" size={16} color={Colors.light.tint} /> },
|
| 26 | { label: 'Social', value: 'SOCIAL', icon: <Ionicons name="people-outline" size={16} color={Colors.light.tint} /> },
|
| 27 | { label: 'Criativo', value: 'CREATIVE', icon: <Ionicons name="color-palette-outline" size={16} color={Colors.light.tint} /> },
|
| 28 | { label: 'Outro', value: 'OTHER', icon: <Ionicons name="help-outline" size={16} color={Colors.light.tint} /> },
|
| 29 | ];
|
| 30 |
|
| 31 | export default function ActivityCareAction() {
|
| 32 | const [activityType, setActivityType] = useState<ActivityType>('WALK');
|
| 33 | const [activityDuration, setActivityDuration] = useState('');
|
| 34 |
|
| 35 | const createCareAction = useCreateCareAction();
|
| 36 |
|
| 37 | const handleSave = async () => {
|
| 38 | await createCareAction.mutateAsync({
|
| 39 | type: 'ACTIVITY',
|
| 40 | moment: new Date(),
|
| 41 | activity: {
|
| 42 | type: activityType,
|
| 43 | duration: activityDuration ? Number(activityDuration) : undefined,
|
| 44 | },
|
| 45 | });
|
| 46 | router.replace('/(tabs)/actions');
|
| 47 | };
|
| 48 |
|
| 49 | return (
|
| 50 | <KeyboardAvoidingView behavior="height" style={styles.keyboardView}>
|
| 51 | <ScrollView scrollEventThrottle={16}>
|
| 52 | <View style={styles.container}>
|
| 53 | <View style={styles.header}>
|
| 54 | <Text style={styles.headerTitle}>Registrar atividade</Text>
|
| 55 | <Text style={styles.headerSubtitle}>
|
| 56 | Qual atividade você realizou?
|
| 57 | </Text>
|
| 58 | </View>
|
| 59 |
|
| 60 | <Section>
|
| 61 | <SectionHeader title="Tipo de atividade" />
|
| 62 | <CategoryChips
|
| 63 | options={ACTIVITY_TYPES}
|
| 64 | active={activityType}
|
| 65 | onChange={setActivityType}
|
| 66 | />
|
| 67 | </Section>
|
| 68 |
|
| 69 | <Section>
|
| 70 | <SectionHeader title="Duração (min, opcional)" />
|
| 71 | <Card style={{ padding: Spacing.cardGap }}>
|
| 72 | <Input
|
| 73 | label="Duração em minutos"
|
| 74 | value={activityDuration}
|
| 75 | onChangeText={setActivityDuration}
|
| 76 | placeholder="Ex: 30"
|
| 77 | keyboardType="numeric"
|
| 78 | variant="darkGhost"
|
| 79 | />
|
| 80 | </Card>
|
| 81 | </Section>
|
| 82 |
|
| 83 | <Button
|
| 84 | title="Salvar"
|
| 85 | onPress={handleSave}
|
| 86 | loading={createCareAction.isPending}
|
| 87 | style={{ ...Shadows.lg }}
|
| 88 | />
|
| 89 | </View>
|
| 90 | </ScrollView>
|
| 91 | </KeyboardAvoidingView>
|
| 92 | );
|
| 93 | }
|
| 94 |
|
| 95 | const styles = StyleSheet.create({
|
| 96 | keyboardView: {
|
| 97 | flex: 1,
|
| 98 | },
|
| 99 | container: {
|
| 100 | gap: 24,
|
| 101 | paddingHorizontal: Spacing.containerPadding,
|
| 102 | paddingVertical: Spacing.sectionGap,
|
| 103 | marginBottom: 50,
|
| 104 | },
|
| 105 | header: {
|
| 106 | gap: 8,
|
| 107 | },
|
| 108 | headerTitle: {
|
| 109 | ...Typography.headlineMd,
|
| 110 | },
|
| 111 | headerSubtitle: {
|
| 112 | ...Typography.bodyMd,
|
| 113 | color: Colors.light.textSecondary,
|
| 114 | },
|
| 115 | });
|