| 1 | import {
|
| 2 | View,
|
| 3 | Text,
|
| 4 | StyleSheet,
|
| 5 | ScrollView
|
| 6 | } from 'react-native';
|
| 7 | import { useEffect, useState } from 'react';
|
| 8 |
|
| 9 | import { Card } from '@/components/ui/Cards';
|
| 10 | import { Input, TextArea } from '@/components/ui/Input';
|
| 11 | import { Button } from '@/components/ui/Button';
|
| 12 | import { Spacing, Typography, Colors, BorderRadius } from '@/constants/theme';
|
| 13 | import { Ionicons } from '@expo/vector-icons';
|
| 14 | import DatePickerField from '@/components/ui/DatePickerField';
|
| 15 | import { ScaleSlider } from '@/components/ui/ScaleSlider';
|
| 16 |
|
| 17 | export default function NewSleepRecord() {
|
| 18 | const [date, setDate] = useState(new Date())
|
| 19 | const [annotations, setAnnotations] = useState();
|
| 20 | const [average, setAverage] = useState(7.5);
|
| 21 |
|
| 22 | const formatValue = (value: number): string => {
|
| 23 | return String(value).replaceAll('.', ',');
|
| 24 | };
|
| 25 |
|
| 26 | const save = async () => {
|
| 27 | const data = {
|
| 28 | date,
|
| 29 | annotations,
|
| 30 | average
|
| 31 | };
|
| 32 |
|
| 33 | console.log("Sleep record:", data)
|
| 34 | //await createSleepRecord.mutateAsync(data)
|
| 35 | //router.replace("/")
|
| 36 | };
|
| 37 |
|
| 38 | return (
|
| 39 | <View>
|
| 40 | <ScrollView scrollEventThrottle={16}>
|
| 41 | <View style={styles.container}>
|
| 42 | <View style={styles.header}>
|
| 43 | <View style={styles.innerHeaderWrapper}>
|
| 44 | <View style={[styles.headerIcon, { backgroundColor: '#EFF6FF' }]}>
|
| 45 | <Ionicons name="moon-outline" size={20} color="#2563EB" />
|
| 46 | </View>
|
| 47 |
|
| 48 | <View style={styles.headerTitleSubtitle}>
|
| 49 | <Text style={styles.headerTitle}>Bom descanso</Text>
|
| 50 | <Text style={styles.headerSubtitle}>Registre sua noite de sono</Text>
|
| 51 | </View>
|
| 52 | </View>
|
| 53 |
|
| 54 | <Text style={styles.description}>
|
| 55 | Acompanhar seu sono ajuda a entender como seu corpo se recupera
|
| 56 | e melhora sua performance diária.
|
| 57 | </Text>
|
| 58 | </View>
|
| 59 |
|
| 60 | <Card style={styles.mainCard}>
|
| 61 | <DatePickerField
|
| 62 | label="Data do Registro"
|
| 63 | initialDate={date}
|
| 64 | maximumDate={new Date()}
|
| 65 | onChange={setDate}
|
| 66 | />
|
| 67 |
|
| 68 | <View style={{ marginVertical: 15 }}>
|
| 69 | <ScaleSlider
|
| 70 | label="Duração"
|
| 71 | value={average}
|
| 72 | onValueChange={setAverage}
|
| 73 | onValueFormat={formatValue}
|
| 74 | step={0.5}
|
| 75 | min={0.0}
|
| 76 | max={15.0}
|
| 77 | minLabel="0h"
|
| 78 | maxLabel="15h" />
|
| 79 | </View>
|
| 80 |
|
| 81 | <TextArea
|
| 82 | label="Notas sobre a qualidade"
|
| 83 | type="text"
|
| 84 | variant="darkGhost"
|
| 85 | onChangeText={(val) => setAnnotations(val)}
|
| 86 | value={annotations}
|
| 87 | minRows={5}
|
| 88 | maxRows={10}
|
| 89 | placeholder="Como você se sentiu ao acordar? Teve sonhos marcantes?"
|
| 90 | style={styles.notes}
|
| 91 | />
|
| 92 | </Card>
|
| 93 |
|
| 94 | <Button title="Salvar Registro" onPress={save} />
|
| 95 | </View>
|
| 96 | </ScrollView>
|
| 97 | </View>
|
| 98 | );
|
| 99 | }
|
| 100 |
|
| 101 | const styles = StyleSheet.create({
|
| 102 | container: {
|
| 103 | gap: 24,
|
| 104 | paddingHorizontal: Spacing.containerPadding,
|
| 105 | paddingVertical: Spacing.sectionGap,
|
| 106 | },
|
| 107 | mainCard: {
|
| 108 | padding: Spacing.cardGap
|
| 109 | },
|
| 110 | // Header
|
| 111 | header: {
|
| 112 | },
|
| 113 | headerIcon: {
|
| 114 | paddingVertical: 15,
|
| 115 | paddingHorizontal: 14,
|
| 116 | width: 48,
|
| 117 | borderRadius: BorderRadius.md,
|
| 118 | },
|
| 119 | innerHeaderWrapper: {
|
| 120 | flex: 1,
|
| 121 | flexDirection: 'row',
|
| 122 | alignItems: 'center'
|
| 123 | },
|
| 124 | headerTitleSubtitle: {
|
| 125 | marginLeft: 10
|
| 126 | },
|
| 127 | headerTitle: {
|
| 128 | ...Typography.headlineMd
|
| 129 | },
|
| 130 | headerSubtitle: {
|
| 131 | ...Typography.bodyMd,
|
| 132 | color: Colors.light.textSecondary
|
| 133 | },
|
| 134 | description: {
|
| 135 | ...Typography.bodyMd,
|
| 136 | color: Colors.light.textSecondary,
|
| 137 | marginTop: 20
|
| 138 | }
|
| 139 | })
|