Skip to content

Commit

Permalink
feat: Update axios client and API usage
Browse files Browse the repository at this point in the history
  • Loading branch information
art7cf committed Mar 4, 2024
1 parent 192a889 commit 9fee983
Show file tree
Hide file tree
Showing 18 changed files with 109 additions and 39 deletions.
2 changes: 1 addition & 1 deletion web/.env
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# API Base URL
VITE_REACT_APP_API_BASE_URL=https://api.nepflow.dev/v1
VITE_REACT_APP_API_BASE_URL=https://widget-api.nepflow.dev/v1
2 changes: 1 addition & 1 deletion web/.env.development
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# API Base URL
VITE_REACT_APP_API_BASE_URL=http://localhost:5690/v1
VITE_REACT_APP_API_BASE_URL=http://localhost:8675/v1
6 changes: 4 additions & 2 deletions web/src/clients/api/queries/getGuide.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ import { appHost } from '../../../globals'
import { type IntegrationGuide } from '../../../models/integrationGuide'

async function getGuide (serviceId: string, secondServiceId: string, triggerId: string, actionId: string, guidedRecipeId?: string): Promise<IntegrationGuide> {
const res = await apiClient.get(`/services/${serviceId}/guide/${secondServiceId}/triggers/${triggerId}/actions/${actionId}`, {
const res = await apiClient.get(`/services/${serviceId}/guides/${secondServiceId}`, {
params: {
appHost,
guidedRecipeId
guidedRecipeId,
triggerId,
actionId
}
})
const result = await res.data
Expand Down
6 changes: 3 additions & 3 deletions web/src/clients/api/queries/getRecommendations.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import apiClient from '..'
import { type Recommendation } from '../../../models/recommendation'

async function getRecommendations (serviceKey: string, secondServiceKey: string): Promise<Recommendation[]> {
async function getRecommendations (serviceId: string, secondServiceId: string): Promise<Recommendation[]> {
const res = await apiClient.get('/services/recommendations', {
params: {
serviceKey,
secondServiceKey
serviceId,
secondServiceId
}
})
const result = await res.data
Expand Down
4 changes: 2 additions & 2 deletions web/src/clients/api/queries/getService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import apiClient from '..'
import { appHost } from '../../../globals'
import { type Service } from '../../../models/service'

async function getService (key: string, secondServiceKey?: string): Promise<Service> {
async function getService (key: string, secondServiceId?: string): Promise<Service> {
const res = await apiClient.get(`/services/${key}`, {
params: {
appHost,
secondServiceKey
secondServiceId
}
})
const result = await res.data
Expand Down
9 changes: 8 additions & 1 deletion web/src/components/BackButton/backButton.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,11 @@
}
.backButton:hover {
background-color: rgba(0, 0, 0, 0.07);
}
}

@media (max-width: 480px) {
.backButton {
float: none;
margin-bottom: 16px;
}
}
2 changes: 1 addition & 1 deletion web/src/components/FullScreenLoading/FullScreenLoading.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function FullScreenLoading () {
<div
className={styles.container}
>
<Icon className={styles.containerLoadingIcon} icon='loading' size={48} />
<Icon className={styles.containerLoadingIcon} icon='loading' size={36} />
</div>
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
position: absolute;
top: 50%;
left: 50%;
width: 48px;
height: 48px;
margin: -24px 0 0 -24px;
width: 36px;
height: 36px;
margin: -18px 0 0 -18px;
opacity: 0.5;
}
40 changes: 23 additions & 17 deletions web/src/components/ServiceCatalog/ServiceCatalog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default function ServiceCatalog () {
const { rootServiceId } = useParams()

const [search, setSearch] = useState('')
const [searchValue] = useDebounce(search, 1000)
const [searchValue] = useDebounce(search, 500)

const config = useContext(ConfigContext)

Expand All @@ -33,22 +33,10 @@ export default function ServiceCatalog () {
appendLoading: false
})

const newCustomCardsCount = useMemo(() => {
const originalCustomCardsCount = useMemo(() => {
return searchValue ? 0 : config.customCards?.filter(c => !c.replacedZapierAppId)?.length
}, [config.customCards, searchValue])

useEffect(() => {
setData({ services: [], loading: true })

loadServices(undefined, 0, 60 - newCustomCardsCount)
}, [])

useEffect(() => {
setData({ services: [], loading: true })

loadServices(searchValue, 0, 60 - newCustomCardsCount)
}, [searchValue, newCustomCardsCount])

const loadServices = useCallback(async (search: string = '', skip: number = 0, take: number = 60) => {
const services = await getServices(rootServiceId || undefined, search, skip, take)

Expand All @@ -60,10 +48,22 @@ export default function ServiceCatalog () {
})
}, [data])

useEffect(() => {
setData({ services: [], loading: true })

loadServices(undefined, 0, 60 - originalCustomCardsCount)
}, [])

useEffect(() => {
setData({ services: [], loading: true })

loadServices(searchValue, 0, 60 - originalCustomCardsCount)
}, [searchValue, originalCustomCardsCount])

const loadNextServices = useCallback(async () => {
setData({ services: data.services, appendLoading: true })

await loadServices(searchValue, data.services.length + newCustomCardsCount)
await loadServices(searchValue, data.services.length + originalCustomCardsCount)
}, [data, searchValue])

const handleSearchChange = useCallback((e: React.FormEvent<HTMLInputElement>) => {
Expand Down Expand Up @@ -106,7 +106,13 @@ export default function ServiceCatalog () {
actions: []
}
};
} else if (!searchValue) {
} else {
const isCardMatch = () => `${customCard.name} ${customCard.id}`.toLowerCase().includes(searchValue.trim().toLowerCase())

if (searchValue && !isCardMatch()) {
return
}

services.unshift({
id: customCard.id,
name: customCard.name,
Expand All @@ -120,7 +126,7 @@ export default function ServiceCatalog () {
};

return services
}, [data.services, config.customCards])
}, [data.services, config.customCards, searchValue])

return (
<div>
Expand Down
10 changes: 5 additions & 5 deletions web/src/components/ServiceCatalog/serviceCatalog.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@
.listItem {
min-width: 0;
border-radius: 12px;
padding: 0 18px 0 56px;
line-height: 54px;
height: 56px;
padding: 0 18px 0 52px;
line-height: 51px;
height: 52px;
font-size: 16px;
font-weight: 500;
cursor: pointer;
Expand Down Expand Up @@ -77,7 +77,7 @@
position: absolute;
left: 16px;
top: 14px;
width: 26px;
width: 22px;
}

.buttonWrapper {
Expand Down Expand Up @@ -117,7 +117,7 @@
}
}

@media (max-width: 360px) {
@media (max-width: 480px) {
.listLink {
flex: 0 0 100%;
max-width: 100%;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,13 @@
margin-right: 8px;
opacity: 0.8;
}


@media (max-width: 480px) {
.card {
width: auto;
margin-left: -25px;
margin-right: -25px;
border-radius: 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,14 @@
line-height: 20px;
padding: 7px 12px;
border-top: solid 1px #ccc;
}

@media (max-width: 480px) {
.childStep {
margin-right: 0;
display: block;
}
.childSteps {
margin: 16px 0 16px -24px;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,11 @@
font-size: 14px;
line-height: 24px;
color: #888;
}

@media (max-width: 480px) {
.banner {
padding-left: 0;
padding-right: 0;
}
}
21 changes: 21 additions & 0 deletions web/src/components/ServicePage/Methods/methods.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,24 @@
text-overflow: ellipsis;
}


@media (max-width: 480px) {
.card {
width: auto;
margin-left: -25px;
margin-right: -25px;
border-radius: 0;
}

.recommendationIcons {
float: none;
display: inline-block;
vertical-align: top;
margin: 0 0 12px;
}

.recommendationTitle {
white-space: normal;
line-height: 24px;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ export default function TriggerToActionSelector ({ action, trigger, rootService,
<div className={styles.headerTrigger}>
<div className={styles.headerFieldLabel}>Trigger</div>
<Select
autoFocus={!trigger?.id}
styles={selectStyles}
placeholder='Select a trigger'
isSearchable
Expand Down
6 changes: 5 additions & 1 deletion web/src/routes/root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export default function Root () {
postMessageToParent({
action: 'setWidgetHeight',
data: {
widgetHeight: height + (config.innerSpace * 2)
widgetHeight: height + (config.innerSpace * 2) + 50
}
})
}
Expand Down Expand Up @@ -59,6 +59,10 @@ export default function Root () {
}
}, [rootServiceId])

useEffect(() => {
postMessageToParent({ action: 'handleLoaded' })
}, [])

return (
<ConfigContext.Provider value={config}>
<RootServiceContext.Provider value={rootService}>
Expand Down
1 change: 1 addition & 0 deletions web/src/utils/postMessageToParent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { entityId } from '../globals'
type Action =
| { action: 'setWidgetHeight', data: { widgetHeight: number } }
| { action: 'handleCardClick', data: { id: string } }
| { action: 'handleLoaded', data?: unknown }

// Send a message from the iframe to the parent window
function postMessageToParent (action: Action) {
Expand Down
5 changes: 4 additions & 1 deletion web/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@ import react from '@vitejs/plugin-react'

// https://vitejs.dev/config/
export default defineConfig({
plugins: [react()]
plugins: [react()],
server: {
port: 3090
}
})

0 comments on commit 9fee983

Please sign in to comment.