From 292ad806664a20958eb2a3120cb59a8b8017b055 Mon Sep 17 00:00:00 2001 From: Thanh Pham Date: Tue, 14 Jan 2020 14:59:57 +0700 Subject: [PATCH] [CLD-689] fix modal initial state (#265) * [CLD-689] fix modal initial state * [CLD-689] update chaining fallback --- src/components/pages/__tests__/client.tsx | 15 ++++++++++++--- src/components/pages/client.tsx | 21 +++++++++++++++++---- 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/src/components/pages/__tests__/client.tsx b/src/components/pages/__tests__/client.tsx index c129aa02db..aa9649c13f 100644 --- a/src/components/pages/__tests__/client.tsx +++ b/src/components/pages/__tests__/client.tsx @@ -12,7 +12,8 @@ import { mapDispatchToProps, handleAfterClose, handleOnChange, - handleOnCardClick + handleOnCardClick, + onCardClickParams } from '../client' import { addQuery } from '@/utils/client-url-params' import { AppSummaryModel } from '@reapit/foundations-ts-definitions' @@ -216,10 +217,18 @@ describe('Client', () => { describe('handleOnCardClick', () => { it('should run correctly', () => { - const mockProps = { + const mockProps: onCardClickParams = { setVisible: jest.fn(), appDetail: { - appDetailData: appsDataStub.data, + authentication: { + loading: false, + code: '200' + }, + error: false, + loading: false, + appDetailData: { + data: appsDataStub.data.data![0] + }, isStale: true }, setStateViewBrowse: jest.fn(), diff --git a/src/components/pages/client.tsx b/src/components/pages/client.tsx index 045ccd9212..0a9d1eeba2 100644 --- a/src/components/pages/client.tsx +++ b/src/components/pages/client.tsx @@ -38,14 +38,27 @@ export const handleAfterClose = ({ setVisible }) => () => setVisible(false) export const handleOnChange = history => (page: number) => { history.push(addQuery({ page })) } -export const handleOnCardClick = ({ setVisible, setStateViewBrowse, appDetail, fetchAppDetail, clientId }) => ( - app: AppSummaryModel -) => { + +export interface onCardClickParams { + setVisible: (isVisible: boolean) => void + setStateViewBrowse: () => void + appDetail: AppDetailState + fetchAppDetail: (id: string, client: string) => void + clientId: string +} + +export const handleOnCardClick = ({ + setVisible, + setStateViewBrowse, + appDetail, + fetchAppDetail, + clientId +}: onCardClickParams) => (app: AppSummaryModel) => { setVisible(true) setStateViewBrowse() const isCacheEmpty = !appDetail.appDetailData const isCacheStale = appDetail.isStale - const currentAppIdNotMatchWithCachedAppId = appDetail.appDetailData.data.id !== app.id + const currentAppIdNotMatchWithCachedAppId = appDetail.appDetailData?.data?.id !== app.id if (app.id && (isCacheEmpty || isCacheStale || currentAppIdNotMatchWithCachedAppId)) { fetchAppDetail(app.id, clientId)