Skip to content

Commit

Permalink
Merge pull request #2310 from CruGlobal/feature/join-community-unauth…
Browse files Browse the repository at this point in the history
…enticated
  • Loading branch information
SeijiV13 authored Jan 6, 2024
2 parents 48bac15 + f4df949 commit 240553d
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 5 deletions.
3 changes: 3 additions & 0 deletions src/AppRoutes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ import {
SIGN_IN_FLOW,
SIGN_UP_FLOW,
CREATE_COMMUNITY_UNAUTHENTICATED_FLOW,
JOIN_COMMUNITY_UNAUTHENTICATED_FLOW,
COMPLETE_STEP_FLOW_NAVIGATE_BACK,
ADD_MY_STEP_FLOW,
ADD_PERSON_STEP_FLOW,
Expand Down Expand Up @@ -138,6 +139,7 @@ import {
VideoFullScreen,
VIDEO_FULL_SCREEN,
} from './containers/VideoFullScreen';
import { JoinCommunityUnauthenticatedFlowNavigator } from './routes/groups/joinCommunityUnauthenticatedFlow';

// Do custom animations between pages
// import CardStackStyleInterpolator from 'react-navigation/src/views/CardStack/CardStackStyleInterpolator';
Expand Down Expand Up @@ -283,6 +285,7 @@ const screens = {
[SIGN_IN_FLOW]: SignInFlowNavigator,
[SIGN_UP_FLOW]: SignUpFlowNavigator,
[CREATE_COMMUNITY_UNAUTHENTICATED_FLOW]: CreateCommunityUnauthenticatedFlowNavigator,
[JOIN_COMMUNITY_UNAUTHENTICATED_FLOW]: JoinCommunityUnauthenticatedFlowNavigator,
[JOIN_BY_CODE_FLOW]: JoinByCodeFlowNavigator,
[JOIN_BY_CODE_ONBOARDING_FLOW]: JoinByCodeOnboardingFlowNavigator,
[ADD_SOMEONE_ONBOARDING_FLOW]: AddSomeoneOnboardingFlowNavigator,
Expand Down
6 changes: 6 additions & 0 deletions src/containers/Auth/SignUpScreen/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import styles from './styles';

export const SIGNUP_TYPES = {
CREATE_COMMUNITY: 'login/CREATE_COMMUNITY',
JOIN_COMMUNITY: 'login/JOIN_COMMUNITY',
SETTINGS_MENU: 'login/SIDE_MENU',
};

Expand All @@ -48,6 +49,11 @@ const headerContentOptions: {
title: i18Next.t('loginOptions:createCommunityTitle'),
description: i18Next.t('loginOptions:createCommunityDescription'),
},
[SIGNUP_TYPES.JOIN_COMMUNITY]: {
image: PEOPLE,
title: i18Next.t('loginOptions:joinCommunityTitle'),
description: i18Next.t('loginOptions:joinCommunityDescription'),
},
};

const SignUpScreen = ({
Expand Down
9 changes: 8 additions & 1 deletion src/containers/Groups/GroupsListScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { resetScrollGroups } from '../../actions/swipe';
import { ACTIONS, GLOBAL_COMMUNITY_ID } from '../../constants';
import {
CREATE_COMMUNITY_UNAUTHENTICATED_FLOW,
JOIN_COMMUNITY_UNAUTHENTICATED_FLOW,
JOIN_BY_CODE_FLOW,
} from '../../routes/constants';
import { useRefreshing } from '../../utils/hooks/useRefreshing';
Expand Down Expand Up @@ -195,7 +196,13 @@ const GroupsListScreen = () => {
};

const join = () => {
dispatch(navigatePush(JOIN_BY_CODE_FLOW));
dispatch(
navigatePush(
isAnonymousUser
? JOIN_COMMUNITY_UNAUTHENTICATED_FLOW
: JOIN_BY_CODE_FLOW,
),
);
};

const create = () => {
Expand Down
20 changes: 20 additions & 0 deletions src/containers/Groups/__tests__/GroupsListScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { resetScrollGroups } from '../../../actions/swipe';
import { ACTIONS } from '../../../constants';
import {
CREATE_COMMUNITY_UNAUTHENTICATED_FLOW,
JOIN_COMMUNITY_UNAUTHENTICATED_FLOW,
JOIN_BY_CODE_FLOW,
} from '../../../routes/constants';
import {
Expand Down Expand Up @@ -194,10 +195,29 @@ describe('GroupsListScreen', () => {
expect(navigatePush).toHaveBeenCalledWith(JOIN_BY_CODE_FLOW);
expect(store.getActions()).toEqual([navigatePushResponse]);
});

it('navigates to Upgrade Account Screen if not signed in', () => {
(useIsAnonymousUser as jest.Mock).mockReturnValue(true);

const { getByTestId, store } = renderWithContext(<GroupsListScreen />, {
initialState: {
...initialState,
},
});

fireEvent.press(getByTestId('joinCommunity'));

expect(navigatePush).toHaveBeenCalledWith(
JOIN_COMMUNITY_UNAUTHENTICATED_FLOW,
);
expect(store.getActions()).toEqual([navigatePushResponse]);
});
});

describe('create community button press', () => {
it('navigates to create community screen if signed', () => {
(useIsAnonymousUser as jest.Mock).mockReturnValue(false);

const { getByTestId, store } = renderWithContext(<GroupsListScreen />, {
initialState,
});
Expand Down
6 changes: 4 additions & 2 deletions src/containers/LandingScreen/__tests__/LandingScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { navigatePush } from '../../../actions/navigation';
import { startOnboarding } from '../../../actions/onboarding';
import {
FULL_ONBOARDING_FLOW,
JOIN_BY_CODE_ONBOARDING_FLOW,
JOIN_COMMUNITY_UNAUTHENTICATED_FLOW,
SIGN_IN_FLOW,
} from '../../../routes/constants';
import { useAnalytics } from '../../../utils/hooks/useAnalytics';
Expand Down Expand Up @@ -54,7 +54,9 @@ describe('a button is clicked', () => {
fireEvent.press(getByTestId('communityCodeButton'));

expect(startOnboarding).toHaveBeenCalledWith();
expect(navigatePush).toHaveBeenCalledWith(JOIN_BY_CODE_ONBOARDING_FLOW);
expect(navigatePush).toHaveBeenCalledWith(
JOIN_COMMUNITY_UNAUTHENTICATED_FLOW,
);
expect(store.getActions()).toEqual([
startOnboardingResult,
navigatePushResult,
Expand Down
4 changes: 2 additions & 2 deletions src/containers/LandingScreen/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { Button } from '../../components/common';
import { useAnalytics } from '../../utils/hooks/useAnalytics';
import {
FULL_ONBOARDING_FLOW,
JOIN_BY_CODE_ONBOARDING_FLOW,
JOIN_COMMUNITY_UNAUTHENTICATED_FLOW,
SIGN_IN_FLOW,
} from '../../routes/constants';
import { startOnboarding } from '../../actions/onboarding';
Expand Down Expand Up @@ -40,7 +40,7 @@ const LandingScreen = () => {

const communityCode = () => {
dispatch(startOnboarding());
dispatch(navigatePush(JOIN_BY_CODE_ONBOARDING_FLOW));
dispatch(navigatePush(JOIN_COMMUNITY_UNAUTHENTICATED_FLOW));
};

const signIn = () => {
Expand Down
2 changes: 2 additions & 0 deletions src/i18n/locales/en-US.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ export default {
member: 'Already a Member?',
createCommunityTitle: 'Create a Community',
createCommunityDescription: 'Sign Up to create a MissionHub community.',
joinCommunityTitle: 'Join a Community',
joinCommunityDescription: 'Sign Up to join a MissionHub community.',
},
keyLogin: {
emailLabel: 'Email',
Expand Down
2 changes: 2 additions & 0 deletions src/routes/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ export const SIGN_IN_FLOW = 'nav/SIGN_IN_FLOW';
export const SIGN_UP_FLOW = 'nav/SIGN_UP_FLOW';
export const CREATE_COMMUNITY_UNAUTHENTICATED_FLOW =
'nav/CREATE_COMMUNITY_UNAUTHENTICATED_FLOW';
export const JOIN_COMMUNITY_UNAUTHENTICATED_FLOW =
'nav/JOIN_COMMUNITY_UNAUTHENTICATED_FLOW';
export const JOIN_BY_CODE_FLOW = 'nav/JOIN_BY_CODE_FLOW';
export const JOIN_BY_CODE_ONBOARDING_FLOW = 'nav/JOIN_BY_CODE_ONBOARDING_FLOW';
export const ADD_SOMEONE_ONBOARDING_FLOW = 'nav/ADD_SOMEONE_ONBOARDING_FLOW';
Expand Down
29 changes: 29 additions & 0 deletions src/routes/groups/joinCommunityUnauthenticatedFlow.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { createStackNavigator } from 'react-navigation-stack';

import { navigateNestedReset } from '../../actions/navigation';
import { COMMUNITIES_TAB, MAIN_TABS } from '../../constants';
import { JOIN_GROUP_SCREEN } from '../../containers/Groups/JoinGroupScreen';
import { authFlowGenerator } from '../auth/authFlowGenerator';
import { SIGNUP_TYPES } from '../../containers/Auth/SignUpScreen';

const JoinCommunityUnauthenticatedFlowScreens = authFlowGenerator({
completeAction: navigateNestedReset([
{
routeName: MAIN_TABS,
tabName: COMMUNITIES_TAB,
},
{ routeName: JOIN_GROUP_SCREEN },
]),
includeSignUp: true,
// @ts-ignore
signUpType: SIGNUP_TYPES.JOIN_COMMUNITY,
});

export const JoinCommunityUnauthenticatedFlowNavigator = createStackNavigator(
JoinCommunityUnauthenticatedFlowScreens,
{
defaultNavigationOptions: {
header: null,
},
},
);

0 comments on commit 240553d

Please sign in to comment.