Skip to content

Commit

Permalink
[#20] Ajustado titulos (#120)
Browse files Browse the repository at this point in the history
  • Loading branch information
salomaoluiz authored Apr 5, 2021
1 parent c0303d2 commit dfb0d15
Show file tree
Hide file tree
Showing 19 changed files with 183 additions and 23 deletions.
Binary file modified .github/screenshots/4.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .github/screenshots/8.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion README.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ Read this in other languages: [English](README.en.md), [Português](README.md)

<div style="display:flex;" >
<img src=".github/screenshots/6.jpg" width="19%" >
<img src=".github/screenshots/7.jpg" width="19%" >
<img src=".github/screenshots/7.jpg" style="margin-left:10px;" width="19%" >
<img src=".github/screenshots/8.jpg" style="margin-left:10px;" width="19%" >
</div>

## Firebase
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ Read this in other languages: [English](README.en.md), [Português](README.md)

<div style="display:flex;" >
<img src=".github/screenshots/6.jpg" width="19%" >
<img src=".github/screenshots/7.jpg" width="19%" >
<img src=".github/screenshots/7.jpg" style="margin-left:10px;" width="19%" >
<img src=".github/screenshots/8.jpg" style="margin-left:10px;" width="19%" >
</div>

## Firebase
Expand Down
6 changes: 6 additions & 0 deletions src/__tests__/navigation-mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,9 @@ export const useNavigationMocks = {
setParams: jest.fn(),
openDrawer: jest.fn(),
};

export const useRouteMock = {
params: {},
key: '',
name: ''
};
1 change: 1 addition & 0 deletions src/locales/enUS/general.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const general = {
yes: `Yes`,
no: `No`,
currency: '$',
logout: 'Logout',
};

export default general;
1 change: 1 addition & 0 deletions src/locales/enUS/product-items.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const productItems = {
items: `Items`,
newItem: `New item`,
editItem: 'Edit item',
total: `Total`,
amount: `Amount`,
qtd: `Quantity`,
Expand Down
2 changes: 2 additions & 0 deletions src/locales/enUS/product-lists.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
const productLists = {
lists: `Lists`,
productLists: "Product lists",
newList: `New list`,
editList: 'Edit List',
buyDate: 'Purchase date'
};

Expand Down
1 change: 1 addition & 0 deletions src/locales/ptBR/general.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const general = {
yes: 'Sim',
no: 'Não',
currency: 'R$',
logout: 'Desconectar',
};

export default general;
1 change: 1 addition & 0 deletions src/locales/ptBR/product-items.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const productItems = {
items: 'Itens',
newItem: 'Novo item',
editItem: 'Editar item',
total: 'Total',
amount: `Valor`,
qtd: `Quantidade`,
Expand Down
2 changes: 2 additions & 0 deletions src/locales/ptBR/product-lists.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
const productLists = {
lists: 'Listas',
productLists: "Listas de produtos",
newList: 'Nova lista',
editList: 'Editar lista',
buyDate: 'Data de compra'
};

Expand Down
4 changes: 4 additions & 0 deletions src/navigator/authenticated.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { createDrawerNavigator } from '@react-navigation/drawer';
import React from 'react';

import { translate } from '@locales';
import { Routes } from '@routes';

import Drawer from './components/drawer';
Expand All @@ -23,14 +24,17 @@ const AuthenticatedNavigator = () => {
<AuthenticatedStack.Screen
name={Routes.ProductNavigator}
component={ProductNavigator}
options={{ title: translate('productLists.productLists') }}
/>
<AuthenticatedStack.Screen
name={Routes.StockNavigator}
component={StockNavigator}
options={{ title: translate('stock.stock') }}
/>
<AuthenticatedStack.Screen
name={Routes.SettingsNavigator}
component={SettingsNavigator}
options={{ title: translate('settings.settings') }}
/>
<AuthenticatedStack.Screen
name={Routes.UnauthenticatedNavigator}
Expand Down
3 changes: 2 additions & 1 deletion src/navigator/components/drawer-bottom/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ import * as React from 'react';
import { View } from 'react-native';

import Button from '@components/button';
import { translate } from '@locales';

import useDrawerBottom from './useDrawerBottom';

const DrawerBottom = () => {
const { onLogoutPress } = useDrawerBottom();
return (
<View>
<Button title="Logout" onPress={onLogoutPress} mode="text" />
<Button title={translate('general.logout')} onPress={onLogoutPress} mode="text" />
</View>
);
};
Expand Down
35 changes: 35 additions & 0 deletions src/routes/new-item/__tests__/useScreenSettings.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@

import * as reactNavigation from '@react-navigation/native';
import { renderHook } from '@testing-library/react-hooks';

import { translate } from '@locales';
import { useRouteMock } from 'src/__tests__/navigation-mocks';

import useScreenSettings from '../useScreenSettings';

jest.mock('@react-navigation/native');

describe('useScreenSettings', () => {
const routeSpy = jest.spyOn(reactNavigation, 'useRoute');

// should return the screen name as New Item and the addition icon
test('deve retornar o nome da tela como novo item e o icone de adição', () => {
routeSpy.mockReturnValue({ ...useRouteMock, params: {} });

const { result } = renderHook(useScreenSettings);

expect(result.current.screenTitle).toEqual(translate('productItems.newItem'));
expect(result.current.fabIcon).toEqual('plus');
});

// if the screen receive a productItem on params, should return the screen name as Edit Item and a check icon
test('caso a tela receba um productItem como paramêtro, deve retornar o nome da tela como editar item e o icone de check', () => {
routeSpy.mockReturnValue({ ...useRouteMock, params: { productItem: { id: '1234' } } });

const { result } = renderHook(useScreenSettings);

expect(result.current.screenTitle).toEqual(translate('productItems.editItem'));
expect(result.current.fabIcon).toEqual('check');
});

});
8 changes: 6 additions & 2 deletions src/routes/new-item/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
import useForm from './useForm';
import useItemStore from './useItemStore';
import useNewItem from './useNewItem';
import useScreenSettings from './useScreenSettings';

const NewItem = () => {
const { formParams, setParams, handleErrorMessage, checkForm } = useForm();
Expand All @@ -44,6 +45,7 @@ const NewItem = () => {
handleAutoCompleteItemPress,
handleBarCodeDetected,
} = useItemStore({ formParams, setParams });

const {
onSaveButtonPress,
handleModalVisible,
Expand All @@ -57,9 +59,11 @@ const NewItem = () => {
checkForm,
});

const { screenTitle, fabIcon } = useScreenSettings();

return (
<>
<Header title={translate('productItems.newItem')} backButton />
<Header title={screenTitle} backButton />
<Container keyboardShouldPersistTaps="handled">
<SubContainer>
<TextInput
Expand Down Expand Up @@ -129,7 +133,7 @@ const NewItem = () => {
/>
</Container>
<ButtonContainer>
<CircleButton icon="check" onPress={onSaveButtonPress} />
<CircleButton icon={fabIcon} onPress={onSaveButtonPress} />
</ButtonContainer>

<Portal>
Expand Down
32 changes: 32 additions & 0 deletions src/routes/new-item/useScreenSettings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { RouteProp, useRoute } from '@react-navigation/native';
import { useEffect, useState } from 'react';

import { translate } from '@locales';
import { ProductNavigatorParamsList } from '@navigator/product-navigator';

type Route = RouteProp<ProductNavigatorParamsList, 'NewListItem'>;

const useScreenSettings = () => {
const [screenTitle, setScreenTitle] = useState(
translate('productItems.newItem'),
);

const [fabIcon, setFabIcon] = useState('plus');

const route = useRoute<Route>();
const hasParams = !!route.params.productItem;

useEffect(() => {
if (hasParams) {
setScreenTitle(translate('productItems.editItem'));
setFabIcon('check');
}
}, [hasParams]);

return {
screenTitle,
fabIcon,
};
};

export default useScreenSettings;
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@

import * as reactNavigation from '@react-navigation/native';
import { renderHook } from '@testing-library/react-hooks';

import { translate } from '@locales';
import { useRouteMock } from 'src/__tests__/navigation-mocks';

import useScreenSettings from '../useScreenSettings';

jest.mock('@react-navigation/native');

describe('useScreenSettings', () => {
const routeSpy = jest.spyOn(reactNavigation, 'useRoute');

// should return the screen name as New List and the addition icon
test('deve retornar o nome da tela como nova lista e o icone de adição', () => {
routeSpy.mockReturnValue({ ...useRouteMock, params: {} });

const { result } = renderHook(useScreenSettings);

expect(result.current.screenTitle).toEqual(translate('productLists.newList'));
expect(result.current.fabIcon).toEqual('plus');
});

// if the screen receive a productList on params, should return the screen name as Edit List and the check icon
test('caso a tela receba um productList como paramêtro, deve retornar o nome da tela como editar lista e o icone de check', () => {
routeSpy.mockReturnValue({ ...useRouteMock, params: { productList: { id: '1234' } } });

const { result } = renderHook(useScreenSettings);

expect(result.current.screenTitle).toEqual(translate('productLists.editList'));
expect(result.current.fabIcon).toEqual('check');
});

});
37 changes: 19 additions & 18 deletions src/routes/product-list/new-list/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { formatDate } from '@utils/date';
import { Container, SubContainer, ButtonContainer } from './styles';
import useForm from './useForm';
import useNewList from './useNewList';
import useScreenSettings from './useScreenSettings';

const NewList = () => {
const {
Expand All @@ -27,9 +28,11 @@ const NewList = () => {
handleDatePickerVisible,
} = useNewList({ listParams, checkForm });

const { fabIcon, screenTitle } = useScreenSettings();

return (
<>
<Header title={translate('productLists.newList')} backButton />
<Header title={screenTitle} backButton />
<Container>
<SubContainer keyboardShouldPersistTaps="handled">
<TextInput
Expand All @@ -38,25 +41,23 @@ const NewList = () => {
onChangeText={setName}
{...handleErrorMessage('name')}
/>
<TouchableRipple
withoutBackground
onPress={handleDatePickerVisible}>
<TextInput
editable={false}
fixedValue={buyDate ? formatDate(buyDate) : undefined}
label={translate('productLists.buyDate')}
/>
</TouchableRipple>
<TouchableRipple withoutBackground onPress={handleDatePickerVisible}>
<TextInput
editable={false}
fixedValue={buyDate ? formatDate(buyDate) : undefined}
label={translate('productLists.buyDate')}
/>
</TouchableRipple>
</SubContainer>
<DateTimePicker
getDateTime={setBuyDate}
mode="date"
isVisible={datePickerVisible}
handleModalVisible={handleDatePickerVisible}
value={buyDate}
/>
<DateTimePicker
getDateTime={setBuyDate}
mode="date"
isVisible={datePickerVisible}
handleModalVisible={handleDatePickerVisible}
value={buyDate}
/>
<ButtonContainer behavior="height">
<CircleButton icon="check" onPress={onAddPress} />
<CircleButton icon={fabIcon} onPress={onAddPress} />
</ButtonContainer>
</Container>
</>
Expand Down
32 changes: 32 additions & 0 deletions src/routes/product-list/new-list/useScreenSettings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { RouteProp, useRoute } from '@react-navigation/native';
import { useEffect, useState } from 'react';

import { translate } from '@locales';
import { ProductNavigatorParamsList } from '@navigator/product-navigator';

type Route = RouteProp<ProductNavigatorParamsList, 'NewList'>;

const useScreenSettings = () => {
const [screenTitle, setScreenTitle] = useState(
translate('productLists.newList'),
);

const [fabIcon, setFabIcon] = useState('plus');

const route = useRoute<Route>();
const hasParams = !!route.params.productList;

useEffect(() => {
if (hasParams) {
setScreenTitle(translate('productLists.editList'));
setFabIcon('check');
}
}, [hasParams]);

return {
screenTitle,
fabIcon,
};
};

export default useScreenSettings;

0 comments on commit dfb0d15

Please sign in to comment.