Skip to content

Commit

Permalink
chore: #1033 update api
Browse files Browse the repository at this point in the history
  • Loading branch information
andt committed May 25, 2020
1 parent 12d00e1 commit 3cd37c0
Show file tree
Hide file tree
Showing 14 changed files with 41 additions and 54 deletions.
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/aml-checklist/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.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions packages/elements/src/components/RadioSelect/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const RadioSelect: React.FC<RadioSelectProps> = ({
{options.map(({ label, value }: RadioSelectOption, index: number) => (
<div key={index} data-test={dataTest} className="radio-wrap">
<input
id={(name + label) as string}
id={`${name}${label}`}
className={`checkbox ${hasError ? 'checkbox-error' : ''}`}
type="radio"
key={value}
Expand All @@ -56,7 +56,7 @@ export const RadioSelect: React.FC<RadioSelectProps> = ({
disabled={disabled}
onChange={() => setFieldValue(name, value)}
/>
<label htmlFor={(name + label) as string}>{label}</label>
<label htmlFor={`${name}${label}`}>{label}</label>
</div>
))}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ exports[`Config-modal-inner should WebComponentConfigModalInner match a snapshot
closeModal={[MockFunction]}
config={
Object {
"subtext": "Please use the following form to configure your diary settings for your ‘Book a Viewing’ widget on your website",
"subtext": "Please use the following form to configure your diary settings for your
Book a Viewingwidget on your website",
"title": "Book a Viewing Configuration",
}
}
Expand Down Expand Up @@ -177,7 +178,8 @@ exports[`Config-modal-inner should WebComponentConfigModalInner match a snapshot
},
}
}
subtext="Please use the following form to configure your diary settings for your ‘Book a Viewing’ widget on your website"
subtext="Please use the following form to configure your diary settings for your
‘Book a Viewing’ widget on your website"
/>
}
>
Expand Down Expand Up @@ -249,10 +251,12 @@ exports[`Config-modal-inner should WebComponentConfigModalInner match a snapshot
},
}
}
subtext="Please use the following form to configure your diary settings for your ‘Book a Viewing’ widget on your website"
subtext="Please use the following form to configure your diary settings for your
‘Book a Viewing’ widget on your website"
>
<p>
Please use the following form to configure your diary settings for your ‘Book a Viewing’ widget on your website
Please use the following form to configure your diary settings for your
‘Book a Viewing’ widget on your website
</p>
<Component
className="checkbox-inline mt-5"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ exports[`Config-modal should match snapshot 1`] = `
closeModal={[MockFunction]}
config={
Object {
"subtext": "Please use the following form to configure your diary settings for your ‘Book a Viewing’ widget on your website",
"subtext": "Please use the following form to configure your diary settings for your
Book a Viewingwidget on your website",
"title": "Book a Viewing Configuration",
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { mount } from 'enzyme'
import configureStore from 'redux-mock-store'
import { ReduxState } from '@/types/core'
import { Provider } from 'react-redux'
import { BOOK_VIEWING_CONSTANT } from '../config-modal'
import { WEB_COMPONENT_TYPES } from '../config-modal'
import { PutWebComponentConfigParams } from '@/services/web-component'
import { clientPutWebComponentConfig, clientFetchWebComponentConfig } from '@/actions/client'

Expand Down Expand Up @@ -74,7 +74,7 @@ describe('Config-modal-inner', () => {
expect(
mount(
<Provider store={store}>
<WebComponentConfigModalInner config={BOOK_VIEWING_CONSTANT} closeModal={jest.fn()} />
<WebComponentConfigModalInner config={WEB_COMPONENT_TYPES['BOOK_VIEWING']} closeModal={jest.fn()} />
</Provider>,
),
).toMatchSnapshot()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,29 @@ import * as React from 'react'
import { Modal } from '@reapit/elements'
import { WebComponentConfigModalInner } from './config-modal-inner'

export const BOOK_VIEWING_CONSTANT = {
title: 'Book a Viewing Configuration',
subtext:
'Please use the following form to configure your diary settings for your ‘Book a Viewing’ widget on your website',
}

export const BOOK_VALUATION_CONSTANT = {
title: 'Book a Valuation Configuration',
subtext:
'Please use the following form to configure your diary settings for your ‘Book a Valuation’ widget on your website',
}

export type WebComponentModalProps = {
type: 'BOOK_VIEWING' | 'BOOK_VALUATION'
afterClose: () => void
closeModal: () => void
}

export const WebComponentModal = ({ type, afterClose, closeModal }: WebComponentModalProps) => {
const config = type === 'BOOK_VIEWING' ? BOOK_VIEWING_CONSTANT : BOOK_VALUATION_CONSTANT
export const WEB_COMPONENT_TYPES = {
BOOK_VALUATION: {
title: 'Book a Valuation Configuration',
subtext: `Please use the following form to configure your diary settings for your
‘Book a Valuation’ widget on your website`,
},
BOOK_VIEWING: {
title: 'Book a Viewing Configuration',
subtext: `Please use the following form to configure your diary settings for your
‘Book a Viewing’ widget on your website`,
},
}

export const WebComponentModal = ({ type, afterClose, closeModal }: WebComponentModalProps) => {
return (
<Modal visible renderChildren afterClose={afterClose}>
<WebComponentConfigModalInner config={config} closeModal={closeModal} />
<WebComponentConfigModalInner config={WEB_COMPONENT_TYPES[type]} closeModal={closeModal} />
</Modal>
)
}
Expand Down
1 change: 1 addition & 0 deletions packages/marketplace/src/core/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ window.reapit = {
chatbotAppId: '',
marketplaceUrl: '',
platformApiUrl: '',
webComponentConfigApiUrl: '',
},
}

Expand Down
1 change: 1 addition & 0 deletions packages/marketplace/src/services/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ export const URLS = {
trafficEventBilling: '/trafficevents/billing',
trafficEventStatistics: '/trafficevents/trafficStatistics',
negotiators: '/negotiators',
webComponentConfig: '/v1/web-components-config',
}
30 changes: 5 additions & 25 deletions packages/marketplace/src/services/web-component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { fetcher } from '@reapit/elements'
import { generateHeader } from './utils'
import { logger } from 'logger'
import { URLS } from './constants'

export interface FetchWebComponentConfigParams {
customerId: string
Expand All @@ -24,17 +25,14 @@ export type WebComponentConfigResult = {
negotiatorIds: string[]
} | null

const API = '/dev/v1/web-components-config'

export const fetchWebComponentConfig = async (
params: FetchWebComponentConfigParams,
): Promise<WebComponentConfigResult> => {
return sampleRespone() //SHOULD REMOVE WHEN API READY
try {
const { customerId } = params
const response = await fetcher({
url: `${API}/${customerId}`,
api: 'http://localhost:3000',
url: `${URLS.webComponentConfig}/${customerId}`,
api: window.reapit.config.webComponentConfigApiUrl,
method: 'GET',
headers: generateHeader(window.reapit.config.marketplaceApiKey),
})
Expand All @@ -46,12 +44,11 @@ export const fetchWebComponentConfig = async (
}

export const putWebComponentConfig = async (params: PutWebComponentConfigParams): Promise<WebComponentConfigResult> => {
return sampleRespone() //SHOULD REMOVE WHEN API READY
try {
const { customerId = 'DXX', ...rest } = params
const response = await fetcher({
url: `${API}/${customerId}`,
api: 'http://localhost:3000',
url: `${URLS.webComponentConfig}/${customerId}`,
api: window.reapit.config.webComponentConfigApiUrl,
method: 'PATCH',
headers: generateHeader(window.reapit.config.marketplaceApiKey),
body: rest,
Expand All @@ -62,20 +59,3 @@ export const putWebComponentConfig = async (params: PutWebComponentConfigParams)
throw new Error(error)
}
}

//SHOULD REMOVE WHEN API READY
function sampleRespone(): Promise<WebComponentConfigResult> {
return new Promise(res => {
setTimeout(() => {
const data = {
appointmentLength: 15,
appointmentTimeGap: 60,
appointmentTypes: [{ value: 'value1', id: 'id1' }],
customerId: 'DXX',
daysOfWeek: ['1', '2', '3', '5', '6'],
negotiatorIds: ['AACC', 'AAAN'],
} as WebComponentConfigResult
res(data)
}, 1000)
})
}
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.
1 change: 1 addition & 0 deletions packages/marketplace/src/types/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export type Config = {
chatbotAppId: string
marketplaceUrl: string
platformApiUrl: string
webComponentConfigApiUrl: string
}

declare global {
Expand Down

0 comments on commit 3cd37c0

Please sign in to comment.