Skip to content

Commit

Permalink
feat: add Toast component and toast configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
heitorgandolfi committed Feb 22, 2024
1 parent f2696ed commit 3f7c680
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
3 changes: 3 additions & 0 deletions App.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import Toast from "react-native-toast-message";
import { ActivityIndicator, StatusBar } from "react-native";
import { ThemeProvider } from "styled-components/native";
import { GestureHandlerRootView } from "react-native-gesture-handler";
Expand All @@ -12,6 +13,7 @@ import {

import { Routes } from "./src/routes";
import { defaultTheme } from "./src/styles/themes/default";
import { toastConfig } from "./src/shared/utils/toastConfigs";

export default function App() {
const [LoadFonts] = useFonts({
Expand All @@ -38,6 +40,7 @@ export default function App() {
<>
<GestureHandlerRootView style={{ flex: 1 }}>
<ThemeProvider theme={defaultTheme}>{handleFontsLoading()}</ThemeProvider>
<Toast config={toastConfig} />
</GestureHandlerRootView>

<StatusBar backgroundColor="transparent" translucent />
Expand Down
24 changes: 24 additions & 0 deletions src/shared/utils/toastConfigs/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { ErrorToast } from "react-native-toast-message";

export const toastConfig = {
defaultToast: (props: any) => (
<ErrorToast
{...props}
contentContainerStyle={{

}}
style={{
backgroundColor: "#FAFAFA",
borderColor: "#6A59FF",
}}
text1Style={{
fontSize: 16,
}}
text2Style={{
fontSize: 14,
color: "#262A50",
fontWeight: "400",
}}
/>
),
};
16 changes: 15 additions & 1 deletion src/useCases/getFilteredTrainningsUseCase/index.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,34 @@
import Toast from "react-native-toast-message";

import { TrainningRepository } from "../../data/Repositories";
import { NewWorkoutFormFieldsProps } from "../../models/newWorkoutFormFieldsModel";
import {
loadFilteredTrainnings,
loadFilteredTrainningsDone,
loadFilteredTrainningsFail,
} from "../../stores/getTrainningsStore/filteredTrainnings/getTrainningsEvents";
import { NewWorkoutFormFieldsProps } from "../../models/newWorkoutFormFieldsModel";

type Props = {
days: string;
};

const showToast = () => {
Toast.show({
autoHide: true,
visibilityTime: 3500,
type: "defaultToast",
text1: "Ops...",
text2: "There is no trainnings in this time interval",
position: "bottom",
});
};

const execute = async ({ days }: Props): Promise<void> => {
loadFilteredTrainnings();

return TrainningRepository.getFilteredTrainnings(days)
.then((FilteredTrainnings: NewWorkoutFormFieldsProps[]) => {
if (FilteredTrainnings.length === 0) showToast();
loadFilteredTrainningsDone(FilteredTrainnings);
})
.catch(({ message }) => {
Expand Down

0 comments on commit 3f7c680

Please sign in to comment.