feat: habit frequency & type labels

This commit is contained in:
Xc165543337 2024-04-04 17:33:51 +02:00
parent bc9d7ae1af
commit a2d187a27a

View File

@ -5,6 +5,7 @@ import {
Button, Button,
HelperText, HelperText,
SegmentedButtons, SegmentedButtons,
Text,
TextInput, TextInput,
} from "react-native-paper" } from "react-native-paper"
import { SafeAreaView } from "react-native-safe-area-context" import { SafeAreaView } from "react-native-safe-area-context"
@ -14,11 +15,11 @@ import ColorPicker, {
Preview, Preview,
} from "reanimated-color-picker" } from "reanimated-color-picker"
import type { GoalFrequency, GoalType } from "@/domain/entities/Goal"
import { GOAL_FREQUENCIES, GOAL_TYPES } from "@/domain/entities/Goal"
import type { HabitCreateData } from "@/domain/entities/Habit" import type { HabitCreateData } from "@/domain/entities/Habit"
import { HabitCreateSchema } from "@/domain/entities/Habit" import { HabitCreateSchema } from "@/domain/entities/Habit"
import type { User } from "@/domain/entities/User" import type { User } from "@/domain/entities/User"
import type { GoalFrequency, GoalType } from "@/domain/entities/Goal"
import { GOAL_FREQUENCIES, GOAL_TYPES } from "@/domain/entities/Goal"
import { capitalize } from "@/presentation/presenters/utils/strings" import { capitalize } from "@/presentation/presenters/utils/strings"
export interface HabitCreateFormProps { export interface HabitCreateFormProps {
@ -154,17 +155,20 @@ export const HabitCreateForm: React.FC<HabitCreateFormProps> = ({ user }) => {
control={control} control={control}
render={({ field: { onChange, value } }) => { render={({ field: { onChange, value } }) => {
return ( return (
<SegmentedButtons <>
onValueChange={onChange} <Text style={{ margin: 8 }}>Habit frequency</Text>
value={value} <SegmentedButtons
buttons={GOAL_FREQUENCIES.map((frequency) => { onValueChange={onChange}
return { value={value}
label: capitalize(frequency), buttons={GOAL_FREQUENCIES.map((frequency) => {
value: frequency, return {
icon: frequenciesIcons[frequency], label: capitalize(frequency),
} value: frequency,
})} icon: frequenciesIcons[frequency],
/> }
})}
/>
</>
) )
}} }}
name="goal.frequency" name="goal.frequency"
@ -174,17 +178,20 @@ export const HabitCreateForm: React.FC<HabitCreateFormProps> = ({ user }) => {
control={control} control={control}
render={({ field: { onChange, value } }) => { render={({ field: { onChange, value } }) => {
return ( return (
<SegmentedButtons <>
onValueChange={onChange} <Text style={{ margin: 8 }}>Habit type</Text>
value={value} <SegmentedButtons
buttons={GOAL_TYPES.map((type) => { onValueChange={onChange}
return { value={value}
label: habitTypesTranslations[type].label, buttons={GOAL_TYPES.map((type) => {
value: type, return {
icon: habitTypesTranslations[type].icon, label: habitTypesTranslations[type].label,
} value: type,
})} icon: habitTypesTranslations[type].icon,
/> }
})}
/>
</>
) )
}} }}
name="goal.target.type" name="goal.target.type"