Skip to content

Commit

Permalink
fix: provider sidebar from 'get-started' screen (#5535)
Browse files Browse the repository at this point in the history
Co-authored-by: Adam Chmara <[email protected]>
  • Loading branch information
ChmaraX and Adam Chmara committed May 9, 2024
1 parent 3f635fc commit e43be82
Showing 1 changed file with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { sortProviders } from './sort-providers';
import { When } from '../../../../components/utils/When';
import { CONTEXT_PATH } from '../../../../config';
import { useProviders } from '../../useProviders';
import { useNavigate } from 'react-router-dom';
import { useLocation, useNavigate } from 'react-router-dom';
import { ROUTES } from '../../../../constants/routes.enum';

const filterSearch = (list, search: string) =>
Expand All @@ -46,6 +46,7 @@ export function SelectProviderSidebar({
const [selectedTab, setSelectedTab] = useState(ChannelTypeEnum.IN_APP);
const { isLoading: isIntegrationsLoading, providers: integrations } = useProviders();
const navigate = useNavigate();
const { pathname } = useLocation();

const inAppCount: number = useMemo(() => {
const count = integrations.filter(
Expand Down Expand Up @@ -79,10 +80,15 @@ export function SelectProviderSidebar({

const onTabChange = useCallback(
(channel: ChannelTypeEnum) => {
navigate(`${ROUTES.INTEGRATIONS_CREATE}?scrollTo=${channel}`);
setSelectedTab(scrollTo as ChannelTypeEnum);
setSelectedTab(channel as ChannelTypeEnum);

if (pathname.includes(ROUTES.INTEGRATIONS_CREATE)) {
navigate(`${ROUTES.INTEGRATIONS_CREATE}?scrollTo=${channel}`);

return;
}
},
[navigate, scrollTo]
[navigate, pathname]
);

const onSidebarClose = () => {
Expand All @@ -101,12 +107,20 @@ export function SelectProviderSidebar({
}
};

// TODO: sometime the scrollTo url param needs to change and sometimes not (e.g. from /get-started)
useEffect(() => {
if (selectedTab && !isIntegrationsLoading) {
onTabChange(selectedTab);
scrollToElement(selectedTab);
}
}, [selectedTab, isIntegrationsLoading, onTabChange]);

useEffect(() => {
if (scrollTo && !isIntegrationsLoading) {
onTabChange(scrollTo);
scrollToElement(scrollTo);
}
}, [selectedTab, isIntegrationsLoading, scrollTo, onTabChange]);
}, [scrollTo, isIntegrationsLoading, onTabChange]);

return (
<Sidebar
Expand Down

0 comments on commit e43be82

Please sign in to comment.