Skip to content

Commit

Permalink
feat: #1127 preview app from app details page (#1573)
Browse files Browse the repository at this point in the history
  • Loading branch information
Trường An authored Jun 5, 2020
1 parent 141b67f commit 689fc8f
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -195,12 +195,7 @@ describe('ClientAppDetail', () => {
})
describe('onBackToAppsButtonClick', () => {
it('should run correctly', () => {
const fn = onBackToAppsButtonClick(history, 'DEVELOPER')
fn()
expect(history.push).toBeCalledWith(Routes.DEVELOPER_MY_APPS)
})
it('should run correctly', () => {
const fn = onBackToAppsButtonClick(history, 'CLIENT')
const fn = onBackToAppsButtonClick(history)
fn()
expect(history.push).toBeCalledWith(Routes.CLIENT)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { Loader, Button, Alert, FormSection } from '@reapit/elements'
import clientAppDetailStyles from '@/styles/pages/client-app-detail.scss?mod'
import ClientAppInstallConfirmation from '@/components/ui/client-app-detail/client-app-install-confirmation'
import { Aside } from './aside'
import { clientFetchAppDetailFailed } from '@/actions/client'
import { clientFetchAppDetail } from '@/actions/client'
import { developerApplyAppDetails } from '@/actions/developer'
import { useParams } from 'react-router'
import { Dispatch } from 'redux'
Expand Down Expand Up @@ -52,11 +52,8 @@ export const handleUnInstallAppButtonClick = (setIsVisibleUnInstallConfirmation:
}
}

export const onBackToAppsButtonClick = (history: History, loginType: LoginType) => {
export const onBackToAppsButtonClick = (history: History) => {
return () => {
if (loginType === 'DEVELOPER') {
history.push(Routes.DEVELOPER_MY_APPS)
}
history.push(Routes.CLIENT)
}
}
Expand All @@ -69,18 +66,14 @@ export const handleApplyAppDetailsFromLocalStorage = (
if (loginType !== 'DEVELOPER' || !appId) return
try {
const appDataString = localStorage.getItem('developer-preview-app')
if (!appDataString) {
throw 'No app preview'
}
if (!appDataString) throw 'No preview data'

const appData = JSON.parse(appDataString)
if (appData.id !== appId) {
throw 'No app preview'
}
if (appData.id !== appId) throw 'Preview data not match appId'

dispatch(developerApplyAppDetails(appData))
} catch (err) {
dispatch(clientFetchAppDetailFailed(err))
dispatch(clientFetchAppDetail({ id: appId }))
}
}

Expand Down Expand Up @@ -186,20 +179,22 @@ const ClientAppDetail: React.FC<ClientAppDetailProps> = () => {
)}
/>
<AppContent desktopIntegrationTypes={userDesktopIntegrationTypes} appDetailData={appDetailData} />
<FormSection className={clientAppDetailStyles.footerContainer}>
<div className={clientAppDetailStyles.hiddenInDesktopScreenSize}>
<ContactDeveloperSection
contact={{
developer,
telephone,
supportEmail,
homePage,
}}
hasGutter={false}
/>
</div>
<Button onClick={onBackToAppsButtonClick(history, loginType)}>Back To Apps</Button>
</FormSection>
{loginType !== 'DEVELOPER' && (
<FormSection className={clientAppDetailStyles.footerContainer}>
<div className={clientAppDetailStyles.hiddenInDesktopScreenSize}>
<ContactDeveloperSection
contact={{
developer,
telephone,
supportEmail,
homePage,
}}
hasGutter={false}
/>
</div>
<Button onClick={onBackToAppsButtonClick(history)}>Back To Apps</Button>
</FormSection>
)}
{isVisibleUninstallConfirmation && (
<ClientAppUninstallConfirmation
visible={isVisibleUninstallConfirmation}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,21 @@ exports[`AppContent AppContent - should match snapshoot 1`] = `
See listing preview
</span>
<FaExternalLinkAlt>
<FaExternalLinkAlt
onClick={[Function]}
>
<IconBase
attr={
Object {
"viewBox": "0 0 512 512",
}
}
onClick={[Function]}
>
<svg
fill="currentColor"
height="1em"
onClick={[Function]}
stroke="currentColor"
strokeWidth="0"
style={
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import AppContent, {
handleUninstallSuccess,
renderAuthentication,
renderInstallationsTable,
handleOpenAppPreview,
} from '../app-content/app-content'
import { Provider } from 'react-redux'
import { ReduxState } from '@/types/core'
Expand Down Expand Up @@ -100,4 +101,14 @@ describe('AppContent', () => {
expect(wrapper).toMatchSnapshot()
})
})

describe('handleOpenAppPreview', () => {
it('should run correctly', () => {
const appId = 'appId'
const spyOpenUrl = jest.spyOn(window, 'open')
const fn = handleOpenAppPreview(appId)
fn()
expect(spyOpenUrl).toBeCalledWith('developer/apps/appId/preview', '_blank')
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ export const handleUninstallSuccess = ({
)
}

export const handleOpenAppPreview = (appId: string) => () => {
const url = `developer/apps/${appId}/preview`
window.open(url, '_blank')
}

export const CustomUninstallCell: React.FC<{ onClick: () => void }> = ({ onClick }) => (
<a onClick={onClick}>Uninstall</a>
)
Expand Down Expand Up @@ -146,7 +151,7 @@ const AppContent: React.FC<AppContentProps> = ({ appDetailState }) => {
<div className={appDetailStyles.gutter}>
<H5 className="flex items-center">
<span className="mr-1">See listing preview</span>{' '}
<FaExternalLinkAlt className={developerAppDetailStyles.listPreviewIcon} />
<FaExternalLinkAlt className={developerAppDetailStyles.listPreviewIcon} onClick={handleOpenAppPreview(id)} />
</H5>
<p>The listing preview will display your app as it would appear in the Marketplace</p>
</div>
Expand Down
2 changes: 1 addition & 1 deletion packages/marketplace/src/tests/badges/badge-functions.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion packages/marketplace/src/tests/badges/badge-lines.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 689fc8f

Please sign in to comment.