Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Premium via QR code #41

Draft
wants to merge 7 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions src/components/BotaoVoltar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,17 @@ import { useNavigation } from '@react-navigation/core'

interface Props {
destino?: any
testID?: string
semTexto?: boolean
marginLeft?: number
}

const BotaoVoltar = ({ destino, semTexto = false, marginLeft }: Props) => {
const BotaoVoltar = ({
destino,
testID,
semTexto = false,
marginLeft
}: Props) => {
const { t } = i18n
const navigation = useNavigation()
const handlePress = () => {
Expand All @@ -23,7 +29,12 @@ const BotaoVoltar = ({ destino, semTexto = false, marginLeft }: Props) => {
}
}
return (
<Pressable onPress={handlePress} style={[styles.botao, { marginLeft }]}>
<Pressable
onPress={handlePress}
testID={testID}
accessibilityLabel={testID}
style={[styles.botao, { marginLeft }]}
>
<MaterialCommunityIcons
name="arrow-left"
size={22}
Expand Down
5 changes: 4 additions & 1 deletion src/components/NavigationList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ import { FlatList, StyleSheet, Text } from 'react-native'
import { Divider, List } from 'react-native-paper'
import { theme } from '../../theme'

interface INavigationItem {
export interface INavigationItem {
icone?: ReactNode
texto: string
onPress?: () => void
iconeSecundario?: ReactNode
testID?: string
}

interface INavigationListProps {
Expand All @@ -26,6 +27,8 @@ const NavigationList = ({ itens }: INavigationListProps) => {
left={() => <Text style={styles.icone}>{item.icone}</Text>}
right={() => <Text style={styles.icone}>{item.iconeSecundario}</Text>}
onPress={item.onPress}
testID={item.testID}
accessibilityLabel={item.testID}
/>
)

Expand Down
18 changes: 17 additions & 1 deletion src/entities/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ interface IUserAttributes {
tokens?: Array<string>
idioma?: string
aceitouPolitica?: boolean
premium?: boolean
temLivroPromocode?: boolean
inicioPromocode?: Date
duracaoPromocode?: number
}

export type IUser = IUserAttributes
Expand All @@ -31,6 +35,10 @@ export default class User implements IUser {
public tokens?: Array<string>
public idioma: string
public aceitouPolitica?: boolean
public premium?: boolean
public temLivroPromocode?: boolean
public inicioPromocode?: Date
public duracaoPromocode?: number

constructor({
id,
Expand All @@ -45,7 +53,11 @@ export default class User implements IUser {
canaisDeNotificacao,
tokens,
idioma,
aceitouPolitica
aceitouPolitica,
premium,
temLivroPromocode,
inicioPromocode,
duracaoPromocode
}: IUserAttributes) {
this.id = id
this.nome = nome
Expand All @@ -60,6 +72,10 @@ export default class User implements IUser {
this.tokens = tokens
this.idioma = idioma
this.aceitouPolitica = aceitouPolitica
this.premium = premium
this.temLivroPromocode = temLivroPromocode
this.inicioPromocode = inicioPromocode
this.duracaoPromocode = duracaoPromocode
}

novidadeDispensada(slug: string): boolean {
Expand Down
14 changes: 12 additions & 2 deletions src/factories/UserFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,17 @@ export default class UserFactory {
canaisDeNotificacao,
tokens,
idioma,
aceitouPolitica
aceitouPolitica,
premium,
temLivroPromocode
} = dados

const lastAccess = dados.lastAccess ? dados.lastAccess.toDate() : null
const countAccess = dados.countAccess ? dados.countAccess : 0
const inicioPromocode = dados.inicioPromocode
? dados.inicioPromocode.toDate()
: null
const duracaoPromocode = dados.duracaoPromocode ? dados.duracaoPromocode : 0

return new User({
id,
Expand All @@ -42,7 +48,11 @@ export default class UserFactory {
canaisDeNotificacao: canaisDeNotificacao || [],
tokens: tokens || [],
idioma: idioma || idiomaAtual,
aceitouPolitica
aceitouPolitica,
premium,
temLivroPromocode,
inicioPromocode,
duracaoPromocode
})
}
}
9 changes: 8 additions & 1 deletion src/i18n/translations/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ const en = {
aceitePolitica: {
respeitamos: 'We respect your privacy.',
declaracao:
'By using this app, you agree to our use of local storage to improve your experience.',
'By using this app, you agree to our use of local storage to improve ' +
'your experience.',
conheca: 'Learn about our Privacy Policy',
botao: 'Ok, I get it'
},
Expand Down Expand Up @@ -161,6 +162,12 @@ const en = {
notificacoes: 'Notifications',
ajuda: 'Help',
textoAjuda: 'Need help? Send an email to [email protected]',
ativarPremium: 'Activate Premium',
premiumAtivo: 'Congratulations! You are Premium',
tituloPremium: 'Congratulations',
textoPremium:
'For buying the Solar Journey 2022 book, you win' +
' one month of Premium access',
sair: 'Sign Out',
ok: 'Ok',
notificaEventos: 'Solar Journey Events',
Expand Down
14 changes: 14 additions & 0 deletions src/i18n/translations/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,14 @@ const es = {
anotacoes: 'Escribe sobre tu día',
verMais: 'Ver más'
},
aceitePolitica: {
respeitamos: 'Respetamos su privacidad.',
declaracao:
'Al utilizar esta aplicación, aceptas que utilicemos el' +
' almacenamiento local para mejorar tu experiencia.',
conheca: 'Conozca nuestra política de privacidad',
botao: 'OK, lo tengo'
},
signos: {
capricornio: 'Capricornio',
aquario: 'Acuario',
Expand Down Expand Up @@ -158,6 +166,12 @@ const es = {
ajuda: 'Ayuda',
textoAjuda:
'¿Necesita ayuda? Envíe un correo electrónico a [email protected]',
ativarPremium: 'Activar Premium',
premiumAtivo: 'Enhorabuena. Usted es Premium',
tituloPremium: 'Enhorabuena',
textoPremium:
'Por haber comprado el libro Jornada Solar 2022, has ganado' +
' un mes de acceso Premium',
sair: 'Salir',
ok: 'Ok',
notificaEventos: 'Eventos de la Jornada Solar',
Expand Down
9 changes: 8 additions & 1 deletion src/i18n/translations/pt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ const pt = {
aceitePolitica: {
respeitamos: 'Respeitamos sua privacidade.',
declaracao:
'Ao utilizar este app, você aceita a utilização do armazenamento local para melhorarmos a sua experiência.',
'Ao utilizar este app, você aceita a utilização do armazenamento ' +
'local para melhorarmos a sua experiência.',
conheca: 'Conheça nossa Política de privacidade',
botao: 'Ok, entendi'
},
Expand Down Expand Up @@ -167,6 +168,12 @@ const pt = {
notificacoes: 'Notificações',
ajuda: 'Ajuda',
textoAjuda: 'Precisa de ajuda? Envie um e-mail para [email protected]',
ativarPremium: 'Ativar Premium',
premiumAtivo: 'Parabéns! Você é Premium',
tituloPremium: 'Parabéns',
textoPremium:
'Por ter comprado o livro da Jornada Solar 2022, você ganhou' +
' um mês de acesso Premium',
sair: 'Sair',
ok: 'Ok',
notificaEventos: 'Eventos do Jornada Solar',
Expand Down
15 changes: 13 additions & 2 deletions src/routes/App.routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@ import Sentimentos from '../screens/app/Sentimentos'
import Habitos from '../screens/app/Habitos'
import Anotacoes from '../screens/app/Anotacoes'
import Player from '../screens/app/Player'
import { BottomTabs } from './BottomTabs.routes'
import { BottomTabs, BottomTabsParams } from './BottomTabs.routes'
import AlterarSenha from '../screens/app/perfil/AlterarSenha'
import MeusDados from '../screens/app/perfil/MeusDados'
import Notificacoes from '../screens/app/perfil/Notificacoes'
import AlterarNome from '../screens/app/perfil/AlterarNome'
import Premium from '../screens/app/perfil/Premium'
import { BottomTabScreenProps } from '@react-navigation/bottom-tabs'
import { CompositeScreenProps } from '@react-navigation/core'

type AppStackParams = {
Abas: undefined
Expand All @@ -25,11 +28,17 @@ type AppStackParams = {
AlterarNome: undefined
AlterarSenha: undefined
Notificacoes: undefined
Premium: { origem?: string }
}

type AppNavigationProps = NativeStackScreenProps<AppStackParams, 'Abas'>
type DiaNavigationProps = NativeStackScreenProps<AppStackParams, 'Dia'>
type PlayerNavigationProps = NativeStackScreenProps<AppStackParams, 'Player'>
type RootStackScreenProps<Screen extends keyof AppStackParams> =
CompositeScreenProps<
NativeStackScreenProps<AppStackParams, Screen>,
BottomTabScreenProps<BottomTabsParams>
>

const { Navigator, Screen } = createNativeStackNavigator<AppStackParams>()

Expand All @@ -46,6 +55,7 @@ function AppRoutes() {
<Screen name="AlterarNome" component={AlterarNome} />
<Screen name="AlterarSenha" component={AlterarSenha} />
<Screen name="Notificacoes" component={Notificacoes} />
<Screen name="Premium" component={Premium} />
</Navigator>
)
}
Expand All @@ -55,5 +65,6 @@ export {
AppStackParams,
AppNavigationProps,
DiaNavigationProps,
PlayerNavigationProps
PlayerNavigationProps,
RootStackScreenProps
}
2 changes: 1 addition & 1 deletion src/routes/BottomTabs.routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,4 @@ function BottomTabs() {
)
}

export { BottomTabs, TabsNavigationProps }
export { BottomTabs, BottomTabsParams, TabsNavigationProps }
3 changes: 2 additions & 1 deletion src/routes/linking.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ const config = {
},
Dia: 'dia',
Perfil: 'perfil',
Player: 'meditacao'
Player: 'meditacao',
Premium: 'premium'
}
}

Expand Down
44 changes: 37 additions & 7 deletions src/screens/app/perfil/Perfil.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import React, { useState } from 'react'
import React, { useContext, useState } from 'react'
import { StyleSheet, View } from 'react-native'
import { Text } from 'react-native-paper'
import Emoji from '../../../components/Emoji'
import NavigationList from '../../../components/NavigationList'
import NavigationList, {
INavigationItem
} from '../../../components/NavigationList'
import { AppNavigationProps } from '../../../routes/App.routes'
import SignOutUser from '../../../services/user/SignOutUser'
import { MaterialIcons } from '@expo/vector-icons'
Expand All @@ -13,8 +15,10 @@ import { t } from 'i18n-js'
import Dialogo from '../../../components/Dialogo'
import Novidade from '../../../components/Novidade'
import Telas from '../../../enums/Telas'
import AuthContext from '../../../context/AuthContext'

const Perfil = ({ navigation }: AppNavigationProps) => {
const { user } = useContext(AuthContext)
const handleSair = () => {
new SignOutUser().call()
}
Expand All @@ -36,37 +40,63 @@ const Perfil = ({ navigation }: AppNavigationProps) => {
navigation.navigate('Notificacoes')
}

const handlePremium = () => {
navigation.navigate('Premium', { origem: 'Perfil' })
}

const ChevronRight = (
<MaterialIcons name="chevron-right" size={24} color={theme.colors.text} />
)

const menus = [
const menus: INavigationItem[] = [
{
icone: <Emoji nome="perfil" />,
texto: t('perfil.meusDados'),
onPress: handleMeusDados,
iconeSecundario: ChevronRight
iconeSecundario: ChevronRight,
testID: 'perfilMeusDados'
},
{
icone: <Emoji nome="sino" />,
texto: t('perfil.notificacoes'),
onPress: handleNotificacoes,
iconeSecundario: ChevronRight
iconeSecundario: ChevronRight,
testID: 'perfilNotificacao'
},
{
icone: <Emoji nome="duvida" />,
texto: t('perfil.ajuda'),
onPress: abrirDialogo,
iconeSecundario: ChevronRight
iconeSecundario: ChevronRight,
testID: 'perfilAjuda'
},
{
icone: <Emoji nome="sair" />,
texto: t('perfil.sair'),
onPress: handleSair,
iconeSecundario: ChevronRight
iconeSecundario: ChevronRight,
testID: 'perfilSair'
}
]

const botaoPremium = user.premium
? {
icone: <Emoji emoji={'\u{2B50}'} />,
texto: t('perfil.premiumAtivo'),
testID: 'perfilPremiumAtivo'
}
: {
icone: <Emoji emoji={'\u{2B50}'} />,
texto: t('perfil.ativarPremium'),
onPress: handlePremium,
iconeSecundario: ChevronRight,
testID: 'perfilAtivarPremium'
}

if (user.temLivroPromocode) {
menus.unshift(botaoPremium)
}

return (
<View style={styles.container}>
<View style={styles.header}>
Expand Down
Loading