MCPcopy Create free account
hub / github.com/OneBitCodeBlog/onebitlife / handleCreateHabit

Function handleCreateHabit

src/Pages/HabitPage/index.jsx:48–98  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

46 const responseListener = useRef();
47
48 function handleCreateHabit() {
49 if (habitInput === undefined || frequencyInput === undefined) {
50 Alert.alert(
51 "Você precisa selecionar um hábito e frequência para continuar"
52 );
53 } else if (
54 notificationToggle === true &&
55 frequencyInput === "Diário" &&
56 timeNotification === undefined
57 ) {
58 Alert.alert("Você precisa dizer o horário da notificação!");
59 } else if (
60 notificationToggle === true &&
61 frequencyInput === "Diário" &&
62 dayNotification === undefined &&
63 timeNotification === undefined
64 ) {
65 Alert.alert(
66 "Você precisa dizer a frequência e o horário da notificação!"
67 );
68 } else {
69 if (notificationToggle) {
70 NotificationService.createNotification(
71 habitInput,
72 frequencyInput,
73 dayNotification,
74 timeNotification
75 );
76 }
77
78 HabitsService.createHabit({
79 habitArea: habit?.habitArea,
80 habitName: habitInput,
81 habitFrequency: frequencyInput,
82 habitHasNotification: notificationToggle,
83 habitNotificationFrequency: dayNotification,
84 habitNotificationTime: timeNotification,
85 lastCheck: formatDate,
86 daysWithoutChecks: 0,
87 habitIsChecked: 0,
88 progressBar: 1,
89 habitChecks: 0,
90 }).then(() => {
91 Alert.alert("Sucesso na criação do hábito!");
92
93 navigation.navigate("Home", {
94 createdHabit: `Created in ${habit?.habitArea}`,
95 });
96 });
97 }
98 }
99
100 function handleUpdateHabit() {
101 if (notificationToggle === true && !dayNotification && !timeNotification) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected