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

Focused Launch: Add DomainPicker to DomainDetail view #47318

Merged
merged 19 commits into from
Nov 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
94d5189
Add jest.config.js to launch package
tjcafferkey Nov 11, 2020
d19840c
Add @testing-library/react to launch devDependencies
tjcafferkey Nov 11, 2020
76e6551
Move launch flow ID to constants.ts file
tjcafferkey Nov 11, 2020
e2987ce
Add DomainPicker component to DomainStep in focused launch
tjcafferkey Nov 11, 2020
4ce6c0d
Move editor_domain_modal to constant variable to avoid duplication
tjcafferkey Nov 11, 2020
3ed3101
Update analyticsUiAlgo values in domain step and summary
tjcafferkey Nov 11, 2020
cb099d9
Rename DomainStep to DomainDetails
tjcafferkey Nov 12, 2020
a43f583
Add calypso-analytics to tsconfig.json references
tjcafferkey Nov 12, 2020
baf4146
Abstract domain selection methods into custom hook and refactor domai…
tjcafferkey Nov 12, 2020
e8c0c73
Add quantity of 10 domains to domain details view
tjcafferkey Nov 12, 2020
fa6d756
Replace Go Back button with BackButton from onboarding package
tjcafferkey Nov 18, 2020
f7deb37
Back to Summary onDomainSelect
tjcafferkey Nov 18, 2020
53620e1
Add focused-launch-container class for the purpose of padding each de…
tjcafferkey Nov 18, 2020
fcb2420
Move quantity value to const variable
tjcafferkey Nov 18, 2020
6f64e4f
Move selectedDomain into useDomainSelection hook
tjcafferkey Nov 18, 2020
6f7360c
Fix confict resolution mistakes
alshakero Nov 18, 2020
2896176
Move setDomainSearch to useDomainSearch hook
alshakero Nov 18, 2020
351b9d4
Adobt the new GoBackButton
alshakero Nov 18, 2020
f5d98a3
Render non-expanded domain picker by default
Nov 19, 2020
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
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,9 @@ import './styles.scss';
const DomainStep: React.FunctionComponent< LaunchStepProps > = ( { onPrevStep, onNextStep } ) => {
const { plan, domain } = useSelect( ( select ) => select( LAUNCH_STORE ).getState() );
const { currentDomainName } = useSite();
const { domainSearch } = useDomainSearch();
const { domainSearch, setDomainSearch } = useDomainSearch();

const {
setDomain,
unsetDomain,
setDomainSearch,
unsetPlan,
confirmDomainSelection,
} = useDispatch( LAUNCH_STORE );
const { setDomain, unsetDomain, unsetPlan, confirmDomainSelection } = useDispatch( LAUNCH_STORE );

const handleNext = () => {
confirmDomainSelection();
Expand Down
7 changes: 7 additions & 0 deletions packages/launch/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
preset: '../../test/packages/jest-preset.js',
testEnvironment: 'jsdom',
globals: {
__i18n_text_domain__: 'default',
},
};
6 changes: 4 additions & 2 deletions packages/launch/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@
"watch": "tsc --build ./tsconfig.json --watch"
},
"dependencies": {
"@automattic/react-i18n": "^1.0.0-alpha.0",
"@automattic/calypso-analytics": "^1.0.0-alpha.1",
tjcafferkey marked this conversation as resolved.
Show resolved Hide resolved
"@automattic/data-stores": "^1.0.0-alpha.1",
"@automattic/domain-picker": "^1.0.0-alpha.0",
"@automattic/onboarding": "^1.0.0",
"@automattic/plans-grid": "^1.0.0-alpha.0",
"@automattic/react-i18n": "^1.0.0-alpha.0",
"@wordpress/components": "^10.0.5",
"@wordpress/icons": "^2.4.0",
"@wordpress/url": "^2.17.0",
Expand All @@ -44,7 +45,8 @@
"devDependencies": {
"@automattic/typography": "^1.0.0",
"@wordpress/base-styles": "^2.0.1",
"copyfiles": "^2.3.0"
"copyfiles": "^2.3.0",
"@testing-library/react": "^10.0.5"
},
"peerDependencies": {
"@wordpress/data": "^4.22.3",
Expand Down
1 change: 1 addition & 0 deletions packages/launch/src/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const FOCUSED_LAUNCH_FLOW_ID = 'focused-launch';
66 changes: 60 additions & 6 deletions packages/launch/src/focused-launch/domain-details/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,76 @@
/**
* External dependencies
*/
import React from 'react';
import { Link } from 'react-router-dom';
import * as React from 'react';
import { useHistory } from 'react-router-dom';

import { __ } from '@wordpress/i18n';
import DomainPicker, { ITEM_TYPE_BUTTON } from '@automattic/domain-picker';
import { Title, SubTitle } from '@automattic/onboarding';
import { recordTracksEvent } from '@automattic/calypso-analytics';
import type { DomainSuggestions } from '@automattic/data-stores';

/**
* Internal dependencies
*/
import { Route } from '../route';
import { useSite, useDomainSearch, useDomainSelection } from '../../hooks';
import { FOCUSED_LAUNCH_FLOW_ID } from '../../constants';
import GoBackButton from '../go-back-button';

import './style.scss';

const ANALYTICS_UI_LOCATION = 'domain_step';

const DomainDetails: React.FunctionComponent = () => {
const { currentDomainName } = useSite();
const { domainSearch, setDomainSearch } = useDomainSearch();
const { onDomainSelect, onExistingSubdomainSelect, selectedDomain } = useDomainSelection();
const history = useHistory();

const goBack = () => {
history.goBack();
};

const handleDomainSelect = ( suggestion: DomainSuggestions.DomainSuggestion ) => {
onDomainSelect( suggestion );
goBack();
};

const trackDomainSearchInteraction = ( query: string ) => {
recordTracksEvent( 'calypso_newsite_domain_search_blur', {
flow: FOCUSED_LAUNCH_FLOW_ID,
query,
where: ANALYTICS_UI_LOCATION,
} );
};

return (
<div>
<Link to={ Route.Summary }>{ __( 'Go back', __i18n_text_domain__ ) }</Link>
<p>{ __( 'Choose a domain', __i18n_text_domain__ ) }</p>
<div className="focused-launch-container">
<div className="focused-launch-domain-details__header">
<div className="focused-launch-plan-details__back-button-wrapper">
<GoBackButton onClick={ goBack } />
</div>
<Title>{ __( 'Choose a domain', __i18n_text_domain__ ) }</Title>
<SubTitle>
{ __( 'Free for the first year with any paid plan.', __i18n_text_domain__ ) }
</SubTitle>
</div>
<div className="focused-launch-domain-details__body">
<DomainPicker
initialDomainSearch={ domainSearch }
onSetDomainSearch={ setDomainSearch }
onDomainSearchBlur={ trackDomainSearchInteraction }
currentDomain={ selectedDomain?.domain_name || currentDomainName }
existingSubdomain={ currentDomainName }
onDomainSelect={ handleDomainSelect }
onExistingSubdomainSelect={ onExistingSubdomainSelect }
analyticsFlowId={ FOCUSED_LAUNCH_FLOW_ID }
analyticsUiAlgo={ ANALYTICS_UI_LOCATION }
segregateFreeAndPaid
locale={ document.documentElement.lang }
itemType={ ITEM_TYPE_BUTTON }
tjcafferkey marked this conversation as resolved.
Show resolved Hide resolved
/>
</div>
</div>
);
};
Expand Down
18 changes: 18 additions & 0 deletions packages/launch/src/focused-launch/domain-details/style.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
@import '~@automattic/onboarding/styles/mixins';

.focused-launch-domain-details__header {
margin-bottom: 38px;

@include break-medium {
margin-bottom: 64px;
}

.focused-launch-domain-details__back-link {
button.action-buttons__back {
color: var( --studio-black );
margin-bottom: 16px;
display: flex;
align-items: center;
}
}
}
44 changes: 44 additions & 0 deletions packages/launch/src/focused-launch/domain-details/test/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* External dependencies
*/
import React from 'react';
import { MemoryRouter as Router } from 'react-router-dom';
import { render, screen } from '@testing-library/react';

/**
* Internal dependencies
*/
import DomainStep from '../';

describe( 'DomainStep', () => {
test( 'Has title and sub-title', () => {
render(
<Router>
<DomainStep />
</Router>
);

expect( screen.queryByText( /Choose a domain/i ) ).toBeTruthy();
expect( screen.queryByText( /Free for the first year with any paid plan/i ) ).toBeTruthy();
} );

test( 'Has domain search input', () => {
render(
<Router>
<DomainStep />
</Router>
);

expect( screen.queryByPlaceholderText( /Search for a domain/i ) ).toBeTruthy();
} );

test( 'Has a back button', () => {
tjcafferkey marked this conversation as resolved.
Show resolved Hide resolved
render(
<Router>
<DomainStep />
</Router>
);

expect( screen.queryByText( /Go back/i ) ).toBeTruthy();
} );
} );
ciampo marked this conversation as resolved.
Show resolved Hide resolved
3 changes: 3 additions & 0 deletions packages/launch/src/focused-launch/style.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.focused-launch-container {
padding: 0 10px;
}
21 changes: 15 additions & 6 deletions packages/launch/src/focused-launch/summary/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,19 @@ import FocusedLaunchSummaryItem, {
* Internal dependencies
*/
import { Route } from '../route';
import { useTitle, useDomainSearch, useSiteDomains, useSite, usePlans } from '../../hooks';
import {
useTitle,
useDomainSearch,
useSiteDomains,
useDomainSelection,
useSite,
usePlans,
} from '../../hooks';

import { LAUNCH_STORE } from '../../stores';
import LaunchContext from '../../context';
import { isDefaultSiteTitle } from '../../utils';
import { FOCUSED_LAUNCH_FLOW_ID } from '../../constants';

import './style.scss';

Expand Down Expand Up @@ -181,8 +190,8 @@ const DomainStep: React.FunctionComponent< DomainStepProps > = ( {
onExistingSubdomainSelect={ onExistingSubdomainSelect }
initialDomainSearch={ initialDomainSearch }
showSearchField={ false }
analyticsFlowId="focused-launch"
analyticsUiAlgo="focused_launch_domain_picker"
analyticsFlowId={ FOCUSED_LAUNCH_FLOW_ID }
analyticsUiAlgo="summary_domain_step"
quantity={ 3 }
quantityExpanded={ 3 }
itemType="individual-item"
Expand Down Expand Up @@ -437,8 +446,8 @@ const Summary: React.FunctionComponent = () => {
const { title, updateTitle, saveTitle, isSiteTitleStepVisible, showSiteTitleStep } = useTitle();

const { sitePrimaryDomain, siteSubdomain, hasPaidDomain } = useSiteDomains();
const { onDomainSelect, onExistingSubdomainSelect } = useDomainSelection();
const selectedDomain = useSelect( ( select ) => select( LAUNCH_STORE ).getSelectedDomain() );
const { setDomain, unsetDomain } = useDispatch( LAUNCH_STORE );
const { domainSearch, isLoading } = useDomainSearch();

const site = useSite();
Expand Down Expand Up @@ -483,14 +492,14 @@ const Summary: React.FunctionComponent = () => {
currentDomain={ selectedDomain?.domain_name ?? sitePrimaryDomain?.domain }
initialDomainSearch={ domainSearch }
hasPaidDomain={ hasPaidDomain }
onDomainSelect={ setDomain }
isLoading={ isLoading }
onDomainSelect={ onDomainSelect }
/** NOTE: this makes the assumption that the user has a free domain,
* thus when they click the free domain, we just remove the value from the store
* this is a valid strategy in this context because they won't even see this step if
* they already have a paid domain
* */
onExistingSubdomainSelect={ unsetDomain }
onExistingSubdomainSelect={ onExistingSubdomainSelect }
locale={ locale }
/>
);
Expand Down
1 change: 1 addition & 0 deletions packages/launch/src/hooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export * from './use-site';
export * from './use-on-launch';
export * from './use-domain-suggestion';
export * from './use-domain-search';
export * from './use-domain-selection';
export * from './use-title';
export * from './use-site-domains';
export * from './use-plans';
10 changes: 8 additions & 2 deletions packages/launch/src/hooks/use-domain-search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,23 @@
* External dependencies
*/
import { useSelect } from '@wordpress/data';

import { useDispatch } from '@wordpress/data';
/**
* External dependencies
*/
import { LAUNCH_STORE } from '../stores';
import { useSite, useTitle } from './';
import { isDefaultSiteTitle } from '../utils';

export function useDomainSearch(): { domainSearch: string; isLoading: boolean } {
export function useDomainSearch(): {
domainSearch: string;
isLoading: boolean;
setDomainSearch: ( search: string ) => void;
} {
const { domainSearch } = useSelect( ( select ) => select( LAUNCH_STORE ).getState() );
const { title } = useTitle();
const { currentDomainName, isLoadingSite } = useSite();
const { setDomainSearch } = useDispatch( LAUNCH_STORE );

let search = domainSearch.trim() || title;

Expand All @@ -24,5 +29,6 @@ export function useDomainSearch(): { domainSearch: string; isLoading: boolean }
return {
domainSearch: search,
isLoading: isLoadingSite,
setDomainSearch,
};
}
34 changes: 34 additions & 0 deletions packages/launch/src/hooks/use-domain-selection.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* External dependencies
*/
import { useDispatch, useSelect } from '@wordpress/data';
import type { DomainSuggestions } from '@automattic/data-stores';

/**
* Internal dependencies
*/
import { LAUNCH_STORE } from '../stores';

export function useDomainSelection() {
const { plan } = useSelect( ( select ) => select( LAUNCH_STORE ).getState() );
const { setDomain, unsetDomain, unsetPlan, confirmDomainSelection } = useDispatch( LAUNCH_STORE );
const { domain: selectedDomain } = useSelect( ( select ) => select( LAUNCH_STORE ).getState() );

function onDomainSelect( suggestion: DomainSuggestions.DomainSuggestion ) {
confirmDomainSelection();
setDomain( suggestion );
if ( plan?.isFree ) {
unsetPlan();
}
}

function onExistingSubdomainSelect() {
unsetDomain();
}

return {
onDomainSelect,
onExistingSubdomainSelect,
selectedDomain,
};
}
3 changes: 2 additions & 1 deletion packages/launch/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
{ "path": "../components" },
{ "path": "../onboarding" },
{ "path": "../domain-picker" },
{ "path": "../plans-grid" }
{ "path": "../plans-grid" },
{ "path": "../calypso-analytics" }
]
}