Skip to content

Commit

Permalink
chore: #1127 enable preview button from submit app page
Browse files Browse the repository at this point in the history
  • Loading branch information
Truong An committed Jun 8, 2020
1 parent fbd560e commit 45691f1
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,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 { clientFetchAppDetail } from '@/actions/client'
import { clientFetchAppDetail, clientFetchAppDetailFailed } from '@/actions/client'
import { developerApplyAppDetails } from '@/actions/developer'
import { useParams } from 'react-router'
import { Dispatch } from 'redux'
Expand Down Expand Up @@ -67,10 +67,23 @@ export const handleApplyAppDetailsFromLocalStorage = (
appId?: string,
) => () => {
if (loginType !== 'DEVELOPER' || !appId) return

if (appId === 'submit-app') {
try {
const appDataString = localStorage.getItem('developer-preview-app')
if (!appDataString) throw 'No preview data'
const appData = JSON.parse(appDataString)
if (appData.id) throw 'No preview data'
dispatch(developerApplyAppDetails(appData))
} catch (err) {
dispatch(clientFetchAppDetailFailed(err))
}
return
}

try {
const appDataString = localStorage.getItem('developer-preview-app')
if (!appDataString) throw 'No preview data'

const appData = JSON.parse(appDataString)
if (appData.id !== appId) throw 'Preview data not match appId'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1979,6 +1979,21 @@ exports[`DeveloperSubmitApp should match a snapshot 1`] = `
<div
className="columns "
>
<Component
onClick={[Function]}
type="button"
variant="primary"
>
<button
className="button is-primary "
data-test=""
disabled={false}
onClick={[Function]}
type="button"
>
Preview
</button>
</Component>
<Component
dataTest="submit-app-button"
disabled={false}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,11 +280,17 @@ export type HandleOpenAppPreview = {
scopes: ScopeModel[]
categories: CategoryModel[]
values: FormikValues
appId?: string
appId: string
appDetails?: AppDetailModel & { apiKey?: string }
}

export const handleOpenAppPreview = ({ appDetails, values, scopes, categories, appId }: HandleOpenAppPreview) => () => {
export const handleOpenAppPreview = ({
appDetails,
values,
scopes,
categories,
appId = 'submit-app',
}: HandleOpenAppPreview) => () => {
const appDetailState = {
...appDetails,
...values,
Expand Down Expand Up @@ -400,21 +406,19 @@ export const DeveloperSubmitApp: React.FC<DeveloperSubmitAppProps> = () => {
{renderErrors((errors as unknown) as Record<string, string | string[]>)}
<LevelRight>
<Grid className={styles.footerButtons}>
{isSubmitRevision && (
<Button
onClick={handleOpenAppPreview({
appDetails: appDetailState?.appDetailData?.data,
values,
scopes,
categories: appCategories,
appId: appid,
})}
variant="primary"
type="button"
>
Preview
</Button>
)}
<Button
onClick={handleOpenAppPreview({
appDetails: appDetailState?.appDetailData?.data,
values,
scopes,
categories: appCategories,
appId: appid,
})}
variant="primary"
type="button"
>
Preview
</Button>
{!isSubmitApp && (
<Button onClick={goBackToApps} variant="primary" type="button">
Back To Apps
Expand Down
2 changes: 1 addition & 1 deletion packages/marketplace/src/tests/badges/badge-branches.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.
2 changes: 1 addition & 1 deletion packages/marketplace/src/tests/badges/badge-statements.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 45691f1

Please sign in to comment.