-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9c940fc
commit 0ec11bc
Showing
6 changed files
with
91 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
export * from './types'; | ||
export * from './use-create-habit'; | ||
export * from './use-delete-habit'; | ||
export * from './use-edit-habit'; | ||
export * from './use-habits'; | ||
export * from './use-press-habit-button'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { showMessage } from 'react-native-flash-message'; | ||
import { createMutation } from 'react-query-kit'; | ||
|
||
import { removeHabitFromOrder } from '@/core'; | ||
|
||
import { addTestDelay, queryClient } from '../common'; | ||
import { mockHabits, setMockHabits } from './mock-habits'; | ||
import { type DbHabitT, type HabitIdT } from './types'; | ||
|
||
type Response = DbHabitT; | ||
type Variables = { | ||
habitId: HabitIdT; | ||
}; | ||
|
||
export const useDeleteHabit = createMutation<Response, Variables, Error>({ | ||
mutationFn: async ({ habitId }) => { | ||
const habit = mockHabits.find((h) => h.id === habitId); | ||
if (!habit) throw new Error('Habit not found'); | ||
|
||
const updatedHabits = mockHabits.filter((h) => h.id !== habitId); | ||
setMockHabits(updatedHabits); | ||
removeHabitFromOrder(habitId); | ||
|
||
await addTestDelay(null); | ||
return habit.data; | ||
}, | ||
onSuccess: () => { | ||
queryClient.invalidateQueries({ queryKey: ['habits'] }); | ||
showMessage({ | ||
message: 'Habit deleted successfully', | ||
type: 'success', | ||
duration: 2000, | ||
}); | ||
}, | ||
onError: () => { | ||
showMessage({ | ||
message: 'Failed to delete habit', | ||
type: 'danger', | ||
duration: 2000, | ||
}); | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters