Skip to content

Commit

Permalink
finish onboarding logic
Browse files Browse the repository at this point in the history
  • Loading branch information
TrillCyborg committed Jun 7, 2019
1 parent b1afdc6 commit 55d3ca7
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 26 deletions.
7 changes: 4 additions & 3 deletions client/src/components/MainLayout/MainLayout.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react'
import { View } from 'react-native'
import styled from 'styled-components'
import { useMeQuery } from '../../generated/graphql'
// import { useMeQuery } from '../../generated/graphql'
import Sidebar from './Sidebar'
import MenuIcon from './MenuIcon'

Expand Down Expand Up @@ -33,9 +33,10 @@ interface MainLayoutProps {
export const SidebarContext = React.createContext({ sidebarOpen: false })

const MainLayout = ({ children }: MainLayoutProps) => {
const { data } = useMeQuery()
// const { data } = useMeQuery()

const [sidebarOpen, setSidebarOpen] = React.useState(!!(data && data.me && data.me.isOnboarded))
// const [sidebarOpen, setSidebarOpen] = React.useState(!!(data && data.me && data.me.isOnboarded))
const [sidebarOpen, setSidebarOpen] = React.useState(true)

return (
<SidebarContext.Provider value={{ sidebarOpen }}>
Expand Down
6 changes: 3 additions & 3 deletions client/src/screens/Home/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,16 @@ const Title = styled(Text)`
`

const Home = () => {
const { data, loading } = useMeQuery()
const { data, loading, refetch } = useMeQuery()
const { sidebarOpen } = React.useContext(SidebarContext)
const firstName = data && data.me && data.me.profile.firstName
const isOnboarded = data && data.me && data.me.isOnboarded
return (
<Wrapper sidebarOpen={sidebarOpen && width > 930}>
{loading ? null : (
<View style={{ width: '75%', height: '85%', overflow: 'hidden' }}>
<View style={{ position: 'relative', width: '75%', height: '85%' }}>
<Title>{`Hello, ${firstName}!`}</Title>
{isOnboarded ? <Dashboard /> : <Onboard />}
{isOnboarded ? <Dashboard /> : <Onboard done={refetch} />}
</View>
)}
</Wrapper>
Expand Down
38 changes: 19 additions & 19 deletions client/src/screens/Home/components/Onboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,41 +39,38 @@ const DotRow = styled(View)`
margin-bottom: 20px;
`

const Onboard = () => {
const Onboard = (props: { done: () => void }) => {
const onboardUser = useOnboardUserMutation()
const [selectedItem, setSelectedItem] = React.useState<MapsPrediction | null>(null)
const [publicToken, setPublicToken] = React.useState<string>('')
const [rent, setRent] = React.useState()
const [page, setPage] = React.useState(0)
const isNextDisabled = [!selectedItem || !selectedItem.place_id, !rent, !publicToken]

const onPressNext = async () => {
if (page === 2) {
await onboardUser({
variables: {
publicToken,
property: {
address: selectedItem!.description,
placeId: selectedItem!.place_id,
rentAmount: parseInt(rent),
},
const onPressDone = async (publicToken: string) => {
await setPublicToken(publicToken)
await onboardUser({
variables: {
publicToken,
property: {
address: selectedItem!.description,
placeId: selectedItem!.place_id,
rentAmount: parseInt(rent),
},
})
console.log('DONE!!!')
} else {
setPage(page + 1)
}
},
})
props.done()
}

return (
<Box style={{ height: '75%' }}>
<BoxInner>
<OnboardPages
rent={rent}
page={page}
setRent={setRent}
setSelectedItem={setSelectedItem}
setPublicToken={setPublicToken}
page={page}
setPublicToken={onPressDone}
/>
<View
style={{ position: 'relative', marginBottom: 40, marginTop: 52, alignItems: 'center' }}
Expand All @@ -83,7 +80,10 @@ const Onboard = () => {
<Dot active={i === page} />
))}
</DotRow>
<Button onPress={onPressNext} disabled={isNextDisabled[page]}>
<Button
onPress={page !== 2 ? () => setPage(page + 1) : () => {}}
disabled={isNextDisabled[page]}
>
{page === 2 ? 'Done' : 'Next'}
</Button>
</View>
Expand Down
8 changes: 7 additions & 1 deletion server/config/local.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,11 @@
"PORT": 4000,
"DB_NAME": "oneFraction",
"MONGO_HOST": "",
"ACCOUNTS_SECRET": "979083ce-a9b6-483d-a899-ea22d5b0a1dd"
"ACCOUNTS_SECRET": "979083ce-a9b6-483d-a899-ea22d5b0a1dd",
"PLAID_CLIENT_ID": "5cf92b434c3aa500121bfad9",
"PLAID_SECRET": "7bec015f38a285e9d48d8fd16ba79b",
"PLAID_PUBLIC_KEY": "3bc02bb8840d84f2e9b803add9191e",
"PLAID_PRODUCTS": "transactions",
"PLAID_COUNTRY_CODES": "US",
"PLAID_ENV": "sandbox"
}
1 change: 1 addition & 0 deletions server/src/modules/user/UserResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ export default class UserResolver {
itemId: response.item_id,
}
user.properties = [property]
user.isOnboarded = true
await user.save()

resolve(true)
Expand Down

0 comments on commit 55d3ca7

Please sign in to comment.