diff --git a/src/components/AdoptionInterestNotification/index.tsx b/src/components/AdoptionInterestNotification/index.tsx deleted file mode 100644 index c43adad..0000000 --- a/src/components/AdoptionInterestNotification/index.tsx +++ /dev/null @@ -1,57 +0,0 @@ -/* eslint-disable camelcase */ -// Package imports. -import React, { useEffect, useState } from 'react'; -import { Text } from 'react-native'; -import { useNavigation } from '@react-navigation/native'; - -// Component imports. - -// Service imports. -import { FirebaseFirestoreTypes } from '@react-native-firebase/firestore'; -import { TouchableOpacity } from 'react-native-gesture-handler'; -import userAPI from '../../services/user/api'; -import animalAPI from '../../services/animal/api'; -import { INotificationDoc, INotificationAdoptionInterestData } from '../../services/notifications/api'; - -// Style imports. - -// Type declaration. -interface IAdoptionInterestNotificationProps { - notification: INotificationDoc, -} - -// Component. -export default function AdoptionInterestNotification({ notification }: IAdoptionInterestNotificationProps) : JSX.Element { - // Variables. - const navigation = useNavigation(); - const [requester, setRequester] = useState(); - const [animal, setAnimal] = useState(); - - // Styled components. - - // Function declaration. - const fetchData = (): void => { - const data = notification.data as unknown as INotificationAdoptionInterestData; - if (!data) return; - - userAPI.getUser(notification.from).then((result) => setRequester(result.data())); - animalAPI.getAnimal(data.animalId).then((result) => setAnimal({ id: result.id, data: result.data() })); - }; - - // Page effects. - - useEffect(() => { - fetchData(); - }); - - // JSX returned. - return ( - { - navigation.navigate('AnimalDetails', { animalUID: animal?.id }); - }} - > - {requester?.full_name} está interessado no seu pet {animal?.data.name} - - ); -} diff --git a/src/components/AdoptionInterestNotification/styles.ts b/src/components/AdoptionInterestNotification/styles.ts deleted file mode 100644 index 733a948..0000000 --- a/src/components/AdoptionInterestNotification/styles.ts +++ /dev/null @@ -1,13 +0,0 @@ -// Package imports. -import { ViewProps } from 'react-native'; -import styled from 'styled-components/native'; - -// Style imports. -import { Theme } from '../../constants'; - -// Styled components. -export const Container = styled.View` - flex: 1; - align-items: center; - background-color: ${Theme.default.background}; -`; diff --git a/src/components/AnimalCard/index.tsx b/src/components/AnimalCard/index.tsx index 09bed90..1ffead2 100644 --- a/src/components/AnimalCard/index.tsx +++ b/src/components/AnimalCard/index.tsx @@ -1,4 +1,4 @@ -import React, { ReactNode, useState } from 'react'; +import React, { useState } from 'react'; import { ActivityIndicator } from 'react-native'; import { TouchableWithoutFeedback } from 'react-native-gesture-handler'; @@ -6,19 +6,11 @@ import animalAPI from '../../services/animal/api'; import { Images, Theme } from '../../constants'; +import { IAnimalCardProps } from '../../types/components/AnimalCard'; import { CardBody, CardBox, CardHeader, CardImage, CardImageLoading, CardOptions, CardTitle, } from './styles'; -interface IAnimalCardProps { - title: string; - imageUrl: string | null; - headerOptions?: ReactNode; - body?: ReactNode; - headerBackground: string; - onPress?: () => void; -} - const AnimalCard = ({ title, body, headerOptions, imageUrl, headerBackground, onPress, } : IAnimalCardProps) : JSX.Element => { diff --git a/src/components/AnimalCard/styles.ts b/src/components/AnimalCard/styles.ts index 744931e..6a70548 100644 --- a/src/components/AnimalCard/styles.ts +++ b/src/components/AnimalCard/styles.ts @@ -1,10 +1,7 @@ import { ImageProps, TextProps, ViewProps } from 'react-native'; import styled from 'styled-components/native'; import { Theme } from '../../constants'; - -interface CardHeaderProps extends ViewProps { - backgroundColor: string; -} +import { CardHeaderProps } from '../../types/components/AnimalCard'; export const CardBox = styled.View` width: 344px; diff --git a/src/components/AsyncButton/index.tsx b/src/components/AsyncButton/index.tsx index daacff3..ec71d30 100644 --- a/src/components/AsyncButton/index.tsx +++ b/src/components/AsyncButton/index.tsx @@ -1,16 +1,9 @@ import React, { useState } from 'react'; import { ActivityIndicator, GestureResponderEvent } from 'react-native'; -import { Button, ButtonType } from './styles'; +import { Button } from './styles'; import { Theme } from '../../constants'; - -interface IButtonProps extends ButtonType { - children: React.ReactNode, - asyncAction: boolean, - callback: (arg: GestureResponderEvent) => void, - activityIndicator?: Record, - styles?: Record, -} +import { IButtonProps } from '../../types/components/AsyncButton'; const AsyncButton : React.FC = (props : IButtonProps) => { const [disabled, setDisabled] = useState(false); diff --git a/src/components/AsyncButton/styles.ts b/src/components/AsyncButton/styles.ts index 39ae578..224995b 100644 --- a/src/components/AsyncButton/styles.ts +++ b/src/components/AsyncButton/styles.ts @@ -1,23 +1,7 @@ import styled from 'styled-components/native'; -import { TouchableOpacityProps } from 'react-native'; import { Theme } from '../../constants'; - -export interface ButtonType extends TouchableOpacityProps { - flex?: number, - flexDirection?: string, - width?: string, - height?: string, - backgroundColor?: string, - marginTop?: string, - marginBottom?: string, - marginLeft?: string, - marginRight?: string, - borderRadius?: string, - alignSelf?: string, - alignItems?: string, - justifyContent?: string, -} +import { ButtonType } from '../../types/components/AsyncButton'; export const Button = styled.TouchableOpacity` flex: ${(props) => props.flex}; diff --git a/src/components/CustomTextInput/index.tsx b/src/components/CustomTextInput/index.tsx index 50a6e3a..7b06c87 100644 --- a/src/components/CustomTextInput/index.tsx +++ b/src/components/CustomTextInput/index.tsx @@ -3,14 +3,8 @@ import { HelperText, TextInput, } from 'react-native-paper'; -import { FormikProps } from 'formik'; import { NativeSyntheticEvent, TextInputFocusEventData } from 'react-native'; - -interface ICustomTextInput { - formikHelpers: FormikProps, - fieldName: keyof T, - [propName: string]: unknown; -} +import { ICustomTextInput } from '../../types/components/CustomTextInput'; const CustomTextInput = ({ formikHelpers, fieldName, ...rest diff --git a/src/components/DrawerContent/index.tsx b/src/components/DrawerContent/index.tsx index 56bebca..89ca7e7 100644 --- a/src/components/DrawerContent/index.tsx +++ b/src/components/DrawerContent/index.tsx @@ -10,19 +10,16 @@ import useIsMounted from 'ismounted'; import MaterialIcons from 'react-native-vector-icons/MaterialIcons'; import { TouchableOpacity } from 'react-native-gesture-handler'; -import { styledComponents, styles } from './styles'; import { Theme } from '../../constants'; -import { getNameInitials } from '../../utils/getNameInitials'; +import { useAuth } from '../../contexts/user/context'; import userAPI from '../../services/user/api'; import notificationAPI from '../../services/notifications/api'; -import { useAuth } from '../../contexts/user/context'; -export interface IDrawerProps { - parentDrawerOpen: boolean, - setParentDrawerOpen: (_: boolean) => void, -} +import { getNameInitials } from '../../utils/getNameInitials'; +import { IDrawerProps } from '../../types/components/DrawerContent'; +import { styledComponents, styles } from './styles'; const fetchProfile = async (currentUser: FirebaseAuthTypes.User | null) : Promise<{displayName: string, photo: string | undefined} | undefined> => { if (currentUser != null) { diff --git a/src/components/InfiniteScroll/index.tsx b/src/components/InfiniteScroll/index.tsx index 86850a1..2360459 100644 --- a/src/components/InfiniteScroll/index.tsx +++ b/src/components/InfiniteScroll/index.tsx @@ -9,28 +9,8 @@ import { useFocusEffect } from '@react-navigation/native'; // Style imports. import { defaultProps, styledComponents } from './styles'; -// Type declaration. -type InfiniteScrollState = { - allDataFetched: boolean, - data: Array, - error: string | null, - loadingMore: boolean, - page: number, -} - -// Interface declaration. -interface IInfiniteScroll { - activityIndicatorColor?: string, - contentBatchSize: number, - contentContainerStyles?: Record, - dataFetchQuery: (lastEntry: T | null, pageNumber: number, pageSize: number) => Promise>, - errorContainerStyles?: Record, - formatContent: (queryResponseData : T) => JSX.Element, - keyExtractorFunction: (item: T) => string, - loadingContainerStyles?: Record, - noDataFoundContainerStyles?: Record, - numColumns: number, -} +// Typings imports +import { InfiniteScrollState, IInfiniteScroll } from '../../types/components/InfiniteScroll'; // Styled components. const { diff --git a/src/contexts/user/context.ts b/src/contexts/user/context.ts index 033705b..18dac64 100644 --- a/src/contexts/user/context.ts +++ b/src/contexts/user/context.ts @@ -1,9 +1,5 @@ import React, { useContext } from 'react'; -import { FirebaseAuthTypes } from '@react-native-firebase/auth'; - -interface IContext { - currentUser: FirebaseAuthTypes.User | null -} +import { IContext } from '../../types/contexts/user'; const Context = React.createContext({ currentUser: null, diff --git a/src/contexts/user/contextService.tsx b/src/contexts/user/contextService.tsx index 8511b75..ed91698 100644 --- a/src/contexts/user/contextService.tsx +++ b/src/contexts/user/contextService.tsx @@ -1,11 +1,8 @@ import React from 'react'; -import auth, { FirebaseAuthTypes } from '@react-native-firebase/auth'; +import auth from '@react-native-firebase/auth'; import Context from './context'; - -interface IGlobalServiceState { - currentUser: FirebaseAuthTypes.User | null -} +import { IGlobalServiceState } from '../../types/contexts/user'; export default class GlobalState extends React.Component, IGlobalServiceState> { constructor(props: Record) { diff --git a/src/layouts/HeaderLayout/index.tsx b/src/layouts/HeaderLayout/index.tsx index 0db70e2..e78b7af 100644 --- a/src/layouts/HeaderLayout/index.tsx +++ b/src/layouts/HeaderLayout/index.tsx @@ -11,35 +11,8 @@ import DrawerContent from '../../components/DrawerContent'; import { Theme } from '../../constants'; -import { styledComponents, IHeaderProps, ITitleProps } from './styles'; - -type HeaderActions = 'back' | 'drawer' | 'share' | 'search' | 'options'; - -interface IButtonAction { - hidden?: boolean, - actionType?: HeaderActions, - iconColor?: string, - onPress?: () => void, -} - -interface IRoutesDrawer { - path: string, - displayName: string, - icon: JSX.Element -} - -interface IHeaderLayoutProps { - disableScrollView?: boolean, - headerShown: boolean, - headerStyles?: IHeaderProps, - title: string, - titleStyles?: ITitleProps, - leftAction: IButtonAction, - rightAction: IButtonAction, - children: React.ReactNode, - drawerRoutes?: Array, - drawerUser?: boolean -} +import { IHeaderLayoutProps, IButtonAction } from '../../types/layouts/HeaderLayout'; +import { styledComponents } from './styles'; export default function HeaderLayout({ disableScrollView, diff --git a/src/layouts/HeaderLayout/styles.ts b/src/layouts/HeaderLayout/styles.ts index dd9813e..078bec0 100644 --- a/src/layouts/HeaderLayout/styles.ts +++ b/src/layouts/HeaderLayout/styles.ts @@ -1,18 +1,8 @@ -import { TouchableOpacityProps, TextProps, ViewProps } from 'react-native'; +import { TouchableOpacityProps, ViewProps } from 'react-native'; import styled from 'styled-components/native'; import Constants from 'expo-constants'; -export interface ITitleProps extends TextProps { - fontFamily?: string, - fontSize?: string, - color?: string, -} - -export interface IHeaderProps extends ViewProps { - maxHeight?: string, - height?: string, - backgroundColor?: string, -} +import { ITitleProps, IHeaderProps } from '../../types/layouts/HeaderLayout'; export const styledComponents = { LayoutContainer: styled.View` diff --git a/src/mocks/MockedNavigation/index.tsx b/src/mocks/MockedNavigation/index.tsx index b0de023..dff6600 100644 --- a/src/mocks/MockedNavigation/index.tsx +++ b/src/mocks/MockedNavigation/index.tsx @@ -3,15 +3,11 @@ import React from 'react'; import { NavigationContainer } from '@react-navigation/native'; import { createStackNavigator } from '@react-navigation/stack'; +import { StackScreen } from '../../types/mocks/MockedNavigation'; + // Navigation configuration. const Stack = createStackNavigator(); -// Interfaces. -interface StackScreen { - component: React.FC, - params?: Record -} - // Component. export default function MockedNavigator( { component, params = {} } : StackScreen, diff --git a/src/pages/Animal/Details/index.tsx b/src/pages/Animal/Details/index.tsx index 39e718a..40a8f12 100644 --- a/src/pages/Animal/Details/index.tsx +++ b/src/pages/Animal/Details/index.tsx @@ -33,7 +33,7 @@ import { styles, styledComponents } from './styles'; // Type imports. import * as AnimalTypes from '../../../types/animal'; -import * as CarouselTypes from '../../../types/carousel'; +import * as CarouselTypes from '../../../types/globals/Carousel'; import * as RouteTypes from '../../../types/routes'; // Utils imports. diff --git a/src/pages/Animal/Interested/index.tsx b/src/pages/Animal/Interested/index.tsx index 5e08516..570db9e 100644 --- a/src/pages/Animal/Interested/index.tsx +++ b/src/pages/Animal/Interested/index.tsx @@ -5,37 +5,31 @@ import { useNavigation, useRoute, } from '@react-navigation/native'; + import { setStatusBarBackgroundColor } from 'expo-status-bar'; import { ActivityIndicator, Text, Image, TouchableOpacity, Alert, } from 'react-native'; + import { fromUnixTime, differenceInYears } from 'date-fns'; import InfiniteScroll from '../../../components/InfiniteScroll'; -import { Theme } from '../../../constants'; import HeaderLayout from '../../../layouts/HeaderLayout'; -import { - Container, LoadingContainer, LoadingText, -} from './styles'; -import { DocumentData, DocumentRefData } from '../../../types/firebase'; -import * as RouteTypes from '../../../types/routes'; + +import { Theme } from '../../../constants'; // Service imports. import userAPI from '../../../services/user/api'; import animalAPI from '../../../services/animal/api'; import adoptionAPI from '../../../services/adoption/api'; -interface InterestedUser { - id: string; - ref: DocumentRefData; - imageURI: string; - userName: string; - birthDate: number; -} - -interface UserCircleProps { - user: InterestedUser; - callback: (user: InterestedUser) => void; -} +// Type imports +import * as RouteTypes from '../../../types/routes'; +import { DocumentData, DocumentRefData } from '../../../types/services/Firebase'; +import { UserCircleProps, InterestedUser } from '../../../types/pages/Animal'; + +import { + Container, LoadingContainer, LoadingText, +} from './styles'; const getAge = (birthDateTimestamp: number): number => differenceInYears(new Date(), fromUnixTime(birthDateTimestamp)); diff --git a/src/pages/Animal/Registration/index.tsx b/src/pages/Animal/Registration/index.tsx index 0aed8a5..cc43536 100644 --- a/src/pages/Animal/Registration/index.tsx +++ b/src/pages/Animal/Registration/index.tsx @@ -39,19 +39,10 @@ import FileOperations from '../../../utils/FileOperations'; // Type imports. import * as AnimalTypes from '../../../types/animal'; +import { IUploadedPicture } from '../../../types/pages/Animal'; +import { IDialogState } from '../../../types/globals/Dialog'; // Interface declarations. -interface IUploadedPicture { - id: string, - remoteName: string, - localUri: string, -} - -interface IDialogState { - open: boolean, - title: string, - message: string, -} // Component export. export default function AnimalRegistration() : JSX.Element { diff --git a/src/pages/Chat/Chat/index.tsx b/src/pages/Chat/Chat/index.tsx index 76a004c..eed380a 100644 --- a/src/pages/Chat/Chat/index.tsx +++ b/src/pages/Chat/Chat/index.tsx @@ -16,7 +16,7 @@ import { Button, Modal, Portal } from 'react-native-paper'; import HeaderLayout from '../../../layouts/HeaderLayout'; import { Theme } from '../../../constants'; import * as RouteTypes from '../../../types/routes'; -import { DocumentRefData, QuerySnapshotDocuments } from '../../../types/firebase'; +import { DocumentRefData, QuerySnapshotDocuments } from '../../../types/services/Firebase'; import chatAPI from '../../../services/chat/api'; import userAPI from '../../../services/user/api'; diff --git a/src/pages/Chat/ChatList/index.tsx b/src/pages/Chat/ChatList/index.tsx index 1cbb106..b9d1430 100644 --- a/src/pages/Chat/ChatList/index.tsx +++ b/src/pages/Chat/ChatList/index.tsx @@ -27,7 +27,7 @@ import { styles, styledComponents } from './styles'; // Type imports. import { ChatListEntry } from '../../../types/chat'; -import * as FirebaseTypes from '../../../types/firebase'; +import * as FirebaseTypes from '../../../types/services/Firebase'; // Page exported. export default function ChatList() : JSX.Element { diff --git a/src/pages/Login/index.tsx b/src/pages/Login/index.tsx index ffa7a99..0c2b222 100644 --- a/src/pages/Login/index.tsx +++ b/src/pages/Login/index.tsx @@ -33,15 +33,8 @@ import HeaderLayout from '../../layouts/HeaderLayout'; import CustomTextInput from '../../components/CustomTextInput'; import { Theme, Values } from '../../constants'; -interface LoginForm { - email: string, - password: string, -} -interface IDialogState { - open: boolean, - title: string, - message: string, -} +import { ILoginForm } from '../../types/pages/Login'; +import { IDialogState } from '../../types/globals/Dialog'; // Component export. export default function Login() : JSX.Element { @@ -60,7 +53,7 @@ export default function Login() : JSX.Element { }, []), ); - const signIn = async ({ email, password }: LoginForm): Promise => { + const signIn = async ({ email, password }: ILoginForm): Promise => { try { const response = await userAPI.signIn(email, password); if (response && response.user) { diff --git a/src/pages/NotificationsList/index.tsx b/src/pages/NotificationsList/index.tsx index 8c6c5bd..cd3e5dc 100644 --- a/src/pages/NotificationsList/index.tsx +++ b/src/pages/NotificationsList/index.tsx @@ -12,10 +12,11 @@ import { Container } from './styles'; // Component imports. // Service imports. -import notificationAPI, { NotificationType, NotificationModels } from '../../services/notifications/api'; +import notificationAPI from '../../services/notifications/api'; // Style imports. // Type declaration. +import { NotificationType, NotificationModels } from '../../types/services/Notifications'; // Component. export default function NotificationsList() : JSX.Element { @@ -44,28 +45,32 @@ export default function NotificationsList() : JSX.Element { ); const notificationRenderer = (notification: (NotificationModels)): JSX.Element => { + // eslint-disable-next-line camelcase + const fromName = notification.from.data()?.full_name || 'Usuário deletado'; switch (notification.type) { case NotificationType.adoptionInterest: { + const animalName = notification.animal.data()?.name || 'Animal deletado'; return ( { navigation.navigate('AnimalDetails', { animalUID: notification.animal.id }); }} > - {notification.from.data().full_name} está interessado no seu pet {notification.animal.data().name} + {fromName} está interessado no seu pet {animalName} ); } case NotificationType.adoptionRefused: { + const animalName = notification.animal.data()?.name || 'Animal deletado'; return ( { navigation.navigate('AnimalDetails', { animalUID: notification.animal.id }); }} > - {notification.from.data().full_name} recusou sua solicitação ao pet {notification.animal.data().name} + {fromName} recusou sua solicitação ao pet {animalName} ); } diff --git a/src/pages/Registration/index.tsx b/src/pages/Registration/index.tsx index 653fd9b..90b13f4 100644 --- a/src/pages/Registration/index.tsx +++ b/src/pages/Registration/index.tsx @@ -29,32 +29,13 @@ import { Theme, Values } from '../../constants'; import HeaderLayout from '../../layouts/HeaderLayout'; import FileOperations from '../../utils/FileOperations'; +// Type imports +import { IDialogState } from '../../types/globals/Dialog'; +import { picturePath, ISignUpForm } from '../../types/pages/Registration'; + // Theme imports. import { styles, styledComponents } from './styles'; -// Type declarations. -type picturePath = string | null; - -// Interface declarations. -interface IDialogState { - open: boolean, - title: string, - message: string, -} - -interface ISignUpForm { - fullName: string, - birthDate: Date | null, - email: string, - state: string, - city: string, - address: string, - phoneNumber: string, - username: string, - password: string, - passwordConfirmation: string, -} - // Component. export default function Registration() : JSX.Element { // Variable declaration. diff --git a/src/routes.tsx b/src/routes.tsx index ad03567..d6b7db2 100644 --- a/src/routes.tsx +++ b/src/routes.tsx @@ -19,17 +19,7 @@ import NotificationsList from './pages/NotificationsList'; import Interested from './pages/Animal/Interested'; import Chat from './pages/Chat/Chat'; -interface IRouteRule { - name: string, - component: () => JSX.Element, - privateComponent?: () => JSX.Element, - requireSession?: boolean, -} - -interface IRoute { - name: string, - component: () => JSX.Element, -} +import { IRouteRule, IRoute } from './types/routes'; // Routes. export default class Routes extends React.Component { diff --git a/src/services/adoption/api.ts b/src/services/adoption/api.ts index 8097ee5..d003e18 100644 --- a/src/services/adoption/api.ts +++ b/src/services/adoption/api.ts @@ -1,8 +1,13 @@ import firestore from '@react-native-firebase/firestore'; + import animalAPI from '../animal/api'; -import notificationAPI, { NotificationType } from '../notifications/api'; -import { DocumentData, DocumentRefData, DocumentSnapshot } from '../../types/firebase'; -import { PaginatedMetaData, filterPaginated } from '../paginated/api'; +import notificationAPI from '../notifications/api'; + +import { NotificationType } from '../../types/services/Notifications'; +import { DocumentData, DocumentRefData, DocumentSnapshot } from '../../types/services/Firebase'; +import { filterPaginated } from '../paginated/api'; + +import { PaginatedMetaData } from '../../types/services/Paginated'; const addInterestToAnimal = async (animal: DocumentRefData, user: DocumentRefData): Promise => { const animalData = (await animal.get()).data(); diff --git a/src/services/animal/api.ts b/src/services/animal/api.ts index 312574b..3a25527 100644 --- a/src/services/animal/api.ts +++ b/src/services/animal/api.ts @@ -5,17 +5,11 @@ import storage from '@react-native-firebase/storage'; // Type imports. import { FirebaseFirestoreTypes } from '@react-native-firebase/firestore'; import { FirebaseStorageTypes } from '@react-native-firebase/storage'; +import { QueryParams } from '../../types/services/Firebase'; // User module imports. import { Values } from '../../constants'; -// Type declarations. -type QueryParams = { - orderBy? : string | undefined, - startAfter? : FirebaseFirestoreTypes.DocumentFieldType | undefined, - limit? : number | undefined -} - // Service implementation. const api = { diff --git a/src/services/chat/api.ts b/src/services/chat/api.ts index 8b8e8ca..fb43b58 100644 --- a/src/services/chat/api.ts +++ b/src/services/chat/api.ts @@ -1,7 +1,7 @@ import firestore from '@react-native-firebase/firestore'; import { DocumentData, DocumentRefData, Query, QuerySnapshot, -} from '../../types/firebase'; +} from '../../types/services/Firebase'; const chatDocument = (chatUID: string): DocumentRefData => firestore().collection('chats').doc(chatUID); diff --git a/src/services/notifications/api.ts b/src/services/notifications/api.ts index 10f56aa..cf8bc5b 100644 --- a/src/services/notifications/api.ts +++ b/src/services/notifications/api.ts @@ -1,42 +1,13 @@ import firestore from '@react-native-firebase/firestore'; -import { DocumentData, DocumentRefData } from '../../types/firebase'; +import { DocumentData, DocumentRefData } from '../../types/services/Firebase'; +import { + NotificationType, + INotificationAdoptionInterestData, + NotificationModels, +} from '../../types/services/Notifications'; import userAPI from '../user/api'; -export enum NotificationType { - standard = 'STD', - adoptionInterest = 'AIN', - adoptionRefused = 'ARE', -} - -export interface INotificationAdoptionInterestData { - animal: DocumentRefData, -} - -export interface NotificationModel { - id: string, - from: DocumentData, - to: DocumentRefData, - message: string, - seen: false, -} - -export interface NotificationStandardModel extends NotificationModel { - type: NotificationType.standard, -} - -export interface NotificationAdoptionModel extends NotificationModel { - type: NotificationType.adoptionInterest, - animal: DocumentData, -} - -export interface NotificationAdoptionRefusedModel extends NotificationModel { - type: NotificationType.adoptionRefused, - animal: DocumentData, -} - -export type NotificationModels = NotificationStandardModel | NotificationAdoptionModel | NotificationAdoptionRefusedModel; - const sendToUser = ( user: DocumentRefData, message: string, diff --git a/src/services/paginated/api.ts b/src/services/paginated/api.ts index ad81359..988432c 100644 --- a/src/services/paginated/api.ts +++ b/src/services/paginated/api.ts @@ -1,12 +1,6 @@ -import { Query, CollectionRef } from '../../types/firebase'; +import { Query, CollectionRef } from '../../types/services/Firebase'; -export interface PaginatedMetaData { - pageNumber: number; - pageSize: number; - lastElementMarker: unknown[]; - marker: string; - orderByDirection?: 'asc' | 'desc'; -} +import { PaginatedMetaData } from '../../types/services/Paginated'; export const filterPaginated = (source: Query | CollectionRef, paginatedMetaData?: PaginatedMetaData): Query => { if (!paginatedMetaData) return source; diff --git a/src/services/user/api.ts b/src/services/user/api.ts index 5a4f350..9438caa 100644 --- a/src/services/user/api.ts +++ b/src/services/user/api.ts @@ -7,17 +7,11 @@ import storage from '@react-native-firebase/storage'; import { FirebaseAuthTypes } from '@react-native-firebase/auth'; import { FirebaseFirestoreTypes } from '@react-native-firebase/firestore'; import { FirebaseStorageTypes } from '@react-native-firebase/storage'; +import { QueryParams } from '../../types/services/Firebase'; // User module imports. import { Values } from '../../constants'; -// Type declarations. -type QueryParams = { - orderBy? : string | undefined, - startAfter? : FirebaseFirestoreTypes.DocumentFieldType | undefined, - limit? : number | undefined -} - // Service implementation. const api = { createAuth( diff --git a/src/types/chat.ts b/src/types/chat.ts index d60922c..c5b91a8 100644 --- a/src/types/chat.ts +++ b/src/types/chat.ts @@ -2,7 +2,7 @@ import { ImageSourcePropType } from 'react-native'; // User type imports. -import * as FirebaseTypes from './firebase'; +import * as FirebaseTypes from './services/Firebase'; // Type declarations. export type ChatListEntry = { diff --git a/src/types/components/AnimalCard/index.ts b/src/types/components/AnimalCard/index.ts new file mode 100644 index 0000000..ca7d16e --- /dev/null +++ b/src/types/components/AnimalCard/index.ts @@ -0,0 +1,15 @@ +import { ReactNode } from 'react'; +import { ViewProps } from 'react-native'; + +export interface IAnimalCardProps { + title: string; + imageUrl: string | null; + headerOptions?: ReactNode; + body?: ReactNode; + headerBackground: string; + onPress?: () => void; +} + +export interface CardHeaderProps extends ViewProps { + backgroundColor: string; +} diff --git a/src/types/components/AsyncButton/index.ts b/src/types/components/AsyncButton/index.ts new file mode 100644 index 0000000..e423411 --- /dev/null +++ b/src/types/components/AsyncButton/index.ts @@ -0,0 +1,26 @@ +import React from 'react'; +import { TouchableOpacityProps } from 'react-native'; + +export interface ButtonType extends TouchableOpacityProps { + flex?: number, + flexDirection?: string, + width?: string, + height?: string, + backgroundColor?: string, + marginTop?: string, + marginBottom?: string, + marginLeft?: string, + marginRight?: string, + borderRadius?: string, + alignSelf?: string, + alignItems?: string, + justifyContent?: string, +} + +export interface IButtonProps extends ButtonType { + children: React.ReactNode, + asyncAction: boolean, + callback: (arg: GestureResponderEvent) => void, + activityIndicator?: Record, + styles?: Record, +} diff --git a/src/types/components/CustomTextInput/index.ts b/src/types/components/CustomTextInput/index.ts new file mode 100644 index 0000000..c46bb11 --- /dev/null +++ b/src/types/components/CustomTextInput/index.ts @@ -0,0 +1,7 @@ +import { FormikProps } from 'formik'; + +export interface ICustomTextInput { + formikHelpers: FormikProps, + fieldName: keyof T, + [propName: string]: unknown; +} diff --git a/src/types/components/DrawerContent/index.ts b/src/types/components/DrawerContent/index.ts new file mode 100644 index 0000000..a318c7e --- /dev/null +++ b/src/types/components/DrawerContent/index.ts @@ -0,0 +1,4 @@ +export interface IDrawerProps { + parentDrawerOpen: boolean, + setParentDrawerOpen: (_: boolean) => void, +} diff --git a/src/types/components/InfiniteScroll/index.ts b/src/types/components/InfiniteScroll/index.ts new file mode 100644 index 0000000..5443457 --- /dev/null +++ b/src/types/components/InfiniteScroll/index.ts @@ -0,0 +1,22 @@ +// Type declaration. +export type InfiniteScrollState = { + allDataFetched: boolean, + data: Array, + error: string | null, + loadingMore: boolean, + page: number, +} + +// Interface declaration. +export interface IInfiniteScroll { + activityIndicatorColor?: string, + contentBatchSize: number, + contentContainerStyles?: Record, + dataFetchQuery: (lastEntry: T | null, pageNumber: number, pageSize: number) => Promise>, + errorContainerStyles?: Record, + formatContent: (queryResponseData : T) => JSX.Element, + keyExtractorFunction: (item: T) => string, + loadingContainerStyles?: Record, + noDataFoundContainerStyles?: Record, + numColumns: number, +} diff --git a/src/types/contexts/user/index.ts b/src/types/contexts/user/index.ts new file mode 100644 index 0000000..2eba55e --- /dev/null +++ b/src/types/contexts/user/index.ts @@ -0,0 +1,9 @@ +import { FirebaseAuthTypes } from '@react-native-firebase/auth'; + +export interface IContext { + currentUser: FirebaseAuthTypes.User | null +} + +export interface IGlobalServiceState { + currentUser: FirebaseAuthTypes.User | null +} diff --git a/src/types/carousel.ts b/src/types/globals/Carousel/index.ts similarity index 100% rename from src/types/carousel.ts rename to src/types/globals/Carousel/index.ts diff --git a/src/types/globals/Dialog/index.ts b/src/types/globals/Dialog/index.ts new file mode 100644 index 0000000..5f95f88 --- /dev/null +++ b/src/types/globals/Dialog/index.ts @@ -0,0 +1,5 @@ +export interface IDialogState { + open: boolean, + title: string, + message: string, +} diff --git a/src/types/layouts/HeaderLayout/index.ts b/src/types/layouts/HeaderLayout/index.ts new file mode 100644 index 0000000..c7d989a --- /dev/null +++ b/src/types/layouts/HeaderLayout/index.ts @@ -0,0 +1,41 @@ +import { TextProps, ViewProps } from 'react-native'; + +export interface ITitleProps extends TextProps { + fontFamily?: string, + fontSize?: string, + color?: string, +} + +export interface IHeaderProps extends ViewProps { + maxHeight?: string, + height?: string, + backgroundColor?: string, +} + +export type HeaderActions = 'back' | 'drawer' | 'share' | 'search' | 'options'; + +export interface IButtonAction { + hidden?: boolean, + actionType?: HeaderActions, + iconColor?: string, + onPress?: () => void, +} + +export interface IRoutesDrawer { + path: string, + displayName: string, + icon: JSX.Element +} + +export interface IHeaderLayoutProps { + disableScrollView?: boolean, + headerShown: boolean, + headerStyles?: IHeaderProps, + title: string, + titleStyles?: ITitleProps, + leftAction: IButtonAction, + rightAction: IButtonAction, + children: React.ReactNode, + drawerRoutes?: Array, + drawerUser?: boolean +} diff --git a/src/types/mocks/MockedNavigation/index.ts b/src/types/mocks/MockedNavigation/index.ts new file mode 100644 index 0000000..9e59ed3 --- /dev/null +++ b/src/types/mocks/MockedNavigation/index.ts @@ -0,0 +1,7 @@ +import React from 'react'; + +// Interfaces. +export interface StackScreen { + component: React.FC, + params?: Record +} diff --git a/src/types/pages/Animal/index.ts b/src/types/pages/Animal/index.ts new file mode 100644 index 0000000..8557517 --- /dev/null +++ b/src/types/pages/Animal/index.ts @@ -0,0 +1,21 @@ +import { DocumentRefData } from '../../services/Firebase'; + +export interface InterestedUser { + id: string; + ref: DocumentRefData; + imageURI: string; + userName: string; + birthDate: number; +} + +export interface UserCircleProps { + user: InterestedUser; + callback: (user: InterestedUser) => void; +} + +// Interface declarations. +export interface IUploadedPicture { + id: string, + remoteName: string, + localUri: string, +} diff --git a/src/types/pages/Login/index.ts b/src/types/pages/Login/index.ts new file mode 100644 index 0000000..09c3266 --- /dev/null +++ b/src/types/pages/Login/index.ts @@ -0,0 +1,4 @@ +export interface ILoginForm { + email: string, + password: string, +} diff --git a/src/types/pages/Registration/index.ts b/src/types/pages/Registration/index.ts new file mode 100644 index 0000000..6e7a838 --- /dev/null +++ b/src/types/pages/Registration/index.ts @@ -0,0 +1,14 @@ +export type picturePath = string | null; + +export interface ISignUpForm { + fullName: string, + birthDate: Date | null, + email: string, + state: string, + city: string, + address: string, + phoneNumber: string, + username: string, + password: string, + passwordConfirmation: string, +} diff --git a/src/types/routes.ts b/src/types/routes.ts index 913844f..6ff9c65 100644 --- a/src/types/routes.ts +++ b/src/types/routes.ts @@ -12,3 +12,15 @@ export type RouteParams = { chatUID: string, } }; + +export interface IRouteRule { + name: string, + component: () => JSX.Element, + privateComponent?: () => JSX.Element, + requireSession?: boolean, +} + +export interface IRoute { + name: string, + component: () => JSX.Element, +} diff --git a/src/types/firebase.ts b/src/types/services/Firebase/index.ts similarity index 80% rename from src/types/firebase.ts rename to src/types/services/Firebase/index.ts index acbd428..0675d25 100644 --- a/src/types/firebase.ts +++ b/src/types/services/Firebase/index.ts @@ -8,3 +8,9 @@ export type Query = FirebaseFirestoreTypes.Query; export type QuerySnapshot = FirebaseFirestoreTypes.QuerySnapshot; export type QuerySnapshotDocuments = FirebaseFirestoreTypes.QueryDocumentSnapshot[]; export type Timestamp = FirebaseFirestoreTypes.Timestamp; + +export type QueryParams = { + orderBy? : string | undefined, + startAfter? : FirebaseFirestoreTypes.DocumentFieldType | undefined, + limit? : number | undefined +} diff --git a/src/types/services/Notifications/index.ts b/src/types/services/Notifications/index.ts new file mode 100644 index 0000000..7b53c25 --- /dev/null +++ b/src/types/services/Notifications/index.ts @@ -0,0 +1,35 @@ +import { DocumentData, DocumentRefData } from '../Firebase'; + +export enum NotificationType { + standard = 'STD', + adoptionInterest = 'AIN', + adoptionRefused = 'ARE', +} + +export interface INotificationAdoptionInterestData { + animal: DocumentRefData, +} + +export interface NotificationModel { + id: string, + from: DocumentData, + to: DocumentRefData, + message: string, + seen: false, +} + +export interface NotificationStandardModel extends NotificationModel { + type: NotificationType.standard, +} + +export interface NotificationAdoptionModel extends NotificationModel { + type: NotificationType.adoptionInterest, + animal: DocumentData, +} + +export interface NotificationAdoptionRefusedModel extends NotificationModel { + type: NotificationType.adoptionRefused, + animal: DocumentData, +} + +export type NotificationModels = NotificationStandardModel | NotificationAdoptionModel | NotificationAdoptionRefusedModel; diff --git a/src/types/services/Paginated/index.ts b/src/types/services/Paginated/index.ts new file mode 100644 index 0000000..663e7c7 --- /dev/null +++ b/src/types/services/Paginated/index.ts @@ -0,0 +1,7 @@ +export interface PaginatedMetaData { + pageNumber: number; + pageSize: number; + lastElementMarker: unknown[]; + marker: string; + orderByDirection?: 'asc' | 'desc'; +}